com.intellij.ui.AppUIUtil Java Examples

The following examples show how to use com.intellij.ui.AppUIUtil. 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: CreateDesktopEntryAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static File prepare() throws IOException {
  File distributionDirectory = ContainerPathManager.get().getAppHomeDirectory();
  String name = ApplicationNamesInfo.getInstance().getFullProductName();

  final String iconPath = AppUIUtil.findIcon(distributionDirectory.getPath());
  if (iconPath == null) {
    throw new RuntimeException(ApplicationBundle.message("desktop.entry.icon.missing", distributionDirectory.getPath()));
  }

  final File execPath = new File(distributionDirectory, "consulo.sh");
  if (!execPath.exists()) {
    throw new RuntimeException(ApplicationBundle.message("desktop.entry.script.missing", distributionDirectory.getPath()));
  }

  final String wmClass = AppUIUtil.getFrameClass();

  final String content = ExecUtil.loadTemplate(CreateDesktopEntryAction.class.getClassLoader(), "entry.desktop", ContainerUtil
          .newHashMap(Arrays.asList("$NAME$", "$SCRIPT$", "$ICON$", "$WM_CLASS$"), Arrays.asList(name, execPath.getPath(), iconPath, wmClass)));

  final String entryName = wmClass + ".desktop";
  final File entryFile = new File(FileUtil.getTempDirectory(), entryName);
  FileUtil.writeToFile(entryFile, content);
  entryFile.deleteOnExit();
  return entryFile;
}
 
Example #2
Source File: BrowserLauncherImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doShowError(@Nullable final String error, @Nullable final WebBrowser browser, @Nullable final Project project, final String title, @Nullable final Runnable launchTask) {
  AppUIUtil.invokeOnEdt(new Runnable() {
    @Override
    public void run() {
      if (Messages.showYesNoDialog(project, StringUtil.notNullize(error, "Unknown error"), title == null ? IdeBundle.message("browser" + ".error") : title, Messages.OK_BUTTON,
                                   IdeBundle.message("button.fix"), null) == Messages.NO) {
        final BrowserSettings browserSettings = new BrowserSettings();

        AsyncResult<Void> result = ShowSettingsUtil.getInstance().editConfigurable(project, browserSettings, browser == null ? null : (Runnable)() -> browserSettings.selectBrowser(browser));
        result.doWhenDone(() -> {
          if (launchTask != null) {
            launchTask.run();
          }
        });
      }
    }
  }, project == null ? null : project.getDisposed());
}
 
Example #3
Source File: XJumpToSourceActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void perform(final XValueNodeImpl node, @Nonnull final String nodeName, final AnActionEvent e) {
  XValue value = node.getValueContainer();
  XNavigatable navigatable = new XNavigatable() {
    public void setSourcePosition(@Nullable final XSourcePosition sourcePosition) {
      if (sourcePosition != null) {
        AppUIUtil.invokeOnEdt(new Runnable() {
          public void run() {
            Project project = node.getTree().getProject();
            if (project.isDisposed()) return;

            sourcePosition.createNavigatable(project).navigate(true);
          }
        });
      }
    }
  };
  startComputingSourcePosition(value, navigatable);
}
 
Example #4
Source File: XDebugSessionTab.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void rebuildViews() {
  AppUIUtil.invokeLaterIfProjectAlive(myProject, () -> {
    if (mySession != null) {
      for (XDebugView view : myViews.values()) {
        view.processSessionEvent(XDebugView.SessionEvent.SETTINGS_CHANGED, mySession);
      }
    }
  });
}
 
Example #5
Source File: FlatWelcomeFrame.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public FlatWelcomeFrame(Runnable clearInstance) {
  myClearInstance = clearInstance;
  final JRootPane rootPane = getRootPane();
  FlatWelcomeScreen screen = new FlatWelcomeScreen(this);

  final IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(rootPane);

  setGlassPane(glassPane);
  glassPane.setVisible(false);
  //setUndecorated(true);
  setContentPane(screen);
  setDefaultTitle();
  AppUIUtil.updateWindowIcon(this);
  SwingUIDecorator.apply(SwingUIDecorator::decorateWindowTitle, rootPane);
  setSize(TargetAWT.to(WelcomeFrameManager.getDefaultWindowSize()));
  setResizable(false);
  Point location = WindowStateService.getInstance().getLocation(WelcomeFrameManager.DIMENSION_KEY);
  Rectangle screenBounds = ScreenUtil.getScreenRectangle(location != null ? location : new Point(0, 0));
  setLocation(new Point(screenBounds.x + (screenBounds.width - getWidth()) / 2, screenBounds.y + (screenBounds.height - getHeight()) / 3));

  myBalloonLayout = new WelcomeDesktopBalloonLayoutImpl(rootPane, JBUI.insets(8), screen.getMainWelcomePanel().myEventListener, screen.getMainWelcomePanel().myEventLocation);

  setupCloseAction(this);
  MnemonicHelper.init(this);
  Disposer.register(ApplicationManager.getApplication(), this);
}
 
