mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
Bug - 326307
Initial version with dropdown expressions list. Also this code contains fixes for 330468. I had these edits in place when I started working with Alain's patch. Randy 781-354-2226
This commit is contained in:
parent
2f04b81343
commit
c681894c31
5 changed files with 216 additions and 17 deletions
|
@ -13,7 +13,7 @@
|
|||
providerName = Eclipse CDT
|
||||
pluginName = Memory Browser
|
||||
view.name.0 = Memory Browser
|
||||
|
||||
view.clearExpressionList = Clear Expressions
|
||||
# Pin & Clone
|
||||
PinView.name = Pin to Debug Context
|
||||
OpenNewView.name = Open New View
|
|
@ -10,6 +10,7 @@
|
|||
# Contributors:
|
||||
# Ted R Williams (Wind River) - initial implementation
|
||||
# Patrick Chuong (Texas Instruments) - Pin and Clone Supports (331781)
|
||||
# Randy Rohrbach (Wind River) - Multiple expression support (326307)
|
||||
-->
|
||||
<plugin>
|
||||
|
||||
|
@ -59,4 +60,19 @@
|
|||
</action>
|
||||
</viewContribution>
|
||||
</extension>
|
||||
<!-- Add the ability to clear the expressions list -->
|
||||
<extension point="org.eclipse.ui.viewActions">
|
||||
<viewContribution
|
||||
id="org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser.clearExpressionList"
|
||||
targetID="org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser">
|
||||
<action
|
||||
class="org.eclipse.cdt.debug.ui.memory.memorybrowser.ClearExpressionsListAction"
|
||||
id="org.eclipse.cdt.debug.ui.memory.memorybrowser.ClearExpressionListActionID"
|
||||
label="%view.clearExpressionList"
|
||||
menubarPath="additions">
|
||||
</action>
|
||||
</viewContribution>
|
||||
</extension>
|
||||
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007-2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.debug.ui.memory.memorybrowser;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IViewActionDelegate;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
|
||||
public class ClearExpressionsListAction implements IViewActionDelegate {
|
||||
|
||||
private IViewPart fView;
|
||||
|
||||
public void init(IViewPart view) {
|
||||
fView = view;
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
if ( fView instanceof MemoryBrowser ) {
|
||||
MemoryBrowser browser = (MemoryBrowser) fView;
|
||||
browser.clearExpressionsFromList(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {}
|
||||
}
|
|
@ -11,25 +11,30 @@
|
|||
|
||||
package org.eclipse.cdt.debug.ui.memory.memorybrowser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.fieldassist.ControlDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
public class GoToAddressBarWidget {
|
||||
|
||||
private Text fExpression;
|
||||
private Combo fExpression;
|
||||
private ControlDecoration fEmptyExpression;
|
||||
private ControlDecoration fWrongExpression;
|
||||
|
||||
|
@ -38,8 +43,10 @@ public class GoToAddressBarWidget {
|
|||
private Composite fComposite;
|
||||
|
||||
protected static int ID_GO_NEW_TAB = 2000;
|
||||
|
||||
/**
|
||||
|
||||
private IStatus fExpressionStatus = Status.OK_STATUS;
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
|
@ -68,20 +75,142 @@ public class GoToAddressBarWidget {
|
|||
|
||||
return fComposite;
|
||||
}
|
||||
|
||||
private final static String SAVED_EXPRESSIONS = "saved_expressions"; //$NON-NLS-1$
|
||||
private final static int MAX_SAVED_EXPRESSIONS = 30 ;
|
||||
|
||||
private void saveExpression( String memorySpace, String expr ) {
|
||||
/*
|
||||
* Get the saved expressions if any.
|
||||
*
|
||||
* They are in the form
|
||||
*
|
||||
* expression,expression,.....,expression
|
||||
*/
|
||||
IPreferenceStore store = MemoryBrowserPlugin.getDefault().getPreferenceStore();
|
||||
String currentExpressions = store.getString(SAVED_EXPRESSIONS);
|
||||
if ( currentExpressions != null && currentExpressions.length() != 0 ) {
|
||||
store.setValue(SAVED_EXPRESSIONS, currentExpressions + "," + expr);
|
||||
}
|
||||
else {
|
||||
store.setValue(SAVED_EXPRESSIONS, expr);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteExpressions(String memorySpace) {
|
||||
MemoryBrowserPlugin.getDefault().getPreferenceStore().setValue(SAVED_EXPRESSIONS, "");
|
||||
}
|
||||
|
||||
private Text createExpressionField(Composite parent) {
|
||||
Text expression = new Text(parent, SWT.SINGLE | SWT.BORDER);
|
||||
expression.addModifyListener(new ModifyListener() {
|
||||
private String[] getSavedExpressions(String memorySpace) {
|
||||
/*
|
||||
* Get the saved expressions if any.
|
||||
*
|
||||
* They are in the form
|
||||
*
|
||||
* expression,expression,.....,expression
|
||||
*/
|
||||
IPreferenceStore store = MemoryBrowserPlugin.getDefault().getPreferenceStore();
|
||||
String expressions = store.getString(SAVED_EXPRESSIONS);
|
||||
|
||||
StringTokenizer st = new StringTokenizer(expressions, ","); //$NON-NLS-1$
|
||||
/*
|
||||
* Parse through the list creating an ordered array for display.
|
||||
*/
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while(st.hasMoreElements())
|
||||
{
|
||||
String expr = (String) st.nextElement();
|
||||
list.add(expr);
|
||||
}
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
private String removeOldestExpression( String memorySpace ) {
|
||||
String[] currentSavedExpressions = getSavedExpressions(memorySpace);
|
||||
if ( currentSavedExpressions.length > 0 ) {
|
||||
/*
|
||||
* Remove all expressions and then repopulate the list.
|
||||
*/
|
||||
deleteExpressions(memorySpace);
|
||||
/*
|
||||
* The first in the list is the oldest. So we will delete it by not
|
||||
* putting it back.
|
||||
*/
|
||||
for ( int idx = 1 ; idx < currentSavedExpressions.length; idx ++ ) {
|
||||
saveExpression( memorySpace, currentSavedExpressions[idx]);
|
||||
}
|
||||
return currentSavedExpressions[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addExpressionToList( String memorySpace, String expr ) {
|
||||
/*
|
||||
* Make sure it does not already exist, we do not want to show duplicates.
|
||||
*/
|
||||
if ( fExpression.indexOf(expr) == -1 ) {
|
||||
/*
|
||||
* Cap the size of the list.
|
||||
*/
|
||||
if ( ( fExpression.getItemCount() + 1 ) > MAX_SAVED_EXPRESSIONS ) {
|
||||
fExpression.remove(removeOldestExpression(memorySpace));
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the new expression to the dropdown.
|
||||
*/
|
||||
fExpression.add(expr);
|
||||
|
||||
/*
|
||||
* Add it to the persistense database.
|
||||
*/
|
||||
saveExpression(memorySpace, expr);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearExpressionsFromList(String memorySpace) {
|
||||
/*
|
||||
* Clean up the combo list.
|
||||
*/
|
||||
fExpression.removeAll();
|
||||
fExpression.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
|
||||
|
||||
/*
|
||||
* Clean out the expression persistense.
|
||||
*/
|
||||
deleteExpressions(memorySpace);
|
||||
|
||||
/*
|
||||
* Make sure the status image indicator shows OK.
|
||||
*/
|
||||
handleExpressionStatus(Status.OK_STATUS);
|
||||
}
|
||||
|
||||
private Combo createExpressionField(Composite parent){
|
||||
/*
|
||||
* Create the dropdown box for the editable expressions.
|
||||
*/
|
||||
Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.BORDER);
|
||||
combo.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
updateButtons();
|
||||
}
|
||||
});
|
||||
fEmptyExpression = new ControlDecoration(expression, SWT.LEFT | SWT.CENTER);
|
||||
|
||||
/*
|
||||
* Populate the list with the expressions from the last time the view was brought up.
|
||||
*/
|
||||
String[] expressions = getSavedExpressions("");
|
||||
for ( String expr : expressions ) {
|
||||
combo.add( expr );
|
||||
}
|
||||
|
||||
fEmptyExpression = new ControlDecoration(combo, SWT.LEFT | SWT.CENTER);
|
||||
fEmptyExpression.setDescriptionText(Messages.getString("GoToAddressBarWidget.EnterExpressionMessage")); //$NON-NLS-1$
|
||||
FieldDecoration fieldDec = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
|
||||
fEmptyExpression.setImage(fieldDec.getImage());
|
||||
|
||||
fWrongExpression = new ControlDecoration(expression, SWT.LEFT | SWT.TOP);
|
||||
fWrongExpression = new ControlDecoration(combo, SWT.LEFT | SWT.TOP);
|
||||
fieldDec = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
|
||||
fWrongExpression.setImage(fieldDec.getImage());
|
||||
fWrongExpression.hide();
|
||||
|
@ -89,8 +218,8 @@ public class GoToAddressBarWidget {
|
|||
// leave enough room for decorators
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
data.horizontalIndent = Math.max(fEmptyExpression.getImage().getBounds().width, fWrongExpression.getImage().getBounds().width);
|
||||
expression.setLayoutData(data);
|
||||
return expression;
|
||||
combo.setLayoutData(data);
|
||||
return combo;
|
||||
}
|
||||
|
||||
protected void updateButtons() {
|
||||
|
@ -103,8 +232,11 @@ public class GoToAddressBarWidget {
|
|||
fEmptyExpression.show();
|
||||
else
|
||||
fEmptyExpression.hide();
|
||||
|
||||
fWrongExpression.hide();
|
||||
|
||||
if (fExpressionStatus.isOK())
|
||||
fWrongExpression.hide();
|
||||
else
|
||||
fWrongExpression.show();
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
|
@ -140,7 +272,7 @@ public class GoToAddressBarWidget {
|
|||
fExpression.setText(text);
|
||||
}
|
||||
|
||||
public Text getExpressionWidget()
|
||||
public Combo getExpressionWidget()
|
||||
{
|
||||
return fExpression;
|
||||
}
|
||||
|
@ -156,5 +288,16 @@ public class GoToAddressBarWidget {
|
|||
fWrongExpression.setDescriptionText(message.getMessage());
|
||||
fWrongExpression.show();
|
||||
}
|
||||
|
||||
fExpressionStatus = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the expression status
|
||||
* @return expression status
|
||||
*/
|
||||
public IStatus getExpressionStatus()
|
||||
{
|
||||
return fExpressionStatus;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,6 +320,10 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
|
|||
return false;
|
||||
}
|
||||
|
||||
public void clearExpressionsFromList(String memorySpace) {
|
||||
fGotoAddressBar.clearExpressionsFromList(memorySpace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the presentation context id for this view. Used to support the
|
||||
* pin and clone feature patch from bug 145635.
|
||||
|
@ -393,7 +397,8 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
|
|||
|
||||
String expression = fGotoAddressBar.getExpressionText();
|
||||
if (expression.length() > 0) {
|
||||
performGo(inNewTab, fGotoAddressBar.getExpressionText(), memorySpace);
|
||||
fGotoAddressBar.addExpressionToList(memorySpace, expression);
|
||||
performGo(inNewTab, expression, memorySpace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue