From e8c27d5cae8d60d4c9e587c10b8137fa630e3747 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 20 Mar 2008 14:48:07 +0000 Subject: [PATCH] Fix for 223250: Macro expansion hover only displays _very_ briefly --- ...stractCompareViewerInformationControl.java | 4 +- .../text/c/hover/CMacroExpansionControl.java | 3 +- .../CMacroExpansionExplorationControl.java | 110 ++++++++++-------- 3 files changed, 65 insertions(+), 52 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 c979761f696..eafea150ce6 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 @@ -93,7 +93,7 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo * @param persistBounds flag indicating whether control size and location should be persisted */ public AbstractCompareViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds) { - super(parent, shellStyle, takeFocus, persistBounds, showViewMenu, false, null, null); + super(parent, shellStyle | SWT.ON_TOP, takeFocus, 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. if (hasHeader()) @@ -393,7 +393,7 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo * {@inheritDoc} */ public boolean isFocusControl() { - return fCompareViewerControl.isFocusControl(); + return fCompareViewerControl != null; } /** 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 2c1b85bc781..21186ac3e9c 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 @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.text.c.hover; +import org.eclipse.jface.dialogs.PopupDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; @@ -30,7 +31,7 @@ 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, SWT.NO_TRIM | SWT.TOOL, SWT.NONE, false, false, false); + super(parent, PopupDialog.HOVER_SHELLSTYLE, SWT.NONE, false, false, false); if (statusFieldText != null) { setInfoText(statusFieldText); } 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 a42caa76d17..b7a378bfdbc 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 @@ -42,6 +42,8 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.ui.IEditorPart; @@ -50,6 +52,7 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextService; +import org.eclipse.ui.handlers.IHandlerActivation; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.keys.IBindingService; import org.eclipse.ui.menus.CommandContributionItem; @@ -100,7 +103,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo } private IHandlerService fHandlerService; - private Collection fHandlerActivations; + private Collection fHandlerActivations; private IContextService fContextService; private IContextActivation fContextActivation; private int fIndex; @@ -186,49 +189,66 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo return sourceViewer; } - /* - * @see org.eclipse.jface.dialogs.PopupDialog#open() - */ + + @Override public int open() { - int result= super.open(); + getShell().addListener(SWT.Activate, new Listener() { + public void handleEvent(Event arg0) { + registerCommandHandlers(); + }}); + getShell().addListener(SWT.Deactivate, new Listener() { + public void handleEvent(Event arg0) { + unregisterCommandHandlers(); + }}); - if (fInput != null) { - IHandler backwardHandler= new AbstractHandler() { - public Object execute(ExecutionEvent event) throws ExecutionException { - backward(); - return null; - } - }; - IHandler forwardHandler= new AbstractHandler() { - public Object execute(ExecutionEvent event) throws ExecutionException { - forward(); - return null; - } - }; - IHandler gotoDefinitionHandler= new AbstractHandler() { - public Object execute(ExecutionEvent event) throws ExecutionException { - gotoMacroDefinition(); - return null; - } - }; - - - IWorkbench workbench= PlatformUI.getWorkbench(); - fHandlerService= (IHandlerService) workbench.getService(IHandlerService.class); - fContextService= (IContextService) workbench.getService(IContextService.class); - fContextActivation= fContextService.activateContext(CONTEXT_ID_MACRO_EXPANSION_HOVER); - fHandlerActivations= new ArrayList(); - fHandlerActivations.add(fHandlerService.activateHandler(COMMAND_ID_EXPANSION_BACK, backwardHandler)); - fHandlerActivations.add(fHandlerService.activateHandler(COMMAND_ID_EXPANSION_FORWARD, forwardHandler)); - fHandlerActivations.add(fHandlerService.activateHandler(ICEditorActionDefinitionIds.OPEN_DECL, gotoDefinitionHandler)); + return super.open(); + } - String infoText= getInfoText(); - if (infoText != null) { - setInfoText(infoText); - } + protected void unregisterCommandHandlers() { + if (fHandlerService != null) { + fHandlerService.deactivateHandlers(fHandlerActivations); + fHandlerActivations.clear(); + fHandlerService= null; } - - return result; + if (fContextActivation != null) { + fContextService.deactivateContext(fContextActivation); + fContextActivation= null; + } + } + + protected void registerCommandHandlers() { + IHandler backwardHandler= new AbstractHandler() { + public Object execute(ExecutionEvent event) throws ExecutionException { + backward(); + return null; + } + }; + IHandler forwardHandler= new AbstractHandler() { + public Object execute(ExecutionEvent event) throws ExecutionException { + forward(); + return null; + } + }; + IHandler gotoDefinitionHandler= new AbstractHandler() { + public Object execute(ExecutionEvent event) throws ExecutionException { + gotoMacroDefinition(); + return null; + } + }; + + IWorkbench workbench= PlatformUI.getWorkbench(); + fHandlerService= (IHandlerService) workbench.getService(IHandlerService.class); + fContextService= (IContextService) workbench.getService(IContextService.class); + fContextActivation= fContextService.activateContext(CONTEXT_ID_MACRO_EXPANSION_HOVER); + fHandlerActivations= new ArrayList(); + fHandlerActivations.add(fHandlerService.activateHandler(COMMAND_ID_EXPANSION_BACK, backwardHandler)); + fHandlerActivations.add(fHandlerService.activateHandler(COMMAND_ID_EXPANSION_FORWARD, forwardHandler)); + fHandlerActivations.add(fHandlerService.activateHandler(ICEditorActionDefinitionIds.OPEN_DECL, gotoDefinitionHandler)); + + String infoText= getInfoText(); + if (infoText != null) { + setInfoText(infoText); + } } /* @@ -302,14 +322,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo * @see org.eclipse.jface.dialogs.PopupDialog#close() */ public boolean close() { - if (fHandlerService != null) { - fHandlerService.deactivateHandlers(fHandlerActivations); - fHandlerActivations.clear(); - fHandlerService= null; - } - if (fContextActivation != null) { - fContextService.deactivateContext(fContextActivation); - } + unregisterCommandHandlers(); return super.close(); } @@ -444,5 +457,4 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo return text; } - }