Search in sources :

Example 1 with TodoItemNode

use of com.intellij.ide.todo.nodes.TodoItemNode in project intellij-community by JetBrains.

the class SmartTodoItemPointerComparator method compare.

@Override
public int compare(Object obj1, Object obj2) {
    TextRange range1 = ((TodoItemNode) obj1).getValue().getTodoItem().getTextRange();
    TextRange range2 = ((TodoItemNode) obj2).getValue().getTodoItem().getTextRange();
    return range1.getStartOffset() - range2.getStartOffset();
}
Also used : TextRange(com.intellij.openapi.util.TextRange) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode)

Example 2 with TodoItemNode

use of com.intellij.ide.todo.nodes.TodoItemNode in project intellij-community by JetBrains.

the class ToDoTreeStructureTest method checkOccurrences.

private static void checkOccurrences(final AllTodosTreeBuilder all, final String[] strings) {
    AbstractTreeStructure allTreeStructure = all.getTreeStructure();
    TodoItemNode current = all.getFirstPointerForElement(allTreeStructure.getRootElement());
    for (String string : strings) {
        assertNotNull(current);
        assertEquals(string, current.getTestPresentation());
        current = all.getNextPointer(current);
    }
    assertNull(current);
    current = all.getLastPointerForElement(allTreeStructure.getRootElement());
    for (int i = strings.length - 1; i >= 0; i--) {
        String string = strings[i];
        assertNotNull(current);
        assertEquals(string, current.getTestPresentation());
        current = all.getPreviousPointer(current);
    }
    assertNull(current);
}
Also used : AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode)

Example 3 with TodoItemNode

use of com.intellij.ide.todo.nodes.TodoItemNode in project intellij-community by JetBrains.

the class TodoPanel method initUI.

private void initUI() {
    UIUtil.setLineStyleAngled(myTree);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setCellRenderer(new TodoCompositeRenderer());
    EditSourceOnDoubleClickHandler.install(myTree);
    new TreeSpeedSearch(myTree);
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
    group.addSeparator();
    group.add(ActionManager.getInstance().getAction(IdeActions.GROUP_VERSION_CONTROLS));
    PopupHandler.installPopupHandler(myTree, group, ActionPlaces.TODO_VIEW_POPUP, ActionManager.getInstance());
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (!e.isConsumed() && KeyEvent.VK_ENTER == e.getKeyCode()) {
                TreePath path = myTree.getSelectionPath();
                if (path == null) {
                    return;
                }
                final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
                if (!((userObject instanceof NodeDescriptor ? (NodeDescriptor) userObject : null) instanceof TodoItemNode)) {
                    return;
                }
                OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(TodoPanel.this), false);
            }
        }
    });
    myUsagePreviewPanel = new UsagePreviewPanel(myProject, FindInProjectUtil.setupViewPresentation(false, new FindModel()));
    Disposer.register(this, myUsagePreviewPanel);
    myUsagePreviewPanel.setVisible(mySettings.showPreview);
    setContent(createCenterComponent());
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (myUsagePreviewPanel.isVisible()) {
                    updatePreviewPanel();
                }
            }, ModalityState.NON_MODAL, myProject.getDisposed());
        }
    });
    // Create tool bars and register custom shortcuts
    JPanel toolBarPanel = new JPanel(new GridLayout());
    DefaultActionGroup leftGroup = new DefaultActionGroup();
    leftGroup.add(new PreviousOccurenceToolbarAction(myOccurenceNavigator));
    leftGroup.add(new NextOccurenceToolbarAction(myOccurenceNavigator));
    leftGroup.add(new ContextHelpAction("find.todoList"));
    toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, leftGroup, false).getComponent());
    DefaultActionGroup rightGroup = new DefaultActionGroup();
    AnAction expandAllAction = CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this);
    rightGroup.add(expandAllAction);
    AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this);
    rightGroup.add(collapseAllAction);
    if (!myCurrentFileMode) {
        MyShowModulesAction showModulesAction = new MyShowModulesAction();
        showModulesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(showModulesAction);
        MyShowPackagesAction showPackagesAction = new MyShowPackagesAction();
        showPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(showPackagesAction);
        MyFlattenPackagesAction flattenPackagesAction = new MyFlattenPackagesAction();
        flattenPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
        rightGroup.add(flattenPackagesAction);
    }
    MyAutoScrollToSourceHandler autoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
    autoScrollToSourceHandler.install(myTree);
    rightGroup.add(autoScrollToSourceHandler.createToggleAction());
    SetTodoFilterAction setTodoFilterAction = new SetTodoFilterAction(myProject, mySettings, todoFilter -> setTodoFilter(todoFilter));
    rightGroup.add(setTodoFilterAction);
    rightGroup.add(new MyPreviewAction());
    toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, rightGroup, false).getComponent());
    setToolbar(toolBarPanel);
}
Also used : FindModel(com.intellij.find.FindModel) KeyAdapter(java.awt.event.KeyAdapter) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ContextHelpAction(com.intellij.ide.actions.ContextHelpAction) PreviousOccurenceToolbarAction(com.intellij.ide.actions.PreviousOccurenceToolbarAction) KeyEvent(java.awt.event.KeyEvent) NextOccurenceToolbarAction(com.intellij.ide.actions.NextOccurenceToolbarAction) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 4 with TodoItemNode

