use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.
the class EventLogConsole method createLogEditor.
private Editor createLogEditor() {
Project project = myProjectModel.getProject();
final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
editor.getSettings().setWhitespacesShown(false);
installNotificationsFont(editor);
myProjectModel.getProject().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {
@Override
public void projectClosed(Project project) {
if (project == myProjectModel.getProject()) {
EditorFactory.getInstance().releaseEditor(editor);
}
}
});
((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
final ClearLogAction clearLog = new ClearLogAction(this);
clearLog.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(), editor.getContentComponent());
// disabling default context menu
editor.setContextMenuGroupId(null);
editor.addEditorMouseListener(new EditorPopupHandler() {
public void invokePopup(final EditorMouseEvent event) {
final ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup actions = createPopupActions(actionManager, clearLog, editor, event);
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, actions);
final MouseEvent mouseEvent = event.getMouseEvent();
menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
}
});
return editor;
}
use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.
the class ScratchFileServiceImpl method initFileOpenedListener.
private void initFileOpenedListener(MessageBus messageBus) {
final FileEditorManagerListener editorListener = new FileEditorManagerListener() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (!isEditable(file))
return;
RootType rootType = getRootType(file);
if (rootType == null)
return;
rootType.fileOpened(file, source);
}
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
if (Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN)))
return;
if (!isEditable(file))
return;
RootType rootType = getRootType(file);
if (rootType == null)
return;
rootType.fileClosed(file, source);
}
boolean isEditable(@NotNull VirtualFile file) {
return FileDocumentManager.getInstance().getDocument(file) != null;
}
};
ProjectManagerAdapter projectListener = new ProjectManagerAdapter() {
@Override
public void projectOpened(Project project) {
project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorListener);
FileEditorManager editorManager = FileEditorManager.getInstance(project);
for (VirtualFile virtualFile : editorManager.getOpenFiles()) {
editorListener.fileOpened(editorManager, virtualFile);
}
}
};
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
projectListener.projectOpened(project);
}
messageBus.connect().subscribe(ProjectManager.TOPIC, projectListener);
}
use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.
the class IdeStartupScripts method scheduleStartupScriptsExecution.
private static void scheduleStartupScriptsExecution() {
List<VirtualFile> scripts = getScripts();
LOG.info(scripts.size() + " startup script(s) found");
if (scripts.isEmpty())
return;
final Future<List<Pair<VirtualFile, IdeScriptEngine>>> scriptsAndEnginesFuture = prepareScriptEnginesAsync(scripts);
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
final AtomicBoolean myScriptsExecutionStarted = new AtomicBoolean();
@Override
public void projectOpened(final Project project) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
if (project.isDisposed())
return;
if (!myScriptsExecutionStarted.compareAndSet(false, true))
return;
ProjectManager.getInstance().removeProjectManagerListener(this);
runAllScriptsImpl(project);
});
}
private void runAllScriptsImpl(@NotNull Project project) {
try {
for (Pair<VirtualFile, IdeScriptEngine> pair : scriptsAndEnginesFuture.get()) {
try {
if (pair.second == null) {
LOG.warn(pair.first.getPath() + " not supported (no script engine)");
} else {
runImpl(project, pair.first, pair.second);
}
} catch (Exception e) {
LOG.warn(e);
}
}
} catch (ProcessCanceledException e) {
LOG.warn("... cancelled");
} catch (InterruptedException e) {
LOG.warn("... interrupted");
} catch (Exception e) {
LOG.error(e);
}
}
});
}
use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij by bazelbuild.
the class ProjectDependencyMigration method initComponent.
@Override
public void initComponent() {
ProjectManager projectManager = ProjectManager.getInstance();
projectManager.addProjectManagerListener(new ProjectManagerAdapter() {
@Override
public void projectOpened(Project project) {
if (Blaze.isBlazeProject(project)) {
PluginDependencyHelper.addDependencyOnSyncPlugin(project);
}
}
});
}
use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-code-outline by sitano.
the class CodeOutlinePlugin method addProjectListener.
private void addProjectListener() {
ProjectManager pm = ProjectManager.getInstance();
pm.addProjectManagerListener(new ProjectManagerAdapter() {
public void projectOpened(Project project) {
regForProject(project);
}
public void projectClosed(Project project) {
unregForProject(project);
}
});
}
Aggregations