com.intellij.openapi.project.ProjectManagerListener Java Examples

The following examples show how to use com.intellij.openapi.project.ProjectManagerListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrefetchProjectInitializer.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void initComponent() {
  ApplicationManager.getApplication()
      .getMessageBus()
      .connect()
      .subscribe(
          ProjectManager.TOPIC,
          new ProjectManagerListener() {
            @Override
            public void projectOpened(Project project) {
              if (prefetchOnProjectOpen.getValue()) {
                prefetchProjectFiles(project);
              }
            }
          });
}
 
Example #2
Source File: UnityPluginFileValidator.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Inject
public UnityPluginFileValidator(Application application, Project project)
{
	if(project.isDefault())
	{
		return;
	}

	application.getMessageBus().connect(project).subscribe(ProjectManager.TOPIC, new ProjectManagerListener()
	{
		@Override
		public void projectOpened(Project target, UIAccess uiAccess)
		{
			if(project == target)
			{
				runValidation(project);
			}
		}
	});
}
 
Example #3
Source File: EditorFactoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public EditorFactoryImpl(Application application) {
  MessageBusConnection busConnection = application.getMessageBus().connect();
  busConnection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectClosed(@Nonnull Project project, @Nonnull UIAccess uiAccess) {
      // validate all editors are disposed after fireProjectClosed() was called, because it's the place where editor should be released
      Disposer.register(project, () -> {
        Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
        boolean isLastProjectClosed = openProjects.length == 0;
        // EditorTextField.releaseEditorLater defer releasing its editor; invokeLater to avoid false positives about such editors.
        ApplicationManager.getApplication().invokeLater(() -> validateEditorsAreReleased(project, isLastProjectClosed));
      });
    }
  });
  busConnection.subscribe(EditorColorsManager.TOPIC, scheme -> refreshAllEditors());

  LaterInvocator.addModalityStateListener(new ModalityStateListener() {
    @Override
    public void beforeModalityStateChanged(boolean entering) {
      for (Editor editor : myEditors) {
        ((DesktopEditorImpl)editor).beforeModalityStateChanged();
      }
    }
  }, ApplicationManager.getApplication());
}
 
Example #4
Source File: WelcomeFrameManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected WelcomeFrameManager(Application application) {
  myApplication = application;

  application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectOpened(Project project, UIAccess uiAccess) {
      uiAccess.give(() -> closeFrame());
    }
  });
}
 
Example #5
Source File: EditorTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
  myDisposable = Disposable.newDisposable("ETF dispose");
  Disposer.register(myDisposable, this::releaseEditorLater);
  if (myProject != null) {
    ProjectManagerListener listener = new ProjectManagerListener() {
      @Override
      public void projectClosing(Project project) {
        releaseEditor(myEditor);
        myEditor = null;
      }
    };
    ProjectManager.getInstance().addProjectManagerListener(myProject, listener);
    Disposer.register(myDisposable, () -> ProjectManager.getInstance().removeProjectManagerListener(myProject, listener));
  }

  if (myEditor != null) {
    releaseEditorLater();
  }

  boolean isFocused = isFocusOwner();

  initEditor();

  super.addNotify();

  if (myNextFocusable != null) {
    myEditor.getContentComponent().setNextFocusableComponent(myNextFocusable);
    myNextFocusable = null;
  }
  revalidate();
  if (isFocused) {
    IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(this);
  }
}
 
Example #6
Source File: StatisticsSendManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
private StatisticsSendManager(Application application, Provider<UsageStatisticsPersistenceComponent> usageStatisticsComponent) {
  myUsageStatisticsComponent = usageStatisticsComponent;

  application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectOpened(@Nonnull Project project, @Nonnull UIAccess uiAccess) {
      runStatisticsService();
    }
  });
}
 
Example #7
Source File: CompletionServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CompletionServiceImpl() {
  ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectClosing(@Nonnull Project project) {
      CompletionProgressIndicator indicator = getCurrentCompletionProgressIndicator();
      if (indicator != null && indicator.getProject() == project) {
        indicator.closeAndFinish(true);
        setCompletionPhase(CompletionPhase.NoCompletion);
      }
      else if (indicator == null) {
        setCompletionPhase(CompletionPhase.NoCompletion);
      }
    }
  });
}
 
Example #8
Source File: PsiCopyPasteManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public PsiCopyPasteManager(Application application, CopyPasteManager copyPasteManager) {
  myCopyPasteManager = (CopyPasteManagerEx) copyPasteManager;
  application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectClosing(@Nonnull Project project) {
      if (myRecentData != null && myRecentData.getProject() == project) {
        myRecentData = null;
      }
    }
  });
}
 
Example #9
Source File: DesktopIconDeferrerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public DesktopIconDeferrerImpl(Application application) {
  final MessageBusConnection connection = application.getMessageBus().connect();
  connection.subscribe(PsiModificationTracker.TOPIC, this::clear);
  connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
    @Override
    public void projectClosed(@Nonnull Project project, @Nonnull UIAccess uiAccess) {
      clear();
    }
  });
  LowMemoryWatcher.register(this::clear, this);
}