1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 223250: Macro expansion hover only displays _very_ briefly

This commit is contained in:
Anton Leherbauer 2008-03-20 14:48:07 +00:00
parent e2b4a4cf52
commit e8c27d5cae
3 changed files with 65 additions and 52 deletions

View file

@ -93,7 +93,7 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
* @param persistBounds flag indicating whether control size and location should be persisted * @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) { 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); 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()) if (hasHeader())
@ -393,7 +393,7 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
* {@inheritDoc} * {@inheritDoc}
*/ */
public boolean isFocusControl() { public boolean isFocusControl() {
return fCompareViewerControl.isFocusControl(); return fCompareViewerControl != null;
} }
/** /**

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.ui.text.c.hover; package org.eclipse.cdt.internal.ui.text.c.hover;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell; 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 <code>null</code> * @param statusFieldText text to be displayed in the status field, may be <code>null</code>
*/ */
public CMacroExpansionControl(Shell parent, String statusFieldText) { 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) { if (statusFieldText != null) {
setInfoText(statusFieldText); setInfoText(statusFieldText);
} }

View file

@ -42,6 +42,8 @@ import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite; 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.swt.widgets.Shell;
import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
@ -50,6 +52,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation; import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.keys.IBindingService; import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.menus.CommandContributionItem; import org.eclipse.ui.menus.CommandContributionItem;
@ -100,7 +103,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
} }
private IHandlerService fHandlerService; private IHandlerService fHandlerService;
private Collection fHandlerActivations; private Collection<IHandlerActivation> fHandlerActivations;
private IContextService fContextService; private IContextService fContextService;
private IContextActivation fContextActivation; private IContextActivation fContextActivation;
private int fIndex; private int fIndex;
@ -186,49 +189,66 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
return sourceViewer; return sourceViewer;
} }
/*
* @see org.eclipse.jface.dialogs.PopupDialog#open() @Override
*/
public int open() { 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) { return super.open();
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(); protected void unregisterCommandHandlers() {
if (infoText != null) { if (fHandlerService != null) {
setInfoText(infoText); fHandlerService.deactivateHandlers(fHandlerActivations);
} fHandlerActivations.clear();
fHandlerService= null;
} }
if (fContextActivation != null) {
return result; 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<IHandlerActivation>();
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() * @see org.eclipse.jface.dialogs.PopupDialog#close()
*/ */
public boolean close() { public boolean close() {
if (fHandlerService != null) { unregisterCommandHandlers();
fHandlerService.deactivateHandlers(fHandlerActivations);
fHandlerActivations.clear();
fHandlerService= null;
}
if (fContextActivation != null) {
fContextService.deactivateContext(fContextActivation);
}
return super.close(); return super.close();
} }
@ -444,5 +457,4 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
return text; return text;
} }
} }