static void subscribeTo(NavBarPanel panel) {
    if (panel.getClientProperty(LISTENER) != null) {
      unsubscribeFrom(panel);
    }

    final NavBarListener listener = new NavBarListener(panel);
    final Project project = panel.getProject();
    panel.putClientProperty(LISTENER, listener);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
    FileStatusManager.getInstance(project).addFileStatusListener(listener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);

    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    connection.subscribe(NavBarModelListener.NAV_BAR, listener);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
    panel.putClientProperty(BUS, connection);
    panel.addKeyListener(listener);

    if (panel.isInFloatingMode()) {
      final Window window = SwingUtilities.windowForComponent(panel);
      if (window != null) {
        window.addWindowFocusListener(listener);
      }
    }
  }
Ejemplo n.º 2
0
 public SolutionIdea(@NotNull Module module, SolutionDescriptor descriptor) {
   super(descriptor, null);
   myModule = module;
   // TODO: simply set solution descriptor local variable?
   setModuleDescriptor(descriptor);
   myConnection = myModule.getProject().getMessageBus().connect();
   myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener());
   myConnection.subscribe(FacetManager.FACETS_TOPIC, new MyFacetManagerAdapter());
   final ProjectLibraryTable projectLibraryTable =
       (ProjectLibraryTable) ProjectLibraryTable.getInstance(myModule.getProject());
   ModelAccess.instance()
       .runReadAction(
           new Runnable() {
             @Override
             public void run() {
               for (final Library library : projectLibraryTable.getLibraries()) {
                 if (ModuleLibraryType.isModuleLibrary(library)) {
                   library.getRootProvider().addRootSetChangedListener(myRootSetListener);
                 }
               }
               for (SModel model : getModels()) {
                 ((SModelInternal) model).addModelListener(MODEL_RUNTIME_IMPORTER);
               }
             }
           });
   projectLibraryTable.addListener(myLibrariesListener);
   addModuleListener(myModule.getProject().getComponent(PsiModelReloadListener.class));
   addModuleListener(MODULE_RUNTIME_IMPORTER);
 }
  @Override
  public void moduleAdded() {
    if (!myModuleInitialized) {
      myConnection.subscribe(
          ProjectTopics.PROJECT_ROOTS,
          new ModuleRootAdapter() {
            @Override
            public void rootsChanged(ModuleRootEvent event) {
              scheduleUpdate();
            }
          });
      myConnection.subscribe(GoLibrariesService.LIBRARIES_TOPIC, newRootUrls -> scheduleUpdate());

      Project project = myModule.getProject();
      StartupManager.getInstance(project)
          .runWhenProjectIsInitialized(
              () -> {
                if (!project.isDisposed() && !myModule.isDisposed()) {
                  for (PsiFileSystemItem vendor :
                      FilenameIndex.getFilesByName(
                          project, GoConstants.VENDOR, GoUtil.moduleScope(myModule), true)) {
                    if (vendor.isDirectory()) {
                      showVendoringNotification();
                      break;
                    }
                  }
                }
              });

      VirtualFileManager.getInstance().addVirtualFileListener(myFilesListener);
    }
    scheduleUpdate(0);
    myModuleInitialized = true;
  }
  public synchronized void start() {
    final MessageBusConnection myBusConnection = project.getMessageBus().connect(myQueue);
    myBusConnection.subscribe(
        VirtualFileManager.VFS_CHANGES,
        new BulkFileListener() {
          public void before(List<? extends VFileEvent> vFileEvents) {}

          public void after(List<? extends VFileEvent> vFileEvents) {
            for (VFileEvent vFileEvent : vFileEvents) {
              //                    if (vFileEvent instanceof VFileMoveEvent) {
              //                        if (isRelevant(vFileEvent.getPath())) {
              //                            LeiningenProject leiningenProject =
              // manager.byPath(vFileEvent.getPath());
              //                            if (leiningenProject != null) {
              //                                manager.removeLeiningenProject(leiningenProject);
              //                            }
              //
              //                            VirtualFile newProjectFile =
              // ((VFileMoveEvent)vFileEvent).getNewParent().findFileByRelativePath(((VFileMoveEvent) vFileEvent).getFile().getName());
              //                            if ( newProjectFile != null ) {
              //                                LeiningenProject newProject = new
              // LeiningenProject(newProjectFile, theProject);
              //                            }
              //                        }
              //                    }
              //                    if (vFileEvent instanceof VFileDeleteEvent) {
              //                        if (isRelevant(vFileEvent.getPath())) {
              //                            LeiningenProject leiningenProject =
              // manager.byPath(vFileEvent.getPath());
              //                            if (leiningenProject != null) {
              //                                manager.removeLeiningenProject(leiningenProject);
              //                            }
              //                        }
              //                    }
              if (vFileEvent instanceof VFileCreateEvent) {
                if (isRelevant(vFileEvent.getPath())) {
                  manager.importLeiningenProject(
                      vFileEvent.getFileSystem().findFileByPath(vFileEvent.getPath()), project);
                }
              }
            }
          }

          private boolean isRelevant(String path) {
            return path != null && path.endsWith(LeiningenConstants.PROJECT_CLJ);
          }
        });

    myBusConnection.subscribe(
        ProjectTopics.PROJECT_ROOTS,
        new ModuleRootListener() {
          public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {}

          public void rootsChanged(ModuleRootEvent moduleRootEvent) {}
        });

    myQueue.activate();
  }
  public ProjectRootManagerComponent(Project project, StartupManager startupManager) {
    super(project);

    myConnection = project.getMessageBus().connect(project);
    myConnection.subscribe(
        FileTypeManager.TOPIC,
        new FileTypeListener() {
          @Override
          public void beforeFileTypesChanged(@NotNull FileTypeEvent event) {
            beforeRootsChange(true);
          }

          @Override
          public void fileTypesChanged(@NotNull FileTypeEvent event) {
            rootsChanged(true);
          }
        });

    VirtualFileManager.getInstance()
        .addVirtualFileManagerListener(
            new VirtualFileManagerAdapter() {
              @Override
              public void afterRefreshFinish(boolean asynchronous) {
                doUpdateOnRefresh();
              }
            },
            project);

    startupManager.registerStartupActivity(
        new Runnable() {
          @Override
          public void run() {
            myStartupActivityPerformed = true;
          }
        });

    myHandler =
        new BatchUpdateListener() {
          @Override
          public void onBatchUpdateStarted() {
            myRootsChanged.levelUp();
            myFileTypesChanged.levelUp();
          }

          @Override
          public void onBatchUpdateFinished() {
            myRootsChanged.levelDown();
            myFileTypesChanged.levelDown();
          }
        };

    myConnection.subscribe(VirtualFilePointerListener.TOPIC, new MyVirtualFilePointerListener());
    myDoLogCachesUpdate =
        ApplicationManager.getApplication().isInternal()
            && !ApplicationManager.getApplication().isUnitTestMode();
  }
  @Override
  public void initComponent() {
    MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
    connection.subscribe(
        FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener());
    connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());

    MyVirtualFileListener listener = new MyVirtualFileListener();
    VirtualFileManager.getInstance().addVirtualFileListener(listener, myProject);
    UISettings.getInstance().addUISettingsListener(new MyUISettingsListener(), myProject);
  }
