1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 247416 - [Macro Explorer] no mouse control to navigate through steps

This commit is contained in:
Anton Leherbauer 2009-01-09 09:24:08 +00:00
parent 5b47187366
commit cb8d71c528
12 changed files with 424 additions and 780 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

View file

@ -126,9 +126,9 @@ ActionDefinition.FindWord.description= Select a word and find the next occurrenc
ActionDefinition.toggleSourceHeader.name= Toggle Source/Header ActionDefinition.toggleSourceHeader.name= Toggle Source/Header
ActionDefinition.toggleSourceHeader.description= Toggles between corresponding source and header files ActionDefinition.toggleSourceHeader.description= Toggles between corresponding source and header files
ActionDefinition.backwardMacroExpansion.name= Backward Macro Expansion ActionDefinition.backwardMacroExpansion.name= Back
ActionDefinition.backwardMacroExpansion.description= Step backward in macro expansions ActionDefinition.backwardMacroExpansion.description= Step backward in macro expansions
ActionDefinition.forwardMacroExpansion.name= Forward Macro Expansion ActionDefinition.forwardMacroExpansion.name= Forward
ActionDefinition.forwardMacroExpansion.description= Step forward in macro expansions ActionDefinition.forwardMacroExpansion.description= Step forward in macro expansions
ActionDefinition.showMacroExplorer.name= Explore Macro Expansion ActionDefinition.showMacroExplorer.name= Explore Macro Expansion

View file

