public void testModalityState() { assertReady(null); myMonitor.addActivity(new UiActivity("non_modal_1"), ModalityState.NON_MODAL); assertBusy(null); LaterInvocator.enterModal("dialog"); try { assertReady(null); myMonitor.addActivity(new UiActivity("non_modal2"), ModalityState.NON_MODAL); assertReady(null); myMonitor.addActivity(new UiActivity("modal_1"), new ModalityStateEx(new Object[] {"dialog"})); assertBusy(null); myMonitor.addActivity(new UiActivity("modal_2"), new ModalityStateEx(new Object[] {"dialog", "popup"})); assertBusy(null); } finally { LaterInvocator.leaveModal("dialog"); } assertBusy(null); }
public void makeModalAware(Project project) { MavenUtil.invokeLater(project, new Runnable() { public void run() { final ModalityStateListener listener = new ModalityStateListener() { @Override public void beforeModalityStateChanged(boolean entering) { if (entering) { suspend(); } else { resume(); } } }; LaterInvocator.addModalityStateListener(listener, MavenMergingUpdateQueue.this); if (MavenUtil.isInModalContext()) { suspend(); } } }); }
private void processClose() { if (Registry.getInstance().isRestartNeeded()) { final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication(); final ApplicationInfo info = ApplicationInfo.getInstance(); final int r = Messages.showOkCancelDialog(myContent, "You need to restart " + info.getVersionName() + " for the changes to take effect", "Restart Required", (app.isRestartCapable() ? "Restart Now" : "Shutdown Now"), (app.isRestartCapable() ? "Restart Later": "Shutdown Later") , Messages.getQuestionIcon()); if (r == 0) { LaterInvocator.invokeLater(new Runnable() { @Override public void run() { app.restart(true); } }, ModalityState.NON_MODAL); } } }
public void makeModalAware(Project project) { MavenUtil.invokeAndWait(project, new Runnable() { public void run() { final ModalityStateListener listener = new ModalityStateListener() { public void beforeModalityStateChanged(boolean entering) { if (entering) { suspend(); } else { resume(); } } }; LaterInvocator.addModalityStateListener(listener, MavenMergingUpdateQueue.this); if (MavenUtil.isInModalContext()) { suspend(); } } }); }
private static ListPopupStep buildStep(@Nonnull final List<Pair<AnAction, KeyStroke>> actions, final DataContext ctx) { return new BaseListPopupStep<Pair<AnAction, KeyStroke>>("Choose an action", ContainerUtil.findAll(actions, pair -> { final AnAction action = pair.getFirst(); final Presentation presentation = action.getTemplatePresentation().clone(); AnActionEvent event = new AnActionEvent(null, ctx, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0); ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, event, true); return presentation.isEnabled() && presentation.isVisible(); })) { @Override public PopupStep onChosen(Pair<AnAction, KeyStroke> selectedValue, boolean finalChoice) { invokeAction(selectedValue.getFirst(), ctx); return FINAL_CHOICE; } }; }
private void fillMenu() { DataContext context; boolean mayContextBeInvalid; if (myContext != null) { context = myContext; mayContextBeInvalid = false; } else { @SuppressWarnings("deprecation") DataContext contextFromFocus = DataManager.getInstance().getDataContext(); context = contextFromFocus; if (context.getData(PlatformDataKeys.CONTEXT_COMPONENT) == null) { IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, this); context = DataManager.getInstance().getDataContext(IdeFocusManager.getGlobalInstance().getLastFocusedFor(frame)); } mayContextBeInvalid = true; } Utils.fillMenu(myGroup.getAction(), this, myMnemonicEnabled, myPresentationFactory, context, myPlace, true, mayContextBeInvalid, LaterInvocator.isInModalContext()); }
public void testRenameFileWithoutDir() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); PsiFile psiFile = fileManager.findFile(file); PlatformTestUtil.tryGcSoftlyReachableObjects(); if (((FileManagerImpl)fileManager).getCachedDirectory(myPrjDir1) != null) { Processor<PsiDirectory> isReallyLeak = new Processor<PsiDirectory>() { @Override public boolean process(PsiDirectory directory) { return directory.getVirtualFile().equals(myPrjDir1); } }; LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiDirectory.class, isReallyLeak); LeakHunter.checkLeak(IdeEventQueue.getInstance(), PsiDirectory.class, isReallyLeak); LeakHunter.checkLeak(LaterInvocator.getLaterInvocatorQueue(), PsiDirectory.class, isReallyLeak); String dumpPath = FileUtil.createTempFile( new File(System.getProperty("teamcity.build.tempDir", System.getProperty("java.io.tmpdir"))), "testRenameFileWithoutDir", ".hprof", false, false).getPath(); MemoryDumpHelper.captureMemoryDump(dumpPath); System.out.println(dumpPath); assertNull(((FileManagerImpl)fileManager).getCachedDirectory(myPrjDir1)); fail("directory just died"); } EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); file.rename(null, "b.txt"); String string = listener.getEventsString(); String expected = "beforePropertyChange fileName\n" + "propertyChanged fileName\n"; assertEquals(psiFile.getName(), expected, string); }
@NotNull public static WindowWrapper.Mode getWindowMode(@NotNull DiffDialogHints hints) { WindowWrapper.Mode mode = hints.getMode(); if (mode == null) { boolean isUnderDialog = LaterInvocator.isInModalContext(); mode = isUnderDialog ? WindowWrapper.Mode.MODAL : WindowWrapper.Mode.FRAME; } return mode; }
@Override public void initComponent() { ModalityStateListener myModalityStateListener = new ModalityStateListener() { @Override public void beforeModalityStateChanged(boolean entering) { for (Editor editor : myEditors) { ((EditorImpl)editor).beforeModalityStateChanged(); } } }; LaterInvocator.addModalityStateListener(myModalityStateListener, ApplicationManager.getApplication()); }
@Override public AWTEvent peekEvent() { AWTEvent event = super.peekEvent(); if (event != null) { return event; } if (isTestMode() && LaterInvocator.ensureFlushRequested()) { return super.peekEvent(); } return null; }
@Override protected void tearDown() throws Exception { Object[] entities = LaterInvocator.getCurrentModalEntities(); for (int i = entities.length - 1; i >= 0; i--) { Object state = entities[i]; LaterInvocator.leaveModal(state); } super.tearDown(); }
public void testModalityStateAny() { assertReady(null); myMonitor.addActivity(new UiActivity("non_modal_1"), ModalityState.any()); assertBusy(null); try { LaterInvocator.enterModal("dialog"); assertBusy(null); } finally { LaterInvocator.leaveModal("dialog"); } }
protected void updateModel(DataContext dataContext) { if (LaterInvocator.isInModalContext() || (updated && !isFixedComponent)) return; if (PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext) instanceof NavBarPanel) return; PsiElement psiElement = CommonDataKeys.PSI_FILE.getData(dataContext); if (psiElement == null) { psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext); } psiElement = normalize(psiElement); if (!myModel.isEmpty() && myModel.get(myModel.size() - 1).equals(psiElement) && !myChanged) return; if (psiElement != null && psiElement.isValid()) { updateModel(psiElement); } else { if (UISettings.getInstance().SHOW_NAVIGATION_BAR && !myModel.isEmpty()) return; Object root = calculateRoot(dataContext); if (root != null) { setModel(Collections.singletonList(root)); } } setChanged(false); updated = true; }
@Override protected void prepareShowDialog() { if (myRunnable != null) { LaterInvocator.invokeLater(myRunnable, getModalityState()); } showDialog(); }
protected void updateModel(DataContext dataContext) { if (LaterInvocator.isInModalContext() || (updated && !isFixedComponent)) return; if (PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext) instanceof NavBarPanel) return; PsiElement psiElement = LangDataKeys.PSI_FILE.getData(dataContext); if (psiElement == null) { psiElement = LangDataKeys.PSI_ELEMENT.getData(dataContext); } psiElement = normalize(psiElement); if (!myModel.isEmpty() && myModel.get(myModel.size() - 1).equals(psiElement) && !myChanged) return; if (psiElement != null && psiElement.isValid()) { updateModel(psiElement); } else { if (UISettings.getInstance().SHOW_NAVIGATION_BAR && !myModel.isEmpty()) return; Object moduleOrProject = LangDataKeys.MODULE.getData(dataContext); if (moduleOrProject == null) { moduleOrProject = PlatformDataKeys.PROJECT.getData(dataContext); } if (moduleOrProject != null) { setModel(Collections.singletonList(moduleOrProject)); } } setChanged(false); updated = true; }
@Nonnull public static WindowWrapper.Mode getWindowMode(@Nonnull DiffDialogHints hints) { WindowWrapper.Mode mode = hints.getMode(); if (mode == null) { boolean isUnderDialog = LaterInvocator.isInModalContext(); mode = isUnderDialog ? WindowWrapper.Mode.MODAL : WindowWrapper.Mode.FRAME; } return mode; }
public void testModalityState() { assumeFalse("Test cannot be run in headless environment", GraphicsEnvironment.isHeadless()); assertTrue(ApplicationManager.getApplication() instanceof ApplicationImpl); assertTrue(ApplicationManager.getApplication().isDispatchThread()); assertReady(null); myMonitor.addActivity(new UiActivity("non_modal_1"), ModalityState.NON_MODAL); assertBusy(null); Dialog dialog = new Dialog(new Dialog((Window)null), "d", true); LaterInvocator.enterModal(dialog); try { assertReady(null); myMonitor.addActivity(new UiActivity("non_modal2"), ModalityState.NON_MODAL); assertReady(null); ModalityState m1 = ApplicationManager.getApplication().getModalityStateForComponent(dialog); myMonitor.addActivity(new UiActivity("modal_1"), m1); assertBusy(null); Dialog popup = new Dialog(dialog, "popup", true); LaterInvocator.enterModal(popup); ModalityState m2 = ApplicationManager.getApplication().getModalityStateForComponent(popup); LaterInvocator.leaveModal(popup); assertTrue("m1: "+m1+"; m2:"+m2, m2.dominates(m1)); myMonitor.addActivity(new UiActivity("modal_2"), m2); assertBusy(null); } finally { LaterInvocator.leaveModal(dialog); } assertBusy(null); }
@Override public void addNotify() { super.addNotify(); if (myPresentationListener == null) { myPresentation.addPropertyChangeListener(myPresentationListener = this::presentationPropertyChanded); } AnActionEvent e = AnActionEvent.createFromInputEvent(null, myPlace, myPresentation, getDataContext(), false, true); ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), myAction, e, false); updateToolTipText(); updateIcon(); }
@Override public void show(final Component component, int x, int y) { if (!component.isShowing()) { //noinspection HardCodedStringLiteral throw new IllegalArgumentException("component must be shown on the screen"); } removeAll(); // Fill menu. Only after filling menu has non zero size. int x2 = Math.max(0, Math.min(x, component.getWidth() - 1)); // fit x into [0, width-1] int y2 = Math.max(0, Math.min(y, component.getHeight() - 1)); // fit y into [0, height-1] myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2); Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false, LaterInvocator.isInModalContext()); if (getComponentCount() == 0) { return; } if (myApp != null) { if (myApp.isActive()) { Component frame = UIUtil.findUltimateParent(component); if (frame instanceof IdeFrame) { myFrame = (IdeFrame)frame; } myConnection = myApp.getMessageBus().connect(); myConnection.subscribe(ApplicationActivationListener.TOPIC, ActionPopupMenuImpl.this); } } super.show(component, x, y); }
@Override public void initComponent() { ModalityStateListener myModalityStateListener = entering -> { for (Editor editor : myEditors) { ((EditorImpl)editor).beforeModalityStateChanged(); } }; LaterInvocator.addModalityStateListener(myModalityStateListener, ApplicationManager.getApplication()); }
@Nonnull private Presentation updateActionItem(@Nonnull ActionItem actionItem) { AnAction action = actionItem.getAction(); Presentation presentation = new Presentation(); presentation.setDescription(action.getTemplatePresentation().getDescription()); final AnActionEvent actionEvent = new AnActionEvent(null, DataManager.getInstance().getDataContext(myComponent), myActionPlace, presentation, ActionManager.getInstance(), 0); actionEvent.setInjectedContext(action.isInInjectedContext()); ActionUtil.performDumbAwareUpdate(LaterInvocator.isInModalContext(), action, actionEvent, false); return presentation; }
@Nonnull public static List<AnAction> registerUnversionedActionsShortcuts(@Nonnull DataContext dataContext, @Nonnull JComponent component) { ActionManager manager = ActionManager.getInstance(); List<AnAction> actions = ContainerUtil.newArrayList(); Utils.expandActionGroup(LaterInvocator.isInModalContext(), getUnversionedActionGroup(), actions, new PresentationFactory(), dataContext, "", manager); for (AnAction action : actions) { action.registerCustomShortcutSet(action.getShortcutSet(), component); } return actions; }
protected void updateModel(DataContext dataContext) { if (LaterInvocator.isInModalContext() || (updated && !isFixedComponent)) return; if (dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof NavBarPanel) return; PsiElement psiElement = dataContext.getData(CommonDataKeys.PSI_FILE); if (psiElement == null) { psiElement = dataContext.getData(CommonDataKeys.PSI_ELEMENT); } psiElement = normalize(psiElement); if (!myModel.isEmpty() && myModel.get(myModel.size() - 1).equals(psiElement) && !myChanged) return; if (psiElement != null && psiElement.isValid()) { updateModel(psiElement); } else { if (UISettings.getInstance().getShowNavigationBar() && !myModel.isEmpty()) return; Object root = calculateRoot(dataContext); if (root != null) { setModel(Collections.singletonList(root)); } } setChanged(false); updated = true; }
public static boolean isInModalContext() { if (isNoBackgroundMode()) return false; return LaterInvocator.isInModalContext(); }
public Result doFix(@NotNull final Editor editor, boolean allowPopup, final boolean allowCaretNearRef) { List<PsiClass> classesToImport = getClassesToImport(); if (classesToImport.isEmpty()) return Result.POPUP_NOT_SHOWN; try { String name = getQualifiedName(myElement); if (name != null) { Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN); Matcher matcher = pattern.matcher(name); if (matcher.matches()) { return Result.POPUP_NOT_SHOWN; } } } catch (PatternSyntaxException e) { //ignore } final PsiFile psiFile = myElement.getContainingFile(); if (classesToImport.size() > 1) { reduceSuggestedClassesBasedOnDependencyRuleViolation(psiFile, classesToImport); } PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]); final Project project = myElement.getProject(); CodeInsightUtil.sortIdenticalShortNameClasses(classes, myRef); final QuestionAction action = createAddImportAction(classes, project, editor); boolean canImportHere = true; if (classes.length == 1 && (canImportHere = canImportHere(allowCaretNearRef, editor, psiFile, classes[0].getName())) && (FileTypeUtils.isInServerPageFile(psiFile) ? CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY : CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY) && (ApplicationManager.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(psiFile)) && !autoImportWillInsertUnexpectedCharacters(classes[0]) && !LaterInvocator.isInModalContext() ) { CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { @Override public void run() { action.execute(); } }); return Result.CLASS_AUTO_IMPORTED; } if (allowPopup && canImportHere) { String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName()); if (!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) { HintManager.getInstance().showQuestionHint(editor, hintText, getStartOffset(myElement, myRef), getEndOffset(myElement, myRef), action); } return Result.POPUP_SHOWN; } return Result.POPUP_NOT_SHOWN; }
private void doEnterModality() { if (!myModalityEntered) { LaterInvocator.enterModal(this); myModalityEntered = true; } }
private void doExitModality() { if (myModalityEntered) { myModalityEntered = false; LaterInvocator.leaveModal(this); } }
@Override public Object[] getCurrentModalEntities() { return LaterInvocator.getCurrentModalEntities(); }
@Override public ActionCallback show() { LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only"); if (myTypeAheadCallback != null) { IdeFocusManager.getInstance(myProject).typeAheadUntil(myTypeAheadCallback); } LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only"); final ActionCallback result = new ActionCallback(); final AnCancelAction anCancelAction = new AnCancelAction(); final JRootPane rootPane = getRootPane(); anCancelAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, rootPane); myDisposeActions.add(new Runnable() { @Override public void run() { anCancelAction.unregisterCustomShortcutSet(rootPane); } }); if (!myCanBeParent && myWindowManager != null) { myWindowManager.doNotSuggestAsParent(myDialog.getWindow()); } final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null; final boolean appStarted = commandProcessor != null; boolean changeModalityState = appStarted && myDialog.isModal() && !isProgressDialog(); // ProgressWindow starts a modality state itself if (changeModalityState) { commandProcessor.enterModal(); LaterInvocator.enterModal(myDialog); } if (appStarted) { hidePopupsIfNeeded(); } try { myDialog.show(); } finally { if (changeModalityState) { commandProcessor.leaveModal(); LaterInvocator.leaveModal(myDialog); } myDialog.getFocusManager().doWhenFocusSettlesDown(result.createSetDoneRunnable()); } return result; }
public void installListener() { LaterInvocator.addModalityStateListener(this, this); }
private boolean canSyncOrSave() { return !LaterInvocator.isInModalContext() && !myProgressManager.hasModalProgressIndicator(); }
public void testCommitDocumentInModalDialog() throws IOException { VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc")); PsiFile psiFile = getPsiManager().findFile(vFile); final Document document = getPsiDocumentManager().getDocument(psiFile); final DialogWrapper dialog = new DialogWrapper(getProject()) { @Nullable @Override protected JComponent createCenterPanel() { return null; } }; disposeOnTearDown(new Disposable() { @Override public void dispose() { dialog.close(DialogWrapper.OK_EXIT_CODE); } }); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // commit thread is paused document.setText("xx"); LaterInvocator.enterModal(dialog); } }); assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState()); long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < 10000) { UIUtil.dispatchAllInvocationEvents(); // must not be committed until exit modal dialog assertFalse(getPsiDocumentManager().isCommitted(document)); } LaterInvocator.leaveModal(dialog); assertEquals(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState()); start = System.currentTimeMillis(); // must committ while (System.currentTimeMillis() - start < 10000 && !getPsiDocumentManager().isCommitted(document)) { UIUtil.dispatchAllInvocationEvents(); } assertTrue(getPsiDocumentManager().isCommitted(document)); // check that inside modal dialog commit is possible ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // commit thread is paused LaterInvocator.enterModal(dialog); document.setText("yyy"); } }); assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState()); // must committ while (System.currentTimeMillis() - start < 10000 && !getPsiDocumentManager().isCommitted(document)) { UIUtil.dispatchAllInvocationEvents(); } assertTrue(getPsiDocumentManager().isCommitted(document)); LaterInvocator.leaveModal(dialog); }
public RollbackChangesDialog(final Project project, List<LocalChangeList> changeLists, final List<Change> changes, final boolean refreshSynchronously, final Runnable afterVcsRefreshInAwt) { super(project, true); myProject = project; myRefreshSynchronously = refreshSynchronously; myAfterVcsRefreshInAwt = afterVcsRefreshInAwt; myInvokedFromModalContext = LaterInvocator.isInModalContext(); myInfoCalculator = new ChangeInfoCalculator(); myCommitLegendPanel = new CommitLegendPanel(myInfoCalculator); myListChangeListener = new Runnable() { @Override public void run() { if (myBrowser != null) { myInfoCalculator.update(new ArrayList<Change>(myBrowser.getAllChanges()), new ArrayList<Change>(myBrowser.getChangesIncludedInAllLists())); myCommitLegendPanel.update(); Collection<Change> selected = myBrowser.getChangesIncludedInAllLists(); List<Change> visibleSelected = myBrowser.getCurrentIncludedChanges(); if (selected.size() != visibleSelected.size()) { setErrorText("Selection contains changes from other changelist"); } else { setErrorText(null); } } } }; myBrowser = new MultipleChangeListBrowser(project, changeLists, changes, getDisposable(), null, true, true, myListChangeListener, myListChangeListener); myOperationName = operationNameByChanges(project, changes); setOKButtonText(myOperationName); myOperationName = UIUtil.removeMnemonic(myOperationName); setTitle(VcsBundle.message("changes.action.rollback.custom.title", myOperationName)); setCancelButtonText(CommonBundle.getCloseButtonText()); myBrowser.setToggleActionTitle("&Include in " + myOperationName.toLowerCase()); for (Change c : changes) { if (c.getType() == Change.Type.NEW) { myDeleteLocallyAddedFiles = new JCheckBox(VcsBundle.message("changes.checkbox.delete.locally.added.files")); myDeleteLocallyAddedFiles.setSelected(PropertiesComponent.getInstance().isTrueValue(DELETE_LOCALLY_ADDED_FILES_KEY)); myDeleteLocallyAddedFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final boolean value = myDeleteLocallyAddedFiles.isSelected(); PropertiesComponent.getInstance().setValue(DELETE_LOCALLY_ADDED_FILES_KEY, String.valueOf(value)); } }); break; } } init(); myListChangeListener.run(); }
public Result doFix(@NotNull final Editor editor, boolean allowPopup, final boolean allowCaretNearRef) { List<PsiClass> classesToImport = getClassesToImport(); if (classesToImport.isEmpty()) return Result.POPUP_NOT_SHOWN; try { String name = getQualifiedName(myElement); if (name != null) { Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN); Matcher matcher = pattern.matcher(name); if (matcher.matches()) { return Result.POPUP_NOT_SHOWN; } } } catch (PatternSyntaxException e) { //ignore } final PsiFile psiFile = myElement.getContainingFile(); if (classesToImport.size() > 1) { reduceSuggestedClassesBasedOnDependencyRuleViolation(psiFile, classesToImport); } PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]); final Project project = myElement.getProject(); CodeInsightUtil.sortIdenticalShortNameClasses(classes, myRef); final QuestionAction action = createAddImportAction(classes, project, editor); DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); boolean canImportHere = true; if (classes.length == 1 && (canImportHere = canImportHere(allowCaretNearRef, editor, psiFile, classes[0].getName())) && (JspPsiUtil.isInJspFile(psiFile) ? CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY : CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY) && (ApplicationManager.getApplication().isUnitTestMode() || codeAnalyzer.canChangeFileSilently(psiFile)) && !autoImportWillInsertUnexpectedCharacters(classes[0]) && !LaterInvocator.isInModalContext() ) { CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { @Override public void run() { action.execute(); } }); return Result.CLASS_AUTO_IMPORTED; } if (allowPopup && canImportHere) { String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName()); if (!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) { HintManager.getInstance().showQuestionHint(editor, hintText, getStartOffset(myElement, myRef), getEndOffset(myElement, myRef), action); } return Result.POPUP_SHOWN; } return Result.POPUP_NOT_SHOWN; }
public void projectOpened() { //myFocusWatcher.install(myWindows.getComponent ()); getMainSplitters().startListeningFocus(); MessageBusConnection connection = myProject.getMessageBus().connect(myProject); final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject); if (fileStatusManager != null) { /** * Updates tabs colors */ final MyFileStatusListener myFileStatusListener = new MyFileStatusListener(); fileStatusManager.addFileStatusListener(myFileStatusListener, myProject); } connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener()); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootsListener()); /** * Updates tabs names */ final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener(); VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener, myProject); /** * Extends/cuts number of opened tabs. Also updates location of tabs. */ final MyUISettingsListener myUISettingsListener = new MyUISettingsListener(); UISettings.getInstance().addUISettingsListener(myUISettingsListener, myProject); StartupManager.getInstance(myProject).registerPostStartupActivity(new DumbAwareRunnable() { public void run() { setTabsMode(UISettings.getInstance().EDITOR_TAB_PLACEMENT != UISettings.TABS_NONE); ToolWindowManager.getInstance(myProject).invokeLater(new Runnable() { public void run() { CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { public void run() { LaterInvocator.invokeLater(new Runnable() { public void run() { long currentTime = System.nanoTime(); Long startTime = myProject.getUserData(ProjectImpl.CREATION_TIME); if (startTime != null) { LOG.info("Project opening took " + (currentTime - startTime.longValue()) / 1000000 + " ms"); PluginManager.dumpPluginClassStatistics(); } } }); // group 1 } }, "", null); } }); } }); }