From 73fe0cb5727b94fbdb0df45463caca4cb4cf783c Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 9 May 2008 11:41:44 +0000 Subject: [PATCH] Fix hover move-into behaviour --- ...stractCompareViewerInformationControl.java | 26 +++++++++----- ...bstractSourceViewerInformationControl.java | 15 +++----- .../ui/text/c/hover/CHoverMessages.java | 1 + .../ui/text/c/hover/CHoverMessages.properties | 1 + .../text/c/hover/CMacroExpansionControl.java | 34 +++++++++++-------- .../CMacroExpansionExplorationControl.java | 25 ++++++++++---- .../ui/text/c/hover/CMacroExpansionHover.java | 1 - .../hover/SourceViewerInformationControl.java | 22 ++++-------- 8 files changed, 69 insertions(+), 56 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java index 2bcfff4eaac..c0d0e931fbd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractCompareViewerInformationControl.java @@ -102,7 +102,7 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo public AbstractCompareViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds) { super(parent, shellStyle | SWT.ON_TOP, takeFocus, persistBounds, persistBounds, showViewMenu, false, null, null); fStyle= textStyle & ~(SWT.V_SCROLL | SWT.H_SCROLL); - // Title and status text must be set to get the title label created, so force empty values here. + // Title and status text must be set to get the title label created, so force empty values here. if (hasHeader()) setTitleText(""); //$NON-NLS-1$ setInfoText(""); // //$NON-NLS-1$ @@ -452,10 +452,25 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo * @see org.eclipse.jface.text.IInformationControlExtension3#computeTrim() */ public Rectangle computeTrim() { - Rectangle trim= getShell().computeTrim(0, 0, 0, 50); + Rectangle trim= getShell().computeTrim(0, 0, 0, 0); + addInternalTrim(trim); return trim; } + /** + * Adds the internal trimmings to the given trim of the shell. + * + * @param trim the shell's trim, will be updated + * @since 5.0 + */ + private void addInternalTrim(Rectangle trim) { + Rectangle textTrim= fCompareViewerControl.computeTrim(0, 0, 0, 0); + trim.x+= textTrim.x; + trim.y+= textTrim.y; + trim.width+= textTrim.width; + trim.height+= textTrim.height; + } + /* * @see org.eclipse.jface.text.IInformationControlExtension3#getBounds() */ @@ -527,11 +542,4 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo return null; } - /* - * @see org.eclipse.jface.text.IInformationControlExtension5#allowMoveIntoControl() - */ - public boolean allowMoveIntoControl() { - return false; - } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java index 607be04dc82..cb06020fab7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/AbstractSourceViewerInformationControl.java @@ -90,14 +90,16 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog * @param takeFocus flag indicating whether to take the focus * @param showViewMenu flag indicating whether to show the "view" menu * @param persistBounds flag indicating whether control size and location should be persisted + * @param statusFieldText */ - public AbstractSourceViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds) { + public AbstractSourceViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds, String statusFieldText) { super(parent, shellStyle, takeFocus, persistBounds, persistBounds, showViewMenu, false, null, null); fTextStyle= textStyle; - // Title and status text must be set to get the title label created, so force empty values here. + // Title and status text must be set to get the title label created, so force empty values here. if (hasHeader()) setTitleText(""); //$NON-NLS-1$ - setInfoText(""); // //$NON-NLS-1$ + if (statusFieldText != null) + setInfoText(statusFieldText); // Create all controls create(); @@ -554,11 +556,4 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog return null; } - /* - * @see org.eclipse.jface.text.IInformationControlExtension5#allowMoveIntoControl() - */ - public boolean allowMoveIntoControl() { - return false; - } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java index b4c1b9e2acc..433523e6b0e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.java @@ -31,6 +31,7 @@ public final class CHoverMessages extends NLS { public static String CMacroExpansionControl_title_expansion; public static String CMacroExpansionControl_title_fullyExpanded; public static String CMacroExpansionControl_title_macroExpansion; + public static String CMacroExpansionControl_title_macroExpansionExploration; public static String CMacroExpansionControl_title_original; public static String CMacroExpansionInput_jobTitle; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties index 303793fa34a..e7c7bb1f3f6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CHoverMessages.properties @@ -19,6 +19,7 @@ CMacroExpansionControl_statusText=Press {0} or {1} to step through macro expansi CMacroExpansionControl_title_expansion=Expansion \#{0} of {1} CMacroExpansionControl_title_fullyExpanded=Fully Expanded CMacroExpansionControl_title_macroExpansion=Macro Expansion +CMacroExpansionControl_title_macroExpansionExploration=Explore Macro Expansion ({0} steps) CMacroExpansionControl_title_original=Original CMacroExpansionInput_jobTitle= Computing Macro Expansion diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java index eb6b147d257..30a1d988393 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionControl.java @@ -8,7 +8,6 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import org.eclipse.jface.dialogs.PopupDialog; @@ -26,6 +25,8 @@ import org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl; */ public class CMacroExpansionControl extends AbstractSourceViewerInformationControl { + private CMacroExpansionInput fInput; + /** * Creates a new control for use as a hover which does not take the focus. * @@ -33,10 +34,18 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr * @param statusFieldText text to be displayed in the status field, may be null */ public CMacroExpansionControl(Shell parent, String statusFieldText) { - super(parent, PopupDialog.HOVER_SHELLSTYLE, SWT.NONE, false, false, false); - if (statusFieldText != null) { - setInfoText(statusFieldText); - } + super(parent, PopupDialog.HOVER_SHELLSTYLE, SWT.NONE, false, false, false, statusFieldText); + setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion); + } + + /** + * Creates a new control for use as a hover which optionally takes the focus. + * + * @param parent parent shell + * @param takeFocus whether this control should take the focus + */ + public CMacroExpansionControl(Shell parent, boolean takeFocus) { + super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, SWT.NONE, takeFocus, false, false, null); setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion); } @@ -64,6 +73,7 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr if (input instanceof CMacroExpansionInput) { CMacroExpansionInput macroExpansionInput= (CMacroExpansionInput) input; setInformation(macroExpansionInput.fExplorer.getFullExpansion().getCodeAfterStep()); + fInput= macroExpansionInput; } else { super.setInput(input); } @@ -76,16 +86,12 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr public IInformationControlCreator getInformationPresenterControlCreator() { return new IInformationControlCreator() { public IInformationControl createInformationControl(Shell parent) { - return new CMacroExpansionExplorationControl(parent); + if (fInput != null && fInput.fExplorer.getExpansionStepCount() > 1) { + return new CMacroExpansionExplorationControl(parent); + } else { + return new CMacroExpansionControl(parent, true); + } } }; } - - /* - * @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#allowMoveIntoControl() - */ - @Override - public boolean allowMoveIntoControl() { - return true; - } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java index 7ca85c4c72d..b318ba5103d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java @@ -8,7 +8,6 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import java.util.ArrayList; @@ -302,7 +301,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo } /** - * Returns the text to be shown in the popups's information area. + * Returns the text to be shown in the popups's information area. * May return null. * * @return The text to be shown in the popup's information area or null @@ -315,7 +314,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo String infoText= null; if (formattedBindingBack != null && formattedBindingForward != null) { - infoText= NLS.bind(CHoverMessages.CMacroExpansionControl_statusText, formattedBindingBack, formattedBindingForward); + infoText= NLS.bind(CHoverMessages.CMacroExpansionControl_statusText, formattedBindingBack, formattedBindingForward); } return infoText; } @@ -358,10 +357,24 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo @Override public Rectangle computeTrim() { Rectangle trim= super.computeTrim(); - trim.height += fMacroText.getLineHeight(); + addInternalTrim(trim); return trim; } + /** + * Adds the internal trimmings to the given trim of the shell. + * + * @param trim the shell's trim, will be updated + * @since 5.0 + */ + private void addInternalTrim(Rectangle trim) { + Rectangle textTrim= fMacroText.computeTrim(0, 0, 0, 0); + trim.x+= textTrim.x; + trim.y+= textTrim.y; + trim.width+= textTrim.width; + trim.height+= textTrim.height; + } + /** * Set the input for this information control. * @param input @@ -396,7 +409,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo final ITypedElement left= getContentForIndex(fIndex, true); final ITypedElement right= getContentForIndex(fIndex, false); - setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion); + setTitleText(CHoverMessages.bind(CHoverMessages.CMacroExpansionControl_title_macroExpansionExploration, getStepCount())); fMacroViewer.getDocument().set(getMacroText(fIndex)); setInput(createCompareInput(null, left, right)); } @@ -405,7 +418,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo if (index == 0) { return CHoverMessages.CMacroExpansionControl_title_original; } else if (index < getStepCount()) { - return NLS.bind(CHoverMessages.CMacroExpansionControl_title_expansion, + return NLS.bind(CHoverMessages.CMacroExpansionControl_title_expansion, String.valueOf(index), String.valueOf(getStepCount())); } else { return CHoverMessages.CMacroExpansionControl_title_fullyExpanded; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java index 68f30a97c4a..d32027ed9c8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java @@ -8,7 +8,6 @@ * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.text.c.hover; import java.lang.ref.Reference; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java index d05dbafa785..23d155cd8fd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/SourceViewerInformationControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2007 QNX Software Systems and others. + * Copyright (c) 2002, 2008 QNX Software Systems 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 @@ -56,7 +56,6 @@ import org.eclipse.cdt.internal.ui.text.CTextTools; import org.eclipse.cdt.internal.ui.text.SimpleCSourceViewerConfiguration; /** - * SourceViewerInformationControl * Source viewer based implementation of IInformationControl. * Displays information in a source viewer. * @@ -109,15 +108,15 @@ public class SourceViewerInformationControl implements IInformationControl, IInf private boolean fIsSystemBackgroundColor= true; /** - * Creates a default information control with the given shell as parent. The given - * information presenter is used to process the information to be displayed. The given - * styles are applied to the created styled text widget. + * Creates a source viewer information control with the given shell as parent. The given + * styles are applied to the created styled text widget. The status field will + * contain the given text or be hidden. * * @param parent the parent shell * @param isResizable true if resizable * @param orientation the orientation * @param statusFieldText the text to be used in the optional status field - * or null if the status field should be hidden + * or null if the status field should be hidden */ public SourceViewerInformationControl(Shell parent, boolean isResizable, int orientation, String statusFieldText) { Assert.isLegal(orientation == SWT.RIGHT_TO_LEFT || orientation == SWT.LEFT_TO_RIGHT || orientation == SWT.NONE); @@ -367,7 +366,7 @@ public class SourceViewerInformationControl implements IInformationControl, IInf * @see IInformationControl#isFocusControl() */ public boolean isFocusControl() { - return fText.isFocusControl(); + return fShell.getDisplay().getActiveShell() == fShell; } /* @@ -504,13 +503,4 @@ public class SourceViewerInformationControl implements IInformationControl, IInf return new Point(widthInChars * width, heightInChars * height); } - - /* - * This method has been removed from IInformationControlExtension5 in 3.4 M6. - * TODO Remove this method. Just kept to stay compilable against 3.4 M5. - */ - public boolean allowMoveIntoControl() { - return true; - } - }