Example #6
Source File: DesktopContainerStartup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void start(StatCollector stat, Runnable appInitalizeMark, String[] args) {
  try {
    StartupActionScriptManager.executeActionScript();
  }
  catch (IOException e) {
    Logger.getInstance(DesktopContainerStartup.class).error(e);

    StartupUtil.showMessage("Plugin Installation Error", e);
    return;
  }

  // desktop locker use netty. it will throw error due log4j2 initialize
  // see io.netty.channel.MultithreadEventLoopGroup.logger
  // it will override logger, which is active only if app exists
  // FIXME [VISTALL] see feac1737-76bf-4952-b770-d3f8d1978e59
  // InternalLoggerFactory.setDefaultFactory(ApplicationInternalLoggerFactory.INSTANCE);

  StartupUtil.prepareAndStart(args, DesktopImportantFolderLocker::new, (newConfigFolder, commandLineArgs) -> {
    AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame(), false);
    AppUIUtil.registerBundledFonts();

    ApplicationStarter app = new DesktopApplicationStarter(DesktopApplicationPostStarter.class, commandLineArgs);

    SwingUtilities.invokeLater(() -> {
      PluginManager.installExceptionHandler();
      app.run(stat, appInitalizeMark, newConfigFolder);
    });
  });
}
 
Example #7
Source File: RunContentManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public RunContentManagerImpl(@Nonnull Project project, @Nonnull DockManager dockManager) {
  myProject = project;
  DockableGridContainerFactory containerFactory = new DockableGridContainerFactory();
  dockManager.register(DockableGridContainerFactory.TYPE, containerFactory);
  Disposer.register(myProject, containerFactory);

  AppUIUtil.invokeOnEdt(this::init, myProject.getDisposed());
}
 
Example #8
Source File: ExecutionPointHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updateGutterIcon(@Nullable final GutterIconRenderer renderer) {
  AppUIUtil.invokeOnEdt(() -> {
    if (myRangeHighlighter != null && myGutterIconRenderer != null) {
      myRangeHighlighter.setGutterIconRenderer(renderer);
    }
  });
}
 
Example #9
Source File: ExecutionPointHighlighter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void hide() {
  AppUIUtil.invokeOnEdt(() -> {
    updateRequested.set(false);

    removeHighlighter();
    clearDescriptor();
    myEditor = null;
    myGutterIconRenderer = null;
  });
}
 
Example #10
Source File: DebuggerUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void errorOccurred(@Nonnull final String errorMessage) {
  AppUIUtil.invokeOnEdt(() -> {
    myTextArea.setForeground(XDebuggerUIConstants.ERROR_MESSAGE_ATTRIBUTES.getFgColor());
    myTextArea.setText(errorMessage);
  });
}
 
Example #11
Source File: DebuggerUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluated(@Nonnull final String fullValue, @Nullable final Font font) {
  AppUIUtil.invokeOnEdt(() -> {
    myTextArea.setText(fullValue);
    if (font != null) {
      myTextArea.setFont(font);
    }
  });
}
 
Example #12
Source File: RoboVmFileEditorManagerListener.java    From robovm-idea with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void fileOpened(FileEditorManager source, final VirtualFile file) {
    if(!"storyboard".equals(file.getExtension())) {
        return;
    }
    RoboVmPlugin.logInfo(project, "File opened: " + file.getCanonicalPath());
    Module module = null;
    for(Module m: ModuleManager.getInstance(project).getModules()) {
        if(ModuleRootManager.getInstance(m).getFileIndex().isInContent(file)) {
            module = m;
            break;
        }
    }
    if(module != null) {
        AppUIUtil.invokeOnEdt(new Runnable() {
            @Override
            public void run() {
                FileEditorManager.getInstance(project).closeFile(file);
            }
        });

        final Module foundModule = module;
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
                // this might be the first time someone opened a storyboard, do
                // at least one compilation if the target folder doesn't exist!
                final VirtualFile outputPath = CompilerPaths.getModuleOutputDirectory(foundModule, false);
                CompileScope scope = CompilerManager.getInstance(project).createModuleCompileScope(foundModule, true);
                CompilerManager.getInstance(project).compile(scope, new CompileStatusNotification() {
                    @Override
                    public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
                        IBIntegratorManager.getInstance().moduleChanged(foundModule);
                        openXCodeProject(foundModule, file);
                    }
                });
            }
        });
    }
}
 
