Search in sources :

Example 1 with OccurenceNavigator

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

the class OccurenceNavigatorActionBase method getNavigator.

@Nullable
protected OccurenceNavigator getNavigator(DataContext dataContext) {
    ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(dataContext, false);
    if (contentManager != null) {
        Content content = contentManager.getSelectedContent();
        if (content == null)
            return null;
        JComponent component = content.getComponent();
        return findNavigator(component);
    }
    return (OccurenceNavigator) getOccurenceNavigatorFromContext(dataContext);
}
Also used : Content(com.intellij.ui.content.Content) ContentManager(com.intellij.ui.content.ContentManager) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with OccurenceNavigator

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

the class OccurenceNavigatorActionBase method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null)
        return;
    OccurenceNavigator navigator = getNavigator(e.getDataContext());
    if (navigator == null) {
        return;
    }
    if (!hasOccurenceToGo(navigator)) {
        return;
    }
    OccurenceNavigator.OccurenceInfo occurenceInfo = go(navigator);
    if (occurenceInfo == null) {
        return;
    }
    Navigatable descriptor = occurenceInfo.getNavigateable();
    if (descriptor != null && descriptor.canNavigate()) {
        descriptor.navigate(true);
    }
    if (occurenceInfo.getOccurenceNumber() == -1 || occurenceInfo.getOccurencesCount() == -1) {
        return;
    }
    WindowManager.getInstance().getStatusBar(project).setInfo(IdeBundle.message("message.occurrence.N.of.M", occurenceInfo.getOccurenceNumber(), occurenceInfo.getOccurencesCount()));
}
Also used : Project(com.intellij.openapi.project.Project) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) Navigatable(com.intellij.pom.Navigatable)

Example 3 with OccurenceNavigator

use of com.intellij.ide.OccurenceNavigator in project intellij by bazelbuild.

the class BlazeConsoleView method createToolWindowContent.

void createToolWindowContent(ToolWindow toolWindow) {
    // Create runner UI layout
    RunnerLayoutUi.Factory factory = RunnerLayoutUi.Factory.getInstance(project);
    RunnerLayoutUi layoutUi = factory.create("", "", "session", project);
    Content console = layoutUi.createContent(BlazeConsoleToolWindowFactory.ID, consoleView.getComponent(), "", null, null);
    console.setCloseable(false);
    layoutUi.addContent(console, 0, PlaceInGrid.right, false);
    // Adding actions
    DefaultActionGroup group = new DefaultActionGroup();
    layoutUi.getOptions().setLeftToolbar(group, ActionPlaces.UNKNOWN);
    // Initializing prev and next occurrences actions
    OccurenceNavigator navigator = fromConsoleView(consoleView);
    CommonActionsManager actionsManager = CommonActionsManager.getInstance();
    AnAction prevAction = actionsManager.createPrevOccurenceAction(navigator);
    prevAction.getTemplatePresentation().setText(navigator.getPreviousOccurenceActionName());
    AnAction nextAction = actionsManager.createNextOccurenceAction(navigator);
    nextAction.getTemplatePresentation().setText(navigator.getNextOccurenceActionName());
    group.addAll(prevAction, nextAction);
    AnAction[] consoleActions = consoleView.createConsoleActions();
    for (AnAction action : consoleActions) {
        if (!shouldIgnoreAction(action)) {
            group.add(action);
        }
    }
    group.add(new StopAction());
    JComponent layoutComponent = layoutUi.getComponent();
    // noinspection ConstantConditions
    Content content = ContentFactory.SERVICE.getInstance().createContent(layoutComponent, null, true);
    content.setCloseable(false);
    toolWindow.getContentManager().addContent(content);
}
Also used : RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) Content(com.intellij.ui.content.Content) CommonActionsManager(com.intellij.ide.CommonActionsManager) JComponent(javax.swing.JComponent) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 4 with OccurenceNavigator

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

the class OccurenceNavigatorActionBase method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);
        // make it invisible only in main menu to avoid initial invisibility in toolbars
        presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
        return;
    }
    OccurenceNavigator navigator = getNavigator(event.getDataContext());
    if (navigator == null) {
        presentation.setEnabled(false);
        // make it invisible only in main menu to avoid initial invisibility in toolbars
        presentation.setVisible(!ActionPlaces.isMainMenuOrActionSearch(event.getPlace()));
        return;
    }
    presentation.setVisible(true);
    try {
        presentation.setEnabled(hasOccurenceToGo(navigator));
        presentation.setText(getDescription(navigator));
    } catch (IndexNotReadyException e) {
        presentation.setEnabled(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) OccurenceNavigator(com.intellij.ide.OccurenceNavigator)

Example 5 with OccurenceNavigator

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

the class OccurenceNavigatorActionBase method getOccurenceNavigatorFromContext.

@Nullable
private static Component getOccurenceNavigatorFromContext(DataContext dataContext) {
    Window window = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
    if (window != null) {
        Component component = window.getFocusOwner();
        for (Component c = component; c != null; c = c.getParent()) {
            if (c instanceof OccurenceNavigator) {
                return c;
            }
        }
    }
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return null;
    }
    ToolWindowManagerEx mgr = ToolWindowManagerEx.getInstanceEx(project);
    String id = mgr.getLastActiveToolWindowId(component -> findNavigator(component) != null);
    if (id == null) {
        return null;
    }
    return (Component) findNavigator(mgr.getToolWindow(id).getComponent());
}
Also used : Project(com.intellij.openapi.project.Project) OccurenceNavigator(com.intellij.ide.OccurenceNavigator) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OccurenceNavigator (com.intellij.ide.OccurenceNavigator)5 Project (com.intellij.openapi.project.Project)3 Content (com.intellij.ui.content.Content)2 Nullable (org.jetbrains.annotations.Nullable)2 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1 CommonActionsManager (com.intellij.ide.CommonActionsManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 ToolWindowManagerEx (com.intellij.openapi.wm.ex.ToolWindowManagerEx)1 Navigatable (com.intellij.pom.Navigatable)1 ContentManager (com.intellij.ui.content.ContentManager)1 JComponent (javax.swing.JComponent)1