Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-04-07 19:29:42 +0000
committerKai Maetzel2004-04-07 19:29:42 +0000
commit7214f041d3024c857ae51fbbf6046781520e8da9 (patch)
tree38549762f0f40a1994c40797860fcf77035c5df8
parentfc34b1bbef73235fbf803cd1963040425e4e5b00 (diff)
downloadeclipse.platform.text-7214f041d3024c857ae51fbbf6046781520e8da9.tar.gz
eclipse.platform.text-7214f041d3024c857ae51fbbf6046781520e8da9.tar.xz
eclipse.platform.text-7214f041d3024c857ae51fbbf6046781520e8da9.zip
added support for listening to changes of the visible document; only available to subclasses
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java63
1 files changed, 47 insertions, 16 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index 867be8411..0bddd5a98 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -271,9 +271,9 @@ public class TextViewer extends Viewer implements
}
/**
- * Internal document listener.
+ * Internal document listener on the visible document.
*/
- class DocumentListener implements IDocumentListener {
+ class VisibleDocumentListener implements IDocumentListener {
/*
* @see IDocumentListener#documentAboutToBeChanged
@@ -281,12 +281,14 @@ public class TextViewer extends Viewer implements
public void documentAboutToBeChanged(DocumentEvent e) {
if (e.getDocument() == getVisibleDocument())
fWidgetCommand.setEvent(e);
+ handleVisibleDocumentAboutToBeChanged(e);
}
/*
* @see IDocumentListener#documentChanged
*/
- public void documentChanged(final DocumentEvent e) {
+ public void documentChanged(DocumentEvent e) {
+ handleVisibleDocumentChanged(e);
if (fWidgetCommand.event == e)
updateTextListeners(fWidgetCommand);
fLastSentSelectionChange= null;
@@ -1166,8 +1168,8 @@ public class TextViewer extends Viewer implements
private WidgetCommand fWidgetCommand= new WidgetCommand();
/** The SWT control's scrollbars */
private ScrollBar fScroller;
- /** Document listener */
- private DocumentListener fDocumentListener= new DocumentListener();
+ /** Listener on the visible document */
+ private VisibleDocumentListener fVisibleDocumentListener= new VisibleDocumentListener();
/** Verify listener */
private TextVerifyListener fVerifyListener= new TextVerifyListener();
/** The most recent widget modification as document command */
@@ -1499,10 +1501,10 @@ public class TextViewer extends Viewer implements
fTextHoverManager= null;
}
- if (fDocumentListener !=null) {
+ if (fVisibleDocumentListener !=null) {
if (fVisibleDocument != null)
- fVisibleDocument.removeDocumentListener(fDocumentListener);
- fDocumentListener= null;
+ fVisibleDocument.removeDocumentListener(fVisibleDocumentListener);
+ fVisibleDocumentListener= null;
}
if (fDocumentAdapter != null) {
@@ -2534,7 +2536,7 @@ public class TextViewer extends Viewer implements
if (fTextWidget != null) {
int top= fTextWidget.getTopIndex();
- return widgetlLine2ModelLine(top);
+ return widgetLine2ModelLine(top);
}
return -1;
@@ -2597,7 +2599,7 @@ public class TextViewer extends Viewer implements
if (startLine + lines < endLine) {
int widgetTopIndex= fTextWidget.getTopIndex();
int widgetBottomIndex= widgetTopIndex + lines -1;
- return widgetlLine2ModelLine(widgetBottomIndex);
+ return widgetLine2ModelLine(widgetBottomIndex);
}
return endLine;
@@ -2619,7 +2621,7 @@ public class TextViewer extends Viewer implements
int top= fTextWidget.getTopIndex();
try {
top= getVisibleDocument().getLineOffset(top);
- return widgetlLine2ModelLine(top);
+ return widgetLine2ModelLine(top);
} catch (BadLocationException ex) {
if (TRACE_ERRORS)
System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getTopIndexStartOffset")); //$NON-NLS-1$
@@ -2976,8 +2978,8 @@ public class TextViewer extends Viewer implements
}
if (fVisibleDocument != null) {
- if (fDocumentListener != null)
- fVisibleDocument.removeDocumentListener(fDocumentListener);
+ if (fVisibleDocumentListener != null)
+ fVisibleDocument.removeDocumentListener(fVisibleDocumentListener);
if (fVisibleDocument != document)
freeSlaveDocument(fVisibleDocument);
}
@@ -2990,12 +2992,34 @@ public class TextViewer extends Viewer implements
if (fVisibleDocument != null) {
fFindRepalceDocumentAdapter= new FindReplaceDocumentAdapter(getVisibleDocument());
- if (fDocumentListener != null)
- fVisibleDocument.addDocumentListener(fDocumentListener);
+ if (fVisibleDocumentListener != null)
+ fVisibleDocument.addDocumentListener(fVisibleDocumentListener);
}
}
/**
+ * Hook method called when the visible document is about to be changed.
+ * <p>
+ * Subclasses may override.
+ *
+ * @param event the document event
+ * @since 3.0
+ */
+ protected void handleVisibleDocumentAboutToBeChanged(DocumentEvent event) {
+ }
+
+ /**
+ * Hook method called when the visible document has been changed.
+ * <p>
+ * Subclasses may override.
+ *
+ * @param event the document event
+ * @since 3.0
+ */
+ protected void handleVisibleDocumentChanged(DocumentEvent event) {
+ }
+
+ /**
* Initializes the document information mapping between the given slave document and
* its master document.
*
@@ -4507,12 +4531,19 @@ public class TextViewer extends Viewer implements
return null;
}
-
+
/*
* @see org.eclipse.jface.text.ITextViewerExtension3#widgetlLine2ModelLine(int)
* @since 2.1
*/
public int widgetlLine2ModelLine(int widgetLine) {
+ return widgetLine2ModelLine(widgetLine);
+ }
+
+ /**
+ * @see ITextViewerExtension5#widgetLine2ModelLine(int)
+ */
+ public int widgetLine2ModelLine(int widgetLine) {
if (fInformationMapping == null)
return widgetLine;

Back to the top