Example #13
Source File: SetValueInplaceEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void show(final XValueNodeImpl node, @Nonnull final String nodeName) {
  final SetValueInplaceEditor editor = new SetValueInplaceEditor(node, nodeName);

  if (editor.myModifier != null) {
    editor.myModifier.calculateInitialValueEditorText(initialValue -> AppUIUtil.invokeOnEdt(() -> {
      if (editor.getTree().isShowing()) {
        editor.show(initialValue);
      }
    }));
  }
  else {
    editor.show(null);
  }
}
 
Example #14
Source File: XDebuggerTreeInplaceEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onShown() {
  XDebugSession session = XDebugView.getSession(myTree);
  if (session != null) {
    session.addSessionListener(new XDebugSessionListener() {
      @Override
      public void sessionPaused() {
        cancel();
      }

      @Override
      public void sessionResumed() {
        cancel();
      }

      @Override
      public void sessionStopped() {
        cancel();
      }

      @Override
      public void stackFrameChanged() {
        cancel();
      }

      @Override
      public void beforeSessionResume() {
        cancel();
      }

      private void cancel() {
        AppUIUtil.invokeOnEdt(XDebuggerTreeInplaceEditor.this::cancelEditing);
      }
    }, myDisposable);
  }
}
 
Example #15
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void printMessage(final String message, final String hyperLinkText, @Nullable final HyperlinkInfo info) {
  AppUIUtil.invokeOnEdt(() -> {
    myConsoleView.print(message, ConsoleViewContentType.SYSTEM_OUTPUT);
    if (info != null) {
      myConsoleView.printHyperlink(hyperLinkText, info);
    }
    else if (hyperLinkText != null) {
      myConsoleView.print(hyperLinkText, ConsoleViewContentType.SYSTEM_OUTPUT);
    }
    myConsoleView.print("\n", ConsoleViewContentType.SYSTEM_OUTPUT);
  });
}
 
Example #16
Source File: StartupUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void prepareAndStart(String[] args, BiFunction<String, String, ImportantFolderLocker> lockFactory, PairConsumer<Boolean, CommandLineArgs> appStarter) {
  boolean newConfigFolder;
  CommandLineArgs commandLineArgs = CommandLineArgs.parse(args);

  if (commandLineArgs.isShowHelp()) {
    CommandLineArgs.printUsage();
    System.exit(ExitCodes.USAGE_INFO);
  }

  if (commandLineArgs.isShowVersion()) {
    ApplicationInfo infoEx = ApplicationInfo.getInstance();
    System.out.println(infoEx.getFullApplicationName());
    System.exit(ExitCodes.VERSION_INFO);
  }

  AppUIUtil.updateFrameClass();
  newConfigFolder = !new File(ContainerPathManager.get().getConfigPath()).exists();

  ActivationResult result = lockSystemFolders(lockFactory, args);
  if (result == ActivationResult.ACTIVATED) {
    System.exit(0);
  }
  else if (result != ActivationResult.STARTED) {
    System.exit(ExitCodes.INSTANCE_CHECK_FAILED);
  }

  Logger log = Logger.getInstance(StartupUtil.class);
  logStartupInfo(log);
  loadSystemLibraries(log);
  fixProcessEnvironment(log);

  appStarter.consume(newConfigFolder, commandLineArgs);
}
 
Example #17
Source File: XFetchValueActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void evaluationComplete(final int index, @Nonnull final String value) {
  AppUIUtil.invokeOnEdt(() -> {
    values.set(index, value);
    finish();
  });
}
 
