Skip to main content
summaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorTeodor Madan2011-05-10 04:29:09 -0400
committerTeodor Madan2011-05-10 04:29:09 -0400
commit2fab85bf1727c50d42f0d434e82e6714680ecc8c (patch)
treeaf270aef1dbc0045039a60835e78b3ef23d6489b /debug
parent496fe2cc92d5cd88f24d7ed029d41a1ef88bdab2 (diff)
downloadorg.eclipse.cdt-2fab85bf1727c50d42f0d434e82e6714680ecc8c.tar.gz
org.eclipse.cdt-2fab85bf1727c50d42f0d434e82e6714680ecc8c.tar.xz
org.eclipse.cdt-2fab85bf1727c50d42f0d434e82e6714680ecc8c.zip
Bug 345134 - Cannot Cast multiple variable at once. Perform cast on all elements from selection
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java54
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java52
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java50
3 files changed, 96 insertions, 60 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java
index 3e37a31b1f..278950ea01 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java
@@ -11,6 +11,10 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.debug.core.model.ICastToArray;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
@@ -225,7 +229,7 @@ public class CastToArrayActionHandler extends AbstractHandler {
}
}
- private ICastToArray fCastToArray = null;
+ private ICastToArray[] fCastableItems = new ICastToArray[0];
private IStatus fStatus = null;
@@ -237,7 +241,7 @@ public class CastToArrayActionHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
fTargetPart = HandlerUtil.getActivePartChecked(event);
- if ( getCastToArray() == null )
+ if ( getCastToArray() == null || getCastToArray().length == 0 )
return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@@ -267,30 +271,36 @@ public class CastToArrayActionHandler extends AbstractHandler {
@Override
public void setEnabled(Object evaluationContext) {
- ICastToArray castToArray = getCastToArray(evaluationContext);
- setBaseEnabled( castToArray != null );
- setCastToArray(castToArray);
+ ICastToArray[] castableItems = getCastToArray(evaluationContext);
+ setBaseEnabled(castableItems.length > 0);
+ setCastToArray(castableItems);
}
- private ICastToArray getCastToArray(Object evaluationContext) {
+ private ICastToArray[] getCastToArray(Object evaluationContext) {
+ List<ICastToArray> castableItems = new ArrayList<ICastToArray>();
if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection)s;
- if (!ss.isEmpty()) {
- return (ICastToArray)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToArray.class);
- }
- }
- }
- return null;
+ Iterator<?> iter = ((IStructuredSelection)s).iterator();
+ while(iter.hasNext()) {
+ Object element = DebugPlugin.getAdapter(iter.next(), ICastToArray.class);
+ if (element instanceof ICastToArray) {
+ if (((ICastToArray)element).canCastToArray()) {
+ castableItems.add((ICastToArray)element);
+ }
+ }
+ }
+ }
+ }
+ return castableItems.toArray(new ICastToArray[castableItems.size()]);
}
- protected ICastToArray getCastToArray() {
- return fCastToArray;
+ protected ICastToArray[] getCastToArray() {
+ return fCastableItems;
}
- protected void setCastToArray( ICastToArray castToArray ) {
- fCastToArray = castToArray;
+ protected void setCastToArray( ICastToArray[] castableItems ) {
+ fCastableItems = castableItems;
}
public IStatus getStatus() {
@@ -301,15 +311,17 @@ public class CastToArrayActionHandler extends AbstractHandler {
fStatus = status;
}
- protected void doAction( ICastToArray castToArray ) throws DebugException {
- String currentType = castToArray.getCurrentType().trim();
+ protected void doAction( ICastToArray[] castableItems ) throws DebugException {
+ String currentType = castableItems[0].getCurrentType().trim();
CastToArrayDialog dialog = new CastToArrayDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType, 0, 1 );
if ( dialog.open() == Window.OK ) {
int firstIndex = dialog.getFirstIndex();
int lastIndex = dialog.getLength();
- castToArray.castToArray( firstIndex, lastIndex );
+ for ( ICastToArray castableItem : castableItems ) {
+ castableItem.castToArray( firstIndex, lastIndex );
+ }
if ( getSelectionProvider() != null )
- getSelectionProvider().setSelection( new StructuredSelection( castToArray ) );
+ getSelectionProvider().setSelection( new StructuredSelection( castableItems ) );
}
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java
index 1494871fae..df9a1409c6 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java
@@ -11,6 +11,10 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
@@ -74,7 +78,7 @@ public class CastToTypeActionHandler extends AbstractHandler {
}
}
- private ICastToType fCastToType = null;
+ private ICastToType[] fCastableItems = new ICastToType[0];
private IStatus fStatus = null;
@@ -87,7 +91,7 @@ public class CastToTypeActionHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
fTargetPart = HandlerUtil.getActivePartChecked(event);
- if ( getCastToType() == null )
+ if ( getCastToType() == null || getCastToType().length == 0 )
return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@@ -117,30 +121,36 @@ public class CastToTypeActionHandler extends AbstractHandler {
@Override
public void setEnabled(Object evaluationContext) {
- ICastToType castToType = getCastToType(evaluationContext);
- setBaseEnabled( castToType != null );
- setCastToType(castToType);
+ ICastToType[] castableItems = getCastToType(evaluationContext);
+ setBaseEnabled(castableItems.length > 0);
+ setCastToType(castableItems);
}
- private ICastToType getCastToType(Object evaluationContext) {
+ private ICastToType[] getCastToType(Object evaluationContext) {
+ List<ICastToType> castableItems = new ArrayList<ICastToType>();
if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection)s;
- if (!ss.isEmpty()) {
- return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class);
- }
- }
+ Iterator<?> iter = ((IStructuredSelection)s).iterator();
+ while(iter.hasNext()) {
+ Object element = DebugPlugin.getAdapter(iter.next(), ICastToType.class);
+ if (element instanceof ICastToType) {
+ if (((ICastToType)element).canCast()) {
+ castableItems.add((ICastToType)element);
+ }
+ }
+ }
+ }
}
- return null;
+ return castableItems.toArray(new ICastToType[castableItems.size()]);
}
- protected ICastToType getCastToType() {
- return fCastToType;
+ protected ICastToType[] getCastToType() {
+ return fCastableItems;
}
- protected void setCastToType( ICastToType castToType ) {
- fCastToType = castToType;
+ protected void setCastToType( ICastToType[] castableItems ) {
+ fCastableItems = castableItems;
}
public IStatus getStatus() {
@@ -151,14 +161,16 @@ public class CastToTypeActionHandler extends AbstractHandler {
fStatus = status;
}
- protected void doAction( ICastToType castToType ) throws DebugException {
- String currentType = castToType.getCurrentType().trim();
+ protected void doAction( ICastToType[] castableItems ) throws DebugException {
+ String currentType = castableItems[0].getCurrentType().trim();
CastToTypeDialog dialog = new CastToTypeDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType );
if ( dialog.open() == Window.OK ) {
String newType = dialog.getValue().trim();
- castToType.cast( newType );
+ for ( ICastToType castableItem : castableItems ) {
+ castableItem.cast( newType );
+ }
if ( getSelectionProvider() != null )
- getSelectionProvider().setSelection( new StructuredSelection( castToType ) );
+ getSelectionProvider().setSelection( new StructuredSelection( castableItems ) );
}
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java
index 2bfb645f1f..20e33687ee 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java
@@ -11,6 +11,10 @@
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.commands.AbstractHandler;
@@ -31,20 +35,20 @@ import org.eclipse.ui.IWorkbenchWindow;
*/
public class RestoreDefaultTypeActionHandler extends AbstractHandler {
- private ICastToType fCastToType = null;
+ private ICastToType[] fCastableItems = new ICastToType[0];
private IStatus fStatus = null;
- protected ICastToType getCastToType() {
- return fCastToType;
+ protected ICastToType[] getCastToType() {
+ return fCastableItems;
}
- protected void setCastToType( ICastToType castToType ) {
- fCastToType = castToType;
+ protected void setCastToType( ICastToType[] castableItems ) {
+ fCastableItems = castableItems;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
- if ( getCastToType() == null )
+ if ( getCastToType() == null || getCastToType().length == 0 )
return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@@ -74,22 +78,28 @@ public class RestoreDefaultTypeActionHandler extends AbstractHandler {
@Override
public void setEnabled(Object evaluationContext) {
- ICastToType castToType = getCastToType(evaluationContext);
- setBaseEnabled( castToType != null && castToType.isCasted() );
- setCastToType(castToType);
+ ICastToType[] castableItems = getCastToType(evaluationContext);
+ setBaseEnabled(castableItems.length > 0);
+ setCastToType(castableItems);
}
- private ICastToType getCastToType(Object evaluationContext) {
+ private ICastToType[] getCastToType(Object evaluationContext) {
+ List<ICastToType> castableItems = new ArrayList<ICastToType>();
if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection)s;
- if (!ss.isEmpty()) {
- return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class);
- }
- }
- }
- return null;
+ Iterator<?> iter = ((IStructuredSelection)s).iterator();
+ while( iter.hasNext() ) {
+ Object element = DebugPlugin.getAdapter(iter.next(), ICastToType.class);
+ if (element instanceof ICastToType) {
+ if (((ICastToType)element).isCasted()) {
+ castableItems.add((ICastToType)element);
+ }
+ }
+ }
+ }
+ }
+ return castableItems.toArray(new ICastToType[castableItems.size()]);
}
public IStatus getStatus() {
@@ -100,7 +110,9 @@ public class RestoreDefaultTypeActionHandler extends AbstractHandler {
fStatus = status;
}
- protected void doAction( ICastToType castToType ) throws DebugException {
- castToType.restoreOriginal();
+ protected void doAction( ICastToType[] castableItems ) throws DebugException {
+ for ( ICastToType castableItem : castableItems ) {
+ castableItem.restoreOriginal();
+ }
}
}

Back to the top