Java Code Examples for org.eclipse.jface.text.IDocument#addDocumentListener()
The following examples show how to use
org.eclipse.jface.text.IDocument#addDocumentListener() .
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: PartEventListener.java From scava with Eclipse Public License 2.0 | 6 votes |
private void subscribeDocumentEventListener(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part instanceof IEditorPart) { IEditorPart editor = (IEditorPart) part; IEditorInput input = editor.getEditorInput(); if (editor instanceof ITextEditor && input instanceof FileEditorInput) { ITextEditor textEditor = (ITextEditor) editor; // EventManager.setEditor(textEditor); saveListener(textEditor); IDocument document = textEditor.getDocumentProvider().getDocument(input); DocumentEventListener documentListener = new DocumentEventListener(textEditor.getTitle()); document.addDocumentListener(documentListener); } } }
Example 2
Source File: DocumentManager.java From ContentAssist with MIT License | 6 votes |
/** * Registers a document manager with an editor. * @param doc the document to be managed * @param st the styled text of the editor * @param dm the document manager */ public static void register(IDocument doc, StyledText st, DocumentManager dm) { if (doc != null) { doc.addDocumentListener(dm); DocumentUndoManagerRegistry.connect(doc); IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc); if (undoManager != null) { undoManager.addDocumentUndoListener(dm); } } if (st != null) { st.addListener(SWT.KeyDown, dm); st.addListener(SWT.MouseDown, dm); st.addListener(SWT.MouseDoubleClick, dm); } }
Example 3
Source File: BaseParser.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public synchronized void setDocument(IDocument doc, boolean addToScheduler, Object input) { this.input = input; // Cleans up old listeners if (this.document != null) { this.document.removeDocumentListener(documentListener); } // Set up new listener this.document = doc; if (doc == null) { Log.log("No document in PyParser::setDocument?"); return; } doc.addDocumentListener(documentListener); if (addToScheduler) { // Reparse document on the initial set (force it) scheduler.parseNow(true); } }
Example 4
Source File: IOConsoleViewer.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@Override public void setDocument(IDocument document) { IDocument oldDocument= getDocument(); super.setDocument(document); if (oldDocument != null) { oldDocument.removeDocumentListener(getDocumentListener()); } if (document != null) { document.addDocumentListener(getDocumentListener()); } }
Example 5
Source File: KbdMacroSupport.java From e4macs with Eclipse Public License 1.0 | 5 votes |
private void addDocumentListener(ITextEditor editor) { IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); if (listening != null) { listening.document.removeDocumentListener(listening); } listening = new KbdMacroAutoFix(document); document.addDocumentListener(listening); }
Example 6
Source File: ScriptConsoleDocumentListener.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Stops listening changes in one document and starts listening another one. * * @param oldDoc may be null (if not null, this class will stop listening changes in it). * @param newDoc the document that should be listened from now on. */ protected synchronized void reconnect(IDocument oldDoc, IDocument newDoc) { Assert.isTrue(disconnectionLevel == 0); if (oldDoc != null) { oldDoc.removeDocumentListener(this); } newDoc.addDocumentListener(this); this.doc = newDoc; }
Example 7
Source File: ConsoleCopyCutHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent) */ @Override public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) { Object result = null; IDocument doc = viewer.getDocument(); try { IWorkbenchPartSite site = activePart.getSite(); if (site != null) { IHandlerService service = (IHandlerService) site.getService(IHandlerService.class); if (doc != null && service != null) { doc.addDocumentListener(KillRing.getInstance()); String cmdId = getId(event, viewer); if (cmdId != null) { result = service.executeCommand(cmdId, null); } } } } catch (CommandException e) { // Shouldn't happen as the Command id will be null or valid e.printStackTrace(); } finally { if (doc != null) { doc.removeDocumentListener(KillRing.getInstance()); } // clear kill command flag KillRing.getInstance().setKill(null, false); } MarkUtils.clearConsoleMark(viewer); return result; }
Example 8
Source File: SemanticHighlightingPresenter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Start managing the given document. * * @param document The document */ private void manageDocument(IDocument document) { if (document != null) { document.addPositionCategory(getPositionCategory()); document.addPositionUpdater(fPositionUpdater); document.addDocumentListener(this); } }
Example 9
Source File: RemoveCoverageMarkersListener.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public RemoveCoverageMarkersListener(IDocument document, PyEdit edit, IFile file) { this.doc = document; this.edit = edit; this.file = file; document.addDocumentListener(this); edit.addPyeditListener(this); }
Example 10
Source File: CommonOccurrencesUpdater.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * install */ public void install() { ISourceViewer sourceViewer = getSourceViewer(); IDocument document = getDocument(); if (sourceViewer != null) { sourceViewer.addTextInputListener(this); } if (document != null) { document.addDocumentListener(this); } }
Example 11
Source File: JsonEditor.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 5 votes |
@Override protected void doSetInput(IEditorInput input) throws CoreException { if (input != null) { super.doSetInput(input); IDocument document = getDocumentProvider().getDocument(getEditorInput()); if (document != null) { document.addDocumentListener(changeListener); // validate content before editor opens runValidate(true); } } }
Example 12
Source File: XdsConsoleViewer.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public void setDocument(IDocument document) { IDocument oldDocument= getDocument(); super.setDocument(document); if (oldDocument != null) { oldDocument.removeDocumentListener(getDocumentListener()); } if (document != null) { document.addDocumentListener(getDocumentListener()); } }
Example 13
Source File: SourceCodeTextEditor.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { if (oldInput != null) { oldInput.removeDocumentListener(documentListener); } if (newInput != null) { newInput.addDocumentListener(documentListener); } modificationStamp = ModificationStamp.OLDEST; }
Example 14
Source File: HighlightingPresenter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Start managing the given document. * * @param document * The document */ private void manageDocument(IDocument document) { if (document != null) { document.addPositionCategory(getPositionCategory()); document.addPositionUpdater(fPositionUpdater); document.addDocumentListener(this); } }
Example 15
Source File: DocumentLineList.java From tm4e with Eclipse Public License 1.0 | 5 votes |
public DocumentLineList(IDocument document) { this.document = document; this.listener = new InternalListener(); document.addDocumentListener(listener); for (int i = 0; i < document.getNumberOfLines(); i++) { addLine(i); } }
Example 16
Source File: CommonOccurrencesUpdater.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { if (newInput != null) { newInput.addDocumentListener(this); } }
Example 17
Source File: TypeScriptEditor.java From typescript.java with MIT License | 4 votes |
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { if (newInput == null) return; newInput.addDocumentListener(this); }
Example 18
Source File: DocumentReconcileManager.java From goclipse with Eclipse Public License 1.0 | 4 votes |
public DocumentReconcileConnection(IDocument document, StructureInfo structureInfo) { this.document = assertNotNull(document); this.structureInfo = assertNotNull(structureInfo); document.addDocumentListener(docListener); }
Example 19
Source File: JSEditor.java From birt with Eclipse Public License 1.0 | 4 votes |
public void createPartControl( Composite parent ) { Composite child = this.initEditorLayout( parent ); // Script combo cmbExprListViewer = new ComboViewer( cmbExpList ); JSExpListProvider provider = new JSExpListProvider( ); cmbExprListViewer.setContentProvider( provider ); cmbExprListViewer.setLabelProvider( provider ); cmbExprListViewer.setData( VIEWER_CATEGORY_KEY, VIEWER_CATEGORY_CONTEXT ); // SubFunctions combo JSSubFunctionListProvider subProvider = new JSSubFunctionListProvider( this ); // also add subProvider as listener of expr viewer. cmbExprListViewer.addSelectionChangedListener( subProvider ); cmbSubFunctions.addListener( CustomChooserComposite.DROPDOWN_EVENT, new Listener( ) { public void handleEvent( Event event ) { cmbSubFunctions.deselectAll( ); ScriptParser parser = new ScriptParser( getEditorText( ) ); Collection<IScriptMethodInfo> coll = parser.getAllMethodInfo( ); for ( Iterator<IScriptMethodInfo> itr = coll.iterator( ); itr.hasNext( ); ) { IScriptMethodInfo mtd = itr.next( ); cmbSubFunctions.markSelection( METHOD_DISPLAY_INDENT + mtd.getName( ) ); } } } ); cmbSubFunctionsViewer = new TextComboViewer( cmbSubFunctions ); cmbSubFunctionsViewer.setContentProvider( subProvider ); cmbSubFunctionsViewer.setLabelProvider( subProvider ); cmbSubFunctionsViewer.addSelectionChangedListener( subProvider ); cmbSubFunctionsViewer.addSelectionChangedListener( propertyDefnChangeListener ); // Initialize the model for the document. Object model = getModel( ); if ( model != null ) { cmbExpList.setVisible( true ); cmbSubFunctions.setVisible( true ); setComboViewerInput( model ); } else { setComboViewerInput( Messages.getString( "JSEditor.Input.trial" ) ); //$NON-NLS-1$ } cmbExprListViewer.addSelectionChangedListener( palettePage.getSupport( ) ); cmbExprListViewer.addSelectionChangedListener( propertyDefnChangeListener ); scriptEditor.createPartControl( child ); scriptValidator = new ScriptValidator( getViewer( ) ); disableEditor( ); SourceViewer viewer = getViewer( ); IDocument document = viewer == null ? null : viewer.getDocument( ); if ( document != null ) { IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager( document ); if ( undoManager != null ) { undoManager.addDocumentUndoListener( undoListener ); } document.addDocumentListener( documentListener ); } }
Example 20
Source File: TMPresentationReconcilerTestGenerator.java From tm4e with Eclipse Public License 1.0 | 4 votes |
@Override public void install(ITextViewer viewer, IDocument document) { this.viewer = viewer; this.document = document; document.addDocumentListener(this); viewer.addTextListener(this); write("package org.eclipse.tm4e.ui.text;", true); write("", true); write("import org.eclipse.jface.text.Document;", true); write("import org.eclipse.jface.text.IDocument;", true); write("import org.eclipse.jface.text.TextViewer;", true); write("import org.eclipse.swt.SWT;", true); write("import org.eclipse.swt.widgets.Display;", true); write("import org.eclipse.swt.widgets.Shell;", true); write("import org.eclipse.tm4e.core.grammar.IGrammar;", true); write("import org.eclipse.tm4e.core.registry.Registry;", true); write("import org.eclipse.tm4e.ui.text.TMPresentationReconciler;", true); write("import org.eclipse.tm4e.ui.themes.ITokenProvider;", true); write("import org.eclipse.tm4e.ui.themes.css.CSSTokenProvider;", true); write("import org.junit.Test;", true); write("", true); write("public class TMPresentationReconcilerTest {", true); write("", true); write("\t@Test", true); write("\tpublic void colorize() throws Exception {", true); write("", true); write("\t\tDisplay display = new Display();", true); write("\t\tShell shell = new Shell(display);", true); write("\t\tTextViewer viewer = new TextViewer(shell, SWT.NONE);", true); write("\t\tIDocument document = new Document();", true); write("\t\tviewer.setDocument(document);", true); write("\t\tdocument.set(\""); write(toText(document.get())); write("\");", true); // commands.add(new Command("document.set(...)")); write("", true); write("\t\tTMPresentationReconciler reconciler = new TMPresentationReconciler();", true); write("\t\treconciler.setTokenProvider(getTokenProvider());", true); write("\t\treconciler.setGrammar(getGrammar());", true); write("\t\treconciler.install(viewer);", true); write("", true); }