Ejemplo n.º 7
0
  private void activate() {

    synchronized (LOCK) {
      for (final Module mod : myModuleManager.getModules()) {

        // currently only modules with MPS facet, later should either take dependencies into account
        // or just take all modules
        if (!hasMPSFacet(mod)) continue;

        trackModule(mod, false);
      }

      // add listeners
      workerConnection = myProject.getMessageBus().connect();
      // setup add/remove module listeners (change in dependencies)
      workerConnection.subscribe(ProjectTopics.MODULES, new ModuleWatcher(myProject));
      // setup project roots listeners
      workerConnection.subscribe(
          ProjectTopics.PROJECT_ROOTS,
          new ModuleRootListener() {
            @Override
            public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
              // To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void rootsChanged(ModuleRootEvent moduleRootEvent) {
              System.out.println("ROOTS DEBUG: event");
            }
          });
      // setup create/delete files listeners
      VirtualFileManager.getInstance()
          .addVirtualFileListener(
              new VirtualFileAdapter() {
                @Override
                public void fileCreated(VirtualFileEvent event) {

                  System.out.println("VIRT FILE DEBUG: " + event.getFile().getName());

                  // check that it's java and under one of our content roots
                  // ...
                }

                @Override
                public void fileDeleted(VirtualFileEvent event) {
                  synchronized (LOCK) {
                  }
                }
              });

      myIsActivated = true;
    }
  }
  public ProjectLevelVcsManagerImpl(
      Project project,
      final FileStatusManager manager,
      MessageBus messageBus,
      final FileIndexFacade excludedFileIndex) {
    myProject = project;
    myMessageBus = messageBus;
    mySerialization = new ProjectLevelVcsManagerSerialization();
    myOptionsAndConfirmations = new OptionsAndConfirmations();

    myDefaultVcsRootPolicy = DefaultVcsRootPolicy.getInstance(project);

    myBackgroundableActionHandlerMap =
        new EnumMap<VcsBackgroundableActions, BackgroundableActionEnabledHandler>(
            VcsBackgroundableActions.class);
    myInitialization = new VcsInitialization(myProject);
    myMappings = new NewMappings(myProject, myMessageBus, this, manager);
    myMappingsToRoots = new MappingsToRoots(myMappings, myProject);

    if (!myProject.isDefault()) {
      myVcsEventListenerManager = new VcsEventsListenerManagerImpl();
    }

    myVcsHistoryCache = new VcsHistoryCache();
    myContentRevisionCache = new ContentRevisionCache();
    myConnect = myMessageBus.connect();
    myVcsFileListenerContextHelper = VcsFileListenerContextHelper.getInstance(myProject);
    VcsListener vcsListener =
        new VcsListener() {
          @Override
          public void directoryMappingChanged() {
            myVcsHistoryCache.clear();
            myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss());
          }
        };
    myExcludedIndex = excludedFileIndex;
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener);
    myConnect.subscribe(
        UpdatedFilesListener.UPDATED_FILES,
        new UpdatedFilesListener() {
          @Override
          public void consume(Set<String> strings) {
            myContentRevisionCache.clearCurrent(strings);
          }
        });
    myAnnotationLocalChangesListener = new VcsAnnotationLocalChangesListenerImpl(myProject, this);
  }