use of com.intellij.ide.todo.nodes.TodoItemNode in project intellij-community by JetBrains.

the class TodoPanel method updatePreviewPanel.

private void updatePreviewPanel() {
    if (myProject == null || myProject.isDisposed())
        return;
    List<UsageInfo> infos = new ArrayList<>();
    final TreePath path = myTree.getSelectionPath();
    if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object userObject = node.getUserObject();
        if (userObject instanceof NodeDescriptor) {
            Object element = ((NodeDescriptor) userObject).getElement();
            TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
            if (pointer != null) {
                final SmartTodoItemPointer value = pointer.getValue();
                final Document document = value.getDocument();
                final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
                final RangeMarker rangeMarker = value.getRangeMarker();
                if (psiFile != null) {
                    infos.add(new UsageInfo(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset()));
                }
            }
        }
    }
    myUsagePreviewPanel.updateLayout(infos.isEmpty() ? null : infos);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) PsiFile(com.intellij.psi.PsiFile) RangeMarker(com.intellij.openapi.editor.RangeMarker) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode) Document(com.intellij.openapi.editor.Document) UsageInfo(com.intellij.usageView.UsageInfo)

Example 5 with TodoItemNode

use of com.intellij.ide.todo.nodes.TodoItemNode in project intellij-community by JetBrains.

the class TodoPanel method getData.

@Override
public Object getData(String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        TreePath path = myTree.getSelectionPath();
        if (path == null) {
            return null;
        }
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object userObject = node.getUserObject();
        if (!(userObject instanceof NodeDescriptor)) {
            return null;
        }
        Object element = ((NodeDescriptor) userObject).getElement();
        if (!(element instanceof TodoFileNode || element instanceof TodoItemNode)) {
            // allow user to use F4 only on files an TODOs
            return null;
        }
        TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
        if (pointer != null) {
            return new OpenFileDescriptor(myProject, pointer.getValue().getTodoItem().getFile().getVirtualFile(), pointer.getValue().getRangeMarker().getStartOffset());
        } else {
            return null;
        }
    } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
        final PsiFile file = getSelectedFile();
        return file != null ? file.getVirtualFile() : null;
    } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        return getSelectedElement();
    } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        PsiFile file = getSelectedFile();
        if (file != null) {
            return new VirtualFile[] { file.getVirtualFile() };
        } else {
            return VirtualFile.EMPTY_ARRAY;
        }
    } else if (PlatformDataKeys.HELP_ID.is(dataId)) {
        //noinspection HardCodedStringLiteral
        return "find.todoList";
    }
    return super.getData(dataId);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TodoFileNode(com.intellij.ide.todo.nodes.TodoFileNode) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiFile(com.intellij.psi.PsiFile) TodoItemNode(com.intellij.ide.todo.nodes.TodoItemNode)

Aggregations

TodoItemNode (com.intellij.ide.todo.nodes.TodoItemNode)5 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)3 TreePath (javax.swing.tree.TreePath)3 PsiFile (com.intellij.psi.PsiFile)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 FindModel (com.intellij.find.FindModel)1 ContextHelpAction (com.intellij.ide.actions.ContextHelpAction)1 NextOccurenceToolbarAction (com.intellij.ide.actions.NextOccurenceToolbarAction)1 PreviousOccurenceToolbarAction (com.intellij.ide.actions.PreviousOccurenceToolbarAction)1 TodoFileNode (com.intellij.ide.todo.nodes.TodoFileNode)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 Document (com.intellij.openapi.editor.Document)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextRange (com.intellij.openapi.util.TextRange)1 UsageInfo (com.intellij.usageView.UsageInfo)1 UsagePreviewPanel (com.intellij.usages.impl.UsagePreviewPanel)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 ArrayList (java.util.ArrayList)1