1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42: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.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.forwardMacroExpansion.name= Forward Macro Expansion
ActionDefinition.forwardMacroExpansion.name= Forward
ActionDefinition.forwardMacroExpansion.description= Step forward in macro expansions
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 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) {
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.CompareUI;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources;
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.IInformationControlExtension3;
import org.eclipse.jface.text.IInformationControlExtension4;
import org.eclipse.jface.text.IInformationControlExtension5;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.cdt.ui.CUIPlugin;
@ -52,7 +49,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
*
* @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 {
private CompareConfiguration fCompareConfiguration;
@ -68,44 +65,41 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
public void setInput(ICompareInput input) {
if (fViewer == null) {
fViewer= createContentViewer(this, input, fCompareConfiguration);
applyBackgroundColor(fBackgroundColor, fViewer.getControl());
setContent(fViewer.getControl());
}
fViewer.setInput(input);
}
}
private final int fStyle;
private CompareViewerControl fCompareViewerControl;
private ICompareInput fCompareInput;
private Color fBackgroundColor;
private boolean fIsSystemBackgroundColor;
private int fMaxWidth;
private int fMaxHeight;
private boolean fUseDefaultBounds;
private Label fTitleLabel;
/**
* Creates a source viewer information control with the given shell as parent. The given
* styles are applied to the shell and the source viewer.
* Creates a compare viewer information control with the given shell as parent.
*
* @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 isResizable flag indicating whether the control is resizable
*/
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.
if (hasHeader())
setTitleText(""); //$NON-NLS-1$
setInfoText(""); // //$NON-NLS-1$
public AbstractCompareViewerInformationControl(Shell parent, boolean isResizable) {
super(parent, isResizable);
// Create all controls
create();
}
/**
* 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();
@ -129,51 +123,27 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
: PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
protected void createContent(Composite parent) {
initializeColors();
Control contents= super.createContents(parent);
applyBackgroundColor(fBackgroundColor, contents);
return contents;
}
@Override
protected void applyBackgroundColor(Color color, Control control) {
super.applyBackgroundColor(fBackgroundColor, control);
}
Composite content= new Composite(parent, SWT.NONE);
final GridLayout gridLayout= new GridLayout();
gridLayout.marginWidth= 0;
gridLayout.marginHeight= 0;
gridLayout.verticalSpacing= 0;
content.setLayout(gridLayout);
/**
* 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) {
if (hasHeader()) {
createTitleLabel(content);
}
CompareConfiguration compareConfig= new CompareConfiguration();
compareConfig.setLeftEditable(false);
compareConfig.setRightEditable(false);
fCompareViewerControl= createCompareViewerControl(parent, fStyle, 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
}
});
fCompareViewerControl= createCompareViewerControl(content, SWT.NONE, compareConfig);
addDisposeListener(this);
return fCompareViewerControl;
}
protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) {
CompareViewerControl compareViewer= new CompareViewerControl(parent, style, compareConfig);
return compareViewer;
@ -183,16 +153,27 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
return CompareUI.findContentViewer(null, input, parent, cc);
}
/**
* 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;
private void createTitleLabel(Composite parent) {
fTitleLabel= new Label(parent, SWT.LEFT);
fTitleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fTitleLabel.setFont(JFaceResources.getDialogFont());
Display display= parent.getDisplay();
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;
}
/**
* {@inheritDoc}
*/
@Override
public void setInformation(String content) {
}
/**
* {@inheritDoc}
*/
public void setInput(Object input) {
if (input instanceof ICompareInput) {
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
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 void dispose() {
if (!fIsSystemBackgroundColor) {
fBackgroundColor.dispose();
}
close();
}
@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);
super.dispose();
}
/**
@ -314,145 +246,39 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
fCompareViewerControl= null;
}
/**
* {@inheritDoc}
*/
public boolean hasContents() {
return fCompareViewerControl != null && fCompareInput != null;
}
/**
* {@inheritDoc}
*/
public void setSizeConstraints(int maxWidth, int maxHeight) {
fMaxWidth= maxWidth;
fMaxHeight= maxHeight;
}
/**
* {@inheritDoc}
*/
@Override
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
Point constraints= getSizeConstraints();
if (constraints != null) {
if (size.x < constraints.x)
x= constraints.x;
if (size.y < constraints.y)
y= constraints.y;
}
// recompute using the constraints if the preferred size is smaller than the constraints
if (x != SWT.DEFAULT || y != SWT.DEFAULT)
size= getShell().computeSize(x, y, false);
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
protected Control getFocusControl() {
return fCompareViewerControl;
}
/**
* {@inheritDoc}
*/
public boolean isFocusControl() {
return fCompareViewerControl != null;
}
/**
* {@inheritDoc}
*/
public void setFocus() {
getShell().forceFocus();
super.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
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() {
Rectangle trim= getShell().computeTrim(0, 0, 0, 0);
Rectangle trim= super.computeTrim();
addInternalTrim(trim);
return trim;
}
@ -469,39 +295,12 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
trim.y+= textTrim.y;
trim.width+= textTrim.width;
trim.height+= textTrim.height;
if (fTitleLabel != null) {
trim.height+= fTitleLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
}
}
/*
* @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)
*/
@Override
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
GC gc= new GC(fCompareViewerControl);
@ -513,33 +312,42 @@ public abstract class AbstractCompareViewerInformationControl extends PopupDialo
return new Point(widthInChars * width, heightInChars * height);
}
/*
* @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()
*/
@Override
public IInformationControlCreator getInformationPresenterControlCreator() {
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;
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.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
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.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.SourceViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
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.Point;
import org.eclipse.swt.graphics.RGB;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.cdt.ui.CUIPlugin;
@ -60,51 +47,53 @@ import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
*
* @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 Color fBackgroundColor;
private boolean fIsSystemBackgroundColor;
private int fMaxWidth;
private int fMaxHeight;
private List<Control> fColorExclusionControls= new ArrayList<Control>();
private Font fTextFont;
private StyledText fText;
private Label fTitleLabel;
/**
* 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 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
*/
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.
if (hasHeader())
setTitleText(""); //$NON-NLS-1$
if (statusFieldText != null)
setInfoText(statusFieldText);
public AbstractSourceViewerInformationControl(Shell parent, String statusFieldText) {
super(parent, statusFieldText);
// Create all controls
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() {
RGB bgRGB= getHoverBackgroundColorRGB();
if (bgRGB != null) {
@ -123,28 +112,19 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
: PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR);
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Control contents= super.createContents(parent);
for (Control ctrl : fColorExclusionControls) {
ctrl.setBackground(fBackgroundColor);
public void createContent(Composite parent) {
Composite content= new Composite(parent, SWT.NONE);
final GridLayout gridLayout= new GridLayout();
gridLayout.marginWidth= 0;
gridLayout.marginHeight= 0;
gridLayout.verticalSpacing= 0;
content.setLayout(gridLayout);
if (hasHeader()) {
createTitleLabel(content);
}
return contents;
}
/**
* 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);
fSourceViewer= createSourceViewer(content, SWT.NONE);
final StyledText text= fSourceViewer.getTextWidget();
text.addKeyListener(new KeyListener() {
@ -158,7 +138,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
});
addDisposeListener(this);
return ((Viewer)fSourceViewer).getControl();
}
protected final ISourceViewer createSourceViewer(Composite parent, int style) {
@ -174,7 +153,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
initializeColors();
fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
fText.setBackground(fBackgroundColor);
fColorExclusionControls.add(fText);
fTextFont= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
fText.setFont(fTextFont);
@ -182,58 +160,25 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return sourceViewer;
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createInfoTextArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createInfoTextArea(Composite parent) {
Control infoText= super.createInfoTextArea(parent);
fColorExclusionControls.add(infoText);
return infoText;
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#createTitleControl(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createTitleControl(Composite parent) {
Control titleText= super.createTitleControl(parent);
fColorExclusionControls.add(titleText);
return titleText;
private void createTitleLabel(Composite parent) {
fTitleLabel= new Label(parent, SWT.LEFT);
fTitleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fTitleLabel.setFont(JFaceResources.getDialogFont());
Display display= parent.getDisplay();
Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
fTitleLabel.setForeground(foreground);
fTitleLabel.setBackground(background);
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#getBackgroundColorExclusions()
*/
@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;
public void setTitleText(String titleText) {
if (fTitleLabel != null) {
fTitleLabel.setText(titleText);
}
}
/**
@ -245,22 +190,7 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return fSourceViewer;
}
/**
* 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}
*/
@Override
public void setInformation(String content) {
if (content == null) {
fSourceViewer.setDocument(null);
@ -272,9 +202,6 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
fSourceViewer.setDocument(doc);
}
/**
* {@inheritDoc}
*/
public void setInput(Object input) {
if (input instanceof String)
setInformation((String)input);
@ -282,56 +209,12 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
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
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() {
if (!fIsSystemBackgroundColor) {
fBackgroundColor.dispose();
}
close();
}
@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);
super.dispose();
}
/**
@ -345,179 +228,17 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
fSourceViewer= null;
}
/**
* {@inheritDoc}
*/
public boolean hasContents() {
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
protected Control getFocusControl() {
return fSourceViewer.getTextWidget();
}
/**
* {@inheritDoc}
*/
public boolean isFocusControl() {
final Shell shell = getShell();
return shell.getDisplay().getActiveShell() == shell;
}
/**
* {@inheritDoc}
*/
public void setFocus() {
getShell().forceFocus();
super.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
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) {
GC gc= new GC(fText);
gc.setFont(fTextFont);
@ -528,33 +249,23 @@ public abstract class AbstractSourceViewerInformationControl extends PopupDialog
return new Point(widthInChars * width, heightInChars * height);
}
/*
* @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;
}
@Override
public Point computeSizeHint() {
// compute the preferred size
int x= SWT.DEFAULT;
int y= SWT.DEFAULT;
Point size= getShell().computeSize(x, y);
Point constraints= getSizeConstraints();
if (constraints != null) {
if (size.x > constraints.x)
x= constraints.x;
if (size.y > constraints.y)
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);
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#isVisible()
*/
public boolean isVisible() {
Shell shell= getShell();
return shell != null && !shell.isDisposed() && shell.isVisible();
return size;
}
/*
* @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) {
final IInformationControlCreator controlCreator= getMacroExplorationControlCreator();
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.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
final IInformationProvider provider = new CMacroExpansionInformationProvider(getEditor());
@ -980,6 +982,17 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
presenter.setSizeConstraints(50, 20, true, false);
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.

View file

@ -26,6 +26,7 @@ public final class CHoverMessages extends NLS {
public static String AbstractAnnotationHover_message_singleQuickFix;
public static String AbstractAnnotationHover_message_multipleQuickFix;
public static String CMacroExpansionControl_exploreMacroExpansion;
public static String CMacroExpansionControl_statusText;
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_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_title_expansion=Expansion \#{0} of {1}
CMacroExpansionControl_title_fullyExpanded=Fully Expanded

View file

@ -10,11 +10,13 @@
*******************************************************************************/
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.IInformationControlCreator;
import org.eclipse.swt.SWT;
import org.eclipse.osgi.util.NLS;
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;
@ -34,7 +36,7 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr
* @param statusFieldText text to be displayed in the status field, may be <code>null</code>
*/
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);
}
@ -42,52 +44,51 @@ public class CMacroExpansionControl extends AbstractSourceViewerInformationContr
* 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
* @param isResizable whether this control should be resizable
*/
public CMacroExpansionControl(Shell parent, boolean takeFocus) {
super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, SWT.NONE, takeFocus, false, false, null);
public CMacroExpansionControl(Shell parent, boolean isResizable) {
super(parent, isResizable);
setTitleText(CHoverMessages.CMacroExpansionControl_title_macroExpansion);
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl#hasHeader()
*/
@Override
protected boolean hasHeader() {
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
public void setInput(Object input) {
if (input instanceof CMacroExpansionInput) {
CMacroExpansionInput macroExpansionInput= (CMacroExpansionInput) input;
setInformation(macroExpansionInput.fExplorer.getFullExpansion().getCodeAfterStep());
fInput= macroExpansionInput;
updateStatusText();
} else {
super.setInput(input);
}
}
/*
* @see org.eclipse.jface.text.IInformationControlExtension5#getInformationPresenterControlCreator()
*/
private void updateStatusText() {
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
public IInformationControlCreator getInformationPresenterControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
if (fInput != null && fInput.fExplorer.getExpansionStepCount() > 1) {
return new CMacroExpansionExplorationControl(parent);
return new CMacroExpansionExplorationControl(parent, true);
} else {
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.NullProgressMonitor;
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.resource.JFaceResources;
import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
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.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
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.Image;
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.text.ICPartitions;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
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 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 {
public CDiffNode(DocumentRangeNode parent, int type, String id, IDocument doc, int start, int length) {
super(parent, type, id, doc, start, length);
@ -114,6 +128,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
private CMacroCompareViewer fMacroCompareViewer;
private ISourceViewer fMacroViewer;
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.
@ -122,8 +139,22 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
* @param input the input object, may be <code>null</code>
*/
public CMacroExpansionExplorationControl(Shell parent, CMacroExpansionInput input) {
super(parent, SWT.RESIZE, SWT.NONE, true, true, true);
super(parent, new ToolBarManager(SWT.FLAT));
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);
}
/*
* @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
protected boolean hasHeader() {
return true;
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#createCompareViewerControl(org.eclipse.swt.widgets.Composite, int, org.eclipse.compare.CompareConfiguration)
*/
@Override
protected CompareViewerControl createCompareViewerControl(Composite parent, int style, CompareConfiguration compareConfig) {
Splitter splitter= new Splitter(parent, SWT.VERTICAL);
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);
splitter.setWeights(new int[] { 20, 80 });
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
protected Viewer createContentViewer(Composite parent, ICompareInput input, CompareConfiguration cc) {
fMacroCompareViewer= new CMacroCompareViewer(parent, SWT.NULL, cc);
@ -192,21 +270,6 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
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() {
if (fHandlerService != null) {
fHandlerService.deactivateHandlers(fHandlerActivations);
@ -220,6 +283,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
}
protected void registerCommandHandlers() {
if (fContextActivation != null) {
return;
}
IHandler backwardHandler= new AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException {
backward();
@ -250,7 +316,7 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
String infoText= getInfoText();
if (infoText != null) {
setInfoText(infoText);
setStatusText(infoText);
//bug 234952 - truncation in the info label
PixelConverter converter = new PixelConverter(getShell());
Point pt = getShell().getSize();
@ -261,15 +327,22 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
}
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#fillViewMenu(org.eclipse.jface.action.IMenuManager)
*/
@Override
protected void fillViewMenu(IMenuManager viewMenu) {
super.fillViewMenu(viewMenu);
final CommandContributionItemParameter params= new CommandContributionItemParameter(
PlatformUI.getWorkbench(), null, ICEditorActionDefinitionIds.OPEN_DECL, CommandContributionItem.STYLE_PUSH);
viewMenu.add(new CommandContributionItem(params));
private void fillToolBar() {
ToolBarManager mgr = getToolBarManager();
if (mgr == null) {
return;
}
IWorkbench workbench= PlatformUI.getWorkbench();
CommandContributionItemParameter param= new CommandContributionItemParameter(workbench, null, COMMAND_ID_EXPANSION_BACK, CommandContributionItem.STYLE_PUSH);
param.icon= CPluginImages.DESC_ELCL_NAVIGATE_BACKWARD;
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() {
@ -329,26 +402,42 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
return infoText;
}
/*
* @see org.eclipse.jface.dialogs.PopupDialog#close()
*/
@Override
public boolean close() {
public void dispose() {
unregisterCommandHandlers();
return super.close();
super.dispose();
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#getId()
*/
@Override
protected String getId() {
return "org.eclipse.cdt.ui.text.hover.CMacroExpansionExploration"; //$NON-NLS-1$
public boolean restoresLocation() {
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
public void setInput(Object input) {
if (input instanceof CMacroExpansionInput) {
@ -361,9 +450,28 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
}
}
/*
* @see org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl#computeTrim()
*/
private void widgetClosed() {
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
public Rectangle computeTrim() {
Rectangle trim= super.computeTrim();
@ -421,6 +529,9 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
setTitleText(CHoverMessages.bind(CHoverMessages.CMacroExpansionControl_title_macroExpansionExploration, getStepCount()));
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));
}
@ -458,41 +569,35 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
}
private String getMacroText(int index) {
final String text;
final int count= getStepCount();
if (index < count) {
final IMacroExpansionStep expansionStep= fInput.fExplorer.getExpansionStep(index);
IMacroBinding binding= expansionStep.getExpandedMacro();
StringBuffer buffer= new StringBuffer();
buffer.append("#define ").append(binding.getName()); //$NON-NLS-1$
char[][] params= binding.getParameterList();
if (params != null) {
buffer.append('(');
for (int i= 0; i < params.length; i++) {
if (i > 0) {
buffer.append(',');
buffer.append(' ');
}
char[] param= params[i];
buffer.append(new String(param));
index= index < getStepCount() ? index : 0;
final IMacroExpansionStep expansionStep= fInput.fExplorer.getExpansionStep(index);
IMacroBinding binding= expansionStep.getExpandedMacro();
StringBuffer buffer= new StringBuffer();
buffer.append("#define ").append(binding.getName()); //$NON-NLS-1$
char[][] params= binding.getParameterList();
if (params != null) {
buffer.append('(');
for (int i= 0; i < params.length; i++) {
if (i > 0) {
buffer.append(',');
buffer.append(' ');
}
buffer.append(')');
char[] param= params[i];
buffer.append(new String(param));
}
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$
buffer.append(')');
}
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();
}
}