aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2013-02-15 09:47:06 (EST)
committerMatthias Sohn2013-02-20 18:04:34 (EST)
commit23251a552f7f01d2934d0c3b9e497a17f5a84a64 (patch)
tree4ac244fb7854b233e5dab278156b1806200dd642
parent1295b048f7b196e6ef6b7ac69fcf09a1bda2f8a5 (diff)
downloadegit-23251a552f7f01d2934d0c3b9e497a17f5a84a64.zip
egit-23251a552f7f01d2934d0c3b9e497a17f5a84a64.tar.gz
egit-23251a552f7f01d2934d0c3b9e497a17f5a84a64.tar.bz2
Workaround for bug in StyledText#addBidiSegmentListener(..)refs/changes/87/10387/2
Due to bug 400727, that listener is only called on Windows when an RTL input language is installed. The fix is to detect this situation and resort to a workaround: Restrict the maximum width of the message area to MAX_LINE_WIDTH. Bug: 400662 Change-Id: Ic05725cd37230b2ecdac769dfdadb03dacfe7276 Signed-off-by: Markus Keller <markus_keller@ch.ibm.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java61
1 files changed, 60 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
index 93de599..bb0c5a4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/SpellcheckableMessageArea.java
@@ -77,9 +77,11 @@ import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Layout;
import org.eclipse.ui.ActiveShellExpression;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
@@ -212,6 +214,9 @@ public class SpellcheckableMessageArea extends Composite {
private BidiSegmentListener hardWrapSegmentListener;
+ // XXX: workaround for https://bugs.eclipse.org/400727
+ private int brokenBidiPlatformTextWidth;
+
private ActionHandler quickFixActionHandler;
private ActionHandler contentAssistActionHandler;
@@ -258,6 +263,8 @@ public class SpellcheckableMessageArea extends Composite {
Point size = getTextWidget().computeSize(textWidth, textHeight);
getTextWidget().setSize(size);
+ computeBrokenBidiPlatformTextWidth(size.x);
+
getTextWidget().setEditable(!readOnly);
createMarginPainter();
@@ -269,6 +276,9 @@ public class SpellcheckableMessageArea extends Composite {
getDisplay().asyncExec(new Runnable() {
public void run() {
configureHardWrap();
+ if (brokenBidiPlatformTextWidth != -1) {
+ layout();
+ }
}
});
}
@@ -320,6 +330,24 @@ public class SpellcheckableMessageArea extends Composite {
});
}
+ private void computeBrokenBidiPlatformTextWidth(int textWidth) {
+ class BidiSegmentListenerTester implements BidiSegmentListener {
+ boolean called;
+
+ public void lineGetSegments(BidiSegmentEvent event) {
+ called = true;
+ }
+ }
+ BidiSegmentListenerTester tester = new BidiSegmentListenerTester();
+ StyledText textWidget = getTextWidget();
+ textWidget.addBidiSegmentListener(tester);
+ textWidget.setText(" "); //$NON-NLS-1$
+ textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ textWidget.removeBidiSegmentListener(tester);
+
+ brokenBidiPlatformTextWidth = tester.called ? -1 : textWidth;
+ }
+
private boolean isEditable(ISourceViewer viewer) {
return viewer != null && viewer.getTextWidget().getEditable();
}
@@ -327,7 +355,7 @@ public class SpellcheckableMessageArea extends Composite {
private void configureHardWrap() {
if (shouldHardWrap()) {
if (hardWrapSegmentListener == null) {
- StyledText textWidget = getTextWidget();
+ final StyledText textWidget = getTextWidget();
hardWrapSegmentListener = new BidiSegmentListener() {
public void lineGetSegments(BidiSegmentEvent e) {
int[] segments = calculateWrapOffsets(e.lineText, MAX_LINE_WIDTH);
@@ -341,12 +369,43 @@ public class SpellcheckableMessageArea extends Composite {
};
textWidget.addBidiSegmentListener(hardWrapSegmentListener);
textWidget.setText(textWidget.getText()); // XXX: workaround for https://bugs.eclipse.org/384886
+
+ if (brokenBidiPlatformTextWidth != -1) {
+ Layout restrictedWidthLayout = new Layout() {
+ @Override
+ protected Point computeSize(Composite composite,
+ int wHint, int hHint, boolean flushCache) {
+ Point size = SpellcheckableMessageArea.this
+ .getSize();
+ Rectangle trim = SpellcheckableMessageArea.this
+ .computeTrim(0, 0, 0, 0);
+ size.x -= trim.width;
+ size.y -= trim.height;
+ if (size.x > brokenBidiPlatformTextWidth)
+ size.x = brokenBidiPlatformTextWidth;
+ return size;
+ }
+
+ @Override
+ protected void layout(Composite composite,
+ boolean flushCache) {
+ Point size = computeSize(composite, SWT.DEFAULT,
+ SWT.DEFAULT, flushCache);
+ textWidget.setBounds(0, 0, size.x, size.y);
+ }
+ };
+ setLayout(restrictedWidthLayout);
+ }
}
+
} else if (hardWrapSegmentListener != null) {
StyledText textWidget = getTextWidget();
textWidget.removeBidiSegmentListener(hardWrapSegmentListener);
textWidget.setText(textWidget.getText()); // XXX: workaround for https://bugs.eclipse.org/384886
hardWrapSegmentListener = null;
+
+ if (brokenBidiPlatformTextWidth != -1)
+ setLayout(new FillLayout());
}
}