use of com.intellij.openapi.project.ProjectManagerListener in project intellij-community by JetBrains.
the class EditorTextField method addNotify.
@Override
public void addNotify() {
myDisposable = Disposer.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().doWhenFocusSettlesDown(() -> {
requestFocus();
});
}
}
use of com.intellij.openapi.project.ProjectManagerListener in project intellij-plugins by JetBrains.
the class OsmorcPostStartupActivity method runActivity.
@Override
public void runActivity(@NotNull Project project) {
if (project.isDefault()) {
return;
}
MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {
@Override
public void facetAdded(@NotNull Facet facet) {
handleFacetChange(facet, project);
}
@Override
public void facetConfigurationChanged(@NotNull Facet facet) {
handleFacetChange(facet, project);
}
});
connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void projectClosing(Project project) {
for (Module module : ModuleManager.getInstance(project).getModules()) {
AdditionalJARContentsWatcherManager.getInstance(module).cleanup();
}
}
});
}
use of com.intellij.openapi.project.ProjectManagerListener in project intellij-plugins by JetBrains.
the class DesignerApplicationManager method attachProjectAndModuleListeners.
void attachProjectAndModuleListeners(Disposable parentDisposable) {
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void projectClosed(Project project) {
if (isApplicationClosed()) {
return;
}
Client client = Client.getInstance();
if (client.getRegisteredProjects().contains(project)) {
client.closeProject(project);
}
}
});
// unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
// we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
// one by one)
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
Client client = Client.getInstance();
if (!client.isModuleRegistered(module)) {
return;
}
if (unregisterTaskQueueProcessor == null) {
unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
boolean hasError = true;
final ActionCallback callback;
initialRenderQueue.suspend();
try {
callback = Client.getInstance().unregisterModule(module1);
hasError = false;
} finally {
if (hasError) {
initialRenderQueue.resume();
}
}
callback.doWhenProcessed(() -> initialRenderQueue.resume());
});
}
unregisterTaskQueueProcessor.add(module);
}
});
}
use of com.intellij.openapi.project.ProjectManagerListener in project azure-tools-for-java by Microsoft.
the class ServerExplorerToolWindowFactory method addToolbarItems.
private void addToolbarItems(ToolWindow toolWindow, final Project project, final AzureModule azureModule) {
if (toolWindow instanceof ToolWindowEx) {
ToolWindowEx toolWindowEx = (ToolWindowEx) toolWindow;
try {
Runnable forceRefreshTitleActions = () -> {
ApplicationManager.getApplication().invokeLater(() -> {
try {
toolWindowEx.setTitleActions(new AnAction("Refresh", "Refresh Azure Nodes List", null) {
@Override
public void actionPerformed(AnActionEvent event) {
azureModule.load(true);
}
@Override
public void update(AnActionEvent e) {
boolean isDarkTheme = DefaultLoader.getUIHelper().isDarkTheme();
final String iconPath = isDarkTheme ? RefreshableNode.REFRESH_ICON_DARK : RefreshableNode.REFRESH_ICON_LIGHT;
e.getPresentation().setIcon(UIHelperImpl.loadIcon(iconPath));
}
}, new AzureSignInAction(), new SelectSubscriptionsAction());
} catch (Exception e) {
AzurePlugin.log(e.getMessage(), e);
}
});
};
AuthMethodManager.getInstance().addSignInEventListener(forceRefreshTitleActions);
AuthMethodManager.getInstance().addSignOutEventListener(forceRefreshTitleActions);
// Remove the sign in/out listener when project close
ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {
@Override
public void projectClosing(@NotNull Project project) {
AuthMethodManager.getInstance().removeSignInEventListener(forceRefreshTitleActions);
AuthMethodManager.getInstance().removeSignOutEventListener(forceRefreshTitleActions);
}
});
forceRefreshTitleActions.run();
} catch (Exception e) {
AzurePlugin.log(e.getMessage(), e);
}
}
}
use of com.intellij.openapi.project.ProjectManagerListener in project google-cloud-intellij by GoogleCloudPlatform.
the class GcpCheckoutProvider method clone.
private static void clone(@NotNull final Project project, @NotNull final Git git, @Nullable final Listener listener, @NotNull final VirtualFile destinationParent, @NotNull final String sourceRepositoryUrl, @NotNull final String directoryName, @NotNull final String parentDirectory, @Nullable final String gcpUserName) {
final AtomicBoolean cloneResult = new AtomicBoolean();
new Task.Backgroundable(project, GctBundle.message("clonefromgcp.repository", sourceRepositoryUrl)) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
GcpHttpAuthDataProvider.Context context = GcpHttpAuthDataProvider.createContext(gcpUserName);
try {
cloneResult.set(doClone(project, indicator, git, directoryName, parentDirectory, sourceRepositoryUrl));
} finally {
context.close();
}
}
@Override
public void onSuccess() {
if (!cloneResult.get()) {
return;
}
destinationParent.refresh(true, true, new Runnable() {
@Override
public void run() {
if (project.isOpen() && (!project.isDisposed()) && (!project.isDefault())) {
final VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project);
mgr.fileDirty(destinationParent);
}
}
});
ProjectManagerListener configWriter = new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
PropertiesComponent.getInstance(project).setValue(GcpHttpAuthDataProvider.GCP_USER, gcpUserName == null ? "" : gcpUserName);
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
// no-op
}
@Override
public void projectClosing(Project project) {
// no-op
}
};
ProjectManager.getInstance().addProjectManagerListener(configWriter);
try {
if (listener != null) {
listener.directoryCheckedOut(new File(parentDirectory, directoryName), GitVcs.getKey());
listener.checkoutCompleted();
}
} finally {
ProjectManager.getInstance().removeProjectManagerListener(configWriter);
}
}
}.queue();
}
Aggregations