use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.
the class EditorWindow method closeFile.
public void closeFile(@NotNull final VirtualFile file, final boolean disposeIfNeeded, final boolean transferFocus) {
final FileEditorManagerImpl editorManager = getManager();
editorManager.runChange(splitters -> {
final List<EditorWithProviderComposite> editors = splitters.findEditorComposites(file);
if (editors.isEmpty())
return;
try {
final EditorWithProviderComposite editor = findFileComposite(file);
final FileEditorManagerListener.Before beforePublisher = editorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER);
beforePublisher.beforeFileClosed(editorManager, file);
if (myTabbedPane != null && editor != null) {
final int componentIndex = findComponentIndex(editor.getComponent());
if (componentIndex >= 0) {
final int indexToSelect = calcIndexToSelect(file, componentIndex);
Pair<String, Integer> pair = Pair.create(file.getUrl(), componentIndex);
myRemovedTabs.push(pair);
if (myTabsHidingInProgress.get()) {
myHiddenTabs.push(pair);
}
myTabbedPane.removeTabAt(componentIndex, indexToSelect, transferFocus);
editorManager.disposeComposite(editor);
}
} else {
if (inSplitter()) {
Splitter splitter = (Splitter) myPanel.getParent();
JComponent otherComponent = splitter.getOtherComponent(myPanel);
if (otherComponent != null) {
IdeFocusManager.findInstance().requestFocus(otherComponent, true);
}
}
myPanel.removeAll();
if (editor != null) {
editorManager.disposeComposite(editor);
}
}
if (disposeIfNeeded && getTabCount() == 0) {
removeFromSplitter();
if (UISettings.getInstance().getEditorTabPlacement() == UISettings.TABS_NONE) {
final EditorsSplitters owner = getOwner();
if (owner != null) {
final ThreeComponentsSplitter splitter = UIUtil.getParentOfType(ThreeComponentsSplitter.class, owner);
if (splitter != null) {
splitter.revalidate();
splitter.repaint();
}
}
}
} else {
myPanel.revalidate();
if (myTabbedPane == null) {
myPanel.repaint();
}
}
} finally {
editorManager.removeSelectionRecord(file, this);
editorManager.notifyPublisher(() -> {
final Project project = editorManager.getProject();
if (!project.isDisposed()) {
final FileEditorManagerListener afterPublisher = project.getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
afterPublisher.fileClosed(editorManager, file);
}
});
splitters.afterFileClosed(file);
}
}, myOwner);
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.
the class OutdatedVersionNotifier method projectOpened.
@Override
public void projectOpened() {
final FileEditorManagerListener myFileEditorManagerListener = new MyFileEditorManagerListener();
myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener, myProject);
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project android by JetBrains.
the class FloatingToolWindowManagerTest method before.
@Before
public void before() {
initMocks(this);
KeyboardFocusManager.setCurrentKeyboardFocusManager(myKeyboardFocusManager);
Project project = ProjectManager.getInstance().getDefaultProject();
myEditorManager = FileEditorManager.getInstance(project);
when(myWorkBench1.getFloatingToolWindows()).thenReturn(ImmutableList.of(myAttachedToolWindow1));
when(myWorkBench2.getFloatingToolWindows()).thenReturn(ImmutableList.of(myAttachedToolWindow2));
when(myAttachedToolWindow1.getDefinition()).thenReturn(PalettePanelToolContent.getDefinition());
when(myAttachedToolWindow2.getDefinition()).thenReturn(PalettePanelToolContent.getOtherDefinition());
when(myFloatingToolWindowFactory.create(any(Project.class), any(ToolWindowDefinition.class))).thenReturn(myFloatingToolWindow1, myFloatingToolWindow2, null);
myManager = new FloatingToolWindowManager(ApplicationManager.getApplication(), project, StartupManager.getInstance(project), FileEditorManager.getInstance(project));
myManager.initComponent();
myManager.setFloatingToolWindowFactory(myFloatingToolWindowFactory);
assert myManager.getComponentName().equals("FloatingToolWindowManager");
when(myEditorManager.getSelectedEditors()).thenReturn(new FileEditor[0]);
when(project.getMessageBus()).thenReturn(myMessageBus);
when(myMessageBus.connect(eq(project))).thenReturn(myConnection).thenReturn(null);
myManager.projectOpened();
ArgumentCaptor<FileEditorManagerListener> captor = ArgumentCaptor.forClass(FileEditorManagerListener.class);
//noinspection unchecked
verify(myConnection).subscribe(any(Topic.class), captor.capture());
when(myFileEditor1.getComponent()).thenReturn(new JPanel());
when(myFileEditor2.getComponent()).thenReturn(new JPanel());
myListener = captor.getValue();
myManager.register(myFileEditor1, myWorkBench1);
myManager.register(myFileEditor2, myWorkBench2);
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.
the class EditorTracker method projectOpened.
@Override
public void projectOpened() {
myIdeFrame = ((WindowManagerEx) myWindowManager).getFrame(myProject);
myProject.getMessageBus().connect(myProject).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
if (myIdeFrame == null || myIdeFrame.getFocusOwner() == null)
return;
setActiveWindow(myIdeFrame);
}
});
final MyEditorFactoryListener myEditorFactoryListener = new MyEditorFactoryListener();
myEditorFactory.addEditorFactoryListener(myEditorFactoryListener, myProject);
Disposer.register(myProject, new Disposable() {
@Override
public void dispose() {
myEditorFactoryListener.executeOnRelease(null);
}
});
}
use of com.intellij.openapi.fileEditor.FileEditorManagerListener in project intellij-community by JetBrains.
the class BraceHighlighter method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
// sorry, upsource
if (ApplicationManager.getApplication().isHeadlessEnvironment())
return;
final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster();
CaretListener myCaretListener = new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
myAlarm.cancelAllRequests();
Editor editor = e.getEditor();
final SelectionModel selectionModel = editor.getSelectionModel();
// Don't update braces in case of the active selection.
if (editor.getProject() != project || selectionModel.hasSelection()) {
return;
}
final Document document = editor.getDocument();
int line = e.getNewPosition().line;
if (line < 0 || line >= document.getLineCount()) {
return;
}
updateBraces(editor, myAlarm);
}
};
eventMulticaster.addCaretListener(myCaretListener, project);
final SelectionListener mySelectionListener = new SelectionListener() {
@Override
public void selectionChanged(SelectionEvent e) {
myAlarm.cancelAllRequests();
Editor editor = e.getEditor();
if (editor.getProject() != project) {
return;
}
final TextRange oldRange = e.getOldRange();
final TextRange newRange = e.getNewRange();
if (oldRange != null && newRange != null && !(oldRange.isEmpty() ^ newRange.isEmpty())) {
// Don't perform braces update in case of active/absent selection.
return;
}
updateBraces(editor, myAlarm);
}
};
eventMulticaster.addSelectionListener(mySelectionListener, project);
DocumentListener documentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
myAlarm.cancelAllRequests();
Editor[] editors = EditorFactory.getInstance().getEditors(e.getDocument(), project);
for (Editor editor : editors) {
updateBraces(editor, myAlarm);
}
}
};
eventMulticaster.addDocumentListener(documentListener, project);
final FocusChangeListener myFocusChangeListener = new FocusChangeListener() {
@Override
public void focusLost(Editor editor) {
clearBraces(editor);
}
@Override
public void focusGained(Editor editor) {
updateBraces(editor, myAlarm);
}
};
((EditorEventMulticasterEx) eventMulticaster).addFocusChangeListner(myFocusChangeListener, project);
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent e) {
myAlarm.cancelAllRequests();
}
}, project);
}
Aggregations