Ejemplo n.º 9
0
  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;
            SvnConfiguration.SvnSupportOptions supportOptions = null;
            try {
              ChangeListManager.getInstance(myProject)
                  .setReadOnly(SvnChangeProvider.ourDefaultListName, true);
              supportOptions = myConfiguration.getSupportOptions(myProject);

              if (!supportOptions.changeListsSynchronized()) {
                processChangeLists(lists);
              }
            } catch (ProcessCanceledException e) {
              //
            } finally {
              if (supportOptions != null) {
                supportOptions.upgrade();
              }
            }

            connection.disconnect();
          }
        });
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    MessageBusConnection connection =
        ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable);
    connection.subscribe(
        VirtualFileManager.VFS_CHANGES,
        new BulkFileListener() {
          @Override
          public void before(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, true);
          }

          @Override
          public void after(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, false);
          }

          private void checkFiles(List<? extends VFileEvent> events, boolean before) {
            for (VFileEvent event : events) {
              VirtualFile file = event.getFile();
              if (file != null) {
                boolean shouldBeInvalid =
                    event instanceof VFileCreateEvent
                            && before
                            && !((VFileCreateEvent) event).isReCreation()
                        || event instanceof VFileDeleteEvent && !before;
                assertEquals(event.toString(), !shouldBeInvalid, file.isValid());
              }
            }
          }
        });
  }
  private void startListening(
      @NotNull final List<Trinity<PsiModifierListOwner, String, Boolean>> expectedSequence) {
    myBusConnection = myProject.getMessageBus().connect();
    myBusConnection.subscribe(
        ExternalAnnotationsManager.TOPIC,
        new DefaultAnnotationsListener() {
          private int index = 0;

          @Override
          public void afterExternalAnnotationChanging(
              @NotNull PsiModifierListOwner owner,
              @NotNull String annotationFQName,
              boolean successful) {
            if (index < expectedSequence.size()
                && expectedSequence.get(index).first == owner
                && expectedSequence.get(index).second.equals(annotationFQName)
                && expectedSequence.get(index).third == successful) {
              index++;
              myExpectedEventWasProduced = true;
            } else {
              super.afterExternalAnnotationChanging(owner, annotationFQName, successful);
            }
          }
        });
  }
  @Override
  protected void setUp() throws Exception {
    LOG.debug("================== setting up " + getName() + " ==================");

    super.setUp();

    myFileSystem = LocalFileSystem.getInstance();
    assertNotNull(myFileSystem);

    myWatcher = ((LocalFileSystemImpl) myFileSystem).getFileWatcher();
    assertNotNull(myWatcher);
    assertFalse(myWatcher.isOperational());
    myWatcher.startup(myNotifier);
    assertTrue(myWatcher.isOperational());

    myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getProject());
    myTimeout = NATIVE_PROCESS_DELAY;

    myConnection = ApplicationManager.getApplication().getMessageBus().connect();
    myConnection.subscribe(
        VirtualFileManager.VFS_CHANGES,
        new BulkFileListener.Adapter() {
          @Override
          public void after(@NotNull List<? extends VFileEvent> events) {
            synchronized (myEvents) {
              myEvents.addAll(events);
            }
          }
        });

    ((LocalFileSystemImpl) myFileSystem).cleanupForNextTest();

    LOG = FileWatcher.getLog();
    LOG.debug("================== setting up " + getName() + " ==================");
  }
  public SvnCommittedChangesProvider(final Project project) {
    myProject = project;
    myVcs = SvnVcs.getInstance(myProject);
    myZipper = new MyZipper();

    myConnection = myProject.getMessageBus().connect();

    myConnection.subscribe(
        VcsConfigurationChangeListener.BRANCHES_CHANGED_RESPONSE,
        new VcsConfigurationChangeListener.DetailedNotification() {
          public void execute(
              final Project project,
              final VirtualFile vcsRoot,
              final List<CommittedChangeList> cachedList) {
            ApplicationManager.getApplication()
                .invokeLater(
                    new Runnable() {
                      public void run() {
                        if (project.isDisposed()) {
                          return;
                        }
                        for (CommittedChangeList committedChangeList : cachedList) {
                          if ((committedChangeList instanceof SvnChangeList)
                              && ((vcsRoot == null)
                                  || (vcsRoot.equals(
                                      ((SvnChangeList) committedChangeList).getVcsRoot())))) {
                            ((SvnChangeList) committedChangeList).forceReloadCachedInfo(true);
                          }
                        }
                      }
                    });
          }
        });
  }
