use of com.intellij.openapi.roots.ModuleRootEvent in project intellij-community by JetBrains.
the class MavenMergingUpdateQueue method makeUserAware.
public void makeUserAware(final Project project) {
AccessToken accessToken = ReadAction.start();
try {
EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
multicaster.addCaretListener(new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
MavenMergingUpdateQueue.this.restartTimer();
}
}, this);
multicaster.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
MavenMergingUpdateQueue.this.restartTimer();
}
}, this);
project.getMessageBus().connect(this).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
int beforeCalled;
@Override
public void beforeRootsChange(ModuleRootEvent event) {
if (beforeCalled++ == 0) {
suspend();
}
}
@Override
public void rootsChanged(ModuleRootEvent event) {
if (beforeCalled == 0)
// This may occur if listener has been added between beforeRootsChange() and rootsChanged() calls.
return;
if (--beforeCalled == 0) {
resume();
MavenMergingUpdateQueue.this.restartTimer();
}
}
});
} finally {
accessToken.finish();
}
}
use of com.intellij.openapi.roots.ModuleRootEvent in project intellij-community by JetBrains.
the class GeneratedSourceFileChangeTrackerImpl method projectOpened.
@Override
public void projectOpened() {
final Update check = new Update("check for changes in generated files") {
@Override
public void run() {
checkFiles();
}
};
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
VirtualFile file = myDocumentManager.getFile(e.getDocument());
if (file != null) {
myFilesToCheck.add(file);
myCheckingQueue.queue(check);
}
}
}, myProject);
MessageBusConnection connection = myProject.getMessageBus().connect();
connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
myFilesToCheck.remove(file);
if (myEditedGeneratedFiles.remove(file)) {
myEditorNotifications.updateNotifications(file);
}
}
});
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
myEditedGeneratedFiles.remove(file);
}
});
connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
myFilesToCheck.addAll(myEditedGeneratedFiles);
myEditedGeneratedFiles.clear();
myCheckingQueue.queue(check);
}
});
myCheckingQueue.activate();
}
use of com.intellij.openapi.roots.ModuleRootEvent in project intellij-community by JetBrains.
the class ExternalSystemProjectsWatcher method makeUserAware.
private static void makeUserAware(final MergingUpdateQueue mergingUpdateQueue, final Project project) {
AccessToken accessToken = ReadAction.start();
try {
EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
multicaster.addCaretListener(new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
mergingUpdateQueue.restartTimer();
}
}, mergingUpdateQueue);
multicaster.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent event) {
mergingUpdateQueue.restartTimer();
}
}, mergingUpdateQueue);
project.getMessageBus().connect(mergingUpdateQueue).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
int beforeCalled;
@Override
public void beforeRootsChange(ModuleRootEvent event) {
if (beforeCalled++ == 0) {
mergingUpdateQueue.suspend();
}
}
@Override
public void rootsChanged(ModuleRootEvent event) {
if (beforeCalled == 0) {
// This may occur if listener has been added between beforeRootsChange() and rootsChanged() calls.
return;
}
if (--beforeCalled == 0) {
mergingUpdateQueue.resume();
mergingUpdateQueue.restartTimer();
}
}
});
} finally {
accessToken.finish();
}
}
use of com.intellij.openapi.roots.ModuleRootEvent in project intellij-community by JetBrains.
the class LibraryDependentToolWindowManager method projectOpened.
@Override
public void projectOpened() {
final ModuleRootListener rootListener = new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
if (!myProject.isDisposed()) {
checkToolWindowStatuses(myProject);
}
}
};
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
if (!myProject.isDisposed()) {
checkToolWindowStatuses(myProject);
final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
connection.subscribe(ProjectTopics.PROJECT_ROOTS, rootListener);
}
});
}
use of com.intellij.openapi.roots.ModuleRootEvent in project android by JetBrains.
the class JavaFacet method initFacet.
@Override
public void initFacet() {
MessageBusConnection connection = getModule().getMessageBus().connect(this);
connection.subscribe(PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
ApplicationManager.getApplication().invokeLater(() -> {
if (!isDisposed()) {
PsiDocumentManager.getInstance(getModule().getProject()).commitAllDocuments();
updateConfiguration();
}
});
}
});
updateConfiguration();
}
Aggregations