Example #18
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void stopImpl() {
  if (!myStopped.compareAndSet(false, true)) {
    return;
  }

  try {
    if (breakpointsInitialized) {
      XBreakpointManagerImpl breakpointManager = myDebuggerManager.getBreakpointManager();
      if (myBreakpointListener != null) {
        breakpointManager.removeBreakpointListener(myBreakpointListener);
      }
      if (myDependentBreakpointListener != null) {
        breakpointManager.getDependentBreakpointManager().removeListener(myDependentBreakpointListener);
      }
    }
  }
  finally {
    //noinspection unchecked
    myDebugProcess.stopAsync().doWhenDone(value -> {
      if (!myProject.isDisposed()) {
        myProject.getMessageBus().syncPublisher(XDebuggerManager.TOPIC).processStopped(myDebugProcess);
      }

      if (mySessionTab != null) {
        AppUIUtil.invokeOnEdt(() -> {
          ((XWatchesViewImpl)mySessionTab.getWatchesView()).updateSessionData();
          mySessionTab.detachFromSession();
        });
      }
      else if (myConsoleView != null) {
        AppUIUtil.invokeOnEdt(() -> Disposer.dispose(myConsoleView));
      }

      myTopFramePosition = null;
      myCurrentExecutionStack = null;
      myCurrentStackFrame = null;
      mySuspendContext = null;

      updateExecutionPosition();

      if (myValueMarkers != null) {
        myValueMarkers.clear();
      }
      if (XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isUnmuteOnStop()) {
        mySessionData.setBreakpointsMuted(false);
      }
      myDebuggerManager.removeSession(this);
      myDispatcher.getMulticaster().sessionStopped();
      myDispatcher.getListeners().clear();

      myProject.putUserData(XDebuggerEditorLinePainter.CACHE, null);

      synchronized (myRegisteredBreakpoints) {
        myRegisteredBreakpoints.clear();
      }
    });
  }
}
 
Example #19
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void positionReachedInternal(@Nonnull final XSuspendContext suspendContext, boolean attract) {
  enableBreakpoints();
  mySuspendContext = suspendContext;
  myCurrentExecutionStack = suspendContext.getActiveExecutionStack();
  myCurrentStackFrame = myCurrentExecutionStack != null ? myCurrentExecutionStack.getTopFrame() : null;
  myIsTopFrame = true;
  myTopFramePosition = myCurrentStackFrame != null ? myCurrentStackFrame.getSourcePosition() : null;

  myPaused.set(true);

  updateExecutionPosition();

  final boolean showOnSuspend = myShowTabOnSuspend.compareAndSet(true, false);
  if (showOnSuspend || attract) {
    AppUIUtil.invokeLaterIfProjectAlive(myProject, () -> {
      if (showOnSuspend) {
        initSessionTab(null);
        showSessionTab();
      }

      // user attractions should only be made if event happens independently (e.g. program paused/suspended)
      // and should not be made when user steps in the code
      if (attract) {
        if (mySessionTab == null) {
          LOG.debug("Cannot request focus because Session Tab is not initialized yet");
          return;
        }

        if (XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isShowDebuggerOnBreakpoint()) {
          mySessionTab.toFront(true, this::updateExecutionPosition);
        }

        if (myTopFramePosition == null) {
          // if there is no source position available, we should somehow tell the user that session is stopped.
          // the best way is to show the stack frames.
          XDebugSessionTab.showFramesView(this);
        }

        mySessionTab.getUi().attractBy(XDebuggerUIConstants.LAYOUT_VIEW_BREAKPOINT_CONDITION);
      }
    });
  }

  myDispatcher.getMulticaster().sessionPaused();
}
 
Example #20
Source File: XStandaloneVariablesView.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void rebuildView() {
  AppUIUtil.invokeLaterIfProjectAlive(getTree().getProject(), () -> {
    saveCurrentTreeState(myStackFrame);
    buildTreeAndRestoreState(myStackFrame);
  });
}
 
