List of usage examples for com.intellij.openapi.fileEditor FileEditorManagerAdapter FileEditorManagerAdapter
FileEditorManagerAdapter
From source file:com.intellij.codeInsight.daemon.impl.EditorTracker.java
License:Apache License
@Override public void projectOpened() { myIdeFrame = ((WindowManagerEx) myWindowManager).getFrame(myProject); myProject.getMessageBus().connect(myProject).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override/* ww w . j ava 2 s . c o m*/ 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.dispose(null); } }); }
From source file:com.intellij.codeInsight.daemon.impl.StatusBarUpdater.java
License:Apache License
public StatusBarUpdater(Project project) { myProject = project;/*w w w.j a va 2 s . co m*/ project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void selectionChanged(@NotNull FileEditorManagerEvent event) { updateLater(); } }); project.getMessageBus().connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListener() { @Override public void daemonFinished() { updateLater(); } @Override public void daemonCancelEventOccurred() { } }); }
From source file:com.intellij.codeInsight.highlighting.BraceHighlighter.java
License:Apache License
@Override public void runActivity(final Project project) { final EditorEventMulticaster eventMulticaster = EditorFactory.getInstance().getEventMulticaster(); CaretListener myCaretListener = new CaretAdapter() { @Override/*from ww w. j av a2 s. co m*/ 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() || selectionModel.hasBlockSelection()) { 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 FileEditorManagerAdapter() { @Override public void selectionChanged(@NotNull FileEditorManagerEvent e) { myAlarm.cancelAllRequests(); } }, project); }
From source file:com.intellij.execution.console.LanguageConsoleImpl.java
License:Apache License
private void installEditorFactoryListener() { FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override//from ww w. j ava 2s . c o m public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (myConsoleEditor == null || !Comparing.equal(file, myVirtualFile)) { return; } Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) { continue; } final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); editor.getCaretModel().addCaretListener(new CaretAdapter() { @Override public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) { return; } if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) { myCurrentEditor = null; } ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }
From source file:com.intellij.ui.AutoScrollFromSourceHandler.java
License:Apache License
public void install() { final MessageBusConnection connection = myProject.getMessageBus().connect(myProject); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override//from w ww . j a va 2 s . c o m public void selectionChanged(@NotNull FileEditorManagerEvent event) { final FileEditor editor = event.getNewEditor(); if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) { myAlarm.cancelAllRequests(); myAlarm.addRequest(new Runnable() { @Override public void run() { selectElementFromEditor(editor); } }, getAlarmDelay(), getModalityState()); } } }); }
From source file:com.intellij.ui.EditorNotifications.java
License:Apache License
public EditorNotifications(final Project project, FileEditorManager fileEditorManager) { super(project); myFileEditorManager = fileEditorManager; project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override/*from w w w.j a v a 2s .c om*/ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { updateNotifications(file); } }); project.getMessageBus().connect(project).subscribe(BackgroundTaskByVfsChangeManager.TOPIC, new BackgroundTaskByVfsChangeManager.ListenerAdapter() { @Override public void taskChanged(@NotNull BackgroundTaskByVfsChangeTask task) { for (VirtualFile virtualFile : task.getGeneratedFiles()) { updateNotifications(virtualFile); } } }); }
From source file:com.intellij.util.xml.ui.PerspectiveFileEditor.java
License:Apache License
protected PerspectiveFileEditor(final Project project, final VirtualFile file) { myProject = project;// w ww.j a v a 2s.c o m myUndoHelper = new UndoHelper(project, this); myFile = file; FileEditorManager.getInstance(myProject).addFileEditorManagerListener(new FileEditorManagerAdapter() { public void selectionChanged(@Nonnull FileEditorManagerEvent event) { if (!isValid()) return; ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { if (myUndoHelper.isShowing() && !getComponent().isShowing()) { deselectNotify(); } else if (!myUndoHelper.isShowing() && getComponent().isShowing()) { selectNotify(); } } }); final FileEditor oldEditor = event.getOldEditor(); final FileEditor newEditor = event.getNewEditor(); if (oldEditor == null || newEditor == null) return; if (oldEditor.getComponent().isShowing() && newEditor.getComponent().isShowing()) return; if (PerspectiveFileEditor.this.equals(oldEditor)) { if (newEditor instanceof TextEditor) { ensureInitialized(); setSelectionInTextEditor((TextEditor) newEditor, getSelectedDomElement()); } } else if (PerspectiveFileEditor.this.equals(newEditor)) { if (oldEditor instanceof TextEditor) { final DomElement element = getSelectedDomElementFromTextEditor((TextEditor) oldEditor); if (element != null) { ensureInitialized(); setSelectedDomElement(element); } } else if (oldEditor instanceof PerspectiveFileEditor) { ensureInitialized(); setSelectedDomElement(((PerspectiveFileEditor) oldEditor).getSelectedDomElement()); } } } }, this); myUndoHelper.startListeningDocuments(); final PsiFile psiFile = getPsiFile(); if (psiFile != null) { final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(psiFile); if (document != null) { addWatchedDocument(document); } } }
From source file:com.intellij.xdebugger.impl.XDebuggerManagerImpl.java
License:Apache License
public XDebuggerManagerImpl(final Project project, final StartupManager startupManager, MessageBus messageBus) { myProject = project;//from www . j av a2 s .c om myBreakpointManager = new XBreakpointManagerImpl(project, this, startupManager); myWatchesManager = new XDebuggerWatchesManager(); mySessions = new LinkedHashMap<ProcessHandler, XDebugSessionImpl>(); myExecutionPointHighlighter = new ExecutionPointHighlighter(project); MessageBusConnection messageBusConnection = messageBus.connect(); messageBusConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void fileContentLoaded(@NotNull VirtualFile file, @NotNull Document document) { updateExecutionPoint(file, true); } @Override public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) { updateExecutionPoint(file, true); } }); messageBusConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() { @Override public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { updateExecutionPoint(file, false); } }); myBreakpointManager.addBreakpointListener(new XBreakpointAdapter<XBreakpoint<?>>() { @Override public void breakpointChanged(@NotNull XBreakpoint<?> breakpoint) { if (!(breakpoint instanceof XLineBreakpoint)) { final XDebugSessionImpl session = getCurrentSession(); if (session != null && breakpoint.equals(session.getActiveNonLineBreakpoint())) { final XBreakpointBase breakpointBase = (XBreakpointBase) breakpoint; breakpointBase.clearIcon(); myExecutionPointHighlighter.updateGutterIcon(breakpointBase.createGutterIconRenderer()); } } } }); messageBusConnection.subscribe(RunContentManager.TOPIC, new RunContentWithExecutorListener() { @Override public void contentSelected(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) { if (descriptor != null && executor.equals(DefaultDebugExecutor.getDebugExecutorInstance())) { XDebugSessionImpl session = mySessions.get(descriptor.getProcessHandler()); if (session != null) { session.activateSession(); } else { setActiveSession(null, null, false, null); } } } @Override public void contentRemoved(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) { if (descriptor != null && executor.equals(DefaultDebugExecutor.getDebugExecutorInstance())) { mySessions.remove(descriptor.getProcessHandler()); } } }); }
From source file:com.maddyhome.idea.copyright.CopyrightProjectPluginImpl.java
License:Open Source License
public void projectOpened() { if (project != null) { listener = new FileEditorManagerAdapter() { public void fileOpened(FileEditorManager fileEditorManager, VirtualFile virtualFile) { if (NewFileTracker.getInstance().contains(virtualFile)) { NewFileTracker.getInstance().remove(virtualFile); if (FileTypeUtil.getInstance().isSupportedFile(virtualFile)) { Module module = ProjectRootManager.getInstance(project).getFileIndex() .getModuleForFile(virtualFile); if (module != null) { PsiFile file = PsiManager.getInstance(project).findFile(virtualFile); if (file != null) { (new UpdateCopyrightProcessor(project, module, file)).run(); }//from ww w . j a va2 s.co m } } } } }; FileEditorManager.getInstance(project).addFileEditorManagerListener(listener); } }
From source file:javarepl.plugin.JavaREPLLanguageConsole.java
License:Apache License
private void installEditorFactoryListener() { final FileEditorManagerAdapter fileEditorListener = new FileEditorManagerAdapter() { @Override//from w ww.j a v a2 s . c o m public void fileOpened(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile) || myConsoleEditor == null) return; Editor selectedTextEditor = source.getSelectedTextEditor(); for (FileEditor fileEditor : source.getAllEditors(file)) { if (!(fileEditor instanceof TextEditor)) continue; final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor(); editor.addFocusListener(myFocusListener); if (selectedTextEditor == editor) { // already focused myCurrentEditor = editor; } EmptyAction.registerActionShortcuts(editor.getComponent(), myConsoleEditor.getComponent()); editor.getCaretModel().addCaretListener(new CaretListener() { public void caretPositionChanged(CaretEvent e) { queueUiUpdate(false); } }); } queueUiUpdate(false); } @Override public void fileClosed(FileEditorManager source, VirtualFile file) { if (!Comparing.equal(file, myVirtualFile)) return; if (myUiUpdateRunnable != null && !Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) { if (myCurrentEditor != null && myCurrentEditor.isDisposed()) myCurrentEditor = null; ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable); } } }; myProject.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener); FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); if (editorManager.isFileOpen(myVirtualFile)) { fileEditorListener.fileOpened(editorManager, myVirtualFile); } }