Java Code Examples for com.intellij.openapi.wm.WindowManager#getInstance()

The following examples show how to use com.intellij.openapi.wm.WindowManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HighlightingUtil.java    From needsmoredojo with Apache License 2.0 6 votes vote down vote up
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements)
{
    final HighlightManager highlightManager =
            HighlightManager.getInstance(project);
    final EditorColorsManager editorColorsManager =
            EditorColorsManager.getInstance();
    final EditorColorsScheme globalScheme =
            editorColorsManager.getGlobalScheme();
    final TextAttributes textattributes =
            globalScheme.getAttributes(
                    EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);

    highlightManager.addOccurrenceHighlights(
            editor, elements, textattributes, true, null);
    final WindowManager windowManager = WindowManager.getInstance();
    final StatusBar statusBar = windowManager.getStatusBar(project);
    statusBar.setInfo("Press Esc to remove highlighting");
}
 
Example 2
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public DialogWrapperPeerImpl(@Nonnull final DialogWrapper wrapper, final Window owner, final boolean canBeParent, final DialogWrapper.IdeModalityType ideModalityType) {
  myWrapper = wrapper;
  myWindowManager = null;
  Application application = ApplicationManager.getApplication();
  if (application != null) {
    myWindowManager = (DesktopWindowManagerImpl)WindowManager.getInstance();
  }
  createDialog(owner, canBeParent);

  if (!isHeadless()) {
    Dialog.ModalityType modalityType = DialogWrapper.IdeModalityType.IDE.toAwtModality();
    if (ModalityPerProjectEAPDescriptor.is()) {
      modalityType = ideModalityType.toAwtModality();
    }
    myDialog.setModalityType(modalityType);
  }
}
 
Example 3
Source File: LSPServerStatusWidget.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private void updateWidget() {
    WindowManager manager = WindowManager.getInstance();
    if (manager != null && project != null && !project.isDisposed()) {
        StatusBar statusBar = manager.getStatusBar(project);
        if (statusBar != null) {
            statusBar.updateWidget(ID());
        }
    }
}
 
Example 4
Source File: LSPServerStatusWidget.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
public void dispose() {
    WindowManager manager = WindowManager.getInstance();
    if (manager != null && project != null && !project.isDisposed()) {
        StatusBar statusBar = manager.getStatusBar(project);
        LSPServerStatusWidget.removeWidgetID(this);
        if (statusBar != null)
            ApplicationUtils.invokeLater(() -> statusBar.removeWidget(ID()));

    }
}
 
Example 5
Source File: ProjectUtils.java    From EasyCode with MIT License 5 votes vote down vote up
/**
 * 获取当前项目对象
 *
 * @return 当前项目对象
 */
public static Project getCurrProject() {

    ProjectManager projectManager = ProjectManager.getInstance();
    Project[] openProjects = projectManager.getOpenProjects();
    if (openProjects.length == 0) {
        return projectManager.getDefaultProject();//正常情况下不会发生
    } else if (openProjects.length == 1) {
        // 只存在一个打开的项目则使用打开的项目
        return openProjects[0];
    }

    //如果有项目窗口处于激活状态
    try {
        WindowManager wm = WindowManager.getInstance();
        for (Project project : openProjects) {
            Window window = wm.suggestParentWindow(project);
            if (window != null && window.isActive()) {
                return project;
            }
        }
    } catch (Exception ignored) {
    }

    //否则使用默认项目
    return projectManager.getDefaultProject();
}
 
Example 6
Source File: StatusIndicator.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
public void update(State state) {
	WindowManager windowManager = WindowManager.getInstance();
	final StatusBar statusBar = windowManager.getStatusBar(this.project);
	if (statusBar == null) {
		windowManager.addListener(new UpdateOnFrameCreateListener(state));
		return;
	}
	if (state == State.ACTIVE) {
		show(statusBar);
	}
	else {
		hide(statusBar);
	}
}
 
Example 7
Source File: AbstractPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showInFocusCenter() {
  final Component focused = getWndManager().getFocusedComponent(myProject);
  if (focused != null) {
    showInCenterOf(focused);
  }
  else {
    final WindowManager manager = WindowManager.getInstance();
    final JFrame frame = myProject != null ? manager.getFrame(myProject) : manager.findVisibleFrame();
    showInCenterOf(frame.getRootPane());
  }
}
 
Example 8
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param parent parent component which is used to calculate heavy weight window ancestor.
 *               <code>parent</code> cannot be <code>null</code> and must be showing.
 */