Example #21
Source File: CompletionPhase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void scheduleAsyncCompletion(@Nonnull Editor _editor,
                                           @Nonnull CompletionType completionType,
                                           @Nullable Condition<? super PsiFile> condition,
                                           @Nonnull Project project,
                                           @Nullable CompletionProgressIndicator prevIndicator) {
  Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(_editor);
  int offset = topLevelEditor.getCaretModel().getOffset();

  CommittingDocuments phase = new CommittingDocuments(prevIndicator, topLevelEditor);
  CompletionServiceImpl.setCompletionPhase(phase);
  phase.ignoreCurrentDocumentChange();

  boolean autopopup = prevIndicator == null || prevIndicator.isAutopopupCompletion();

  ReadAction.nonBlocking(() -> {
    // retrieve the injected file from scratch since our typing might have destroyed the old one completely
    PsiFile topLevelFile = PsiDocumentManager.getInstance(project).getPsiFile(topLevelEditor.getDocument());
    Editor completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(topLevelEditor, topLevelFile, offset);
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(completionEditor.getDocument());
    if (file == null || autopopup && shouldSkipAutoPopup(completionEditor, file) || condition != null && !condition.value(file)) {
      return null;
    }

    loadContributorsOutsideEdt(completionEditor, file);

    return completionEditor;
  }).withDocumentsCommitted(project).expireWith(phase).expireWhen(() -> phase.isExpired()).finishOnUiThread(ModalityState.current(), completionEditor -> {
    if (completionEditor != null) {
      int time = prevIndicator == null ? 0 : prevIndicator.getInvocationCount();
      CodeCompletionHandlerBase handler = CodeCompletionHandlerBase.createHandler(completionType, false, autopopup, false);
      handler.invokeCompletion(project, completionEditor, time, false);
    }
    else if (phase == CompletionServiceImpl.getCompletionPhase()) {
      CompletionServiceImpl.setCompletionPhase(NoCompletion);
    }
  }).submit(ourExecutor).onError(__ -> AppUIUtil.invokeOnEdt(() -> {
    if (phase == CompletionServiceImpl.getCompletionPhase()) {
      CompletionServiceImpl.setCompletionPhase(NoCompletion);
    }
  }));
}
 
Example #22
Source File: ChangeListTodosPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void defaultListChanged(final ChangeList oldDefaultList, final ChangeList newDefaultList) {
  rebuildWithAlarm(myAlarm);
  AppUIUtil.invokeOnEdt(() -> setDisplayName(IdeBundle.message("changelist.todo.title", newDefaultList.getName())));
}
 
Example #23
Source File: ChangeListTodosPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void changeListRenamed(final ChangeList list, final String oldName) {
  AppUIUtil.invokeOnEdt(() -> setDisplayName(IdeBundle.message("changelist.todo.title", list.getName())));
}
 
Example #24
Source File: FrameWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void show(boolean restoreBounds) {
  myFocusedCallback = AsyncResult.undefined();

  if (myProject != null) {
    IdeFocusManager.getInstance(myProject).typeAheadUntil(myFocusedCallback);
  }

  final Window frame = getFrame();

  if (myStatusBar != null) {
    consulo.ui.Window uiWindow = TargetAWT.from(frame);
    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    myStatusBar.install(ideFrame);
  }

  if (frame instanceof JFrame) {
    ((JFrame)frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  }
  else {
    ((JDialog)frame).setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  }

  SwingUIDecorator.apply(SwingUIDecorator::decorateWindowTitle, ((RootPaneContainer)frame).getRootPane());

  final WindowAdapter focusListener = new WindowAdapter() {
    @Override
    public void windowOpened(WindowEvent e) {
      IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
      JComponent toFocus = getPreferredFocusedComponent();
      if (toFocus == null) {
        toFocus = fm.getFocusTargetFor(myComponent);
      }

      if (toFocus != null) {
        fm.requestFocus(toFocus, true).notify(myFocusedCallback);
      }
      else {
        myFocusedCallback.setRejected();
      }
    }
  };
  frame.addWindowListener(focusListener);
  if (ModalityPerProjectEAPDescriptor.is()) {
    frame.setAlwaysOnTop(true);
  }
  Disposer.register(this, () -> frame.removeWindowListener(focusListener));
  if (myCloseOnEsc) addCloseOnEsc((RootPaneContainer)frame);
  ((RootPaneContainer)frame).getContentPane().add(myComponent, BorderLayout.CENTER);
  if (frame instanceof JFrame) {
    ((JFrame)frame).setTitle(myTitle);
  }
  else {
    ((JDialog)frame).setTitle(myTitle);
  }
  if (myImages != null) {
    // unwrap the image before setting as frame's icon
    frame.setIconImages(ContainerUtil.map(myImages, ImageUtil::toBufferedImage));
  }
  else {
    AppUIUtil.updateWindowIcon(myFrame);
  }

  WindowState state = myDimensionKey == null ? null : getWindowStateService(myProject).getState(myDimensionKey, frame);
  if (restoreBounds) {
    loadFrameState(state);
  }

  myFocusWatcher = new FocusWatcher();
  myFocusWatcher.install(myComponent);
  myShown = true;
  frame.setVisible(true);
}