1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 345134 - Cannot Cast multiple variable at once. Perform cast on all elements from selection

This commit is contained in:
Teodor Madan 2011-05-10 08:29:09 +00:00
parent 496fe2cc92
commit 2fab85bf17
3 changed files with 96 additions and 60 deletions

View file

@ -11,6 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; 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.core.model.ICastToArray;
import org.eclipse.cdt.debug.internal.ui.CDebugImages; import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; 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; private IStatus fStatus = null;
@ -237,7 +241,7 @@ public class CastToArrayActionHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
fTargetPart = HandlerUtil.getActivePartChecked(event); fTargetPart = HandlerUtil.getActivePartChecked(event);
if ( getCastToArray() == null ) if ( getCastToArray() == null || getCastToArray().length == 0 )
return null; return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@ -267,30 +271,36 @@ public class CastToArrayActionHandler extends AbstractHandler {
@Override @Override
public void setEnabled(Object evaluationContext) { public void setEnabled(Object evaluationContext) {
ICastToArray castToArray = getCastToArray(evaluationContext); ICastToArray[] castableItems = getCastToArray(evaluationContext);
setBaseEnabled( castToArray != null ); setBaseEnabled(castableItems.length > 0);
setCastToArray(castToArray); setCastToArray(castableItems);
} }
private ICastToArray getCastToArray(Object evaluationContext) { private ICastToArray[] getCastToArray(Object evaluationContext) {
List<ICastToArray> castableItems = new ArrayList<ICastToArray>();
if (evaluationContext instanceof IEvaluationContext) { if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME); Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) { if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)s; Iterator<?> iter = ((IStructuredSelection)s).iterator();
if (!ss.isEmpty()) { while(iter.hasNext()) {
return (ICastToArray)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToArray.class); Object element = DebugPlugin.getAdapter(iter.next(), ICastToArray.class);
} if (element instanceof ICastToArray) {
} if (((ICastToArray)element).canCastToArray()) {
} castableItems.add((ICastToArray)element);
return null; }
}
}
}
}
return castableItems.toArray(new ICastToArray[castableItems.size()]);
} }
protected ICastToArray getCastToArray() { protected ICastToArray[] getCastToArray() {
return fCastToArray; return fCastableItems;
} }
protected void setCastToArray( ICastToArray castToArray ) { protected void setCastToArray( ICastToArray[] castableItems ) {
fCastToArray = castToArray; fCastableItems = castableItems;
} }
public IStatus getStatus() { public IStatus getStatus() {
@ -301,15 +311,17 @@ public class CastToArrayActionHandler extends AbstractHandler {
fStatus = status; fStatus = status;
} }
protected void doAction( ICastToArray castToArray ) throws DebugException { protected void doAction( ICastToArray[] castableItems ) throws DebugException {
String currentType = castToArray.getCurrentType().trim(); String currentType = castableItems[0].getCurrentType().trim();
CastToArrayDialog dialog = new CastToArrayDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType, 0, 1 ); CastToArrayDialog dialog = new CastToArrayDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType, 0, 1 );
if ( dialog.open() == Window.OK ) { if ( dialog.open() == Window.OK ) {
int firstIndex = dialog.getFirstIndex(); int firstIndex = dialog.getFirstIndex();
int lastIndex = dialog.getLength(); int lastIndex = dialog.getLength();
castToArray.castToArray( firstIndex, lastIndex ); for ( ICastToArray castableItem : castableItems ) {
castableItem.castToArray( firstIndex, lastIndex );
}
if ( getSelectionProvider() != null ) if ( getSelectionProvider() != null )
getSelectionProvider().setSelection( new StructuredSelection( castToArray ) ); getSelectionProvider().setSelection( new StructuredSelection( castableItems ) );
} }
} }

View file