protected DialogWrapperPeerImpl(@Nonnull DialogWrapper wrapper, @Nonnull Component parent, final boolean canBeParent) {
  myWrapper = wrapper;

  myWindowManager = null;
  Application application = ApplicationManager.getApplication();
  if (application != null) {
    myWindowManager = (DesktopWindowManagerImpl)WindowManager.getInstance();
  }

  OwnerOptional.fromComponent(parent).ifWindow(window -> {
    createDialog(window, canBeParent);
  });
}
 
Example 9
Source File: WindowManagerEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static WindowManagerEx getInstanceEx() {
  return (WindowManagerEx)WindowManager.getInstance();
}
 
Example 10
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected DialogWrapperPeerImpl(@Nonnull DialogWrapper wrapper, @Nullable Project project, boolean canBeParent, @Nonnull DialogWrapper.IdeModalityType ideModalityType) {
  myWrapper = wrapper;
  myWindowManager = null;
  Application application = ApplicationManager.getApplication();
  if (application != null) {
    myWindowManager = (DesktopWindowManagerImpl)WindowManager.getInstance();
  }

  consulo.ui.Window window = null;
  if (myWindowManager != null) {

    if (project == null) {
      //noinspection deprecation
      project = DataManager.getInstance().getDataContext().getData(CommonDataKeys.PROJECT);
    }

    myProject = project;

    window = myWindowManager.suggestParentWindow(project);
    if (window == null) {
      consulo.ui.Window focusedWindow = myWindowManager.getMostRecentFocusedWindow();
      if (IdeFrameUtil.isRootIdeFrameWindow(focusedWindow)) {
        window = focusedWindow;
      }
    }
    if (window == null) {
      IdeFrame[] frames = myWindowManager.getAllProjectFrames();
      for (IdeFrame frame : frames) {
        if (frame.isActive()) {
          window = frame.getWindow();
          break;
        }
      }
    }
  }

  Window owner;
  if (window != null) {
    owner = TargetAWT.to(window);
  }
  else {
    if (!isHeadless()) {
      owner = JOptionPane.getRootFrame();
    }
    else {
      owner = null;
    }
  }

  createDialog(owner, canBeParent, ideModalityType);
}
 
Example 11
Source File: DesktopApplicationPostStarter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
public void main(StatCollector stat, Runnable appInitializeMark, ApplicationEx app, boolean newConfigFolder, @Nonnull CommandLineArgs args) {
  SystemDock.getInstance().updateMenu();

  // if OS has dock, RecentProjectsManager will be already created, but not all OS have dock, so, we trigger creation here to ensure that RecentProjectsManager app listener will be added
  RecentProjectsManager.getInstance();

  // Event queue should not be changed during initialization of application components.
  // It also cannot be changed before initialization of application components because IdeEventQueue uses other
  // application components. So it is proper to perform replacement only here.
  DesktopWindowManagerImpl windowManager = (DesktopWindowManagerImpl)WindowManager.getInstance();
  IdeEventQueue.getInstance().setWindowManager(windowManager);

  RecentProjectsManagerBase recentProjectsManager = RecentProjectsManagerBase.getInstanceEx();

  appInitializeMark.run();

  stat.dump("Startup statistics", LOG::info);

  PluginLoadStatistics.get().dumpPluginClassStatistics(LOG::info);

  app.invokeAndWait(() -> {
    StartupProgress desktopSplash = mySplashRef.get();
    if (desktopSplash != null) {
      desktopSplash.dispose();
      mySplashRef.set(null);  // Allow GC collect the splash window
    }
  }, ModalityState.NON_MODAL);

  if (newConfigFolder && !ApplicationProperties.isInSandbox()) {
    FirstStartCustomizeUtil.show(true);
  }

  boolean willOpenProject = recentProjectsManager.willReopenProjectOnStart() && !args.isNoRecentProjects();

  AppLifecycleListener lifecyclePublisher = app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC);
  lifecyclePublisher.appFrameCreated(args, willOpenProject);

  if (recentProjectsManager.willReopenProjectOnStart() && !args.isNoRecentProjects()) {
    windowManager.showFrame();
  }
  else {
    WelcomeFrameManager.getInstance().showFrame();
  }

  app.invokeLater(() -> {
    if (!args.isNoRecentProjects()) {
      AsyncResult<Project> projectFromCommandLine = AsyncResult.rejected();

      if (myApplicationStarter.isPerformProjectLoad()) {
        projectFromCommandLine = CommandLineProcessor.processExternalCommandLine(args, null);
      }

      projectFromCommandLine.doWhenRejected(recentProjectsManager::doReopenLastProject);
    }

    SwingUtilities.invokeLater(() -> reportPluginError(myPluginsInitializeInfo));

    UsageTrigger.trigger("consulo.app.started");
  }, ModalityState.NON_MODAL);
}