diff options
Diffstat (limited to 'memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java')
-rw-r--r-- | memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java | 173 |
1 files changed, 158 insertions, 15 deletions
diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java index 607258118c1..0264a0d1678 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/GoToAddressBarWidget.java @@ -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; } -}
\ No newline at end of file + + /** + * Return the expression status + * @return expression status + */ + public IStatus getExpressionStatus() + { + return fExpressionStatus; + } +} |