Example usage for com.intellij.openapi.actionSystem PlatformDataKeys FILE_EDITOR

List of usage examples for com.intellij.openapi.actionSystem PlatformDataKeys FILE_EDITOR

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem PlatformDataKeys FILE_EDITOR.

Prototype

DataKey FILE_EDITOR

To view the source code for com.intellij.openapi.actionSystem PlatformDataKeys FILE_EDITOR.

Click Source Link

Usage

From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java

License:Apache License

@Nullable
@Override//from   w w w  . j ava  2 s  .co m
public Object getData(@NonNls String dataId) {
    // This is required since the Image Editor's actions are dependent on the context
    // being a ImageFileEditor.
    return PlatformDataKeys.FILE_EDITOR.getName().equals(dataId) ? myImageFileEditor : null;
}

From source file:com.android.tools.idea.uibuilder.surface.DesignSurface.java

License:Apache License

@Override
public Object getData(@NonNls String dataId) {
    if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
        return myFileEditorDelegate.get();
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId)
            || PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return new DesignSurfaceActionHandler(this);
    }//  www  .  j a  v a  2 s  .  c  om
    return null;
}

From source file:com.intellij.find.actions.FindUsagesInFileAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return;/* ww  w. j a va 2s . c o  m*/
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);

    UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataContext);
    if (usageTargets != null) {
        FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
        if (fileEditor != null) {
            usageTargets[0].findUsagesInEditor(fileEditor);
        }
    } else if (editor == null) {
        Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    } else {
        HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
    }
}

From source file:com.intellij.ide.actions.SearchAgainAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
    if (editor == null || project == null)
        return;//from   w  w w.  java 2 s  .c o  m
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, new Runnable() {
        @Override
        public void run() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
            if (FindManager.getInstance(project).findNextUsageInEditor(editor)) {
                return;
            }

            FindUtil.searchAgain(project, editor, e.getDataContext());
        }
    }, IdeBundle.message("command.find.next"), null);
}

From source file:com.intellij.ide.actions.SearchAgainAction.java

License:Apache License

@Override
public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);//from   ww  w. jav  a 2  s  .c  o  m
        return;
    }
    FileEditor editor = event.getData(PlatformDataKeys.FILE_EDITOR);
    presentation.setEnabled(editor instanceof TextEditor);
}

From source file:com.intellij.ide.actions.SearchBackAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final FileEditor editor = e.getData(PlatformDataKeys.FILE_EDITOR);
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, new Runnable() {
        @Override/*from  w w w .  j  a v  a2 s . c o  m*/
        public void run() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (FindManager.getInstance(project).findPreviousUsageInEditor(editor)) {
                return;
            }
            FindUtil.searchBack(project, editor, e.getDataContext());
        }
    }, IdeBundle.message("command.find.previous"), null);
}

From source file:com.intellij.ide.actions.SearchBackAction.java

License:Apache License

@Override
public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);//from w ww  . j a v a2 s. com
        return;
    }
    final FileEditor editor = event.getData(PlatformDataKeys.FILE_EDITOR);
    presentation.setEnabled(editor instanceof TextEditor);
}

From source file:com.intellij.ide.actions.SearchEverywhereAction.java

License:Apache License

