From 0fa115d5fb762bfc17fd924fb1f0e33fa877c1f8 Mon Sep 17 00:00:00 2001
From: Dani Megert
Date: Thu, 5 Dec 2013 17:31:34 +0100
Subject: Fixed bug 420662: [content assist] Context selection window should
remember its size
---
org.eclipse.jface.text/META-INF/MANIFEST.MF | 2 +-
org.eclipse.jface.text/pom.xml | 2 +-
.../jface/text/contentassist/ContentAssistant.java | 106 ++++++++++++++++++---
.../contentassist/ContextInformationPopup.java | 33 ++++++-
4 files changed, 128 insertions(+), 15 deletions(-)
diff --git a/org.eclipse.jface.text/META-INF/MANIFEST.MF b/org.eclipse.jface.text/META-INF/MANIFEST.MF
index dd6f22cd7e8..0307e02263d 100644
--- a/org.eclipse.jface.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jface.text
-Bundle-Version: 3.8.200.qualifier
+Bundle-Version: 3.9.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/org.eclipse.jface.text/pom.xml b/org.eclipse.jface.text/pom.xml
index 76b48b8d821..8d1fb6ba8aa 100644
--- a/org.eclipse.jface.text/pom.xml
+++ b/org.eclipse.jface.text/pom.xml
@@ -18,6 +18,6 @@
null
if none
* @since 3.0
*/
protected Point restoreCompletionProposalPopupSize() {
@@ -2123,8 +2164,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt
size.x= fDialogSettings.getInt(STORE_SIZE_X);
size.y= fDialogSettings.getInt(STORE_SIZE_Y);
} catch (NumberFormatException ex) {
- size.x= -1;
- size.y= -1;
+ return null;
}
// sanity check
@@ -2157,10 +2197,54 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt
return size;
}
+ /**
+ * Restores the content assist's context selector pop-up size.
+ *
+ * @return the stored size or null
if none
+ * @since 3.9
+ */
+ protected Point restoreContextSelectorPopupSize() {
+ if (fDialogSettings == null)
+ return null;
+
+ Point size= new Point(-1, -1);
+
+ try {
+ size.x= fDialogSettings.getInt(STORE_CONTEXT_SELECTOR_POPUP_SIZE_X);
+ size.y= fDialogSettings.getInt(STORE_CONTEXT_SELECTOR_POPUP_SIZE_Y);
+ } catch (NumberFormatException ex) {
+ return null;
+ }
+
+ // sanity check
+ if (size.x == -1 && size.y == -1)
+ return null;
+
+ Rectangle maxBounds= null;
+ Display display= Display.getCurrent();
+ if (display == null)
+ display= Display.getDefault();
+ if (display != null && !display.isDisposed())
+ maxBounds= display.getBounds();
+
+ if (size.x > -1 && size.y > -1) {
+ if (maxBounds != null) {
+ size.x= Math.min(size.x, maxBounds.width);
+ size.y= Math.min(size.y, maxBounds.height);
+ }
+
+ // Enforce an absolute minimal size
+ size.x= Math.max(size.x, 30);
+ size.y= Math.max(size.y, 30);
+ }
+
+ return size;
+ }
+
/**
* Sets the prefix completion property. If enabled, content assist delegates completion to
* prefix completion.
- *
+ *
* @param enabled true
to enable prefix completion, false
to
* disable
*/
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
index e3dd1c6c9ae..f4742bcc6ff 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,8 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyEvent;
@@ -112,6 +114,7 @@ class ContextInformationPopup implements IContentAssistListener {
private PopupCloser fPopupCloser= new PopupCloser();
private Shell fContextSelectorShell;
+ private Point fContextSelectorPopupSize;
private Table fContextSelectorTable;
private IContextInformation[] fContextSelectorInput;
private String fLineDelimiter= null;
@@ -509,6 +512,17 @@ class ContextInformationPopup implements IContentAssistListener {
fContextSelectorShell.setLayout(layout);
fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ fContextSelectorShell.addControlListener(new ControlListener() {
+
+ public void controlMoved(ControlEvent e) {
+ }
+
+ public void controlResized(ControlEvent e) {
+ fContextSelectorPopupSize= fContextSelectorShell.getSize();
+ }
+ });
+
+
if (fViewer instanceof ITextViewerExtension) {
final ITextViewerExtension textViewerExtension= (ITextViewerExtension)fViewer;
final StyledText textWidget= fViewer.getTextWidget();
@@ -539,7 +553,11 @@ class ContextInformationPopup implements IContentAssistListener {
gd.widthHint= 300;
fContextSelectorTable.setLayoutData(gd);
- fContextSelectorShell.pack(true);
+ Point size= fContentAssistant.restoreContextSelectorPopupSize();
+ if (size != null)
+ fContextSelectorShell.setSize(size);
+ else
+ fContextSelectorShell.pack(true);
Color c= fContentAssistant.getContextSelectorBackground();
if (c == null)
@@ -584,6 +602,16 @@ class ContextInformationPopup implements IContentAssistListener {
return height;
}
+ /**
+ * Returns the size of the context selector pop-up.
+ *
+ * @return a Point containing the size
+ * @since 3.9
+ */
+ Point getConextSelectorPopupSize() {
+ return fContextSelectorPopupSize;
+ }
+
/**
* Causes the context information of the context selected in the context selector
* to be displayed in the context information popup.
@@ -640,6 +668,7 @@ class ContextInformationPopup implements IContentAssistListener {
*/
private void hideContextSelector() {
if (Helper.okToUse(fContextSelectorShell)) {
+ fContentAssistant.storeContextSelectorPopupSize();
fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_SELECTOR);
fPopupCloser.uninstall();
--
cgit v1.2.3