Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-04-03 17:04:00 +0000
committerMichael Valenta2007-04-03 17:04:00 +0000
commit8d899c94304253509b1324131dcb9e149ad3ec78 (patch)
tree842222f00a4f951219e47bf58b96c922006084b3 /bundles/org.eclipse.compare
parent2d9d459f5f25b8d757dbe6856723fbc38ce45e7a (diff)
downloadeclipse.platform.team-8d899c94304253509b1324131dcb9e149ad3ec78.tar.gz
eclipse.platform.team-8d899c94304253509b1324131dcb9e149ad3ec78.tar.xz
eclipse.platform.team-8d899c94304253509b1324131dcb9e149ad3ec78.zip
Bug 72936 [Viewers] Show line numbers in comparision
Diffstat (limited to 'bundles/org.eclipse.compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java9
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java88
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java9
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java88
4 files changed, 184 insertions, 10 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 1f0aadb3e..16844ba22 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -10,6 +10,7 @@
* channingwalton@mac.com - curved line code
* gilles.querret@free.fr - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72995
* Max Weninger (max.weninger@windriver.com) - Bug 131895 [Edit] Undo in compare
+ * Max Weninger (max.weninger@windriver.com) - Bug 72936 [Viewers] Show line numbers in comparision
*******************************************************************************/
package org.eclipse.compare.contentmergeviewer;
@@ -2884,14 +2885,14 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
x+= fMarginWidth;
width-= fMarginWidth;
}
- fAncestor.getTextWidget().setBounds(x, y, width, height);
+ fAncestor.setBounds(x, y, width, height);
} else {
if (Utilities.okToUse(fAncestorCanvas))
fAncestorCanvas.setVisible(false);
if (fAncestor.isControlOkToUse()) {
StyledText t= fAncestor.getTextWidget();
t.setVisible(false);
- t.setBounds(0, 0, 0, 0);
+ fAncestor.setBounds(0, 0, 0, 0);
if (fFocusPart == fAncestor) {
fFocusPart= fLeft;
fFocusPart.getTextWidget().setFocus();
@@ -2920,7 +2921,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
leftTextWidth-= fMarginWidth;
}
- fLeft.getTextWidget().setBounds(x, y, leftTextWidth, height);
+ fLeft.setBounds(x, y, leftTextWidth, height);
x+= leftTextWidth;
if (fCenter == null || fCenter.isDisposed())
@@ -2946,7 +2947,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
int rightTextWidth= width2-scrollbarWidth;
if (fRightCanvas != null)
rightTextWidth-= fMarginWidth;
- fRight.getTextWidget().setBounds(x, y, rightTextWidth, height);
+ fRight.setBounds(x, y, rightTextWidth, height);
x+= rightTextWidth;
if (fSynchronizedScrolling) {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index 1cb882c82..3e647d3ca 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Max Weninger (max.weninger@windriver.com) - Bug 131895 [Edit] Undo in compare
+ * Max Weninger (max.weninger@windriver.com) - Bug 72936 [Viewers] Show line numbers in comparision
*******************************************************************************/
package org.eclipse.compare.internal;
@@ -29,6 +30,10 @@ import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.*;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.jface.viewers.SelectionChangedEvent;
/**
@@ -80,8 +85,13 @@ public class MergeSourceViewer extends SourceViewer
private boolean fAddSaveAction= true;
private boolean isConfigured = false;
+ // line number ruler support
+ private IPropertyChangeListener fPreferenceChangeListener;
+ private boolean fShowLineNumber=false;
+ private LineNumberRulerColumn fLineNumberColumn;
+
public MergeSourceViewer(Composite parent, int style, ResourceBundle bundle, ICompareContainer container) {
- super(parent, null, style | SWT.H_SCROLL | SWT.V_SCROLL);
+ super(parent, new CompositeRuler(), style | SWT.H_SCROLL | SWT.V_SCROLL);
fResourceBundle= bundle;
@@ -91,6 +101,18 @@ public class MergeSourceViewer extends SourceViewer
StyledText te= getTextWidget();
te.setMenu(menu.createContextMenu(te));
container.registerContextMenu(menu, this);
+
+ // for listening to editor show/hide line number preference value
+ fPreferenceChangeListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ MergeSourceViewer.this.handlePropertyChangeEvent(event);
+ }
+ };
+ EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener);
+ fShowLineNumber= EditorsUI.getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
+ if(fShowLineNumber){
+ updateLineNumberRuler();
+ }
}
public void rememberDocument(IDocument doc) {
@@ -425,6 +447,7 @@ public class MergeSourceViewer extends SourceViewer
removeTextListener(this);
removeSelectionChangedListener(this);
+ EditorsUI.getPreferenceStore().removePropertyChangeListener(fPreferenceChangeListener);
super.handleDispose();
}
@@ -447,4 +470,67 @@ public class MergeSourceViewer extends SourceViewer
isConfigured = true;
super.configure(configuration);
}
+
+ /**
+ * specific implemenation to support a vertical ruler
+ * @param x
+ * @param y
+ * @param width
+ * @param height
+ */
+ public void setBounds (int x, int y, int width, int height) {
+ if(getControl() instanceof Composite){
+ ((Composite)getControl()).setBounds(x, y, width, height);
+ } else {
+ getTextWidget().setBounds(x, y, width, height);
+ }
+ }
+
+ /**
+ * handle show/hide line numbers from editor preferences
+ * @param event
+ */
+ protected void handlePropertyChangeEvent(PropertyChangeEvent event) {
+
+ String key= event.getProperty();
+
+ if(key.equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER)){
+ boolean b= EditorsUI.getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
+ if (b != fShowLineNumber){
+ toogleLineNumberRuler();
+ }
+ }
+ }
+
+ /**
+ * Hides or shows line number ruler column based of pref setting
+ */
+ private void updateLineNumberRuler()
+ {
+ IVerticalRuler v= getVerticalRuler();
+ if (v!=null && v instanceof CompositeRuler) {
+ CompositeRuler c= (CompositeRuler) v;
+
+ if(!fShowLineNumber){
+ if(fLineNumberColumn!=null){
+ c.removeDecorator(fLineNumberColumn);
+ }
+ } else {
+ if(fLineNumberColumn==null){
+ fLineNumberColumn = new LineNumberRulerColumn();
+ }
+ c.addDecorator(0, fLineNumberColumn);
+ }
+ }
+ }
+
+ /**
+ * Toogles line number ruler column.
+ */
+ private void toogleLineNumberRuler()
+ {
+ fShowLineNumber=!fShowLineNumber;
+
+ updateLineNumberRuler();
+ }
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 1f0aadb3e..16844ba22 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -10,6 +10,7 @@
* channingwalton@mac.com - curved line code
* gilles.querret@free.fr - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72995
* Max Weninger (max.weninger@windriver.com) - Bug 131895 [Edit] Undo in compare
+ * Max Weninger (max.weninger@windriver.com) - Bug 72936 [Viewers] Show line numbers in comparision
*******************************************************************************/
package org.eclipse.compare.contentmergeviewer;
@@ -2884,14 +2885,14 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
x+= fMarginWidth;
width-= fMarginWidth;
}
- fAncestor.getTextWidget().setBounds(x, y, width, height);
+ fAncestor.setBounds(x, y, width, height);
} else {
if (Utilities.okToUse(fAncestorCanvas))
fAncestorCanvas.setVisible(false);
if (fAncestor.isControlOkToUse()) {
StyledText t= fAncestor.getTextWidget();
t.setVisible(false);
- t.setBounds(0, 0, 0, 0);
+ fAncestor.setBounds(0, 0, 0, 0);
if (fFocusPart == fAncestor) {
fFocusPart= fLeft;
fFocusPart.getTextWidget().setFocus();
@@ -2920,7 +2921,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
leftTextWidth-= fMarginWidth;
}
- fLeft.getTextWidget().setBounds(x, y, leftTextWidth, height);
+ fLeft.setBounds(x, y, leftTextWidth, height);
x+= leftTextWidth;
if (fCenter == null || fCenter.isDisposed())
@@ -2946,7 +2947,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
int rightTextWidth= width2-scrollbarWidth;
if (fRightCanvas != null)
rightTextWidth-= fMarginWidth;
- fRight.getTextWidget().setBounds(x, y, rightTextWidth, height);
+ fRight.setBounds(x, y, rightTextWidth, height);
x+= rightTextWidth;
if (fSynchronizedScrolling) {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
index 1cb882c82..3e647d3ca 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Max Weninger (max.weninger@windriver.com) - Bug 131895 [Edit] Undo in compare
+ * Max Weninger (max.weninger@windriver.com) - Bug 72936 [Viewers] Show line numbers in comparision
*******************************************************************************/
package org.eclipse.compare.internal;
@@ -29,6 +30,10 @@ import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.*;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.jface.viewers.SelectionChangedEvent;
/**
@@ -80,8 +85,13 @@ public class MergeSourceViewer extends SourceViewer
private boolean fAddSaveAction= true;
private boolean isConfigured = false;
+ // line number ruler support
+ private IPropertyChangeListener fPreferenceChangeListener;
+ private boolean fShowLineNumber=false;
+ private LineNumberRulerColumn fLineNumberColumn;
+
public MergeSourceViewer(Composite parent, int style, ResourceBundle bundle, ICompareContainer container) {
- super(parent, null, style | SWT.H_SCROLL | SWT.V_SCROLL);
+ super(parent, new CompositeRuler(), style | SWT.H_SCROLL | SWT.V_SCROLL);
fResourceBundle= bundle;
@@ -91,6 +101,18 @@ public class MergeSourceViewer extends SourceViewer
StyledText te= getTextWidget();
te.setMenu(menu.createContextMenu(te));
container.registerContextMenu(menu, this);
+
+ // for listening to editor show/hide line number preference value
+ fPreferenceChangeListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ MergeSourceViewer.this.handlePropertyChangeEvent(event);
+ }
+ };
+ EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener);
+ fShowLineNumber= EditorsUI.getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
+ if(fShowLineNumber){
+ updateLineNumberRuler();
+ }
}
public void rememberDocument(IDocument doc) {
@@ -425,6 +447,7 @@ public class MergeSourceViewer extends SourceViewer
removeTextListener(this);
removeSelectionChangedListener(this);
+ EditorsUI.getPreferenceStore().removePropertyChangeListener(fPreferenceChangeListener);
super.handleDispose();
}
@@ -447,4 +470,67 @@ public class MergeSourceViewer extends SourceViewer
isConfigured = true;
super.configure(configuration);
}
+
+ /**
+ * specific implemenation to support a vertical ruler
+ * @param x
+ * @param y
+ * @param width
+ * @param height
+ */
+ public void setBounds (int x, int y, int width, int height) {
+ if(getControl() instanceof Composite){
+ ((Composite)getControl()).setBounds(x, y, width, height);
+ } else {
+ getTextWidget().setBounds(x, y, width, height);
+ }
+ }
+
+ /**
+ * handle show/hide line numbers from editor preferences
+ * @param event
+ */
+ protected void handlePropertyChangeEvent(PropertyChangeEvent event) {
+
+ String key= event.getProperty();
+
+ if(key.equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER)){
+ boolean b= EditorsUI.getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
+ if (b != fShowLineNumber){
+ toogleLineNumberRuler();
+ }
+ }
+ }
+
+ /**
+ * Hides or shows line number ruler column based of pref setting
+ */
+ private void updateLineNumberRuler()
+ {
+ IVerticalRuler v= getVerticalRuler();
+ if (v!=null && v instanceof CompositeRuler) {
+ CompositeRuler c= (CompositeRuler) v;
+
+ if(!fShowLineNumber){
+ if(fLineNumberColumn!=null){
+ c.removeDecorator(fLineNumberColumn);
+ }
+ } else {
+ if(fLineNumberColumn==null){
+ fLineNumberColumn = new LineNumberRulerColumn();
+ }
+ c.addDecorator(0, fLineNumberColumn);
+ }
+ }
+ }
+
+ /**
+ * Toogles line number ruler column.
+ */
+ private void toogleLineNumberRuler()
+ {
+ fShowLineNumber=!fShowLineNumber;
+
+ updateLineNumberRuler();
+ }
}

Back to the top