Java Code Examples for com.intellij.openapi.editor.Document#putUserData()
The following examples show how to use
com.intellij.openapi.editor.Document#putUserData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorHighlighterCache.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static EditorHighlighter getEditorHighlighterForCachesBuilding(Document document) { if (document == null) { return null; } final WeakReference<EditorHighlighter> editorHighlighterWeakReference = document.getUserData(ourSomeEditorSyntaxHighlighter); final EditorHighlighter someEditorHighlighter = SoftReference.dereference(editorHighlighterWeakReference); if (someEditorHighlighter instanceof LexerEditorHighlighter && ((LexerEditorHighlighter)someEditorHighlighter).isValid() ) { return someEditorHighlighter; } document.putUserData(ourSomeEditorSyntaxHighlighter, null); return null; }
Example 2
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 6 votes |
private boolean clearUpToDateStateForPsiIndicesOfUnsavedDocuments(@Nonnull VirtualFile file, Collection<? extends ID<?, ?>> affectedIndices) { if (!myUpToDateIndicesForUnsavedOrTransactedDocuments.isEmpty()) { myUpToDateIndicesForUnsavedOrTransactedDocuments.clear(); } Document document = myFileDocumentManager.getCachedDocument(file); if (document != null && myFileDocumentManager.isDocumentUnsaved(document)) { // will be reindexed in indexUnsavedDocuments myLastIndexedDocStamps.clearForDocument(document); // Q: non psi indices document.putUserData(ourFileContentKey, null); return true; } removeTransientFileDataFromIndices(ContainerUtil.intersection(affectedIndices, myPsiDependentIndices), getFileId(file), file); return false; }
Example 3
Source File: DocumentFragmentContent.java From consulo with Apache License 2.0 | 5 votes |
public DocumentFragmentContent(@Nullable Project project, @Nonnull DocumentContent original, @Nonnull RangeMarker rangeMarker) { myOriginal = original; myRangeMarker = rangeMarker; Document document1 = myOriginal.getDocument(); Document document2 = EditorFactory.getInstance().createDocument(""); document2.putUserData(UndoManager.ORIGINAL_DOCUMENT, document1); mySynchronizer = new MyDocumentsSynchronizer(project, myRangeMarker, document1, document2); }
Example 4
Source File: MockFileDocumentManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Document getDocument(@Nonnull VirtualFile file) { Document document = file.getUserData(MOCK_DOC_KEY); if (document == null) { if (file.isDirectory() || isBinaryWithoutDecompiler(file)) return null; CharSequence text = LoadTextUtil.loadText(file); document = myFactory.fun(text); document.putUserData(MOCK_VIRTUAL_FILE_KEY, file); document = file.putUserDataIfAbsent(MOCK_DOC_KEY, document); } return document; }
Example 5
Source File: UndoRedoStacksHolder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private LinkedList<UndoableGroup> doGetStackForDocument(@Nonnull DocumentReference r) { // If document is not associated with file, we have to store its stack in document // itself to avoid memory leaks caused by holding stacks of all documents, ever created, here. // And to know, what documents do exist now, we have to maintain weak reference list of them. Document d = r.getDocument(); LinkedList<UndoableGroup> result = d.getUserData(STACK_IN_DOCUMENT_KEY); if (result == null) { result = new LinkedList<UndoableGroup>(); d.putUserData(STACK_IN_DOCUMENT_KEY, result); myDocumentsWithStacks.add(d); } return result; }
Example 6
Source File: CommitHelper.java From consulo with Apache License 2.0 | 5 votes |
/** * Marks {@link Document documents} related to the given changes as "being committed". * * @return documents which were marked that way. * @see #unmarkCommittingDocuments(java.util.Collection) * @see VetoSavingCommittingDocumentsAdapter */ @Nonnull public static Collection<Document> markCommittingDocuments(@Nonnull Project project, @Nonnull List<Change> changes) { Collection<Document> committingDocs = new ArrayList<Document>(); for (Change change : changes) { Document doc = ChangesUtil.getFilePath(change).getDocument(); if (doc != null) { doc.putUserData(DOCUMENT_BEING_COMMITTED_KEY, project); committingDocs.add(doc); } } return committingDocs; }
Example 7
Source File: PsiDocumentManagerBase.java From consulo with Apache License 2.0 | 5 votes |
public static void addRunOnCommit(@Nonnull Document document, @Nonnull Runnable action) { synchronized (ACTION_AFTER_COMMIT) { List<Runnable> list = document.getUserData(ACTION_AFTER_COMMIT); if (list == null) { document.putUserData(ACTION_AFTER_COMMIT, list = new SmartList<>()); } list.add(action); } }
Example 8
Source File: CodeFoldingManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void dispose() { for (Document document : myDocumentsWithFoldingInfo) { if (document != null) { document.putUserData(myFoldingInfoInDocumentKey, null); } } }
Example 9
Source File: LightFileDocumentManager.java From consulo with Apache License 2.0 | 5 votes |
@Override public Document getDocument(@Nonnull VirtualFile file) { Document document = file.getUserData(MOCK_DOC_KEY); if (document == null) { if (file.isDirectory() || isBinaryWithoutDecompiler(file)) return null; CharSequence text = LoadTextUtil.loadText(file); document = myFactory.apply(text); document.putUserData(MOCK_VIRTUAL_FILE_KEY, file); document = file.putUserDataIfAbsent(MOCK_DOC_KEY, document); } return document; }
Example 10
Source File: UndoUtil.java From consulo with Apache License 2.0 | 4 votes |
public static void disableUndoFor(@Nonnull Document document) { document.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE); }
Example 11
Source File: DesktopEditorsSplitters.java From consulo with Apache License 2.0 | 4 votes |
@Override protected JPanel processFiles(@Nonnull List<Element> fileElements, final JPanel context, Element parent, UIAccess uiAccess) { final Ref<DesktopEditorWindow> windowRef = new Ref<>(); UIUtil.invokeAndWaitIfNeeded((Runnable)() -> { DesktopEditorWindow editorWindow = context == null ? createEditorWindow() : findWindowWith(context); windowRef.set(editorWindow); if (editorWindow != null) { updateTabSizeLimit(editorWindow, parent.getAttributeValue(JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString())); } }); final DesktopEditorWindow window = windowRef.get(); LOG.assertTrue(window != null); VirtualFile focusedFile = null; for (int i = 0; i < fileElements.size(); i++) { final Element file = fileElements.get(i); Element historyElement = file.getChild(HistoryEntry.TAG); String fileName = historyElement.getAttributeValue(HistoryEntry.FILE_ATTR); Activity activity = StartUpMeasurer.startActivity(PathUtil.getFileName(fileName), ActivityCategory.REOPENING_EDITOR); VirtualFile virtualFile = null; try { final FileEditorManagerImpl fileEditorManager = getManager(); final HistoryEntry entry = HistoryEntry.createLight(fileEditorManager.getProject(), historyElement); virtualFile = entry.getFile(); if (virtualFile == null) throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl()); virtualFile.putUserData(OPENED_IN_BULK, Boolean.TRUE); VirtualFile finalVirtualFile = virtualFile; Document document = ReadAction.compute(() -> finalVirtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(finalVirtualFile) : null); boolean isCurrentTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue(); FileEditorOpenOptions openOptions = new FileEditorOpenOptions().withPin(Boolean.valueOf(file.getAttributeValue(PINNED))).withIndex(i).withReopeningEditorsOnStartup(); fileEditorManager.openFileImpl4(uiAccess, window, virtualFile, entry, openOptions); if (isCurrentTab) { focusedFile = virtualFile; } if (document != null) { // This is just to make sure document reference is kept on stack till this point // so that document is available for folding state deserialization in HistoryEntry constructor // and that document will be created only once during file opening document.putUserData(DUMMY_KEY, null); } updateProgress(); } catch (InvalidDataException e) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(e); } } finally { if (virtualFile != null) virtualFile.putUserData(OPENED_IN_BULK, null); } activity.end(); } if (focusedFile != null) { getManager().addSelectionRecord(focusedFile, window); VirtualFile finalFocusedFile = focusedFile; uiAccess.giveAndWaitIfNeed(() -> { EditorWithProviderComposite editor = window.findFileComposite(finalFocusedFile); if (editor != null) { window.setEditor(editor, true, true); } }); } else { ToolWindowManager manager = ToolWindowManager.getInstance(getManager().getProject()); manager.invokeLater(() -> { if (null == manager.getActiveToolWindowId()) { ToolWindow toolWindow = manager.getToolWindow(ToolWindowId.PROJECT_VIEW); if (toolWindow != null) toolWindow.activate(null); } }); } return window.myPanel; }
Example 12
Source File: FileDocumentManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
public static void registerDocument(@Nonnull final Document document, @Nonnull VirtualFile virtualFile) { synchronized (lock) { document.putUserData(FILE_KEY, virtualFile); virtualFile.putUserData(HARD_REF_TO_DOCUMENT_KEY, document); } }
Example 13
Source File: FileDocumentManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
private void unbindFileFromDocument(@Nonnull VirtualFile file, @Nonnull Document document) { removeDocumentFromCache(file); file.putUserData(HARD_REF_TO_DOCUMENT_KEY, null); document.putUserData(FILE_KEY, null); }
Example 14
Source File: EncodingManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
private void setCachedCharsetFromContent(Charset charset, Charset oldCached, @Nonnull Document document) { document.putUserData(CACHED_CHARSET_FROM_CONTENT, charset); firePropertyChange(document, PROP_CACHED_ENCODING_CHANGED, oldCached, charset); }
Example 15
Source File: DiffRangeMarker.java From consulo with Apache License 2.0 | 4 votes |
private void onClientRemoved(@Nonnull Document document, @Nonnull DiffRangeMarker marker, @Nonnull RangeInvalidListener listener) { if (myDiffRangeMarkers.remove(marker) == listener && myDiffRangeMarkers.isEmpty()) { document.putUserData(KEY, null); document.removeDocumentListener(this); } }
Example 16
Source File: CppSupportLoader.java From CppTools with Apache License 2.0 | 4 votes |
private void removeDocumentListener(Document document) { if (isAcceptableDocument(document) && document.getUserData(ourListenerKey) != null) { document.removeDocumentListener(myDocumentListener); document.putUserData(ourListenerKey, null); } }
Example 17
Source File: DocumentUndoProvider.java From consulo with Apache License 2.0 | 4 votes |
public static void startDocumentUndo(@Nullable Document doc) { if (doc != null) doc.putUserData(UNDOING_EDITOR_CHANGE, Boolean.TRUE); }
Example 18
Source File: EditorHighlighterCache.java From consulo with Apache License 2.0 | 4 votes |
public static void rememberEditorHighlighterForCachesOptimization(Document document, @Nonnull final EditorHighlighter highlighter) { document.putUserData(ourSomeEditorSyntaxHighlighter, new WeakReference<EditorHighlighter>(highlighter)); }
Example 19
Source File: CommonCodeStyleSettings.java From consulo with Apache License 2.0 | 4 votes |
public void associateWithDocument(@Nonnull Document document) { document.putUserData(INDENT_OPTIONS_KEY, this); }
Example 20
Source File: CommitHelper.java From consulo with Apache License 2.0 | 2 votes |
/** * Removes the "being committed marker" from the given {@link Document documents}. * * @see #markCommittingDocuments(com.intellij.openapi.project.Project, java.util.List) * @see VetoSavingCommittingDocumentsAdapter */ public static void unmarkCommittingDocuments(@Nonnull Collection<Document> committingDocs) { for (Document doc : committingDocs) { doc.putUserData(DOCUMENT_BEING_COMMITTED_KEY, null); } }