Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Ratz2019-03-28 13:06:33 -0400
committerMatthias Becker2019-04-12 07:22:14 -0400
commit34b73d3a4d5bc0fa21a9df897ec2b04d6e31e411 (patch)
treeeb50ecf7336f5b5f69e348dd11e9f04c98a5ba5c
parent54cac7b35fcbea386f5fa253d5cf644e39769bf7 (diff)
downloadeclipse.platform.ui-34b73d3a4d5bc0fa21a9df897ec2b04d6e31e411.tar.gz
eclipse.platform.ui-34b73d3a4d5bc0fa21a9df897ec2b04d6e31e411.tar.xz
eclipse.platform.ui-34b73d3a4d5bc0fa21a9df897ec2b04d6e31e411.zip
Bug 545918 - Add option to make Form title text selectable
Change-Id: Ia75c4943300c755c6ddffb207facf279554acb05 Signed-off-by: Sebastian Ratz <sebastian.ratz@sap.com>
-rw-r--r--bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.ui.forms/pom.xml2
-rw-r--r--bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java15
-rw-r--r--bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java13
-rw-r--r--bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java55
-rw-r--r--examples/org.eclipse.ui.forms.examples/META-INF/MANIFEST.MF2
-rw-r--r--examples/org.eclipse.ui.forms.examples/pom.xml2
-rw-r--r--examples/org.eclipse.ui.forms.examples/src/org/eclipse/ui/forms/examples/views/FormView.java10
8 files changed, 90 insertions, 11 deletions
diff --git a/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF
index 223760cd24..0814933d8b 100644
--- a/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.ui.forms/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.ui.forms;singleton:=true
-Bundle-Version: 3.7.500.qualifier
+Bundle-Version: 3.8.0.qualifier
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
Export-Package: org.eclipse.ui.forms,
diff --git a/bundles/org.eclipse.ui.forms/pom.xml b/bundles/org.eclipse.ui.forms/pom.xml
index 9ebe788afa..7ed27bfe89 100644
--- a/bundles/org.eclipse.ui.forms/pom.xml
+++ b/bundles/org.eclipse.ui.forms/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.forms</artifactId>
- <version>3.7.500-SNAPSHOT</version>
+ <version>3.8.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java
index e26d1a841e..0d64fc7677 100644
--- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java
+++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Form.java
@@ -282,6 +282,21 @@ public class Form extends Composite {
}
/**
+ * Sets whether ther text in the title region should be selectable.
+ * <p>
+ * Note: If {@link #addTitleDragSupport(int, Transfer[], DragSourceListener)
+ * drag support} is also enabled, text selection has priority. Dragging still
+ * works in the non-text parts of the title area.
+ *
+ * @param selectable whether the title text should be selectable
+ *
+ * @since 3.8
+ */
+ public void setTitleTextSelectable(boolean selectable) {
+ head.setTextSelectable(selectable);
+ }
+
+ /**
* Sets the image to be rendered to the left of the title. This image will
* be temporarily hidden in two cases:
*
diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java
index ab3e419ad1..b959ad0605 100644
--- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java
+++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormHeading.java
@@ -707,6 +707,19 @@ public class FormHeading extends Canvas {
titleRegion.setText(text);
}
+ /**
+ * Sets whether ther text in the title region should be selectable.
+ * <p>
+ * Note: If {@link #addDragSupport(int, Transfer[], DragSourceListener) drag
+ * support} is also enabled, text selection has priority. Dragging still works
+ * in the non-text parts of the title area.
+ *
+ * @param selectable whether the title text should be selectable
+ */
+ public void setTextSelectable(boolean selectable) {
+ titleRegion.setTextSelectable(selectable);
+ }
+
@Override
public void setFont(Font font) {
super.setFont(font);
diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java
index ab95393d17..5c6fc2e2af 100644
--- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java
+++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/TitleRegion.java
@@ -24,6 +24,7 @@ import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
@@ -41,6 +42,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.widgets.ILayoutExtension;
import org.eclipse.ui.forms.widgets.SizeCache;
@@ -62,7 +64,9 @@ public class TitleRegion extends Canvas {
private static final int ARC_HEIGHT = 20;
private Image image;
private BusyIndicator busyLabel;
+ private Control currentTitleControl;
private Label titleLabel;
+ private Text titleText;
private SizeCache titleCache;
private int fontHeight = -1;
private int fontBaselineHeight = -1;
@@ -149,19 +153,19 @@ public class TitleRegion extends Canvas {
}
if (menuManager != null) {
menuHyperlink.setVisible(!menuManager.isEmpty()
- && titleLabel.getVisible());
+ && currentTitleControl.getVisible());
if (menuHyperlink.getVisible())
msize = menuHyperlink.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
if (flushCache)
titleCache.flush();
- titleCache.setControl(titleLabel);
+ titleCache.setControl(currentTitleControl);
int twidth = iwidth == SWT.DEFAULT ? iwidth : iwidth - SPACING * 2;
if (bsize != null && twidth != SWT.DEFAULT)
twidth -= bsize.x + SPACING;
if (msize != null && twidth != SWT.DEFAULT)
twidth -= msize.x + SPACING;
- if (titleLabel.getVisible()) {
+ if (currentTitleControl.getVisible()) {
tsize = titleCache.computeSize(twidth, SWT.DEFAULT);
if (twidth != SWT.DEFAULT) {
// correct for the case when width hint is larger
@@ -203,7 +207,7 @@ public class TitleRegion extends Canvas {
bsize.x, bsize.y);
xloc += bsize.x + SPACING;
}
- if (titleLabel.getVisible()) {
+ if (currentTitleControl.getVisible()) {
int tw = width - HMARGIN * 2 - SPACING * 2;
String os = System.getProperty("os.name"); //$NON-NLS-1$
if (Constants.OS_LINUX.equalsIgnoreCase(os)) {
@@ -213,7 +217,7 @@ public class TitleRegion extends Canvas {
tw -= bsize.x + SPACING;
if (msize != null)
tw -= msize.x + SPACING;
- titleLabel.setBounds(xloc,
+ currentTitleControl.setBounds(xloc,
// yloc + height / 2 - tsize.y / 2,
yloc, tw, tsize.y);
// System.out.println("tw="+tw); //$NON-NLS-1$
@@ -243,6 +247,12 @@ public class TitleRegion extends Canvas {
super(parent, SWT.NULL);
titleLabel = new Label(this, SWT.WRAP);
titleLabel.setVisible(false);
+ titleText = new Text(this, SWT.WRAP);
+ titleText.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_IBEAM));
+ titleText.setEditable(false);
+ titleText.addFocusListener(FocusListener.focusLostAdapter(e -> titleText.setSelection(0)));
+ titleText.setVisible(false);
+ currentTitleControl = titleLabel;
titleCache = new SizeCache();
super.setLayout(new TitleRegionLayout());
hookHoverListeners();
@@ -305,6 +315,8 @@ public class TitleRegion extends Canvas {
Color color = getHoverBackground();
titleLabel.setBackground(color != null ? color
: getColor(FormHeading.COLOR_BASE_BG));
+ titleText.setBackground(color != null ? color
+ : getColor(FormHeading.COLOR_BASE_BG));
if (busyLabel != null)
busyLabel.setBackground(color != null ? color
: getColor(FormHeading.COLOR_BASE_BG));
@@ -363,6 +375,7 @@ public class TitleRegion extends Canvas {
public void setBackground(Color bg) {
super.setBackground(bg);
titleLabel.setBackground(bg);
+ titleText.setBackground(bg);
if (busyLabel != null)
busyLabel.setBackground(bg);
if (menuHyperlink != null)
@@ -373,14 +386,17 @@ public class TitleRegion extends Canvas {
public void setForeground(Color fg) {
super.setForeground(fg);
titleLabel.setForeground(fg);
+ titleText.setForeground(fg);
if (menuHyperlink != null)
menuHyperlink.setForeground(fg);
}
public void setText(String text) {
- if (text != null)
+ if (text != null) {
titleLabel.setText(text);
- titleLabel.setVisible(text != null);
+ titleText.setText(text);
+ }
+ currentTitleControl.setVisible(text != null);
layout();
redraw();
}
@@ -389,10 +405,34 @@ public class TitleRegion extends Canvas {
return titleLabel.getText();
}
+ /**
+ * Sets whether ther text in the title region should be selectable.
+ * <p>
+ * Note: If {@link #addDragSupport(int, Transfer[], DragSourceListener) drag
+ * support} is also enabled, text selection has priority. Dragging still works
+ * in the non-text parts of the title area.
+ *
+ * @param selectable whether the title text should be selectable
+ */
+ public void setTextSelectable(boolean selectable) {
+ if (selectable) {
+ this.titleText.setVisible(currentTitleControl.getVisible());
+ this.titleLabel.setVisible(false);
+ this.currentTitleControl = this.titleText;
+ } else {
+ this.titleLabel.setVisible(currentTitleControl.getVisible());
+ this.titleText.setVisible(false);
+ this.currentTitleControl = this.titleLabel;
+ }
+ layout();
+ redraw();
+ }
+
@Override
public void setFont(Font font) {
super.setFont(font);
titleLabel.setFont(font);
+ titleText.setFont(font);
fontHeight = -1;
fontBaselineHeight = -1;
layout();
@@ -491,6 +531,7 @@ public class TitleRegion extends Canvas {
Menu menu = menuManager.createContextMenu(this);
setMenu(menu);
titleLabel.setMenu(menu);
+ titleText.setMenu(menu);
if (busyLabel != null)
busyLabel.setMenu(menu);
createMenuHyperlink();
diff --git a/examples/org.eclipse.ui.forms.examples/META-INF/MANIFEST.MF b/examples/org.eclipse.ui.forms.examples/META-INF/MANIFEST.MF
index c2c8082a45..78f3290ca1 100644
--- a/examples/org.eclipse.ui.forms.examples/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.ui.forms.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.forms.examples; singleton:=true
-Bundle-Version: 3.2.100
+Bundle-Version: 3.2.200
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.ui.forms.examples.internal.ExamplesPlugin
Bundle-Vendor: Eclipse.org
diff --git a/examples/org.eclipse.ui.forms.examples/pom.xml b/examples/org.eclipse.ui.forms.examples/pom.xml
index 51fe7ff327..e457031cf3 100644
--- a/examples/org.eclipse.ui.forms.examples/pom.xml
+++ b/examples/org.eclipse.ui.forms.examples/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.forms.examples</artifactId>
- <version>3.2.100</version>
+ <version>3.2.200</version>
<packaging>eclipse-plugin</packaging>
<properties>
diff --git a/examples/org.eclipse.ui.forms.examples/src/org/eclipse/ui/forms/examples/views/FormView.java b/examples/org.eclipse.ui.forms.examples/src/org/eclipse/ui/forms/examples/views/FormView.java
index 05014beeef..fd3e98a43e 100644
--- a/examples/org.eclipse.ui.forms.examples/src/org/eclipse/ui/forms/examples/views/FormView.java
+++ b/examples/org.eclipse.ui.forms.examples/src/org/eclipse/ui/forms/examples/views/FormView.java
@@ -16,6 +16,7 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
@@ -45,6 +46,7 @@ public class FormView extends ViewPart {
private ImageHyperlink ih;
private Button enableHyperlink;
private Button clearHyperlinkImage;
+ private boolean titleTextSelectable;
/**
* The constructor.
*/
@@ -61,6 +63,7 @@ public class FormView extends ViewPart {
form.setText("Hello, Eclipse Forms");
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);
+ form.getForm().setTitleTextSelectable(titleTextSelectable);
Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
SWT.WRAP);
@@ -75,6 +78,13 @@ public class FormView extends ViewPart {
TableWrapData td = new TableWrapData();
td.colspan = 2;
link.setLayoutData(td);
+ Button toggleTitleSelectable = toolkit.createButton(form.getBody(), "Toggle Title Text Selectable", SWT.NONE);
+ toggleTitleSelectable.setText("Toggle Title Text Selectable");
+ toggleTitleSelectable.addSelectionListener(SelectionListener.widgetSelectedAdapter(
+ e -> form.getForm().setTitleTextSelectable(titleTextSelectable = !titleTextSelectable)));
+ td = new TableWrapData(TableWrapData.FILL_GRAB);
+ td.colspan = 2;
+ toggleTitleSelectable.setLayoutData(td);
toolkit.createLabel(form.getBody(), "Text field label:");
Text text = toolkit.createText(form.getBody(), "");
td = new TableWrapData(TableWrapData.FILL_GRAB);

Back to the top