Ejemplo n.º 14
0
    public boolean canCloseProject(final Project project) {
      assert project != null;
      if (!project.equals(myProject)) {
        return true;
      }
      if (shouldAskUser()) {
        int result =
            Messages.showOkCancelDialog(
                myProject,
                CompilerBundle.message("warning.compiler.running.on.project.close"),
                CompilerBundle.message("compiler.running.dialog.title"),
                Messages.getQuestionIcon());
        if (result != 0) {
          return false; // veto closing
        }
        myUserAcceptedCancel = true;

        final MessageBusConnection connection = project.getMessageBus().connect();
        connection.subscribe(
            CompilerTopics.COMPILATION_STATUS,
            new CompilationStatusAdapter() {
              public void compilationFinished(
                  boolean aborted, int errors, int warnings, final CompileContext compileContext) {
                connection.disconnect();
                ProjectUtil.closeAndDispose(project);
              }
            });
        cancel();
        return false; // cancel compiler and let it finish, after compilation close the project, but
                      // currently - veto closing
      }
      return !myIndicator.isRunning();
    }
Ejemplo n.º 15
0
 public void setProject() {
   if (!(_project instanceof DefaultProject)) {
     _failureReason = PluginFailureReason.NONE;
     _permanentProjectConnection = _project.getMessageBus().connect();
     _permanentProjectConnection.subscribe(ProjectTopics.PROJECT_ROOTS, _moduleClasspathListener);
   }
 }
  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);
          }
        });
  }
  TextEditorComponent(
      @NotNull final Project project,
      @NotNull final VirtualFile file,
      @NotNull final TextEditorImpl textEditor) {
    super(new BorderLayout(), textEditor);

    myProject = project;
    myFile = file;
    myTextEditor = textEditor;

    myDocument = FileDocumentManager.getInstance().getDocument(myFile);
    LOG.assertTrue(myDocument != null);
    myDocumentListener = new MyDocumentListener();
    myDocument.addDocumentListener(myDocumentListener);

    myEditorMouseListener = new MyEditorMouseListener();
    myEditorPropertyChangeListener = new MyEditorPropertyChangeListener();

    myConnection = project.getMessageBus().connect();
    myConnection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());

    myVirtualFileListener = new MyVirtualFileListener();
    myFile.getFileSystem().addVirtualFileListener(myVirtualFileListener);
    myEditor = createEditor();
    add(myEditor.getComponent(), BorderLayout.CENTER);
    myModified = isModifiedImpl();
    myValid = isEditorValidImpl();
    LOG.assertTrue(myValid);
  }
