Search in sources :

Example 1 with PsiCopyPasteManager

use of com.intellij.ide.PsiCopyPasteManager in project intellij-community by JetBrains.

the class StructureViewComponent method addTreeKeyListener.

private void addTreeKeyListener() {
    getTree().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                DataContext dataContext = DataManager.getInstance().getDataContext(getTree());
                OpenSourceUtil.openSourcesFrom(dataContext, false);
            } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed()) {
                    return;
                }
                PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager)

Example 2 with PsiCopyPasteManager

use of com.intellij.ide.PsiCopyPasteManager in project intellij-community by JetBrains.

the class AbstractProjectViewPSIPane method initTree.

private void initTree() {
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
    myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
    EditSourceOnDoubleClickHandler.install(myTree);
    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fireTreeChangeListener();
        }
    });
    myTree.getModel().addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }
    });
    new MySpeedSearch(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
                if (selectedNode != null && !selectedNode.isLeaf()) {
                    return;
                }
                DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
                OpenSourceUtil.openSourcesFrom(dataContext, ScreenReader.isActive());
            } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed())
                    return;
                PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
    CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeModelListener(javax.swing.event.TreeModelListener) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 3 with PsiCopyPasteManager

use of com.intellij.ide.PsiCopyPasteManager in project netbeans-mmd-plugin by raydac.

the class KnowledgeViewPane method initTree.

private void initTree() {
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
    myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
    EditSourceOnDoubleClickHandler.install(myTree);
    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fireTreeChangeListener();
        }
    });
    myTree.getModel().addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }
    });
    new SpeedSearch(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
                if (selectedNode != null && !selectedNode.isLeaf()) {
                    return;
                }
                DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
                OpenSourceUtil.openSourcesFrom(dataContext, false);
            } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed())
                    return;
                PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
    CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 4 with PsiCopyPasteManager

use of com.intellij.ide.PsiCopyPasteManager in project intellij-community by JetBrains.

the class Commander method createPanel.

private CommanderPanel createPanel() {
    final CommanderPanel panel = new CommanderPanel(myProject, true, false);
    panel.getList().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed())
                    return;
                final PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                final boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
    final ProjectAbstractTreeStructureBase treeStructure = createProjectTreeStructure();
    panel.setBuilder(new ProjectListBuilder(myProject, panel, treeStructure, AlphaComparator.INSTANCE, true));
    panel.setProjectTreeStructure(treeStructure);
    final FocusAdapter focusListener = new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            updateToolWindowTitle(panel);
        }
    };
    final JList list = panel.getList();
    list.addFocusListener(focusListener);
    list.getSelectionModel().addListSelectionListener(mySelectionListener);
    list.getModel().addListDataListener(myListDataListener);
    Disposer.register(this, new Disposable() {

        @Override
        public void dispose() {
            list.removeFocusListener(focusListener);
            list.getSelectionModel().removeListSelectionListener(mySelectionListener);
            list.getModel().removeListDataListener(myListDataListener);
        }
    });
    return panel;
}
Also used : Disposable(com.intellij.openapi.Disposable) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager)

Aggregations

PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)4 KeyAdapter (java.awt.event.KeyAdapter)3 KeyEvent (java.awt.event.KeyEvent)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 TreeModelEvent (javax.swing.event.TreeModelEvent)2 TreeModelListener (javax.swing.event.TreeModelListener)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)1 Disposable (com.intellij.openapi.Disposable)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1