@ -358,6 +358,10 @@ public class CPluginImages {
public static final String IMG_OBJS_NLS_NEVER_TRANSLATE= NAME_PREFIX + "never_translate.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_NLS_NEVER_TRANSLATE= NAME_PREFIX + "never_translate.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_OBJS_NLS_NEVER_TRANSLATE = createManaged(T_OBJ, IMG_OBJS_NLS_NEVER_TRANSLATE); public static final ImageDescriptor DESC_OBJS_NLS_NEVER_TRANSLATE = createManaged(T_OBJ, IMG_OBJS_NLS_NEVER_TRANSLATE);
public static final ImageDescriptor DESC_ELCL_NAVIGATE_BACKWARD = createUnManaged(T_ELCL, "backward_nav.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_NAVIGATE_FORWARD = createUnManaged(T_ELCL, "forward_nav.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_OPEN_DECLARATION = createUnManaged(T_ELCL, "goto_input.gif"); //$NON-NLS-1$
private static ImageDescriptor createManaged(String prefix, String name) { private static ImageDescriptor createManaged(String prefix, String name) {
return createManaged(imageRegistry, prefix, name); return createManaged(imageRegistry, prefix, name);
} }

View file

@ -13,35 +13,32 @@ package org.eclipse.cdt.internal.ui.text;
import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI; import org.eclipse.compare.CompareUI;
import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IInformationControlExtension;
import org.eclipse.jface.text.IInformationControlExtension2; import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.jface.text.IInformationControlExtension3;
import org.eclipse.jface.text.IInformationControlExtension4;
import org.eclipse.jface.text.IInformationControlExtension5;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm; import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -52,7 +49,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
* *
* @since 5.0 * @since 5.0
*/ */
public abstract class AbstractCompareViewerInformationControl extends PopupDialog implements IInformationControl, IInformationControlExtension, IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension4, IInformationControlExtension5, DisposeListener { public abstract class AbstractCompareViewerInformationControl extends org.eclipse.jface.text.AbstractInformationControl implements IInformationControlExtension2, DisposeListener {
protected class CompareViewerControl extends ViewForm { protected class CompareViewerControl extends ViewForm {
private CompareConfiguration fCompareConfiguration; private CompareConfiguration fCompareConfiguration;
@ -68,44 +65,41 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
public void setInput(ICompareInput input) { public void setInput(ICompareInput input) {
if (fViewer == null) { if (fViewer == null) {
fViewer= createContentViewer(this, input, fCompareConfiguration); fViewer= createContentViewer(this, input, fCompareConfiguration);
applyBackgroundColor(fBackgroundColor, fViewer.getControl());
setContent(fViewer.getControl()); setContent(fViewer.getControl());
} }
fViewer.setInput(input); fViewer.setInput(input);
} }
} }
private final int fStyle;
private CompareViewerControl fCompareViewerControl; private CompareViewerControl fCompareViewerControl;
private ICompareInput fCompareInput; private ICompareInput fCompareInput;
private Color fBackgroundColor; private Color fBackgroundColor;
private boolean fIsSystemBackgroundColor; private boolean fIsSystemBackgroundColor;
private int fMaxWidth; private Label fTitleLabel;
private int fMaxHeight;
private boolean fUseDefaultBounds;
/** /**
* Creates a source viewer information control with the given shell as parent. The given * Creates a compare viewer information control with the given shell as parent.
* styles are applied to the shell and the source viewer.
* *
* @param parent the parent shell * @param parent the parent shell
* @param shellStyle the additional styles for the shell * @param isResizable flag indicating whether the control is resizable
* @param textStyle the additional styles for the source viewer
* @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
*/ */
public AbstractCompareViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds) { public AbstractCompareViewerInformationControl(Shell parent, boolean isResizable) {
super(parent, shellStyle | SWT.ON_TOP, takeFocus, persistBounds, persistBounds, showViewMenu, false, null, null); super(parent, isResizable);
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. // Create all controls
if (hasHeader()) create();
setTitleText(""); //$NON-NLS-1$ }
setInfoText(""); // //$NON-NLS-1$
/**
* Creates a compare viewer information control with the given shell as parent.
*
* @param parent
* @param toolBarManager
*/
public AbstractCompareViewerInformationControl(Shell parent, ToolBarManager toolBarManager) {
super(parent, toolBarManager);
// Create all controls // Create all controls
create(); create();
@ -129,51 +123,27 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
: PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR); : PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
} }
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override @Override
protected Control createContents(Composite parent) { protected void createContent(Composite parent) {
initializeColors(); initializeColors();
Control contents= super.createContents(parent); Composite content= new Composite(parent, SWT.NONE);
applyBackgroundColor(fBackgroundColor, contents); final GridLayout gridLayout= new GridLayout();
return contents; gridLayout.marginWidth= 0;
} gridLayout.marginHeight= 0;
gridLayout.verticalSpacing= 0;
@Override content.setLayout(gridLayout);
protected void applyBackgroundColor(Color color, Control control) {
super.applyBackgroundColor(fBackgroundColor, control);
}
/** if (hasHeader()) {
* Create the main content for this information control. createTitleLabel(content);
* }
* @param parent The parent composite
* @return The control representing the main content.
*
*/
@Override
protected Control createDialogArea(Composite parent) {
CompareConfiguration compareConfig= new CompareConfiguration(); CompareConfiguration compareConfig= new CompareConfiguration();
compareConfig.setLeftEditable(false); compareConfig.setLeftEditable(false);
compareConfig.setRightEditable(false); compareConfig.setRightEditable(false);
fCompareViewerControl= createCompareViewerControl(parent, fStyle, compareConfig); fCompareViewerControl= createCompareViewerControl(content, SWT.NONE, compareConfig);
final Control control= fCompareViewerControl;
control.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.character == 0x1B) // ESC
dispose();
}
public void keyReleased(KeyEvent e) {
// do nothing
}
});
addDisposeListener(this); addDisposeListener(this);
return fCompareViewerControl;
} }
protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) { protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) {
CompareViewerControl compareViewer= new CompareViewerControl(parent, style, compareConfig); CompareViewerControl compareViewer= new CompareViewerControl(parent, style, compareConfig);
return compareViewer; return compareViewer;
@ -183,16 +153,27 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
return CompareUI.findContentViewer(null, input, parent, cc); return CompareUI.findContentViewer(null, input, parent, cc);
} }
/** private void createTitleLabel(Composite parent) {
* Returns the name of the dialog settings section. fTitleLabel= new Label(parent, SWT.LEFT);
* <p> fTitleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
* The default is to return <code>null</code>. Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
* </p> separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
* @return the name of the dialog settings section or <code>null</code> if
* nothing should be persisted fTitleLabel.setFont(JFaceResources.getDialogFont());
*/
protected String getId() { Display display= parent.getDisplay();
return null; Color foreground= display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
Color background= display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
fTitleLabel.setForeground(foreground);
fTitleLabel.setBackground(background);
addMoveSupport(fTitleLabel);
}
public void setTitleText(String titleText) {
if (fTitleLabel != null) {
fTitleLabel.setText(titleText);
}
} }
/** /**
@ -226,15 +207,10 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
return false; return false;
} }
/** @Override
* {@inheritDoc}
*/
public void setInformation(String content) { public void setInformation(String content) {
} }
/**
* {@inheritDoc}
*/
public void setInput(Object input) { public void setInput(Object input) {
if (input instanceof ICompareInput) { if (input instanceof ICompareInput) {
fCompareInput= (ICompareInput) input; fCompareInput= (ICompareInput) input;
@ -251,56 +227,12 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
} }
} }
/**
* Fills the view menu.
* Clients can extend or override.
*
* @param viewMenu the menu manager that manages the menu
*/
protected void fillViewMenu(IMenuManager viewMenu) {
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#fillDialogMenu(IMenuManager)
*/
@Override @Override
protected void fillDialogMenu(IMenuManager dialogMenu) { public void dispose() {
super.fillDialogMenu(dialogMenu);
fillViewMenu(dialogMenu);
}
/**
* {@inheritDoc}
*/
public void setVisible(boolean visible) {
if (visible) {
open();
} else {
saveDialogBounds(getShell());
getShell().setVisible(false);
}
}
/**
* {@inheritDoc}
*/
public final void dispose() {
if (!fIsSystemBackgroundColor) { if (!fIsSystemBackgroundColor) {
fBackgroundColor.dispose(); fBackgroundColor.dispose();
} }
close(); super.dispose();
}
@Override
protected Point getInitialLocation(Point initialSize) {
if (!restoresSize()) {
Point size = new Point(400, 400);
Rectangle parentBounds = getParentShell().getBounds();
int x = parentBounds.x + parentBounds.width / 2 - size.x / 2;
int y = parentBounds.y + parentBounds.height / 2 - size.y / 2;
return new Point(x, y);
}
return super.getInitialLocation(initialSize);
} }
/** /**
@ -314,145 +246,39 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
fCompareViewerControl= null; fCompareViewerControl= null;
} }
/**
* {@inheritDoc}
*/
public boolean hasContents() { public boolean hasContents() {
return fCompareViewerControl != null && fCompareInput != null; return fCompareViewerControl != null && fCompareInput != null;
} }
/** @Override
* {@inheritDoc}
*/
public void setSizeConstraints(int maxWidth, int maxHeight) {
fMaxWidth= maxWidth;
fMaxHeight= maxHeight;
}
/**
* {@inheritDoc}
*/
public Point computeSizeHint() { public Point computeSizeHint() {
// compute the preferred size // compute the preferred size
int x= SWT.DEFAULT; int x= SWT.DEFAULT;
int y= SWT.DEFAULT; int y= SWT.DEFAULT;
Point size= getShell().computeSize(x, y); Point size= getShell().computeSize(x, y);
if (size.x > fMaxWidth) Point constraints= getSizeConstraints();
x= fMaxWidth; if (constraints != null) {
if (size.y > fMaxHeight) if (size.x < constraints.x)
y= fMaxHeight; x= constraints.x;
if (size.y < constraints.y)
// recompute using the constraints if the preferred size is larger than the constraints y= constraints.y;
}
// recompute using the constraints if the preferred size is smaller than the constraints
if (x != SWT.DEFAULT || y != SWT.DEFAULT) if (x != SWT.DEFAULT || y != SWT.DEFAULT)
size= getShell().computeSize(x, y, false); size= getShell().computeSize(x, y, false);
return size; return size;
} }
/**
* {@inheritDoc}
*/
public void setLocation(Point location) {
if (!restoresLocation() || getDialogSettings() == null || fUseDefaultBounds)
getShell().setLocation(location);
}
/**
* {@inheritDoc}
*/
public void setSize(int width, int height) {
if (!restoresSize() || getDialogSettings() == null || fUseDefaultBounds) {
getShell().setSize(width, height);
}
}
/**
* {@inheritDoc}
*/
public void addDisposeListener(DisposeListener listener) {
getShell().addDisposeListener(listener);
}
/**
* {@inheritDoc}
*/
public void removeDisposeListener(DisposeListener listener) {
getShell().removeDisposeListener(listener);
}
/**
* {@inheritDoc}
*/
public void setForegroundColor(Color foreground) {
applyForegroundColor(foreground, getContents());
}
/**
* {@inheritDoc}
*/
public void setBackgroundColor(Color background) {
applyBackgroundColor(background, getContents());
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getFocusControl()
*/
@Override @Override
protected Control getFocusControl() {
return fCompareViewerControl;
}
/**
* {@inheritDoc}
*/
public boolean isFocusControl() {
return fCompareViewerControl != null;
}
/**
* {@inheritDoc}
*/
public void setFocus() { public void setFocus() {
getShell().forceFocus(); super.setFocus();
fCompareViewerControl.setFocus(); fCompareViewerControl.setFocus();
} }
/**
* {@inheritDoc}
*/
public void addFocusListener(FocusListener listener) {
getShell().addFocusListener(listener);
}
/**
* {@inheritDoc}
*/
public void removeFocusListener(FocusListener listener) {
getShell().removeFocusListener(listener);
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getDialogSettings()
*/
@Override @Override
protected IDialogSettings getDialogSettings() {
String sectionName= getId();
if (sectionName == null) {
return null;
}
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings().getSection(sectionName);
if (settings == null) {
fUseDefaultBounds= true;
settings= CUIPlugin.getDefault().getDialogSettings().addNewSection(sectionName);
}
return settings;
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#computeTrim()
*/
public Rectangle computeTrim() { public Rectangle computeTrim() {
Rectangle trim= getShell().computeTrim(0, 0, 0, 0); Rectangle trim= super.computeTrim();
addInternalTrim(trim); addInternalTrim(trim);
return trim; return trim;
} }
@ -469,39 +295,12 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
trim.y+= textTrim.y; trim.y+= textTrim.y;
trim.width+= textTrim.width; trim.width+= textTrim.width;
trim.height+= textTrim.height; trim.height+= textTrim.height;
if (fTitleLabel != null) {
trim.height+= fTitleLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
}
} }
/* @Override
* @see org.eclipse.jface.text.IInformationControlExtension3#getBounds()
*/
public Rectangle getBounds() {
return getShell().getBounds();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresLocation()
*/
public boolean restoresLocation() {
return getPersistLocation();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresSize()
*/
public boolean restoresSize() {
return getPersistSize();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension4#setStatusText(java.lang.String)
*/
public void setStatusText(String statusFieldText) {
setInfoText(statusFieldText);
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int)
*/
public Point computeSizeConstraints(int widthInChars, int heightInChars) { public Point computeSizeConstraints(int widthInChars, int heightInChars) {
Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
GC gc= new GC(fCompareViewerControl); GC gc= new GC(fCompareViewerControl);
@ -513,33 +312,42 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
return new Point(widthInChars * width, heightInChars * height); return new Point(widthInChars * width, heightInChars * height);
} }
/* @Override
* @see org.eclipse.jface.text.IInformationControlExtension5#containsControl(org.eclipse.swt.widgets.Control)
*/
public boolean containsControl(Control control) {
do {
if (control == getShell())
return true;
if (control instanceof Shell)
return false;
control= control.getParent();
} while (control != null);
return false;
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#isVisible()
*/
public boolean isVisible() {
Shell shell= getShell();
return shell != null && !shell.isDisposed() && shell.isVisible();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
*/
public IInformationControlCreator getInformationPresenterControlCreator() { public IInformationControlCreator getInformationPresenterControlCreator() {
return null; return null;
} }
protected final void addMoveSupport(final Control control) {
MouseAdapter moveSupport= new MouseAdapter() {
private MouseMoveListener fMoveListener;
private final Control fShell= getShell();
@Override
public void mouseDown(MouseEvent e) {
Point shellLoc= fShell.getLocation();
final int shellX= shellLoc.x;
final int shellY= shellLoc.y;
Point mouseLoc= control.toDisplay(e.x, e.y);
final int mouseX= mouseLoc.x;
final int mouseY= mouseLoc.y;
fMoveListener= new MouseMoveListener() {
public void mouseMove(MouseEvent e2) {
Point mouseLoc2= control.toDisplay(e2.x, e2.y);
int dx= mouseLoc2.x - mouseX;
int dy= mouseLoc2.y - mouseY;
fShell.setLocation(shellX + dx, shellY + dy);
}
};
control.addMouseMoveListener(fMoveListener);
}
@Override
public void mouseUp(MouseEvent e) {
control.removeMouseMoveListener(fMoveListener);
fMoveListener= null;
}
};
control.addMouseListener(moveSupport);
}
} }

View file

@ -10,32 +10,18 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text; package org.eclipse.cdt.internal.ui.text;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IInformationControlExtension;
import org.eclipse.jface.text.IInformationControlExtension2; import org.eclipse.jface.text.IInformationControlExtension2;
import org.eclipse.jface.text.IInformationControlExtension3;
import org.eclipse.jface.text.IInformationControlExtension4;
import org.eclipse.jface.text.IInformationControlExtension5;
import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
@ -43,10 +29,11 @@ import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -60,51 +47,53 @@ import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
* *
* @since 5.0 * @since 5.0
*/ */
public abstract class AbstractSourceViewerInformationControl extends PopupDialog implements IInformationControl, IInformationControlExtension, IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension4, IInformationControlExtension5, DisposeListener { public abstract class AbstractSourceViewerInformationControl extends org.eclipse.jface.text.AbstractInformationControl implements IInformationControlExtension2, DisposeListener {
private int fTextStyle;
private ISourceViewer fSourceViewer; private ISourceViewer fSourceViewer;
private Color fBackgroundColor; private Color fBackgroundColor;
private boolean fIsSystemBackgroundColor; private boolean fIsSystemBackgroundColor;
private int fMaxWidth;
private int fMaxHeight;
private List<Control> fColorExclusionControls= new ArrayList<Control>();
private Font fTextFont; private Font fTextFont;
private StyledText fText; private StyledText fText;
private Label fTitleLabel;
/** /**
* Creates a source viewer information control with the given shell as parent. The given * Creates a source viewer information control with the given shell as parent. The given
* styles are applied to the shell and the source viewer. * styles are applied to the shell and the source viewer.
* *
* @param parent the parent shell * @param parent the parent shell
* @param shellStyle the additional styles for the shell
* @param textStyle the additional styles for the source viewer
* @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 * @param statusFieldText
*/ */
public AbstractSourceViewerInformationControl(Shell parent, int shellStyle, int textStyle, boolean takeFocus, boolean showViewMenu, boolean persistBounds, String statusFieldText) { public AbstractSourceViewerInformationControl(Shell parent, String statusFieldText) {
super(parent, shellStyle, takeFocus, persistBounds, persistBounds, showViewMenu, false, null, null); super(parent, statusFieldText);
fTextStyle= textStyle;
// Title and status text must be set to get the title label created, so force empty values here.
if (hasHeader())
setTitleText(""); //$NON-NLS-1$
if (statusFieldText != null)
setInfoText(statusFieldText);
// Create all controls // Create all controls
create(); create();
} }
/**
* Creates a source viewer information control with the given shell as parent. The given
* styles are applied to the shell and the source viewer.
*
* @param parent the parent shell
* @param isResizable whether the control should be resizable
*/
public AbstractSourceViewerInformationControl(Shell parent, boolean isResizable) {
super(parent, isResizable);
// Create all controls
create();
}
/**
* @return <code>true</code> if the control should have a title label
*/
protected boolean hasHeader() {
return false;
}
private void initializeColors() { private void initializeColors() {
RGB bgRGB= getHoverBackgroundColorRGB(); RGB bgRGB= getHoverBackgroundColorRGB();
if (bgRGB != null) { if (bgRGB != null) {
@ -123,28 +112,19 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
: PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR); : PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
} }
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override @Override
protected Control createContents(Composite parent) { public void createContent(Composite parent) {
Control contents= super.createContents(parent); Composite content= new Composite(parent, SWT.NONE);
for (Control ctrl : fColorExclusionControls) { final GridLayout gridLayout= new GridLayout();
ctrl.setBackground(fBackgroundColor); gridLayout.marginWidth= 0;
gridLayout.marginHeight= 0;
gridLayout.verticalSpacing= 0;
content.setLayout(gridLayout);
if (hasHeader()) {
createTitleLabel(content);
} }
return contents; fSourceViewer= createSourceViewer(content, SWT.NONE);
}
/**
* Create the main content for this information control.
*
* @param parent The parent composite
* @return The control representing the main content.
*
*/
@Override
protected Control createDialogArea(Composite parent) {
fSourceViewer= createSourceViewer(parent, fTextStyle);
final StyledText text= fSourceViewer.getTextWidget(); final StyledText text= fSourceViewer.getTextWidget();
text.addKeyListener(new KeyListener() { text.addKeyListener(new KeyListener() {
@ -158,7 +138,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
}); });
addDisposeListener(this); addDisposeListener(this);
return ((Viewer)fSourceViewer).getControl();
} }
protected final ISourceViewer createSourceViewer(Composite parent, int style) { protected final ISourceViewer createSourceViewer(Composite parent, int style) {
@ -174,7 +153,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
initializeColors(); initializeColors();
fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
fText.setBackground(fBackgroundColor); fText.setBackground(fBackgroundColor);
fColorExclusionControls.add(fText);
fTextFont= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); fTextFont= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
fText.setFont(fTextFont); fText.setFont(fTextFont);
@ -182,58 +160,25 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return sourceViewer; return sourceViewer;
} }
/* private void createTitleLabel(Composite parent) {
* @see org.eclipse.jface.dialogs.PopupDialog#createInfoTextArea(org.eclipse.swt.widgets.Composite) fTitleLabel= new Label(parent, SWT.LEFT);
*/ fTitleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@Override Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
protected Control createInfoTextArea(Composite parent) { separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Control infoText= super.createInfoTextArea(parent);
fColorExclusionControls.add(infoText); fTitleLabel.setFont(JFaceResources.getDialogFont());
return infoText;
} Display display= parent.getDisplay();
Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
/* Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
* @see org.eclipse.jface.dialogs.PopupDialog#createTitleControl(org.eclipse.swt.widgets.Composite) fTitleLabel.setForeground(foreground);
*/ fTitleLabel.setBackground(background);
@Override
protected Control createTitleControl(Composite parent) {
Control titleText= super.createTitleControl(parent);
fColorExclusionControls.add(titleText);
return titleText;
} }
/* public void setTitleText(String titleText) {
* @see org.eclipse.jface.dialogs.PopupDialog#getBackgroundColorExclusions() if (fTitleLabel != null) {
*/ fTitleLabel.setText(titleText);
@Override }
protected List<Control> getBackgroundColorExclusions() {
@SuppressWarnings("unchecked")
List<Control> exclusions= super.getBackgroundColorExclusions();
exclusions.addAll(fColorExclusionControls);
return exclusions;
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getForegroundColorExclusions()
*/
@Override
protected List<Control> getForegroundColorExclusions() {
@SuppressWarnings("unchecked")
List<Control> exclusions= super.getForegroundColorExclusions();
exclusions.addAll(fColorExclusionControls);
return exclusions;
}
/**
* Returns the name of the dialog settings section.
* <p>
* The default is to return <code>null</code>.
* </p>
* @return the name of the dialog settings section or <code>null</code> if
* nothing should be persisted
*/
protected String getId() {
return null;
} }
/** /**
@ -245,22 +190,7 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return fSourceViewer; return fSourceViewer;
} }
/** @Override
* Returns <code>true</code> if the control has a header, <code>false</code> otherwise.
* <p>
* The default is to return <code>false</code>.
* </p>
*
* @return <code>true</code> if the control has a header
*/
protected boolean hasHeader() {
// default is to have no header
return false;
}
/**
* {@inheritDoc}
*/
public void setInformation(String content) { public void setInformation(String content) {
if (content == null) { if (content == null) {
fSourceViewer.setDocument(null); fSourceViewer.setDocument(null);
@ -272,9 +202,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
fSourceViewer.setDocument(doc); fSourceViewer.setDocument(doc);
} }
/**
* {@inheritDoc}
*/
public void setInput(Object input) { public void setInput(Object input) {
if (input instanceof String) if (input instanceof String)
setInformation((String)input); setInformation((String)input);
@ -282,56 +209,12 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
setInformation(null); setInformation(null);
} }
/**
* Fills the view menu.
* Clients can extend or override.
*
* @param viewMenu the menu manager that manages the menu
*/
protected void fillViewMenu(IMenuManager viewMenu) {
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#fillDialogMenu(IMenuManager)
*/
@Override @Override
protected void fillDialogMenu(IMenuManager dialogMenu) {
super.fillDialogMenu(dialogMenu);
fillViewMenu(dialogMenu);
}
/**
* {@inheritDoc}
*/
public void setVisible(boolean visible) {
if (visible) {
open();
} else {
saveDialogBounds(getShell());
getShell().setVisible(false);
}
}
/**
* {@inheritDoc}
*/
public final void dispose() { public final void dispose() {
if (!fIsSystemBackgroundColor) { if (!fIsSystemBackgroundColor) {
fBackgroundColor.dispose(); fBackgroundColor.dispose();
} }
close(); super.dispose();
}
@Override
protected Point getInitialLocation(Point initialSize) {
if (!restoresLocation()) {
Point size = new Point(400, 400);
Rectangle parentBounds = getParentShell().getBounds();
int x = parentBounds.x + parentBounds.width / 2 - size.x / 2;
int y = parentBounds.y + parentBounds.height / 2 - size.y / 2;
return new Point(x, y);
}
return super.getInitialLocation(initialSize);
} }
/** /**
@ -345,179 +228,17 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
fSourceViewer= null; fSourceViewer= null;
} }
/**
* {@inheritDoc}
*/
public boolean hasContents() { public boolean hasContents() {
return fSourceViewer != null && fSourceViewer.getDocument() != null; return fSourceViewer != null && fSourceViewer.getDocument() != null;
} }
/**
* {@inheritDoc}
*/
public void setSizeConstraints(int maxWidth, int maxHeight) {
fMaxWidth= maxWidth;
fMaxHeight= maxHeight;
}
/**
* {@inheritDoc}
*/
public Point computeSizeHint() {
// compute the preferred size
int x= SWT.DEFAULT;
int y= SWT.DEFAULT;
Point size= getShell().computeSize(x, y);
if (size.x > fMaxWidth)
x= fMaxWidth;
if (size.y > fMaxHeight)
y= fMaxHeight;
// recompute using the constraints if the preferred size is larger than the constraints
if (x != SWT.DEFAULT || y != SWT.DEFAULT)
size= getShell().computeSize(x, y, false);
return size;
// return getShell().getSize();
}
/**
* {@inheritDoc}
*/
public void setLocation(Point location) {
if (!restoresLocation() || getDialogSettings() == null)
getShell().setLocation(location);
}
/**
* {@inheritDoc}
*/
public void setSize(int width, int height) {
if (!restoresSize() || getDialogSettings() == null) {
getShell().setSize(width, height);
}
}
/**
* {@inheritDoc}
*/
public void addDisposeListener(DisposeListener listener) {
getShell().addDisposeListener(listener);
}
/**
* {@inheritDoc}
*/
public void removeDisposeListener(DisposeListener listener) {
getShell().removeDisposeListener(listener);
}
/**
* {@inheritDoc}
*/
public void setForegroundColor(Color foreground) {
applyForegroundColor(foreground, getContents());
}
/**
* {@inheritDoc}
*/
public void setBackgroundColor(Color background) {
applyBackgroundColor(background, getContents());
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getFocusControl()
*/
@Override @Override
protected Control getFocusControl() {
return fSourceViewer.getTextWidget();
}
/**
* {@inheritDoc}
*/
public boolean isFocusControl() {
final Shell shell = getShell();
return shell.getDisplay().getActiveShell() == shell;
}
/**
* {@inheritDoc}
*/
public void setFocus() { public void setFocus() {
getShell().forceFocus(); super.setFocus();
fSourceViewer.getTextWidget().setFocus(); fSourceViewer.getTextWidget().setFocus();
} }
/**
* {@inheritDoc}
*/
public void addFocusListener(FocusListener listener) {
getShell().addFocusListener(listener);
}
/**
* {@inheritDoc}
*/
public void removeFocusListener(FocusListener listener) {
getShell().removeFocusListener(listener);
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getDialogSettings()
*/
@Override @Override
protected IDialogSettings getDialogSettings() {
String sectionName= getId();
if (sectionName == null) {
return null;
}
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings().getSection(sectionName);
if (settings == null)
settings= CUIPlugin.getDefault().getDialogSettings().addNewSection(sectionName);
return settings;
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#computeTrim()
*/
public Rectangle computeTrim() {
return getShell().computeTrim(0, 0, 0, 0);
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#getBounds()
*/
public Rectangle getBounds() {
return getShell().getBounds();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresLocation()
*/
public boolean restoresLocation() {
return getPersistLocation();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresSize()
*/
public boolean restoresSize() {
return getPersistSize();
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension4#setStatusText(java.lang.String)
*/
public void setStatusText(String statusFieldText) {
setInfoText(statusFieldText);
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int)
*/
public Point computeSizeConstraints(int widthInChars, int heightInChars) { public Point computeSizeConstraints(int widthInChars, int heightInChars) {
GC gc= new GC(fText); GC gc= new GC(fText);
gc.setFont(fTextFont); gc.setFont(fTextFont);
@ -528,33 +249,23 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return new Point(widthInChars * width, heightInChars * height); return new Point(widthInChars * width, heightInChars * height);
} }
/* @Override
* @see org.eclipse.jface.text.IInformationControlExtension5#containsControl(org.eclipse.swt.widgets.Control) public Point computeSizeHint() {
*/ // compute the preferred size
public boolean containsControl(Control control) { int x= SWT.DEFAULT;
do { int y= SWT.DEFAULT;
if (control == getShell()) Point size= getShell().computeSize(x, y);
return true; Point constraints= getSizeConstraints();
if (control instanceof Shell) if (constraints != null) {
return false; if (size.x > constraints.x)
control= control.getParent(); x= constraints.x;
} while (control != null); if (size.y > constraints.y)
return false; y= constraints.y;
} }
// recompute using the constraints if the preferred size is larger than the constraints
if (x != SWT.DEFAULT || y != SWT.DEFAULT)
size= getShell().computeSize(x, y, false);
/* return size;
* @see org.eclipse.jface.text.IInformationControlExtension5#isVisible()
*/
public boolean isVisible() {
Shell shell= getShell();
return shell != null && !shell.isDisposed() && shell.isVisible();
} }
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
*/
public IInformationControlCreator getInformationPresenterControlCreator() {
return null;
}
} }

View file

@ -971,6 +971,8 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
public IInformationPresenter getMacroExplorationPresenter(ISourceViewer sourceViewer) { public IInformationPresenter getMacroExplorationPresenter(ISourceViewer sourceViewer) {
final IInformationControlCreator controlCreator= getMacroExplorationControlCreator(); final IInformationControlCreator controlCreator= getMacroExplorationControlCreator();
final InformationPresenter presenter = new InformationPresenter(controlCreator); final InformationPresenter presenter = new InformationPresenter(controlCreator);
presenter.setRestoreInformationControlBounds(getDialogSettings(CMacroExpansionExplorationControl.KEY_CONTROL_BOUNDS), true, true);
presenter.setSizeConstraints(320, 120, true, false);
presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL); presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
final IInformationProvider provider = new CMacroExpansionInformationProvider(getEditor()); final IInformationProvider provider = new CMacroExpansionInformationProvider(getEditor());
@ -980,6 +982,17 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
presenter.setSizeConstraints(50, 20, true, false); presenter.setSizeConstraints(50, 20, true, false);
return presenter; return presenter;
} }
protected IDialogSettings getDialogSettings(String sectionName) {
if (sectionName == null) {
return null;
}
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings().getSection(sectionName);
if (settings == null) {
settings= CUIPlugin.getDefault().getDialogSettings().addNewSection(sectionName);
}
return settings;
}
/** /**
* Creates control for macro exploration in editor. * Creates control for macro exploration in editor.

View file

@ -26,6 +26,7 @@ public final class CHoverMessages extends NLS {
public static String AbstractAnnotationHover_message_singleQuickFix; public static String AbstractAnnotationHover_message_singleQuickFix;
public static String AbstractAnnotationHover_message_multipleQuickFix; public static String AbstractAnnotationHover_message_multipleQuickFix;
public static String CMacroExpansionControl_exploreMacroExpansion;
public static String CMacroExpansionControl_statusText; public static String CMacroExpansionControl_statusText;
public static String CMacroExpansionControl_title_expansion; public static String CMacroExpansionControl_title_expansion;

View file

@ -15,6 +15,7 @@ AbstractAnnotationHover_action_configureAnnotationPreferences= Configure Annotat
AbstractAnnotationHover_message_singleQuickFix= 1 quick fix available: AbstractAnnotationHover_message_singleQuickFix= 1 quick fix available:
AbstractAnnotationHover_message_multipleQuickFix= {0} quick fixes available: AbstractAnnotationHover_message_multipleQuickFix= {0} quick fixes available:
CMacroExpansionControl_exploreMacroExpansion=Press "{0}" for macro expansion steps
CMacroExpansionControl_statusText=Press {0} or {1} to step through macro expansion CMacroExpansionControl_statusText=Press {0} or {1} to step through macro expansion
CMacroExpansionControl_title_expansion=Expansion \#{0} of {1} CMacroExpansionControl_title_expansion=Expansion \#{0} of {1}
CMacroExpansionControl_title_fullyExpanded=Fully Expanded CMacroExpansionControl_title_fullyExpanded=Fully Expanded

View file

@ -10,11 +10,13 @@
*******************************************************************************/ *******************************************************************************/
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.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.swt.SWT; import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl; import org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl;
@ -34,7 +36,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, PopupDialog.HOVER_SHELLSTYLE, SWT.NONE, false, false, false, statusFieldText); super(parent, statusFieldText);
setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion); setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion);
} }
@ -42,52 +44,51 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr
* Creates a new control for use as a hover which optionally takes the focus. * Creates a new control for use as a hover which optionally takes the focus.
* *
* @param parent parent shell * @param parent parent shell
* @param takeFocus whether this control should take the focus * @param isResizable whether this control should be resizable
*/ */
public CMacroExpansionControl(Shell parent, boolean takeFocus) { public CMacroExpansionControl(Shell parent, boolean isResizable) {
super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, SWT.NONE, takeFocus, false, false, null); super(parent, isResizable);
setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion); setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion);
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#hasHeader()
*/
@Override @Override
protected boolean hasHeader() { protected boolean hasHeader() {
return true; return true;
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#getId()
*/
@Override
protected String getId() {
return "org.eclipse.cdt.ui.text.hover.CMacroExpansion"; //$NON-NLS-1$
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#setInput(java.lang.Object)
*/
@Override @Override
public void setInput(Object input) { public void setInput(Object input) {
if (input instanceof CMacroExpansionInput) { if (input instanceof CMacroExpansionInput) {
CMacroExpansionInput macroExpansionInput= (CMacroExpansionInput) input; CMacroExpansionInput macroExpansionInput= (CMacroExpansionInput) input;
setInformation(macroExpansionInput.fExplorer.getFullExpansion().getCodeAfterStep()); setInformation(macroExpansionInput.fExplorer.getFullExpansion().getCodeAfterStep());
fInput= macroExpansionInput; fInput= macroExpansionInput;
updateStatusText();
} else { } else {
super.setInput(input); super.setInput(input);
} }
} }
/* private void updateStatusText() {
* @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator() if (fInput == null) {
*/ return;
}
if (fInput.fExplorer.getExpansionStepCount() > 1) {
IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
if (bindingService != null) {
String keySequence= bindingService.getBestActiveBindingFormattedFor(ITextEditorActionDefinitionIds.SHOW_INFORMATION);
if (keySequence != null) {
setStatusText(NLS.bind(CHoverMessages.CMacroExpansionControl_exploreMacroExpansion, keySequence));
}
}
}
}
@Override @Override
public IInformationControlCreator getInformationPresenterControlCreator() { public IInformationControlCreator getInformationPresenterControlCreator() {
return new IInformationControlCreator() { return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) { public IInformationControl createInformationControl(Shell parent) {
if (fInput != null && fInput.fExplorer.getExpansionStepCount() > 1) { if (fInput != null && fInput.fExplorer.getExpansionStepCount() > 1) {
return new CMacroExpansionExplorationControl(parent); return new CMacroExpansionExplorationControl(parent, true);
} else { } else {
return new CMacroExpansionControl(parent, true); return new CMacroExpansionControl(parent, true);
} }

View file

@ -27,9 +27,11 @@ import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewer;
@ -37,7 +39,10 @@ import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
@ -68,6 +73,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer; import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
import org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl; import org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl;
@ -87,6 +93,14 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
private static final String COMMAND_ID_EXPANSION_FORWARD= "org.eclipse.cdt.ui.hover.forwardMacroExpansion"; //$NON-NLS-1$ private static final String COMMAND_ID_EXPANSION_FORWARD= "org.eclipse.cdt.ui.hover.forwardMacroExpansion"; //$NON-NLS-1$
private static final String CONTEXT_ID_MACRO_EXPANSION_HOVER= "org.eclipse.cdt.ui.macroExpansionHoverScope"; //$NON-NLS-1$ private static final String CONTEXT_ID_MACRO_EXPANSION_HOVER= "org.eclipse.cdt.ui.macroExpansionHoverScope"; //$NON-NLS-1$
/** Dialog settings key to persist control bounds. */
public static final String KEY_CONTROL_BOUNDS = "org.eclipse.cdt.ui.text.hover.CMacroExpansionExploration"; //$NON-NLS-1$
private static final String KEY_CONTROL_BOUNDS_INTERNAL = KEY_CONTROL_BOUNDS + ".internal"; //$NON-NLS-1$
private static final int MIN_WIDTH = 320;
private static final int MIN_HEIGHT = 180;
private static class CDiffNode extends DocumentRangeNode implements ITypedElement { private static class CDiffNode extends DocumentRangeNode implements ITypedElement {
public CDiffNode(DocumentRangeNode parent, int type, String id, IDocument doc, int start, int length) { public CDiffNode(DocumentRangeNode parent, int type, String id, IDocument doc, int start, int length) {
super(parent, type, id, doc, start, length); super(parent, type, id, doc, start, length);
@ -114,6 +128,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
private CMacroCompareViewer fMacroCompareViewer; private CMacroCompareViewer fMacroCompareViewer;
private ISourceViewer fMacroViewer; private ISourceViewer fMacroViewer;
private StyledText fMacroText; private StyledText fMacroText;
private boolean fRestoreSize;
private Point fDefaultSize;
private ScrolledComposite fTextScroller;
/** /**
* Creates a new control for use as a "quick view" where the control immediately takes the focus. * Creates a new control for use as a "quick view" where the control immediately takes the focus.
@ -122,8 +139,22 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
* @param input the input object, may be <code>null</code> * @param input the input object, may be <code>null</code>
*/ */
public CMacroExpansionExplorationControl(Shell parent, CMacroExpansionInput input) { public CMacroExpansionExplorationControl(Shell parent, CMacroExpansionInput input) {
super(parent, SWT.RESIZE, SWT.NONE, true, true, true); super(parent, new ToolBarManager(SWT.FLAT));
setMacroExpansionInput(input); setMacroExpansionInput(input);
addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
registerCommandHandlers();
}
public void focusLost(FocusEvent e) {
unregisterCommandHandlers();
}
});
getShell().addListener(SWT.Close, new Listener() {
public void handleEvent(Event event) {
widgetClosed();
}});
fillToolBar();
setDefaultSize(MIN_WIDTH, MIN_HEIGHT);
} }
/** /**
@ -135,30 +166,77 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
this(parent, null); this(parent, null);
} }
/* /**
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#hasHeader() * Creates a new control for use as a "quick view" where the control immediately takes the focus.
*
* @param parent parent shell
* @param restoreSize whether control size should be restored
*/ */
public CMacroExpansionExplorationControl(Shell parent, boolean restoreSize) {
this(parent, null);
fRestoreSize= restoreSize;
if (restoreSize) {
restoreSize();
}
}
private void restoreSize() {
String sectionName= KEY_CONTROL_BOUNDS_INTERNAL;
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings().getSection(sectionName);
if (settings == null) {
return;
}
try {
int width= settings.getInt(AbstractInformationControlManager.STORE_SIZE_WIDTH);
int height= settings.getInt(AbstractInformationControlManager.STORE_SIZE_HEIGHT);
setDefaultSize(width, height);
} catch (NumberFormatException exc) {
// Ignore
}
}
private void setDefaultSize(int width, int height) {
fDefaultSize= new Point(width, height);
}
private void storeSize() {
final Shell shell = getShell();
if (shell == null) {
return;
}
String sectionName= KEY_CONTROL_BOUNDS_INTERNAL;
IDialogSettings settings= CUIPlugin.getDefault().getDialogSettings().getSection(sectionName);
if (settings == null) {
settings= CUIPlugin.getDefault().getDialogSettings().addNewSection(sectionName);
}
Point size= shell.getSize();
settings.put(AbstractInformationControlManager.STORE_SIZE_WIDTH, size.x);
settings.put(AbstractInformationControlManager.STORE_SIZE_HEIGHT, size.y);
}
@Override @Override
protected boolean hasHeader() { protected boolean hasHeader() {
return true; return true;
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#createCompareViewerControl(org.eclipse.swt.widgets.Composite, int, org.eclipse.compare.CompareConfiguration)
*/
@Override @Override
protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) { protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) {
Splitter splitter= new Splitter(parent, SWT.VERTICAL); Splitter splitter= new Splitter(parent, SWT.VERTICAL);
splitter.setLayoutData(new GridData(GridData.FILL_BOTH)); splitter.setLayoutData(new GridData(GridData.FILL_BOTH));
fMacroViewer= createSourceViewer(splitter, style | SWT.V_SCROLL | SWT.H_SCROLL); // text viewer to show the macro definition
fTextScroller= new ScrolledComposite(splitter, SWT.H_SCROLL | SWT.V_SCROLL);
fMacroViewer= createSourceViewer(fTextScroller, style);
final StyledText textWidget= fMacroViewer.getTextWidget();
fTextScroller.setBackground(textWidget.getBackground());
fTextScroller.setContent(textWidget);
final Point size= textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
textWidget.setSize(size);
// compare viewer
CompareViewerControl control= super.createCompareViewerControl(splitter, style, compareConfig); CompareViewerControl control= super.createCompareViewerControl(splitter, style, compareConfig);
splitter.setWeights(new int[] { 20, 80 }); splitter.setWeights(new int[] { 20, 80 });
return control; return control;
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#createContentViewer(org.eclipse.swt.widgets.Composite, org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.CompareConfiguration)
*/
@Override @Override
protected Viewer createContentViewer(Composite parent, ICompareInput input, CompareConfiguration cc) { protected Viewer createContentViewer(Composite parent, ICompareInput input, CompareConfiguration cc) {
fMacroCompareViewer= new CMacroCompareViewer(parent, SWT.NULL, cc); fMacroCompareViewer= new CMacroCompareViewer(parent, SWT.NULL, cc);
@ -192,21 +270,6 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
return sourceViewer; return sourceViewer;
} }
@Override
public int 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();
}});
return super.open();
}
protected void unregisterCommandHandlers() { protected void unregisterCommandHandlers() {
if (fHandlerService != null) { if (fHandlerService != null) {
fHandlerService.deactivateHandlers(fHandlerActivations); fHandlerService.deactivateHandlers(fHandlerActivations);
@ -220,6 +283,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
} }
protected void registerCommandHandlers() { protected void registerCommandHandlers() {
if (fContextActivation != null) {
return;
}
IHandler backwardHandler= new AbstractHandler() { IHandler backwardHandler= new AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
backward(); backward();
@ -250,7 +316,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
String infoText= getInfoText(); String infoText= getInfoText();
if (infoText != null) { if (infoText != null) {
setInfoText(infoText); setStatusText(infoText);
//bug 234952 - truncation in the info label //bug 234952 - truncation in the info label
PixelConverter converter = new PixelConverter(getShell()); PixelConverter converter = new PixelConverter(getShell());
Point pt = getShell().getSize(); Point pt = getShell().getSize();
@ -261,15 +327,22 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
} }
} }
/* private void fillToolBar() {
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#fillViewMenu(org.eclipse.jface.action.IMenuManager) ToolBarManager mgr = getToolBarManager();
*/ if (mgr == null) {
@Override return;
protected void fillViewMenu(IMenuManager viewMenu) { }
super.fillViewMenu(viewMenu); IWorkbench workbench= PlatformUI.getWorkbench();
final CommandContributionItemParameter params= new CommandContributionItemParameter( CommandContributionItemParameter param= new CommandContributionItemParameter(workbench, null, COMMAND_ID_EXPANSION_BACK, CommandContributionItem.STYLE_PUSH);
PlatformUI.getWorkbench(), null, ICEditorActionDefinitionIds.OPEN_DECL, CommandContributionItem.STYLE_PUSH); param.icon= CPluginImages.DESC_ELCL_NAVIGATE_BACKWARD;
viewMenu.add(new CommandContributionItem(params)); mgr.add(new CommandContributionItem(param));
param = new CommandContributionItemParameter(workbench, null, COMMAND_ID_EXPANSION_FORWARD, CommandContributionItem.STYLE_PUSH);
param.icon= CPluginImages.DESC_ELCL_NAVIGATE_FORWARD;
mgr.add(new CommandContributionItem(param));
param = new CommandContributionItemParameter(workbench, null, ICEditorActionDefinitionIds.OPEN_DECL, CommandContributionItem.STYLE_PUSH);
param.icon = CPluginImages.DESC_ELCL_OPEN_DECLARATION;
mgr.add(new CommandContributionItem(param));
mgr.update(true);
} }
protected final void gotoMacroDefinition() { protected final void gotoMacroDefinition() {
@ -329,26 +402,42 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
return infoText; return infoText;
} }
/*
* @see org.eclipse.jface.dialogs.PopupDialog#close()
*/
@Override @Override
public boolean close() { public void dispose() {
unregisterCommandHandlers(); unregisterCommandHandlers();
return super.close(); super.dispose();
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#getId()
*/
@Override @Override
protected String getId() { public boolean restoresLocation() {
return "org.eclipse.cdt.ui.text.hover.CMacroExpansionExploration"; //$NON-NLS-1$ return true;
}
@Override
public boolean restoresSize() {
return true;
}
@Override
public void setSizeConstraints(int maxWidth, int maxHeight) {
Point constraints= getSizeConstraints();
if (constraints != null) {
super.setSizeConstraints(Math.max(constraints.x, maxWidth), Math.max(constraints.y, maxHeight));
} else {
super.setSizeConstraints(maxWidth, maxHeight);
}
}
@Override
public void setSize(int width, int height) {
if (fDefaultSize != null) {
width= Math.max(fDefaultSize.x, width);
height= Math.max(fDefaultSize.y, height);
fDefaultSize= null;
}
super.setSize(width, height);
} }
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#setInput(java.lang.Object)
*/
@Override @Override
public void setInput(Object input) { public void setInput(Object input) {
if (input instanceof CMacroExpansionInput) { if (input instanceof CMacroExpansionInput) {
@ -361,9 +450,28 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
} }
} }
/* private void widgetClosed() {
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#computeTrim() if (fRestoreSize) {
*/ storeSize();
fRestoreSize= false;
}
unregisterCommandHandlers();
}
@Override
public void setVisible(boolean visible) {
if (!visible) {
if (fRestoreSize) {
storeSize();
fRestoreSize= false;
}
}
super.setVisible(visible);
if (visible) {
setFocus();
}
}
@Override @Override
public Rectangle computeTrim() { public Rectangle computeTrim() {
Rectangle trim= super.computeTrim(); Rectangle trim= super.computeTrim();
@ -421,6 +529,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
setTitleText(CHoverMessages.bind(CHoverMessages.CMacroExpansionControl_title_macroExpansionExploration, getStepCount())); setTitleText(CHoverMessages.bind(CHoverMessages.CMacroExpansionControl_title_macroExpansionExploration, getStepCount()));
fMacroViewer.getDocument().set(getMacroText(fIndex)); fMacroViewer.getDocument().set(getMacroText(fIndex));
final StyledText textWidget= fMacroViewer.getTextWidget();
final Point size= textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
textWidget.setSize(size);
setInput(createCompareInput(null, left, right)); setInput(createCompareInput(null, left, right));
} }
@ -458,41 +569,35 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
} }
private String getMacroText(int index) { private String getMacroText(int index) {
final String text; index= index < getStepCount() ? index : 0;
final int count= getStepCount(); final IMacroExpansionStep expansionStep= fInput.fExplorer.getExpansionStep(index);
if (index < count) { IMacroBinding binding= expansionStep.getExpandedMacro();
final IMacroExpansionStep expansionStep= fInput.fExplorer.getExpansionStep(index); StringBuffer buffer= new StringBuffer();
IMacroBinding binding= expansionStep.getExpandedMacro(); buffer.append("#define ").append(binding.getName()); //$NON-NLS-1$
StringBuffer buffer= new StringBuffer(); char[][] params= binding.getParameterList();
buffer.append("#define ").append(binding.getName()); //$NON-NLS-1$ if (params != null) {
char[][] params= binding.getParameterList(); buffer.append('(');
if (params != null) { for (int i= 0; i < params.length; i++) {
buffer.append('('); if (i > 0) {
for (int i= 0; i < params.length; i++) { buffer.append(',');
if (i > 0) { buffer.append(' ');
buffer.append(',');
buffer.append(' ');
}
char[] param= params[i];
buffer.append(new String(param));
} }
buffer.append(')'); char[] param= params[i];
buffer.append(new String(param));
} }
buffer.append(' '); buffer.append(')');
if (!binding.isDynamic()) {
buffer.append(binding.getExpansionImage());
}
else {
ReplaceEdit[] replacements= expansionStep.getReplacements();
if (replacements.length == 1) {
buffer.append(replacements[0].getText());
}
}
text= buffer.toString();
} else {
text= ""; //$NON-NLS-1$
} }
return text; buffer.append(' ');
if (!binding.isDynamic()) {
buffer.append(binding.getExpansionImage());
}
else {
ReplaceEdit[] replacements= expansionStep.getReplacements();
if (replacements.length == 1) {
buffer.append(replacements[0].getText());
}
}
return buffer.toString();
} }
} }