Ejemplo n.º 18
0
  public void initComponent() {
    log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");
    // System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");

    // Set runtime constants
    IDE_NAME = PlatformUtils.getPlatformPrefix();
    IDE_VERSION = ApplicationInfo.getInstance().getFullVersion();

    if (!Dependencies.isCLIInstalled()) {
      log.info("Downloading and installing wakatime-cli ...");
      Dependencies.installCLI();
    } else if (Dependencies.isCLIOld()) {
      log.info("Upgrading wakatime-cli ...");
      Dependencies.upgradeCLI();
    }

    if (Dependencies.isPythonInstalled()) {

      WakaTime.DEBUG = WakaTime.isDebugEnabled();
      if (WakaTime.DEBUG) {
        log.setLevel(Level.DEBUG);
        log.debug("Logging level set to DEBUG");
      }

      log.debug("Python location: " + Dependencies.getPythonLocation());
      log.debug("CLI location: " + Dependencies.getCLILocation());

      // prompt for apiKey if it does not already exist
      if (ApiKey.getApiKey().equals("")) {
        Project project = ProjectManager.getInstance().getDefaultProject();
        ApiKey apiKey = new ApiKey(project);
        apiKey.promptForApiKey();
      }
      log.debug("Api Key: " + ApiKey.getApiKey());

      // add WakaTime item to File menu
      ActionManager am = ActionManager.getInstance();
      PluginMenu action = new PluginMenu();
      am.registerAction("WakaTimeApiKey", action);
      DefaultActionGroup fileMenu = (DefaultActionGroup) am.getAction("FileMenu");
      fileMenu.addSeparator();
      fileMenu.add(action);

      // Setup message listeners
      MessageBus bus = ApplicationManager.getApplication().getMessageBus();
      connection = bus.connect();
      connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());
      EditorFactory.getInstance()
          .getEventMulticaster()
          .addDocumentListener(new CustomDocumentListener());

      log.debug("Finished initializing WakaTime plugin");

    } else {
      Messages.showErrorDialog(
          "WakaTime requires Python to be installed.\nYou can install it from https://www.python.org/downloads/\nAfter installing Python, restart your IDE.",
          "Error");
    }
  }
  @Override
  public void initComponent() {
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(
        ProjectTopics.MODULES,
        new ModuleAdapter() {
          @Override
          public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            refreshPointers(module);
          }

          @Override
          public void modulesRenamed(
              @NotNull Project project,
              @NotNull List<Module> modules,
              @NotNull Function<Module, String> oldNameProvider) {
            for (Module module : modules) {
              refreshPointers(module);
            }
          }
        });
    connection.subscribe(
        FacetManager.FACETS_TOPIC,
        new FacetManagerAdapter() {
          @Override
          public void facetAdded(@NotNull Facet facet) {
            refreshPointers(facet.getModule());
          }

          @Override
          public void beforeFacetRenamed(@NotNull Facet facet) {
            final FacetPointerImpl pointer = myPointers.get(constructId(facet));
            if (pointer != null) {
              pointer.refresh();
            }
          }

          @Override
          public void facetRenamed(@NotNull final Facet facet, @NotNull final String oldName) {
            refreshPointers(facet.getModule());
          }
        });
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
      refreshPointers(module);
    }
  }
  @Override
  protected void attachToProcess(
      @NotNull final RunConfigurationBase configuration,
      @NotNull final ProcessHandler handler,
      @Nullable RunnerSettings runnerSettings) {
    if (runnerSettings == null && isApplicableFor(configuration)) {
      final Alarm processTracesAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, null);
      final MessageBusConnection connection = configuration.getProject().getMessageBus().connect();
      connection.subscribe(
          SMTRunnerEventsListener.TEST_STATUS,
          new SMTRunnerEventsAdapter() {
            private List<String> myCompletedMethodNames = new ArrayList<String>();

            @Override
            public void onTestFinished(@NotNull SMTestProxy test) {
              final SMTestProxy.SMRootTestProxy root = test.getRoot();
              if ((root == null || root.getHandler() == handler)) {
                final String fullTestName = test.getLocationUrl();
                if (fullTestName != null
                    && fullTestName.startsWith(JavaTestLocator.TEST_PROTOCOL)) {
                  myCompletedMethodNames.add(
                      ((JavaTestConfigurationBase) configuration).getFrameworkPrefix()
                          + fullTestName.substring(JavaTestLocator.TEST_PROTOCOL.length() + 3));
                  if (myCompletedMethodNames.size() > 50) {
                    final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
                    myCompletedMethodNames.clear();
                    processTracesAlarm.addRequest(
                        new Runnable() {
                          @Override
                          public void run() {
                            processAvailableTraces(configuration, fullTestNames);
                          }
                        },
                        100);
                  }
                }
              }
            }

            @Override
            public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) {
              if (testsRoot.getHandler() == handler) {
                processTracesAlarm.cancelAllRequests();
                processTracesAlarm.addRequest(
                    new Runnable() {
                      @Override
                      public void run() {
                        processAvailableTraces(configuration);
                        Disposer.dispose(processTracesAlarm);
                      }
                    },
                    0);
                connection.disconnect();
              }
            }
          });
    }
  }
