Search in sources :

Example 6 with IdeFrameImpl

use of com.intellij.openapi.wm.impl.IdeFrameImpl in project intellij-community by JetBrains.

the class GuiTestUtil method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        final MyProjectManagerListener listener = new MyProjectManagerListener();
        //[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
        acceptAgreementIfNeeded(robot);
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        if (listener.myActive) {
            Pause.pause(new Condition("Project to be opened") {

                @Override
                public boolean test() {
                    boolean notified = listener.myNotified;
                    if (notified) {
                        ProgressManager progressManager = ProgressManager.getInstance();
                        boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                        if (isIdle) {
                            ProjectManager.getInstance().removeProjectManagerListener(listener);
                        }
                        return isIdle;
                    }
                    return false;
                }
            }, LONG_TIMEOUT);
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 7 with IdeFrameImpl

use of com.intellij.openapi.wm.impl.IdeFrameImpl in project intellij-community by JetBrains.

the class CustomActionsSchema method initActionIcons.

private void initActionIcons() {
    ActionManager actionManager = ActionManager.getInstance();
    for (String actionId : myIconCustomizations.keySet()) {
        final AnAction anAction = actionManager.getAction(actionId);
        if (anAction != null) {
            Icon icon;
            final String iconPath = myIconCustomizations.get(actionId);
            if (iconPath != null && new File(FileUtil.toSystemDependentName(iconPath)).exists()) {
                Image image = null;
                try {
                    image = ImageLoader.loadFromStream(VfsUtilCore.convertToURL(VfsUtil.pathToUrl(iconPath)).openStream());
                } catch (IOException e) {
                    LOG.debug(e);
                }
                icon = image == null ? null : new JBImageIcon(image);
            } else {
                icon = AllIcons.Toolbar.Unknown;
            }
            anAction.getTemplatePresentation().setIcon(icon);
            anAction.getTemplatePresentation().setDisabledIcon(IconLoader.getDisabledIcon(icon));
            anAction.setDefaultIcon(false);
        }
    }
    final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
    if (frame != null) {
        frame.updateView();
    }
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) JBImageIcon(com.intellij.util.ui.JBImageIcon) IOException(java.io.IOException) JBImageIcon(com.intellij.util.ui.JBImageIcon) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File)

Example 8 with IdeFrameImpl

use of com.intellij.openapi.wm.impl.IdeFrameImpl in project android by JetBrains.

the class GuiTests method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        MyProjectManagerListener listener = new MyProjectManagerListener();
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(robot);
        // we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue.
        try {
            if (SYSTEM_EVENT_QUEUE.peekEvent() != null) {
                SYSTEM_EVENT_QUEUE.getNextEvent();
            }
        } catch (InterruptedException ex) {
        // Ignored.
        }
        if (listener.myActive) {
            Wait.seconds(1).expecting("project to be opened").until(() -> {
                boolean notified = listener.myNotified;
                if (notified) {
                    ProgressManager progressManager = ProgressManager.getInstance();
                    boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                    if (isIdle) {
                        ProjectManager.getInstance().removeProjectManagerListener(listener);
                    }
                    return isIdle;
                }
                return false;
            });
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 9 with IdeFrameImpl

use of com.intellij.openapi.wm.impl.IdeFrameImpl in project intellij-plugins by JetBrains.

the class IDEAFacade method getProject.

@Nullable
public static Project getProject(Component component) {
    Project res = null;
    if (component != null) {
        res = (Project) getData(component, CommonDataKeys.PROJECT.getName());
    } else {
        IdeFrame[] frames = WindowManagerEx.getInstanceEx().getAllProjectFrames();
        for (IdeFrame frame : frames) {
            final IdeFrameImpl eachFrame = (IdeFrameImpl) frame;
            if (eachFrame.isActive()) {
                res = eachFrame.getProject();
                if (res != null)
                    break;
            }
        }
    }
    if (res == null) {
        Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
        res = openProjects.length > 0 ? openProjects[0] : null;
    }
    return res;
}
Also used : Project(com.intellij.openapi.project.Project) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with IdeFrameImpl

use of com.intellij.openapi.wm.impl.IdeFrameImpl in project intellij-community by JetBrains.

the class SearchEverywhereAction method actionPerformed.

public void actionPerformed(AnActionEvent e, MouseEvent me) {
    if (myBalloon != null && myBalloon.isVisible()) {
        showAll.set(!showAll.get());
        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 = AnActionEvent.createFromAnAction(this, me, ActionPlaces.UNKNOWN, DataManager.getInstance().getDataContext(myFocusOwner));
    }
    if (e == null)
        return;
    final Project project = e.getProject();
    if (project == null)
        return;
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(() -> LookupManager.getInstance(project).hideActiveLookup());
    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() + ")  ");
    if (!NonProjectScopeDisablerEP.isSearchInNonProjectDisabled()) {
        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(() -> !mySkipFocusGain).createPopup();
    myBalloon.getContent().setBorder(JBUI.Borders.empty());
    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() {
            ApplicationManager.getApplication().invokeLater(() -> rebuildList(myPopupField.getText()));
        }
    });
    Component parent = UIUtil.findUltimateParent(window);
    registerDataProvider(panel, project);
    final RelativePoint showPoint;
    if (parent != null) {
        int height = UISettings.getInstance().getShowMainToolbar() ? 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);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) RelativePoint(com.intellij.ui.awt.RelativePoint) DumbService(com.intellij.openapi.project.DumbService) RelativePoint(com.intellij.ui.awt.RelativePoint) Project(com.intellij.openapi.project.Project) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder)

Aggregations

IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)14 Project (com.intellij.openapi.project.Project)5 RelativePoint (com.intellij.ui.awt.RelativePoint)4 IdeFrame (com.intellij.openapi.wm.IdeFrame)3 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 ComponentPopupBuilder (com.intellij.openapi.ui.popup.ComponentPopupBuilder)2 JBPopup (com.intellij.openapi.ui.popup.JBPopup)2 FloatingDecorator (com.intellij.openapi.wm.impl.FloatingDecorator)2 File (java.io.File)2 Robot (org.fest.swing.core.Robot)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 Condition (org.fest.swing.timing.Condition)2 NotNull (org.jetbrains.annotations.NotNull)2 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 Editor (com.intellij.openapi.editor.Editor)1 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)1 DumbService (com.intellij.openapi.project.DumbService)1 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)1