Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Variable Format Setting


Hi,

Boy do our AE's hate the ability to only set the format on one variable at a time. Perhaps you all have already fixed this in the head. If not, this fixes it for 1.2.1. Hopefully the head change would be quite similiar.

Thanks!
-Chris
diff -r -u xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/ICDIFormat.java xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/ICDIFormat.java
--- xide/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/ICDIFormat.java	Fri Jan 16 20:25:11 2004
+++ xide_compare/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/cdi/ICDIFormat.java	Tue Jan 27 19:30:21 2004
@@ -9,10 +9,10 @@
  */
 public interface ICDIFormat {
 
+	final static int UNKNOWN = -1;
 	final static int NATURAL = 0;
 	final static int DECIMAL = 1;
 	final static int BINARY  = 2;
 	final static int OCTAL = 3;
 	final static int HEXADECIMAL = 4;
-
 }
diff -r -u xide/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java xide_compare/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java
--- xide/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java	Fri Jan 16 20:25:21 2004
+++ xide_compare/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java	Tue Jan 27 19:30:21 2004
@@ -5,6 +5,9 @@
  */
 package org.eclipse.cdt.debug.internal.ui.actions;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+
 import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
 import org.eclipse.cdt.debug.core.model.ICVariable;
 import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
@@ -28,7 +31,7 @@
 public class VariableFormatActionDelegate implements IObjectActionDelegate
 {
 	private int fFormat = ICDIFormat.DECIMAL;
-	private ICVariable fVariable = null;
+	private ArrayList fVariables = new ArrayList();
 
 	/**
 	 * Constructor for VariableFormatActionDelegate.
@@ -50,7 +53,7 @@
 	 */
 	public void run( IAction action )
 	{
-		if ( getVariable() != null )
+		if ( fVariables.size() > 0 )
 		{
 			final MultiStatus ms = new MultiStatus( CDebugUIPlugin.getUniqueIdentifier(), 
 													DebugException.REQUEST_FAILED, "", null ); 
@@ -61,7 +64,7 @@
 											{
 												try
 												{
-													doAction( getVariable() );
+													doAction( fVariables );
 												}
 												catch( DebugException e )
 												{
@@ -84,49 +87,82 @@
 
 		}
 	}
-
+	
 	/**
-	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+	 * @param selection a selection object to be scanned.
+	 * @return a new arraylist with all the ICVariables in the selection.
 	 */
-	public void selectionChanged( IAction action, ISelection selection )
+	protected ArrayList getSelectedVariables( ISelection selection )
 	{
+		ArrayList ret = new ArrayList();
 		if ( selection instanceof IStructuredSelection )
 		{
-			Object element = ((IStructuredSelection)selection).getFirstElement();
-			if ( element instanceof ICVariable )
+			IStructuredSelection ssel = (IStructuredSelection)selection;
+			Iterator i = ssel.iterator();
+			while( i.hasNext() )
 			{
-				boolean enabled = enablesFor( (ICVariable)element );
-				action.setEnabled( enabled );
-				if ( enabled )
-				{
-					action.setChecked( ( ((ICVariable)element).getFormat() == fFormat ) );
-					setVariable( (ICVariable)element );
-					return;
-				}
+				Object o = i.next();
+				if( o instanceof ICVariable )
+					ret.add(o);
 			}
 		}
-		action.setChecked( false );
-		action.setEnabled( false );
-		setVariable( null );
+		return ret;
 	}
-	
-	private boolean enablesFor( ICVariable var )
+
+	/**
+	 * @return the format that all the fVariables entries have. If they vary, return UNKNOWN.
+	 */
+	protected int getFormat( )
 	{
-		return var.isEditable();
+		if( fVariables.size() == 0 )
+			return ICDIFormat.UNKNOWN;
+		
+		int base = ((ICVariable)fVariables.get(0)).getFormat();
+		for( int i = 1 ; i < fVariables.size() ; i++ )
+		{
+			int format = ((ICVariable)fVariables.get(i)).getFormat();
+			if( format != base )
+				return ICDIFormat.UNKNOWN;
+		}
+		
+		return base;	
 	}
 	
-	private void setVariable( ICVariable var )
+	/**
+	 * @return if the action enables for all the objects in the selection.
+	 */
+	protected boolean enablesForAll()
 	{
-		fVariable = var;
+		Iterator i = fVariables.iterator();
+		while( i.hasNext() )
+		{ 
+			if( !enablesFor( (ICVariable)i.next() ))
+				return false;
+		}
+		return true;
+	}
+
+	/**
+	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+	 */
+	public void selectionChanged( IAction action, ISelection selection )
+	{
+		fVariables = getSelectedVariables(selection);
+		action.setEnabled(enablesForAll());
+		action.setChecked( getFormat() == fFormat );
 	}
 	
-	protected ICVariable getVariable()
+	private boolean enablesFor( ICVariable var )
 	{
-		return fVariable;
+		return var.isEditable();
 	}
-
-	protected void doAction( ICVariable var ) throws DebugException
+	
+	protected void doAction( ArrayList var ) throws DebugException
 	{
-		var.setFormat( fFormat );
+		Iterator i = var.iterator();
+		while( i.hasNext() )
+		{
+			((ICVariable)(i.next())).setFormat( fFormat );
+		}
 	}
 }

Back to the top