Ejemplo n.º 21
0
  @Override
  public void projectOpened() {

    if (hasMPSFacet()) {
      activate();
    }

    // track presence of MPS facet in the project
    // if none are left, we have to stop doing useless parsing work
    facetConnection.subscribe(FacetManager.FACETS_TOPIC, new MPSFacetWatcher());
  }
  public void init(ProjectPaneTree tree) {
    myTree = tree;

    myGenStatusVisitor.setUpdater(myUpdater).setExecutor(myExecutor);
    myErrorVisitor.setUpdater(myUpdater).setExecutor(myExecutor);
    myModifiedMarker.setUpdater(myUpdater).setExecutor(myExecutor);

    myTree.addTreeNodeListener(myNodeListener);

    MessageBusConnection connection = myTree.getProject().getMessageBus().connect();
    Disposer.register(myTree, connection);
    connection.subscribe(DumbService.DUMB_MODE, new MyDumbModeListener());
  }
Ejemplo n.º 23
0
  PsiChangeHandler(
      @NotNull Project project,
      @NotNull final PsiDocumentManagerImpl documentManager,
      @NotNull EditorFactory editorFactory,
      @NotNull MessageBusConnection connection,
      @NotNull FileStatusMap fileStatusMap) {
    myProject = project;
    myFileStatusMap = fileStatusMap;
    editorFactory
        .getEventMulticaster()
        .addDocumentListener(
            new DocumentAdapter() {
              @Override
              public void beforeDocumentChange(DocumentEvent e) {
                final Document document = e.getDocument();
                if (documentManager.getSynchronizer().isInSynchronization(document)) return;
                if (documentManager.getCachedPsiFile(document) == null) return;
                if (document.getUserData(UPDATE_ON_COMMIT_ENGAGED) == null) {
                  document.putUserData(UPDATE_ON_COMMIT_ENGAGED, Boolean.TRUE);
                  PsiDocumentManagerBase.addRunOnCommit(
                      document,
                      () -> {
                        if (document.getUserData(UPDATE_ON_COMMIT_ENGAGED) != null) {
                          updateChangesForDocument(document);
                          document.putUserData(UPDATE_ON_COMMIT_ENGAGED, null);
                        }
                      });
                }
              }
            },
            this);

    connection.subscribe(
        PsiDocumentTransactionListener.TOPIC,
        new PsiDocumentTransactionListener() {
          @Override
          public void transactionStarted(
              @NotNull final Document doc, @NotNull final PsiFile file) {}

          @Override
          public void transactionCompleted(
              @NotNull final Document document, @NotNull final PsiFile file) {
            updateChangesForDocument(document);
            document.putUserData(
                UPDATE_ON_COMMIT_ENGAGED,
                null); // ensure we don't call updateChangesForDocument() twice which can lead to
                       // whole file re-highlight
          }
        });
  }
