List of usage examples for com.intellij.openapi.fileEditor FileDocumentManagerAdapter FileDocumentManagerAdapter
FileDocumentManagerAdapter
From source file:com.android.tools.idea.editors.navigation.NavigationEditor.java
License:Apache License
public NavigationEditor(Project project, VirtualFile file) { // Listen for 'Save All' events FileDocumentManagerListener saveListener = new FileDocumentManagerAdapter() { @Override/*ww w .j a v a 2s .c o m*/ public void beforeAllDocumentsSaving() { try { saveFile(); } catch (IOException e) { LOG.error("Unexpected exception while saving navigation file", e); } } }; project.getMessageBus().connect(this).subscribe(AppTopics.FILE_DOCUMENT_SYNC, saveListener); myFile = file; try { myNavigationModel = read(file); // component = new NavigationModelEditorPanel1(project, file, read(file)); myComponent = new JBScrollPane(new NavigationEditorPanel2(project, file, myNavigationModel)); } catch (Exception e) { myNavigationModel = new NavigationModel(); { JPanel panel = new JPanel(new BorderLayout()); JLabel message = new JLabel("Invalid Navigation File"); Font font = message.getFont(); message.setFont(font.deriveFont(30f)); panel.add(message, BorderLayout.NORTH); panel.add(new JLabel(e.getMessage()), BorderLayout.CENTER); myComponent = new JBScrollPane(panel); } } myNavigationModelListener = new Listener<NavigationModel.Event>() { @Override public void notify(@NotNull NavigationModel.Event event) { myDirty = true; } }; myNavigationModel.getListeners().add(myNavigationModelListener); }
From source file:com.android.tools.idea.editors.NinePatchEditor.java
License:Apache License
public NinePatchEditor(Project project, VirtualFile file) { // Listen for 'Save All' events FileDocumentManagerListener saveListener = new FileDocumentManagerAdapter() { @Override// w ww. j a v a 2 s . c om public void beforeAllDocumentsSaving() { try { saveFile(); } catch (IOException e) { LOG.error("Unexpected exception while saving 9-patch file", e); } } }; project.getMessageBus().connect(this).subscribe(AppTopics.FILE_DOCUMENT_SYNC, saveListener); myFile = file; try { myBufferedImage = loadImage(file); myImageEditorPanel = new ImageEditorPanel(null, myBufferedImage, myFile.getName()); myImageEditorPanel.getViewer().addPatchUpdateListener(this); } catch (IOException e) { LOG.error("Unexpected exception while reading 9-patch file", e); } }
From source file:com.intellij.execution.DelayedDocumentWatcher.java
License:Apache License
public void activate() { EditorFactory.getInstance().getEventMulticaster().addDocumentListener(myListener, myProject); if (myConnection == null) { myConnection = ApplicationManager.getApplication().getMessageBus().connect(myProject); myConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override/*from w ww. ja v a 2 s .c o m*/ public void beforeAllDocumentsSaving() { myDocumentSavingInProgress = true; ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { myDocumentSavingInProgress = false; } }, ModalityState.any()); } }); } }
From source file:com.intellij.psi.impl.PsiDocumentManagerImpl.java
License:Apache License
public PsiDocumentManagerImpl(@NotNull final Project project, @NotNull PsiManager psiManager, @NotNull EditorFactory editorFactory, @NotNull MessageBus bus, @NonNls @NotNull final DocumentCommitThread documentCommitThread) { super(project, psiManager, bus, documentCommitThread); myDocumentCommitThread = documentCommitThread; editorFactory.getEventMulticaster().addDocumentListener(this, project); MessageBusConnection busConnection = bus.connect(); busConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override/*from ww w . j a v a 2 s . c o m*/ public void fileContentLoaded(@NotNull final VirtualFile virtualFile, @NotNull Document document) { PsiFile psiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() { @Override public PsiFile compute() { return myProject.isDisposed() || !virtualFile.isValid() ? null : getCachedPsiFile(virtualFile); } }); fireDocumentCreated(document, psiFile); } }); busConnection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() { @Override public void updateFinished(@NotNull Document doc) { documentCommitThread.queueCommit(project, doc, "Bulk update finished"); } }); }
From source file:com.intellij.util.indexing.FileBasedIndexImpl.java
License:Apache License
public FileBasedIndexImpl(@SuppressWarnings("UnusedParameters") VirtualFileManager vfManager, FileDocumentManager fdm, FileTypeManagerImpl fileTypeManager, @NotNull MessageBus bus, SerializationManagerEx sm) {//from w w w. j a v a 2 s. c o m myFileDocumentManager = fdm; myFileTypeManager = fileTypeManager; mySerializationManagerEx = sm; myIsUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); myConfigPath = calcConfigPath(PathManager.getConfigPath()); myLogPath = calcConfigPath(PathManager.getLogPath()); final MessageBusConnection connection = bus.connect(); connection.subscribe(PsiDocumentTransactionListener.TOPIC, new PsiDocumentTransactionListener() { @Override public void transactionStarted(@NotNull final Document doc, @NotNull final PsiFile file) { myTransactionMap = myTransactionMap.plus(doc, file); myUpToDateIndicesForUnsavedOrTransactedDocuments.clear(); } @Override public void transactionCompleted(@NotNull final Document doc, @NotNull final PsiFile file) { myTransactionMap = myTransactionMap.minus(doc); } }); connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { @Nullable private Map<FileType, Set<String>> myTypeToExtensionMap; @Override public void beforeFileTypesChanged(@NotNull final FileTypeEvent event) { cleanupProcessedFlag(); myTypeToExtensionMap = new THashMap<FileType, Set<String>>(); for (FileType type : myFileTypeManager.getRegisteredFileTypes()) { myTypeToExtensionMap.put(type, getExtensions(type)); } } @Override public void fileTypesChanged(@NotNull final FileTypeEvent event) { final Map<FileType, Set<String>> oldExtensions = myTypeToExtensionMap; myTypeToExtensionMap = null; if (oldExtensions != null) { final Map<FileType, Set<String>> newExtensions = new THashMap<FileType, Set<String>>(); for (FileType type : myFileTypeManager.getRegisteredFileTypes()) { newExtensions.put(type, getExtensions(type)); } // we are interested only in extension changes or removals. // addition of an extension is handled separately by RootsChanged event if (!newExtensions.keySet().containsAll(oldExtensions.keySet())) { rebuildAllIndices(); return; } for (Map.Entry<FileType, Set<String>> entry : oldExtensions.entrySet()) { FileType fileType = entry.getKey(); Set<String> strings = entry.getValue(); if (!newExtensions.get(fileType).containsAll(strings)) { rebuildAllIndices(); return; } } } } @NotNull private Set<String> getExtensions(@NotNull FileType type) { final Set<String> set = new THashSet<String>(); for (FileNameMatcher matcher : myFileTypeManager.getAssociations(type)) { set.add(matcher.getPresentableString()); } return set; } private void rebuildAllIndices() { IndexingStamp.flushCaches(); for (ID<?, ?> indexId : myIndices.keySet()) { try { clearIndex(indexId); } catch (StorageException e) { LOG.info(e); } } scheduleIndexRebuild(); } }); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) { cleanupMemoryStorage(); } @Override public void unsavedDocumentsDropped() { cleanupMemoryStorage(); } }); ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void writeActionStarted(Object action) { myUpToDateIndicesForUnsavedOrTransactedDocuments.clear(); } }); myChangedFilesCollector = new ChangedFilesCollector(); myConnection = connection; }
From source file:com.intellij.xdebugger.impl.XDebuggerManagerImpl.java
License:Apache License
public XDebuggerManagerImpl(final Project project, final StartupManager startupManager, MessageBus messageBus) { myProject = project;/* ww w . j ava 2 s. com*/ 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:io.flutter.editor.FlutterSaveActionsManager.java
License:Open Source License
private FlutterSaveActionsManager(@NotNull Project project) { this.myProject = project; final MessageBus bus = project.getMessageBus(); final MessageBusConnection connection = bus.connect(); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() { @Override/*from w w w . j av a 2 s .c o m*/ public void beforeDocumentSaving(@NotNull Document document) { handleBeforeDocumentSaving(document); } }); }
From source file:org.cordovastudio.editors.storyboard.CordovaStoryboardEditor.java
License:Apache License
public CordovaStoryboardEditor(Project project, VirtualFile file) { // Listen for 'Save All' events FileDocumentManagerListener saveListener = new FileDocumentManagerAdapter() { @Override/*from w w w. j a v a 2 s. c o m*/ public void beforeAllDocumentsSaving() { try { saveFile(); } catch (IOException e) { LOG.error("Unexpected exception while saving navigation file", e); } } }; project.getMessageBus().connect(this).subscribe(AppTopics.FILE_DOCUMENT_SYNC, saveListener); myFile = file; myErrorHandler = new ErrorHandler(); myRenderingParams = StoryboardView.getRenderingParams(project, file, myErrorHandler); if (myRenderingParams != null) { RenderConfiguration configuration = myRenderingParams.myConfiguration; Module module = configuration.getModule(); myAnalyser = new Analyser(project, module); myStoryboardModel = myAnalyser.createModel(); // There is now way to edit the App's structure from within Storyboard. // So there is no need for Code Generation as well. //myCodeGenerator = new CodeGenerator(myStoryboardModel, module); layoutStatesWithUnsetLocations(myStoryboardModel); StoryboardView editor = new StoryboardView(myRenderingParams, myStoryboardModel); JBScrollPane scrollPane = new JBScrollPane(editor); scrollPane.getVerticalScrollBar().setUnitIncrement(SCROLL_UNIT_INCREMENT); JPanel p = new JPanel(new BorderLayout()); JComponent controls = createToolbar(editor); p.add(controls, BorderLayout.NORTH); p.add(scrollPane); myComponent = p; } myNavigationModelListener = new Listener<CordovaStoryboardModel.Event>() { @Override public void notify(@NotNull CordovaStoryboardModel.Event event) { if (event.operation == Operation.INSERT && event.operandType == Transition.class) { ArrayList<Transition> transitions = myStoryboardModel.getTransitions(); Transition transition = transitions.get(transitions.size() - 1); // todo don't rely on this being the last } if (event != PROJECT_READ) { // exempt the case when we are updating the model ourselves (because of a file read) myModified = true; } } }; myStoryboardModel.getListeners().add(myNavigationModelListener); myVirtualFileListener = new VirtualFileAdapter() { private void somethingChanged(String changeType, @NotNull VirtualFileEvent event) { if (DEBUG) System.out.println("NavigationEditor: fileListener:: " + changeType + ": " + event); postDelayedRefresh(); } @Override public void contentsChanged(@NotNull VirtualFileEvent event) { somethingChanged("contentsChanged", event); } @Override public void fileCreated(@NotNull VirtualFileEvent event) { somethingChanged("fileCreated", event); } @Override public void fileDeleted(@NotNull VirtualFileEvent event) { somethingChanged("fileDeleted", event); } }; }