mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 345134 - Cannot Cast multiple variable at once. Perform cast on all elements from selection
This commit is contained in:
parent
496fe2cc92
commit
2fab85bf17
3 changed files with 96 additions and 60 deletions
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue