private void connectToMessageBus(Project project) { logger.info("Connecting to message bus."); MessageBusConnection bus = project.getMessageBus().connect(); bus.setDefaultHandler( (method, objects) -> { logger.info("Method call observed in message bus."); for (Object object : objects) { if (method.toString().toLowerCase().contains("contentselected")) { if (object.toString().toLowerCase().contains("debug")) { new ButtonInputListener().receiveDebugRunAction(); } else if (object.toString().contains("DefaultRunExecutor")) { new ButtonInputListener().receiveRunAction(); } } } }); logger.info("Subscribing to RunContentManager topic."); bus.subscribe(RunContentManager.TOPIC); }
public ExternalAnnotationsManagerImpl(@NotNull final Project project, final PsiManager psiManager) { super(psiManager); myBus = project.getMessageBus(); final MessageBusConnection connection = myBus.connect(project); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { dropCache(); } }); final MyVirtualFileListener fileListener = new MyVirtualFileListener(); VirtualFileManager.getInstance().addVirtualFileListener(fileListener); Disposer.register(myPsiManager.getProject(), new Disposable() { @Override public void dispose() { VirtualFileManager.getInstance().removeVirtualFileListener(fileListener); } }); }
public void install() { final MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void selectionChanged(@NotNull FileEditorManagerEvent event) { final FileEditor editor = event.getNewEditor(); if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) { myAlarm.cancelAllRequests(); myAlarm.addRequest(new Runnable() { @Override public void run() { selectElementFromEditor(editor); } }, getAlarmDelay(), getModalityState()); } } }); }
@Override public void projectOpened() { final ModuleRootListener rootListener = new ModuleRootAdapter() { public void rootsChanged(ModuleRootEvent event) { if (!myProject.isDisposed()) { checkToolWindowStatuses(myProject); } } }; StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() { public void run() { if (!myProject.isDisposed()) { checkToolWindowStatuses(myProject); final MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(ProjectTopics.PROJECT_ROOTS, rootListener); } } }); }
public EditorNotificationsImpl(Project project) { super(project); myUpdateMerger = new MergingUpdateQueue("EditorNotifications update merger", 100, true, null, project); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { updateNotifications(file); } }); connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { @Override public void enteredDumbMode() { updateAllNotifications(); } @Override public void exitDumbMode() { updateAllNotifications(); } }); }
private LibNotifyWrapper() { myLibNotify = (LibNotify)Native.loadLibrary("libnotify.so.4", LibNotify.class); String appName = ApplicationNamesInfo.getInstance().getProductName(); if (myLibNotify.notify_init(appName) == 0) { throw new IllegalStateException("notify_init failed"); } String icon = AppUIUtil.findIcon(PathManager.getBinPath()); myIcon = icon != null ? icon : "dialog-information"; MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { @Override public void appClosing() { synchronized (myLock) { myDisposed = true; myLibNotify.notify_uninit(); } } }); }
public void scheduleInitialVfsRefresh() { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; markContentRootsForRefresh(); Application app = ApplicationManager.getApplication(); if (!app.isHeadlessEnvironment()) { final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener.Adapter() { @Override public void afterProjectClosed(@NotNull Project project) { RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } } }); }
@Override public void projectOpened() { MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); } }, ModalityState.NON_MODAL); } }); final WolfTheProblemSolver.ProblemListener myProblemListener = new MyProblemListener(); WolfTheProblemSolver.getInstance(myProject).addProblemListener(myProblemListener,myProject); }
static void unsubscribeFrom(NavBarPanel panel) { final NavBarListener listener = (NavBarListener)panel.getClientProperty(LISTENER); panel.putClientProperty(LISTENER, null); if (listener != null) { final Project project = panel.getProject(); KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener); FileStatusManager.getInstance(project).removeFileStatusListener(listener); PsiManager.getInstance(project).removePsiTreeChangeListener(listener); WolfTheProblemSolver.getInstance(project).removeProblemListener(listener); ActionManager.getInstance().removeAnActionListener(listener); final MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS); panel.putClientProperty(BUS, null); if (connection != null) { connection.disconnect(); } LafManager.getInstance().removeLafManagerListener(listener); } }
@Override public void initFacet() { MessageBusConnection connection = getModule().getMessageBus().connect(this); connection.subscribe(PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (!isDisposed()) { PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments(); updateConfiguration(); } } }); } }); updateConfiguration(); }
@Override public void initFacet() { MessageBusConnection connection = getModule().getMessageBus().connect(this); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (!isDisposed()) { PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments(); updateConfiguration(); } } }); } }); updateConfiguration(); }
/** * There's a bug in the ModuleClassLoader's cache implementation, which results in crashes during preview rendering. The workaround is * to clear the cache on each build. This registers a build complete listener to trigger the cache refresh. */ private void registerSyncListenerIfNecessary() { if (myBuildCompleteListener != null) { return; } myBuildCompleteListener = new GradleBuildListener() { @Override public void buildFinished(@NotNull Project builtProject, @Nullable BuildMode mode) { if (mode == null || builtProject != myProject) { return; } switch (mode) { case CLEAN: case ASSEMBLE: case COMPILE_JAVA: case REBUILD: ModuleClassLoader.clearCache(); clearCache(); case SOURCE_GEN: case ASSEMBLE_TRANSLATE: } } }; MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(GRADLE_BUILD_TOPIC, myBuildCompleteListener); }
/** * Registers an callback that gets notified when the IDE is closing. */ private static void registerAppClosing() { Application app = ApplicationManager.getApplication(); MessageBusConnection connection = app.getMessageBus().connect(app); connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { @Override public void appClosing() { try { stopAllGradleDaemons(false); } catch (IOException e) { LOG.info("Failed to stop Gradle daemons", e); } } }); }
public AndroidProjectTreeBuilder(@NotNull Project project, @NotNull JTree tree, @NotNull DefaultTreeModel treeModel, @Nullable Comparator<NodeDescriptor> comparator, @NotNull ProjectAbstractTreeStructureBase treeStructure) { super(project, tree, treeModel, comparator, treeStructure); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent e : events) { if (e instanceof VFileDeleteEvent) { removeMapping(e.getFile()); } } } }); }
public IdeaDecompiler() { Application app = ApplicationManager.getApplication(); myLegalNoticeAccepted = app.isUnitTestMode() || PropertiesComponent.getInstance().isValueSet(LEGAL_NOTICE_KEY); if (!myLegalNoticeAccepted) { MessageBusConnection connection = app.getMessageBus().connect(app); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (file.getFileType() == StdFileTypes.CLASS) { FileEditor editor = source.getSelectedEditor(file); if (editor instanceof TextEditor) { CharSequence text = ((TextEditor)editor).getEditor().getDocument().getImmutableCharSequence(); if (StringUtil.startsWith(text, BANNER)) { showLegalNotice(source.getProject(), file); } } } } }); } }
protected GradleToolWindowPanel(@NotNull Project project, @NotNull String place) { super(true); myProject = project; myPlace = place; setContent(myContent); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(GradleSettingsListener.TOPIC, new GradleSettingsListenerAdapter() { // TODO den implement // @Override public void onLinkedProjectConfigChange(@Nullable String oldPath, @Nullable String newPath) { // if (StringUtil.isEmpty(newPath)) { // myLayout.show(myContent, NON_LINKED_CARD_NAME); // return; // } // if (StringUtil.isEmpty(oldPath) && !StringUtil.isEmpty(newPath)) { // myLayout.show(myContent, CONTENT_CARD_NAME); // } // } }); }
public void makeDumbAware(final Project project) { AccessToken accessToken = ReadAction.start(); try { MessageBusConnection connection = project.getMessageBus().connect(this); connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { @Override public void enteredDumbMode() { suspend(); } @Override public void exitDumbMode() { resume(); } }); if (DumbService.getInstance(project).isDumb()) { suspend(); } } finally { accessToken.finish(); } }
protected boolean getWithActive(SvnAuthenticationManager active) throws SVNException { MessageBusConnection connection = null; try { final Project project = myVcs.getProject(); connection = project.getMessageBus().connect(project); connection.subscribe(SvnAuthenticationManager.AUTHENTICATION_PROVIDER_LISTENER, new MyAuthenticationProviderListener()); makeAuthCall(active); } finally { if (connection != null) { connection.disconnect(); } } return afterAuthCall(); }
private void upgradeIfNeeded(final MessageBus bus) { final MessageBusConnection connection = bus.connect(); connection.subscribe(ChangeListManagerImpl.LISTS_LOADED, new LocalChangeListsLoadedListener() { @Override public void processLoadedLists(final List<LocalChangeList> lists) { if (lists.isEmpty()) return; try { ChangeListManager.getInstance(myProject).setReadOnly(SvnChangeProvider.ourDefaultListName, true); if (!myConfiguration.changeListsSynchronized()) { processChangeLists(lists); } } catch (ProcessCanceledException e) { // } finally { myConfiguration.upgrade(); } connection.disconnect(); } }); }
public void installListeners() { LOG.info("installListeners " + project.getName()); // Listen for .stg file saves VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener); // Listen for editor window changes MessageBusConnection msgBus = project.getMessageBus().connect(project); msgBus.subscribe( FileEditorManagerListener.FILE_EDITOR_MANAGER, myFileEditorManagerListener ); // Listen for editor creation and release so that we can install // keyboard listeners that notify us when to reanalyze the file. // listener should be removed by Intellij when project is disposed // per doc. EditorFactory factory = EditorFactory.getInstance(); factory.addEditorFactoryListener(new MyEditorFactoryListener(), project); }
private void doViewSwitch(@NotNull ExternalSystemTaskId id, @NotNull String projectPath) { Project ideProject = id.findProject(); if (ideProject == null) { return; } // Disable zooming on subsequent project resolves/refreshes, // i.e. a project that already has existing modules, because it may zoom at a module // that is going to be replaced by the current resolve. if (ModuleManager.getInstance(ideProject).getModules().length > 0) { return; } MessageBusConnection messageBusConnection = ideProject.getMessageBus().connect(); messageBusConnection.subscribe( ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override public void rootsChanged(ModuleRootEvent event) { // Initiate view switch only when project modules have been created. new ViewSwitchProcessor(ideProject, projectPath).asyncViewSwitch(); } } ); }
@Override public void projectOpened() { super.projectOpened(); if (myProject.isDefault() || !PantsUtil.isPantsProject(myProject)) { return; } final MessageBusConnection connection = myProject.getMessageBus().connect(this); connection.subscribe( ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { @Override public void rootsChanged(ModuleRootEvent event) { myProjectRoots = null; } } ); }
@Override public void projectOpened() { MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (myProject.isDisposed() || !DirectoryIndex.getInstance(myProject).isInitialized()) return; VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty(); } }, ModalityState.NON_MODAL); } }); final WolfTheProblemSolver.ProblemListener myProblemListener = new MyProblemListener(); WolfTheProblemSolver.getInstance(myProject).addProblemListener(myProblemListener,myProject); }
TodoView(Project project, ProjectLevelVcsManager manager){ myProject=project; myVCSManager = manager; myCurrentPanelSettings=new TodoPanelSettings(); myAllPanelSettings=new TodoPanelSettings(); myChangeListTodosPanelSettings = new TodoPanelSettings(); myPanels = new ArrayList<TodoPanel>(); myNotAddedContent = new ArrayList<Content>(); myVCSManager.addVcsListener(myVcsListener); final MyPropertyChangeListener myPropertyChangeListener = new MyPropertyChangeListener(); TodoConfiguration.getInstance().addPropertyChangeListener(myPropertyChangeListener,this); MessageBusConnection connection = myProject.getMessageBus().connect(this); connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener()); }
static void unsubscribeFrom(NavBarPanel panel) { final NavBarListener listener = (NavBarListener)panel.getClientProperty(LISTENER); panel.putClientProperty(LISTENER, null); if (listener != null) { final Project project = panel.getProject(); KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener); FileStatusManager.getInstance(project).removeFileStatusListener(listener); PsiManager.getInstance(project).removePsiTreeChangeListener(listener); WolfTheProblemSolver.getInstance(project).removeProblemListener(listener); ActionManager.getInstance().removeAnActionListener(listener); final MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS); panel.putClientProperty(BUS, null); if (connection != null) { connection.disconnect(); } } }
@Override public void runActivity(@NotNull final Project project) { // We want to automatically refresh linked projects on gradle service directory change. MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(GradleSettings.getInstance(project).getChangesTopic(), new GradleSettingsListenerAdapter() { @Override public void onServiceDirectoryPathChange(@Nullable String oldPath, @Nullable String newPath) { ExternalSystemUtil.refreshProjects(project, GradleConstants.SYSTEM_ID, true); } }); // We used to assume that gradle scripts are always named 'build.gradle' and kept path to that build.gradle file at ide settings. // However, it was found out that that is incorrect assumption (IDEA-109064). Now we keep paths to gradle script's directories // instead. However, we don't want to force old users to re-import gradle projects because of that. That's why we check gradle // config and re-point it from build.gradle to the parent dir if necessary. Map<String, String> adjustedPaths = patchLinkedProjects(project); if (adjustedPaths == null) { return; } GradleLocalSettings localSettings = GradleLocalSettings.getInstance(project); patchRecentTasks(adjustedPaths, localSettings); patchAvailableProjects(adjustedPaths, localSettings); patchAvailableTasks(adjustedPaths, localSettings); }
public void makeDumbAware(final Project project) { AccessToken accessToken = ReadAction.start(); try { MessageBusConnection connection = project.getMessageBus().connect(this); connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { public void enteredDumbMode() { suspend(); } public void exitDumbMode() { resume(); } }); if (DumbService.getInstance(project).isDumb()) { suspend(); } } finally { accessToken.finish(); } }
public void install() { final MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void selectionChanged(@Nonnull FileEditorManagerEvent event) { final FileEditor editor = event.getNewEditor(); if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) { myAlarm.cancelAllRequests(); myAlarm.addRequest(new Runnable() { @Override public void run() { selectElementFromEditor(editor); } }, getAlarmDelay(), getModalityState()); } } }); }
public void addRequest(@Nonnull final Runnable request, final int delay, boolean runWithActiveFrameOnly) { if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) { final MessageBus bus = ApplicationManager.getApplication().getMessageBus(); final MessageBusConnection connection = bus.connect(this); connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() { @Override public void applicationActivated(IdeFrame ideFrame) { connection.disconnect(); addRequest(request, delay); } }); } else { addRequest(request, delay); } }
public VcsLogContentProvider(@Nonnull Project project, @Nonnull VcsProjectLog projectLog) { myProject = project; myProjectLog = projectLog; MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VcsProjectLog.VCS_PROJECT_LOG_CHANGED, new VcsProjectLog.ProjectLogListener() { @Override public void logCreated() { addLogUi(); } @Override public void logDisposed() { myContainer.removeAll(); closeLogTabs(); } }); if (myProjectLog.getLogManager() != null) { addLogUi(); } }
EditorHistoryManager(@Nonnull Project project) { myProject = project; MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(UISettingsListener.TOPIC, new UISettingsListener() { @Override public void uiSettingsChanged(UISettings uiSettings) { trimToSize(); } }); connection.subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, new FileEditorManagerListener.Before.Adapter() { @Override public void beforeFileClosed(@Nonnull FileEditorManager source, @Nonnull VirtualFile file) { updateHistoryEntry(file, false); } }); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyEditorManagerListener()); }
public static void runBatchFoldingOperationOutsideOfBulkUpdate(@Nonnull Editor editor, @Nonnull Runnable operation) { DocumentEx document = ObjectUtils.tryCast(editor.getDocument(), DocumentEx.class); if (document != null && document.isInBulkUpdate()) { MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); disposeWithEditor(editor, connection); connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@Nonnull Document doc) { if (doc == editor.getDocument()) { editor.getFoldingModel().runBatchFoldingOperation(operation); connection.disconnect(); } } }); } else { editor.getFoldingModel().runBatchFoldingOperation(operation); } }
public EditorFactoryImpl(EditorActionManager editorActionManager) { Application application = ApplicationManager.getApplication(); MessageBus bus = application.getMessageBus(); MessageBusConnection connect = bus.connect(); connect.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() { @Override public void beforeProjectLoaded(@Nonnull final Project project) { // validate all editors are disposed after fireProjectClosed() was called, because it's the place where editor should be released Disposer.register(project, () -> { final Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); final boolean isLastProjectClosed = openProjects.length == 0; validateEditorsAreReleased(project, isLastProjectClosed); }); } }); ApplicationManager.getApplication().getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() { @Override public void globalSchemeChange(EditorColorsScheme scheme) { refreshAllEditors(); } }); TypedAction typedAction = editorActionManager.getTypedAction(); TypedActionHandler originalHandler = typedAction.getRawHandler(); typedAction.setupRawHandler(new MyTypedHandler(originalHandler)); }
public EditorNotificationsImpl(Project project) { myProject = project; myUpdateMerger = new MergingUpdateQueue("EditorNotifications update merger", 100, true, null, project); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(@Nonnull FileEditorManager source, @Nonnull VirtualFile file) { updateNotifications(file); } }); connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() { @Override public void enteredDumbMode() { updateAllNotifications(); } @Override public void exitDumbMode() { updateAllNotifications(); } }); }
private LibNotifyWrapper() { myLibNotify = (LibNotify)Native.loadLibrary("libnotify.so.4", LibNotify.class); String appName = ApplicationNamesInfo.getInstance().getProductName(); if (myLibNotify.notify_init(appName) == 0) { throw new IllegalStateException("notify_init failed"); } String icon = AppUIUtil.findIcon(PathManager.getAppHomeDirectory().getPath()); myIcon = icon != null ? icon : "dialog-information"; MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { synchronized (myLock) { myDisposed = true; myLibNotify.notify_uninit(); } } }); }
public void scheduleInitialVfsRefresh() { GuiUtils.invokeLaterIfNeeded(() -> { if (myProject.isDisposed() || myInitialRefreshScheduled) return; myInitialRefreshScheduled = true; ((ProjectRootManagerImpl)ProjectRootManager.getInstance(myProject)).markRootsForRefresh(); Application app = ApplicationManager.getApplication(); if (!app.isCommandLine()) { final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() { @Override public void afterProjectClosed(@Nonnull Project project) { if (project != myProject) return; RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } }, ModalityState.defaultModalityState()); }