@Override public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent) { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { Disposer.dispose(myErrorTreeView); myErrorTreeView = null; if (myIndicator.isRunning()) { cancel(); } if (AppIcon.getInstance().hideProgress(myProject, "compiler")) { AppIcon.getInstance().setErrorBadge(myProject, null); } } } myContentManager.removeContentManagerListener(this); myContent.release(); myContent = null; } }
@Nullable @Override public String execute(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException { final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame(); if (frame instanceof Window) { sendOk(request, context); Runnable runnable = new Runnable() { public void run() { Window window = (Window)frame; window.toFront(); window.requestFocusInWindow(); AppIcon.getInstance().requestFocus(frame); } }; //noinspection SSBasedInspection SwingUtilities.invokeLater(runnable); return "Success"; } sendStatus(HttpResponseStatus.NOT_FOUND, false, context.channel()); return "Can't find IDE Frame"; }
public static void focusProjectWindow(final Project p, boolean executeIfAppInactive) { FocusCommand cmd = new FocusCommand() { @NotNull @Override public ActionCallback run() { JFrame f = WindowManager.getInstance().getFrame(p); if (f != null) { f.toFront(); //f.requestFocus(); } return ActionCallback.DONE; } }; if (executeIfAppInactive) { AppIcon.getInstance().requestFocus((IdeFrame)WindowManager.getInstance().getFrame(p)); cmd.run(); } else { IdeFocusManager.getInstance(p).requestFocus(cmd, true); } }
public static void showIconProgress(Project project, int n, final int maximum, final int problemsCounter, boolean updateWithAttention) { AppIcon icon = AppIcon.getInstance(); if (n < maximum || !updateWithAttention) { if (!updateWithAttention || icon.setProgress(project, TESTS, AppIconScheme.Progress.TESTS, (double)n / (double)maximum, problemsCounter == 0)) { if (problemsCounter > 0) { icon.setErrorBadge(project, String.valueOf(problemsCounter)); } } } else { if (icon.hideProgress(project, TESTS)) { if (problemsCounter > 0) { icon.setErrorBadge(project, String.valueOf(problemsCounter)); icon.requestAttention(project, false); } else { icon.setOkBadge(project, true); icon.requestAttention(project, false); } } } }
@Override public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent) { synchronized (myMessageViewLock) { Project project = getNotNullProject(); if (myErrorTreeView != null && !project.isDisposed()) { Disposer.dispose(myErrorTreeView); myErrorTreeView = null; if (myIndicator.isRunning()) { cancel(); } AppIcon appIcon = AppIcon.getInstance(); if (appIcon.hideProgress(project, APP_ICON_ID)) { //noinspection ConstantConditions appIcon.setErrorBadge(project, null); } } } myContentManager.removeContentManagerListener(this); if (myContent != null) { myContent.release(); } myContent = null; } }
private void stopAppIconProgress() { invokeLaterIfNeeded(new Runnable() { @Override public void run() { AppIcon appIcon = AppIcon.getInstance(); Project project = getNotNullProject(); if (appIcon.hideProgress(project, APP_ICON_ID)) { if (myErrorCount > 0) { appIcon.setErrorBadge(project, String.valueOf(myErrorCount)); appIcon.requestAttention(project, true); } else { appIcon.setOkBadge(project, true); appIcon.requestAttention(project, false); } } } }); }
public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent) { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { myErrorTreeView.dispose(); myErrorTreeView = null; if (myIndicator.isRunning()) { cancel(); } if (AppIcon.getInstance().hideProgress(myProject, "compiler")) { AppIcon.getInstance().setErrorBadge(myProject, null); } } } myContentManager.removeContentManagerListener(this); myContent.release(); myContent = null; } }
public static void focusProjectWindow(final Project p, boolean executeIfAppInactive) { FocusCommand cmd = new FocusCommand() { @NotNull @Override public ActionCallback run() { JFrame f = WindowManager.getInstance().getFrame(p); if (f != null) { f.toFront(); //f.requestFocus(); } return new ActionCallback.Done(); } }; if (executeIfAppInactive) { AppIcon.getInstance().requestFocus((IdeFrame)WindowManager.getInstance().getFrame(p)); cmd.run(); } else { IdeFocusManager.getInstance(p).requestFocus(cmd, false); } }
public static void showIconProgress(Project project, int n, final int maximum, final int problemsCounter) { AppIcon icon = AppIcon.getInstance(); if (n < maximum) { if (icon.setProgress(project, TESTS, AppIconScheme.Progress.TESTS, (double)n / (double)maximum, problemsCounter == 0)) { if (problemsCounter > 0) { icon.setErrorBadge(project, String.valueOf(problemsCounter)); } } } else { if (icon.hideProgress(project, TESTS)) { if (problemsCounter > 0) { icon.setErrorBadge(project, String.valueOf(problemsCounter)); icon.requestAttention(project, false); } else { icon.setOkBadge(project, true); icon.requestAttention(project, false); } } } }
private void requestIdeFocus() { ApplicationManager.getApplication().invokeLater(() -> { final JFrame frame = WindowManager.getInstance().getFrame(project); if (frame instanceof IdeFrame) { AppIcon.getInstance().requestFocus((IdeFrame) frame); AppIcon.getInstance().requestAttention(project, true); AppIcon.getInstance().setOkBadge(project, true); } }); }
private static void focusOnApplicationWindow() { JFrame frame = WindowManager.getInstance().findVisibleFrame(); ApplicationManager.getApplication().invokeLater(() -> { AppIcon.getInstance().requestFocus((IdeFrame)frame); frame.toFront(); }); }
@Override public void initComponent() { final AnyBarIcon anyBarIcon = new AnyBarIcon(AppIcon.getInstance()); for (Field field : ReflectionUtil.getClassDeclaredFields(AppIcon.class)) { if (AppIcon.class.isAssignableFrom(field.getType())) { try { field.setAccessible(true); field.set(null, anyBarIcon); } catch (IllegalAccessException e) { Logger.getInstance(AnyBarConnector.class).error(e); } } } }
@Override public void setFraction(final double fraction) { if (fraction - lastFraction < 0.01d) return; lastFraction = fraction; UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { AppIcon.getInstance().setProgress(myProject, "indexUpdate", AppIconScheme.Progress.INDEXING, fraction, true); } }); }
@Override public void finish(@NotNull TaskInfo task) { if (lastFraction != 0) { // we should call setProgress at least once before UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { AppIcon appIcon = AppIcon.getInstance(); if (appIcon.hideProgress(myProject, "indexUpdate")) { appIcon.requestAttention(myProject, false); appIcon.setOkBadge(myProject, true); } } }); } }
public void toFront(boolean focus, @Nullable final Runnable onShowCallback) { if (ApplicationManager.getApplication().isUnitTestMode()) return; ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (myRunContentDescriptor != null) { ToolWindow toolWindow = ExecutionManager.getInstance(myProject).getContentManager() .getToolWindowByDescriptor(myRunContentDescriptor); if (toolWindow != null) { if (!toolWindow.isVisible()) { toolWindow.show(onShowCallback); } //noinspection ConstantConditions toolWindow.getContentManager().setSelectedContent(myRunContentDescriptor.getAttachedContent()); } } } }); if (focus) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { boolean focusWnd = Registry.is("debugger.mayBringFrameToFrontOnBreakpoint"); ProjectUtil.focusProjectWindow(myProject, focusWnd); if (!focusWnd) { AppIcon.getInstance().requestAttention(myProject, true); } } }); } }
public void toFront() { if (!ApplicationManager.getApplication().isUnitTestMode()) { ExecutionManager.getInstance(getProject()).getContentManager().toFrontRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), myRunContentDescriptor); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { boolean focusWnd = Registry.is("debugger.mayBringFrameToFrontOnBreakpoint"); ProjectUtil.focusProjectWindow(getProject(), focusWnd); if (!focusWnd) { AppIcon.getInstance().requestAttention(getProject(), true); } } }); } }
@Override public void setFraction(final double fraction) { if (fraction - lastFraction < 0.01d) return; lastFraction = fraction; UIUtil.invokeLaterIfNeeded( () -> AppIcon.getInstance().setProgress(myProject, "indexUpdate", AppIconScheme.Progress.INDEXING, fraction, true)); }
@Override public void finish(@Nonnull TaskInfo task) { if (lastFraction != 0) { // we should call setProgress at least once before UIUtil.invokeLaterIfNeeded(() -> { AppIcon appIcon = AppIcon.getInstance(); if (appIcon.hideProgress(myProject, "indexUpdate")) { appIcon.requestAttention(myProject, false); appIcon.setOkBadge(myProject, true); } }); } }
public static void focusProjectWindow(final Project p, boolean executeIfAppInactive) { JFrame f = WindowManager.getInstance().getFrame(p); if (f != null) { if (executeIfAppInactive) { AppIcon.getInstance().requestFocus((IdeFrame)WindowManager.getInstance().getFrame(p)); f.toFront(); } else { IdeFocusManager.getInstance(p).requestFocus(f, true); } } }
public void toFront(boolean focus, @Nullable final Runnable onShowCallback) { if (ApplicationManager.getApplication().isUnitTestMode()) return; ApplicationManager.getApplication().invokeLater(() -> { if (myRunContentDescriptor != null) { RunContentManager manager = ExecutionManager.getInstance(myProject).getContentManager(); ToolWindow toolWindow = manager.getToolWindowByDescriptor(myRunContentDescriptor); if (toolWindow != null) { if (!toolWindow.isVisible()) { toolWindow.show(() -> { if (onShowCallback != null) { onShowCallback.run(); } myRebuildWatchesRunnable.run(); }); } manager.selectRunContent(myRunContentDescriptor); } } }); if (focus) { ApplicationManager.getApplication().invokeLater(() -> { boolean focusWnd = XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isMayBringFrameToFrontOnBreakpoint(); ProjectUtil.focusProjectWindow(myProject, focusWnd); if (!focusWnd) { AppIcon.getInstance().requestAttention(myProject, true); } }); } }
AnyBarIcon(AppIcon icon) { delegate = icon; }
@Override public void requestUserAttention(@NotNull IdeFrame frame, boolean critical) { Project project = frame.getProject(); if (project != null) AppIcon.getInstance().requestAttention(project, critical); }
public static void clearIconProgress(Project project) { AppIcon.getInstance().hideProgress(project, TESTS); AppIcon.getInstance().setErrorBadge(project, null); }
private void addIndicatorDelegate() { ProgressIndicator indicator = myIndicator; if (!(indicator instanceof ProgressIndicatorEx)) return; ((ProgressIndicatorEx)indicator).addStateDelegate(new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); closeUI(); stopAppIconProgress(); } @Override public void stop() { super.stop(); if (!isCanceled()) { closeUI(); } stopAppIconProgress(); } private void stopAppIconProgress() { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { AppIcon appIcon = AppIcon.getInstance(); if (appIcon.hideProgress(myProject, APP_ICON_ID)) { if (myErrorCount > 0) { appIcon.setErrorBadge(myProject, String.valueOf(myErrorCount)); appIcon.requestAttention(myProject, true); } else if (!myCompilationStartedAutomatically) { appIcon.setOkBadge(myProject, true); appIcon.requestAttention(myProject, false); } } } }); } @Override public void setFraction(final double fraction) { super.setFraction(fraction); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { AppIcon.getInstance().setProgress(myProject, APP_ICON_ID, AppIconScheme.Progress.BUILD, fraction, true); } }); } }); }
@Override public void requestUserAttention(@Nonnull IdeFrame frame, boolean critical) { Project project = frame.getProject(); if (project != null) AppIcon.getInstance().requestAttention(project, critical); }
public ApplicationImpl(boolean isHeadless, @Nonnull Ref<? extends StartupProgress> splashRef) { super(null); ApplicationManager.setApplication(this, myLastDisposable); // reset back to null only when all components already disposed getPicoContainer().registerComponentInstance(Application.class, this); getPicoContainer().registerComponentInstance(TransactionGuard.class.getName(), myTransactionGuard); AWTExceptionHandler.register(); // do not crash AWT on exceptions myIsInternal = ApplicationProperties.isInternal(); String debugDisposer = System.getProperty("idea.disposer.debug"); Disposer.setDebugMode((myIsInternal || "on".equals(debugDisposer)) && !"off".equals(debugDisposer)); myStartTime = System.currentTimeMillis(); mySplashRef = splashRef; boolean isUnitTestMode = false; myTestModeFlag = isUnitTestMode; myHeadlessMode = isHeadless; myCommandLineMode = isUnitTestMode; myDoNotSave = isUnitTestMode || isHeadless; gatherStatistics = LOG.isDebugEnabled() || isUnitTestMode() || isInternal(); loadApplicationComponents(); if (myTestModeFlag) { registerShutdownHook(); } if (!isUnitTestMode && !isHeadless) { Disposer.register(this, Disposer.newDisposable(), "ui"); StartupUtil.addExternalInstanceListener(commandLineArgs -> { LOG.info("ApplicationImpl.externalInstanceListener invocation"); final Project project = CommandLineProcessor.processExternalCommandLine(commandLineArgs, null); final IdeFrame frame = WindowManager.getInstance().getIdeFrame(project); if (frame != null) AppIcon.getInstance().requestFocus(frame); }); WindowsCommandLineProcessor.LISTENER = (currentDirectory, commandLine) -> { LOG.info("Received external Windows command line: current directory " + currentDirectory + ", command line " + commandLine); invokeLater(() -> { final List<String> args = StringUtil.splitHonorQuotes(commandLine, ' '); args.remove(0); // process name CommandLineProcessor.processExternalCommandLine(CommandLineArgs.parse(ArrayUtil.toStringArray(args)), currentDirectory); }); }; } Thread edt = UIUtil.invokeAndWaitIfNeeded(() -> { // instantiate AppDelayQueue which starts "Periodic task thread" which we'll mark busy to prevent this EDT to die // that thread was chosen because we know for sure it's running AppScheduledExecutorService service = (AppScheduledExecutorService)AppExecutorUtil.getAppScheduledExecutorService(); Thread thread = service.getPeriodicTasksThread(); AWTAutoShutdown.getInstance().notifyThreadBusy(thread); // needed for EDT not to exit suddenly Disposer.register(this, () -> { AWTAutoShutdown.getInstance().notifyThreadFree(thread); // allow for EDT to exit - needed for Upsource }); return Thread.currentThread(); }); myLock = new ReadMostlyRWLock(edt); if (isUnitTestMode) { ApplicationStarter.ourLoaded = true; } NoSwingUnderWriteAction.watchForEvents(this); }