1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Bug 337881 - Applied Alain Lee patch to deliniate saparate expression lists on a per user/launch basis, where the lists are stored in the launch.

This commit is contained in:
Randy Rohrbach 2011-02-24 18:15:13 +00:00
parent 9749e71126
commit 21fb967107
3 changed files with 246 additions and 52 deletions

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2011, Texas Instruments 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:
* Texas Instruments - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.core.model.provisional;
import org.eclipse.debug.core.DebugException;
/**
* An interface to retrieve the name of the target.
*
* @author Alain Lee
*/
public interface ITargetLabelProvider {
String getLabel() throws DebugException;
}

View file

@ -12,15 +12,24 @@
package org.eclipse.cdt.debug.ui.memory.memorybrowser;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.cdt.debug.core.model.provisional.ITargetLabelProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
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;
@ -34,6 +43,8 @@ import org.eclipse.ui.PlatformUI;
public class GoToAddressBarWidget {
private static String SEPARATOR = "<sperator>";
private static String UNKNOWN_TARGET_NAME = "Unknown";
private Combo fExpression;
private ControlDecoration fEmptyExpression;
private ControlDecoration fWrongExpression;
@ -77,9 +88,9 @@ public class GoToAddressBarWidget {
}
private final static String SAVED_EXPRESSIONS = "saved_expressions"; //$NON-NLS-1$
private final static int MAX_SAVED_EXPRESSIONS = 30 ;
private final static int MAX_SAVED_EXPRESSIONS = 15 ;
private void saveExpression( String memorySpace, String expr ) {
private void saveExpression( String memorySpace, Object context, String expr ) {
/*
* Get the saved expressions if any.
*
@ -87,21 +98,100 @@ public class GoToAddressBarWidget {
*
* 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);
ILaunch launch = getLaunch(context);
if(launch == null)
{
return;
}
else {
store.setValue(SAVED_EXPRESSIONS, expr);
String targetName = getTargetName(context);
ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
String currentExpressions = "";
if (launchConfiguration != null) {
try {
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
if (wc != null) {
currentExpressions = wc.getAttribute(getSaveExpressionKey(targetName,memorySpace), "");
StringTokenizer st = new StringTokenizer(currentExpressions, ","); //$NON-NLS-1$
/*
* Parse through the list creating an ordered array for display.
*/
ArrayList<String> list = new ArrayList<String>();
while(st.hasMoreElements())
{
String expression = (String) st.nextElement();
list.add(expression);
}
if(!list.contains(expr))
{
list.add(expr);
while(list.size() > MAX_SAVED_EXPRESSIONS)
{
list.remove(0);
}
currentExpressions = "";
for ( int idx =0 ; idx < list.size(); idx ++ ) {
if(idx > 0)
{
currentExpressions += ",";
}
currentExpressions += list.get(idx);
}
wc.setAttribute(getSaveExpressionKey(targetName,memorySpace), currentExpressions);
wc.doSave();
}
}
}
catch(CoreException e) {
}
}
}
public void deleteExpressions(String memorySpace) {
MemoryBrowserPlugin.getDefault().getPreferenceStore().setValue(SAVED_EXPRESSIONS, "");
public void deleteExpressions(Object context) {
if(context == null)
{
return;
}
ILaunch launch = getLaunch(context);
if(launch == null)
{
return;
}
ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
if (launchConfiguration != null) {
try {
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
if (wc != null) {
@SuppressWarnings("unchecked")
Map<String,Object> attributes = (Map<String,Object>)wc.getAttributes();
if (attributes != null && !attributes.isEmpty()) {
Iterator<String> iterator = attributes.keySet().iterator();
while(iterator.hasNext())
{
String key = iterator.next();
if(key.startsWith(SAVED_EXPRESSIONS))
{
wc.removeAttribute(key);
}
}
wc.doSave();
}
}
}
catch(CoreException e) {
}
}
}
private String[] getSavedExpressions(String memorySpace) {
private String[] getSavedExpressions(String memorySpace, Object context) {
/*
* Get the saved expressions if any.
*
@ -109,9 +199,23 @@ public class GoToAddressBarWidget {
*
* expression,expression,.....,expression
*/
IPreferenceStore store = MemoryBrowserPlugin.getDefault().getPreferenceStore();
String expressions = store.getString(SAVED_EXPRESSIONS);
ILaunch launch = getLaunch(context);
if(launch == null)
{
return new String[0];
}
ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
String expressions = "";
if (launchConfiguration != null) {
try {
expressions = launchConfiguration.getAttribute(getSaveExpressionKey(getTargetName(context),memorySpace), "");
}
catch(CoreException e) {
}
}
StringTokenizer st = new StringTokenizer(expressions, ","); //$NON-NLS-1$
/*
* Parse through the list creating an ordered array for display.
@ -125,26 +229,22 @@ public class GoToAddressBarWidget {
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];
public void loadSavedExpressions(String memorySpace, Object context)
{
String[] expressions = getSavedExpressions(memorySpace, context);
String text = fExpression.getText();
fExpression.removeAll();
for(int idx=0; idx < expressions.length; idx++)
{
fExpression.add(expressions[idx]);
}
if(text != null)
{
fExpression.setText(text);
}
return null;
}
public void addExpressionToList( String memorySpace, String expr ) {
public void addExpressionToList( String memorySpace, Object context, String expr ) {
/*
* Make sure it does not already exist, we do not want to show duplicates.
*/
@ -152,8 +252,8 @@ public class GoToAddressBarWidget {
/*
* Cap the size of the list.
*/
if ( ( fExpression.getItemCount() + 1 ) > MAX_SAVED_EXPRESSIONS ) {
fExpression.remove(removeOldestExpression(memorySpace));
while ( fExpression.getItemCount() >= MAX_SAVED_EXPRESSIONS ) {
fExpression.remove(0);
}
/*
@ -161,14 +261,14 @@ public class GoToAddressBarWidget {
*/
fExpression.add(expr);
/*
* Add it to the persistense database.
*/
saveExpression(memorySpace, expr);
}
/*
* Add it to the persistense database.
*/
saveExpression(memorySpace, context, expr);
}
public void clearExpressionsFromList(String memorySpace) {
public void clearExpressionsFromList(String[] memorySpaces, Object context) {
/*
* Clean up the combo list.
*/
@ -178,7 +278,7 @@ public class GoToAddressBarWidget {
/*
* Clean out the expression persistense.
*/
deleteExpressions(memorySpace);
deleteExpressions(context);
/*
* Make sure the status image indicator shows OK.
@ -197,14 +297,6 @@ public class GoToAddressBarWidget {
}
});
/*
* 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);
@ -300,4 +392,55 @@ public class GoToAddressBarWidget {
{
return fExpressionStatus;
}
private ILaunch getLaunch(Object context)
{
IAdaptable adaptable = null;
ILaunch launch = null;
if(context instanceof IAdaptable)
{
adaptable = (IAdaptable) context;
launch = ((ILaunch) adaptable.getAdapter(ILaunch.class));
}
return launch;
}
private String getTargetName(Object context)
{
String targetName = null;
if(context instanceof IAdaptable)
{
IAdaptable adaptable = (IAdaptable) context;
ITargetLabelProvider labelProvider = (ITargetLabelProvider)adaptable.getAdapter(ITargetLabelProvider.class);
if(labelProvider != null)
{
try
{
targetName = labelProvider.getLabel();
}
catch(DebugException e)
{
}
}
}
if(targetName == null || targetName.trim().length() == 0)
{
targetName = UNKNOWN_TARGET_NAME;
}
return targetName;
}
private String getSaveExpressionKey(String targetName, String memorySpace)
{
String key = SAVED_EXPRESSIONS + SEPARATOR + targetName.trim();
if(memorySpace != null && memorySpace.trim().length() > 0)
{
key += SEPARATOR + memorySpace.trim();
}
return key;
}
}

View file

@ -23,6 +23,7 @@ import java.util.Map;
import org.eclipse.cdt.debug.core.model.provisional.IMemoryRenderingViewportProvider;
import org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval;
import org.eclipse.cdt.debug.core.model.provisional.ITargetLabelProvider;
import org.eclipse.cdt.debug.internal.core.CRequest;
import org.eclipse.cdt.debug.ui.provisional.IRepositionableMemoryRendering2;
import org.eclipse.core.runtime.CoreException;
@ -36,6 +37,7 @@ import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
@ -260,6 +262,20 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
}
});
fGotoMemorySpaceControl.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
if(fGotoMemorySpaceControl.getItemCount() >= 2)
{
final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl;
if (activeFolder != null) {
final Object context = activeFolder.getData(KEY_CONTEXT);
fGotoAddressBar.loadSavedExpressions(fGotoMemorySpaceControl.getText(), context);
}
}
}
});
FormData data = new FormData();
data.top = new FormAttachment(0);
@ -321,7 +337,11 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
}
public void clearExpressionsFromList(String memorySpace) {
fGotoAddressBar.clearExpressionsFromList(memorySpace);
final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl;
if (activeFolder != null) {
final Object context = activeFolder.getData(KEY_CONTEXT);
fGotoAddressBar.clearExpressionsFromList(fGotoMemorySpaceControl.isVisible() ? fGotoMemorySpaceControl.getItems() : new String[]{""}, context);
}
}
/**
@ -397,7 +417,12 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
String expression = fGotoAddressBar.getExpressionText();
if (expression.length() > 0) {
fGotoAddressBar.addExpressionToList(memorySpace, expression);
final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl;
Object context = null;
if (activeFolder != null) {
context = activeFolder.getData(KEY_CONTEXT);
}
fGotoAddressBar.addExpressionToList(memorySpace, context, expression);
performGo(inNewTab, expression, memorySpace);
}
}
@ -817,13 +842,13 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
IMemoryBlockRetrieval retrieval = null;
ILaunch launch = null;
if(context instanceof IAdaptable)
if(context instanceof IAdaptable)
{
adaptable = (IAdaptable) context;
retrieval = ((IMemoryBlockRetrieval) adaptable.getAdapter(IMemoryBlockRetrieval.class));
launch = ((ILaunch) adaptable.getAdapter(ILaunch.class));
}
if(retrieval != null && launch != null && !launch.isTerminated()) {
if (retrieval instanceof IMemorySpaceAwareMemoryBlockRetrieval) {
final IMemoryBlockRetrieval _retrieval = retrieval;
@ -884,6 +909,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
CTabItem tabItem = (CTabItem)e.item;
updateExpression(tabItem);
updateMemorySpaceControlSelection(tabItem);
fGotoAddressBar.loadSavedExpressions(fGotoMemorySpaceControl.isVisible() ? fGotoMemorySpaceControl.getText() : "", context);
getSite().getSelectionProvider().setSelection(new StructuredSelection(tabItem.getData(KEY_RENDERING)));
handleTabActivated(tabItem);
}
@ -894,6 +920,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
fStackLayout.topControl = tabFolder;
// set empty initial expression
fGotoAddressBar.setExpressionText(""); //$NON-NLS-1$
fGotoAddressBar.loadSavedExpressions(fGotoMemorySpaceControl.isVisible() ? fGotoMemorySpaceControl.getText() : "", context);
}
// update debug context to the new selection
tabFolder.setData(KEY_CONTEXT, context);
@ -928,6 +955,7 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
updateExpression(activeFolder.getSelection());
updateMemorySpaceControlSelection(activeFolder.getSelection());
fGotoAddressBar.loadSavedExpressions(fGotoMemorySpaceControl.isVisible() ? fGotoMemorySpaceControl.getText() : "", context);
fStackLayout.topControl.getParent().layout(true);
}
@ -948,7 +976,6 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM
}
}
protected final void handleTabActivated(CTabItem item) {
if (item != null) {
updateActiveRendering((IMemoryRendering) item.getData(KEY_RENDERING));