Ejemplo n.º 24
0
  /* Invoked by reflection */
  TodoView(Project project, ProjectLevelVcsManager manager) {
    myProject = project;
    myVCSManager = manager;
    myCurrentPanelSettings = new TodoPanelSettings();
    myAllPanelSettings = new TodoPanelSettings();
    myChangeListTodosPanelSettings = new TodoPanelSettings();

    myVCSManager.addVcsListener(myVcsListener);

    final MyPropertyChangeListener myPropertyChangeListener = new MyPropertyChangeListener();
    TodoConfiguration.getInstance().addPropertyChangeListener(myPropertyChangeListener, this);

    MessageBusConnection connection = myProject.getMessageBus().connect(this);
    connection.subscribe(AppTopics.FILE_TYPES, new MyFileTypeListener());
  }
 public ExternalAnnotationsManagerImpl(
     @NotNull final Project project, final PsiManager psiManager) {
   super(psiManager);
   final MessageBusConnection connection = project.getMessageBus().connect(project);
   connection.subscribe(
       ProjectTopics.PROJECT_ROOTS,
       new ModuleRootAdapter() {
         @Override
         public void rootsChanged(ModuleRootEvent event) {
           myExternalAnnotations.clear();
           annotationsFileToDataAndModificationStamp.clear();
           myHasAnyAnnotationsRoots = ThreeState.UNSURE;
         }
       });
 }
Ejemplo n.º 26
0
 @Override
 public void projectOpened(final Project project) {
   final MessageBusConnection conn = project.getMessageBus().connect();
   myConnections.put(project, conn);
   conn.subscribe(
       ProjectTopics.PROJECT_ROOTS,
       new ModuleRootAdapter() {
         @Override
         public void rootsChanged(final ModuleRootEvent event) {
           final Object source = event.getSource();
           if (source instanceof Project) {
             clearState((Project) source);
           }
         }
       });
 }
 private static LightweightHint showErrorHint(Project project, Editor editor, String text) {
   final LightweightHint[] result = {null};
   final EditorHintListener listener =
       new EditorHintListener() {
         public void hintShown(
             final Project project, final LightweightHint hint, final int flags) {
           result[0] = hint;
         }
       };
   final MessageBusConnection connection = project.getMessageBus().connect();
   connection.subscribe(EditorHintListener.TOPIC, listener);
   assert text != null;
   HintManager.getInstance().showErrorHint(editor, text, HintManager.UNDER);
   connection.disconnect();
   return result[0];
 }
  private void startListeningForExternalChanges() {
    myBusConnection = myProject.getMessageBus().connect();
    myBusConnection.subscribe(
        ExternalAnnotationsManager.TOPIC,
        new DefaultAnnotationsListener() {
          private boolean notifiedOnce;

          @Override
          public void externalAnnotationsChangedExternally() {
            if (!notifiedOnce) {
              myExpectedEventWasProduced = true;
              notifiedOnce = true;
            } else {
              super.externalAnnotationsChangedExternally();
            }
          }
        });
  }
Ejemplo n.º 29
0
 private void subscribeForGrayscaleSetting() {
   MessageBusConnection settingsConnection =
       ApplicationManager.getApplication().getMessageBus().connect(this);
   MarkdownApplicationSettings.SettingsChangedListener settingsChangedListener =
       new MarkdownApplicationSettings.SettingsChangedListener() {
         @Override
         public void onSettingsChange(@NotNull final MarkdownApplicationSettings settings) {
           runInPlatformWhenAvailable(
               () -> {
                 if (myWebView != null) {
                   updateFontSmoothingType(
                       myWebView, settings.getMarkdownPreviewSettings().isUseGrayscaleRendering());
                 }
               });
         }
       };
   settingsConnection.subscribe(
       MarkdownApplicationSettings.SettingsChangedListener.TOPIC, settingsChangedListener);
 }
  GitRepositoryUpdater(GitRepository repository) {
    VirtualFile gitDir = repository.getGitDir();
    myWatchRequest = LocalFileSystem.getInstance().addRootToWatch(gitDir.getPath(), true);

    myRepositoryFiles = GitRepositoryFiles.getInstance(gitDir);
    visitGitDirVfs(gitDir);
    myHeadsDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsHeadsPath());
    myRemotesDir = VcsUtil.getVirtualFile(myRepositoryFiles.getRefsRemotesPath());

    Project project = repository.getProject();
    myUpdateQueue =
        new QueueProcessor<GitRepository.TrackedTopic>(
            new Updater(repository), project.getDisposed());
    if (!project.isDisposed()) {
      myMessageBusConnection = project.getMessageBus().connect();
      myMessageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, this);
    } else {
      myMessageBusConnection = null;
    }
  }