@ -11,6 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; 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.core.model.ICastToType;
import org.eclipse.cdt.debug.internal.ui.CDebugImages; import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; 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; private IStatus fStatus = null;
@ -87,7 +91,7 @@ public class CastToTypeActionHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
fTargetPart = HandlerUtil.getActivePartChecked(event); fTargetPart = HandlerUtil.getActivePartChecked(event);
if ( getCastToType() == null ) if ( getCastToType() == null || getCastToType().length == 0 )
return null; return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@ -117,30 +121,36 @@ public class CastToTypeActionHandler extends AbstractHandler {
@Override @Override
public void setEnabled(Object evaluationContext) { public void setEnabled(Object evaluationContext) {
ICastToType castToType = getCastToType(evaluationContext); ICastToType[] castableItems = getCastToType(evaluationContext);
setBaseEnabled( castToType != null ); setBaseEnabled(castableItems.length > 0);
setCastToType(castToType); setCastToType(castableItems);
} }
private ICastToType getCastToType(Object evaluationContext) { private ICastToType[] getCastToType(Object evaluationContext) {
List<ICastToType> castableItems = new ArrayList<ICastToType>();
if (evaluationContext instanceof IEvaluationContext) { if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME); Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) { if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)s; Iterator<?> iter = ((IStructuredSelection)s).iterator();
if (!ss.isEmpty()) { while(iter.hasNext()) {
return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class); 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() { protected ICastToType[] getCastToType() {
return fCastToType; return fCastableItems;
} }
protected void setCastToType( ICastToType castToType ) { protected void setCastToType( ICastToType[] castableItems ) {
fCastToType = castToType; fCastableItems = castableItems;
} }
public IStatus getStatus() { public IStatus getStatus() {
@ -151,14 +161,16 @@ public class CastToTypeActionHandler extends AbstractHandler {
fStatus = status; fStatus = status;
} }
protected void doAction( ICastToType castToType ) throws DebugException { protected void doAction( ICastToType[] castableItems ) throws DebugException {
String currentType = castToType.getCurrentType().trim(); String currentType = castableItems[0].getCurrentType().trim();
CastToTypeDialog dialog = new CastToTypeDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType ); CastToTypeDialog dialog = new CastToTypeDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType );
if ( dialog.open() == Window.OK ) { if ( dialog.open() == Window.OK ) {
String newType = dialog.getValue().trim(); String newType = dialog.getValue().trim();
castToType.cast( newType ); for ( ICastToType castableItem : castableItems ) {
castableItem.cast( newType );
}
if ( getSelectionProvider() != null ) if ( getSelectionProvider() != null )
getSelectionProvider().setSelection( new StructuredSelection( castToType ) ); getSelectionProvider().setSelection( new StructuredSelection( castableItems ) );
} }
} }

View file

@ -11,6 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; 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.core.model.ICastToType;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
@ -31,20 +35,20 @@ import org.eclipse.ui.IWorkbenchWindow;
*/ */
public class RestoreDefaultTypeActionHandler extends AbstractHandler { public class RestoreDefaultTypeActionHandler extends AbstractHandler {
private ICastToType fCastToType = null; private ICastToType[] fCastableItems = new ICastToType[0];
private IStatus fStatus = null; private IStatus fStatus = null;
protected ICastToType getCastToType() { protected ICastToType[] getCastToType() {
return fCastToType; return fCastableItems;
} }
protected void setCastToType( ICastToType castToType ) { protected void setCastToType( ICastToType[] castableItems ) {
fCastToType = castToType; fCastableItems = castableItems;
} }
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
if ( getCastToType() == null ) if ( getCastToType() == null || getCastToType().length == 0 )
return null; return null;
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
@ -74,22 +78,28 @@ public class RestoreDefaultTypeActionHandler extends AbstractHandler {
@Override @Override
public void setEnabled(Object evaluationContext) { public void setEnabled(Object evaluationContext) {
ICastToType castToType = getCastToType(evaluationContext); ICastToType[] castableItems = getCastToType(evaluationContext);
setBaseEnabled( castToType != null && castToType.isCasted() ); setBaseEnabled(castableItems.length > 0);
setCastToType(castToType); setCastToType(castableItems);
} }
private ICastToType getCastToType(Object evaluationContext) { private ICastToType[] getCastToType(Object evaluationContext) {
List<ICastToType> castableItems = new ArrayList<ICastToType>();
if (evaluationContext instanceof IEvaluationContext) { if (evaluationContext instanceof IEvaluationContext) {
Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME); Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (s instanceof IStructuredSelection) { if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)s; Iterator<?> iter = ((IStructuredSelection)s).iterator();
if (!ss.isEmpty()) { while( iter.hasNext() ) {
return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class); Object element = DebugPlugin.getAdapter(iter.next(), ICastToType.class);
} if (element instanceof ICastToType) {
} if (((ICastToType)element).isCasted()) {
} castableItems.add((ICastToType)element);
return null; }
}
}
}
}
return castableItems.toArray(new ICastToType[castableItems.size()]);
} }
public IStatus getStatus() { public IStatus getStatus() {
@ -100,7 +110,9 @@ public class RestoreDefaultTypeActionHandler extends AbstractHandler {
fStatus = status; fStatus = status;
} }
protected void doAction( ICastToType castToType ) throws DebugException { protected void doAction( ICastToType[] castableItems ) throws DebugException {
castToType.restoreOriginal(); for ( ICastToType castableItem : castableItems ) {
castableItem.restoreOriginal();
}
} }
} }