public void actionPerformed(AnActionEvent e, MouseEvent me) {
    if (myBalloon != null && myBalloon.isVisible()) {
        showAll.set(!showAll.get());//from   w ww . j a va  2 s.  c  o m
        myNonProjectCheckBox.setSelected(showAll.get());
        //      myPopupField.getTextEditor().setBackground(showAll.get() ? new JBColor(new Color(0xffffe4), new Color(0x494539)) : UIUtil.getTextFieldBackground());
        rebuildList(myPopupField.getText());
        return;
    }
    myCurrentWorker = ActionCallback.DONE;
    if (e != null) {
        myEditor = e.getData(CommonDataKeys.EDITOR);
        myFileEditor = e.getData(PlatformDataKeys.FILE_EDITOR);
        myFile = e.getData(CommonDataKeys.PSI_FILE);
    }
    if (e == null && myFocusOwner != null) {
        e = new AnActionEvent(me, DataManager.getInstance().getDataContext(myFocusOwner), ActionPlaces.UNKNOWN,
                getTemplatePresentation(), ActionManager.getInstance(), 0);
    }
    if (e == null)
        return;
    final Project project = e.getProject();
    if (project == null)
        return;

    updateComponents();
    myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext());
    Window wnd = myContextComponent != null ? SwingUtilities.windowForComponent(myContextComponent)
            : KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (wnd == null && myContextComponent instanceof Window) {
        wnd = (Window) myContextComponent;
    }
    if (wnd == null || wnd.getParent() != null)
        return;
    myActionEvent = e;
    if (myPopupField != null) {
        Disposer.dispose(myPopupField);
    }
    myPopupField = new MySearchTextField();
    myPopupField.getTextEditor().addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            myHistoryIndex = 0;
            myHistoryItem = null;
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                myList.repaint();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                myList.repaint();
            }
        }
    });
    initSearchField(myPopupField);
    myPopupField.setOpaque(false);
    final JTextField editor = myPopupField.getTextEditor();
    editor.setColumns(SEARCH_FIELD_COLUMNS);
    final JPanel panel = new JPanel(new BorderLayout()) {
        @Override
        protected void paintComponent(Graphics g) {
            final Gradient gradient = getGradientColors();
            ((Graphics2D) g).setPaint(
                    new GradientPaint(0, 0, gradient.getStartColor(), 0, getHeight(), gradient.getEndColor()));
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    final JLabel title = new JLabel(" Search Everywhere:       ");
    final JPanel topPanel = new NonOpaquePanel(new BorderLayout());
    title.setForeground(new JBColor(Gray._240, Gray._200));
    if (SystemInfo.isMac) {
        title.setFont(title.getFont().deriveFont(Font.BOLD, title.getFont().getSize() - 1f));
    } else {
        title.setFont(title.getFont().deriveFont(Font.BOLD));
    }
    topPanel.add(title, BorderLayout.WEST);
    final JPanel controls = new JPanel(new BorderLayout());
    controls.setOpaque(false);
    final JLabel settings = new JLabel(AllIcons.General.SearchEverywhereGear);
    new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            showSettings();
            return true;
        }
    }.installOn(settings);
    controls.add(settings, BorderLayout.EAST);
    myNonProjectCheckBox.setForeground(new JBColor(Gray._240, Gray._200));
    myNonProjectCheckBox.setText("Include non-project items (" + getShortcut() + ")  ");
    controls.add(myNonProjectCheckBox, BorderLayout.WEST);
    topPanel.add(controls, BorderLayout.EAST);
    panel.add(myPopupField, BorderLayout.CENTER);
    panel.add(topPanel, BorderLayout.NORTH);
    panel.setBorder(IdeBorderFactory.createEmptyBorder(3, 5, 4, 5));
    DataManager.registerDataProvider(panel, this);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel,
            editor);
    myBalloon = builder.setCancelOnClickOutside(true).setModalContext(false).setRequestFocus(true)
            .setCancelCallback(new Computable<Boolean>() {
                @Override
                public Boolean compute() {
                    return !mySkipFocusGain;
                }
            }).createPopup();
    myBalloon.getContent().setBorder(new EmptyBorder(0, 0, 0, 0));
    final Window window = WindowManager.getInstance().suggestParentWindow(project);

    project.getMessageBus().connect(myBalloon).subscribe(DumbService.DUMB_MODE,
            new DumbService.DumbModeListener() {
                @Override
                public void enteredDumbMode() {
                }

                @Override
                public void exitDumbMode() {
                    rebuildList(myPopupField.getText());
                }
            });

    Component parent = UIUtil.findUltimateParent(window);
    registerDataProvider(panel, project);
    final RelativePoint showPoint;
    if (me != null) {
        final Component label = me.getComponent();
        final Component button = label.getParent();
        assert button != null;
        showPoint = new RelativePoint(button,
                new Point(button.getWidth() - panel.getPreferredSize().width, button.getHeight()));
    } else {
        if (parent != null) {
            int height = UISettings.getInstance().SHOW_MAIN_TOOLBAR ? 135 : 115;
            if (parent instanceof IdeFrameImpl && ((IdeFrameImpl) parent).isInFullScreen()) {
                height -= 20;
            }
            showPoint = new RelativePoint(parent,
                    new Point((parent.getSize().width - panel.getPreferredSize().width) / 2, height));
        } else {
            showPoint = JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());
        }
    }
    myList.setFont(UIUtil.getListFont());
    myBalloon.show(showPoint);
    initSearchActions(myBalloon, myPopupField);
    IdeFocusManager focusManager = IdeFocusManager.getInstance(project);
    focusManager.requestFocus(editor, true);
    FeatureUsageTracker.getInstance().triggerFeatureUsed(IdeActions.ACTION_SEARCH_EVERYWHERE);
}

From source file:com.intellij.ide.actions.SelectInContextImpl.java

License:Apache License

@Nullable
private static SelectInContext createEditorContext(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
    return createEditorContext(project, editor);
}

From source file:com.intellij.ide.actions.UndoRedoAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
    UndoManager undoManager = getUndoManager(editor, dataContext);
    perform(editor, undoManager);/*from w ww . j a va  2s .c om*/
}