1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Replace range by start index and length in 'Display As Array' action.

This commit is contained in:
Mikhail Khodjaiants 2003-03-17 21:25:20 +00:00
parent c885b918e3
commit fb09a0b4f0
6 changed files with 41 additions and 38 deletions

View file

@ -1,3 +1,9 @@
2003-03-17 Mikhail Khodjaiants
Replace range by start index and length in 'Display As Array' action.
* ICDIVariableManager.java
* ICastToArray.java
* CVariable.java
2003-03-14 Mikhail Khodjaiants 2003-03-14 Mikhail Khodjaiants
Added the 'isEditable' and 'hasChildren' methods to the 'ICVariable' interface. Added the 'isEditable' and 'hasChildren' methods to the 'ICVariable' interface.
* ICVariable.java * ICVariable.java

View file

@ -52,13 +52,13 @@ public interface ICDIVariableManager extends ICDIManager {
ICDIVariableObject getVariableObject(ICDIStackFrame stack, String name) throws CDIException; ICDIVariableObject getVariableObject(ICDIStackFrame stack, String name) throws CDIException;
/** /**
* Consider the variable object as an Array of type and range[start, end] * Consider the variable object as an Array of type and range[start, start + length - 1]
* @param stack * @param stack
* @param name * @param name
* @return ICDIVariableObject * @return ICDIVariableObject
* @throws CDIException * @throws CDIException
*/ */
ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject var, String type, int start, int end) throws CDIException; ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject var, String type, int start, int length) throws CDIException;
/** /**
* Consider the variable object as type. * Consider the variable object as type.

View file

@ -17,5 +17,5 @@ public interface ICastToArray extends ICastToType
{ {
boolean supportsCastToArray(); boolean supportsCastToArray();
void castToArray( String type, int startIndex, int endIndex ) throws DebugException; void castToArray( String type, int startIndex, int length ) throws DebugException;
} }

View file

@ -517,11 +517,11 @@ public abstract class CVariable extends CDebugElement
return null; return null;
} }
private ICDIVariable createShadow( ICDIStackFrame cdiFrame, String type, int start, int end ) throws DebugException private ICDIVariable createShadow( ICDIStackFrame cdiFrame, String type, int start, int length ) throws DebugException
{ {
try try
{ {
ICDIVariableObject varObject = getCDISession().getVariableManager().getVariableObjectAsArray( getOriginalCDIVariable(), type, start, end ); ICDIVariableObject varObject = getCDISession().getVariableManager().getVariableObjectAsArray( getOriginalCDIVariable(), type, start, length );
return getCDISession().getVariableManager().createVariable( varObject ); return getCDISession().getVariableManager().createVariable( varObject );
} }
catch( CDIException e ) catch( CDIException e )
@ -554,11 +554,11 @@ public abstract class CVariable extends CDebugElement
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(java.lang.String, int, int) * @see org.eclipse.cdt.debug.core.model.ICastToArray#castToArray(java.lang.String, int, int)
*/ */
public void castToArray( String type, int startIndex, int endIndex ) throws DebugException public void castToArray( String type, int startIndex, int length ) throws DebugException
{ {
try try
{ {
ICDIVariable newVar = createShadow( getOriginalCDIVariable().getStackFrame(), type, startIndex, endIndex ); ICDIVariable newVar = createShadow( getOriginalCDIVariable().getStackFrame(), type, startIndex, length );
ICDIVariable oldVar = getShadow(); ICDIVariable oldVar = getShadow();
setShadow( newVar ); setShadow( newVar );
if ( oldVar != null ) if ( oldVar != null )

View file

@ -1,3 +1,7 @@
2003-03-17 Mikhail Khodjaiants
Replace range by start index and length in 'Display As Array' action.
* CastToArrayActionDelegate.java
2003-03-14 Mikhail Khodjaiants 2003-03-14 Mikhail Khodjaiants
Fix for the 'Restore Default Type' action. Fix for the 'Restore Default Type' action.
* RestoreDefaultTypeActionDelegate.java * RestoreDefaultTypeActionDelegate.java

View file

@ -46,21 +46,21 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
{ {
private String fType = ""; private String fType = "";
private int fFirstIndex = 0; private int fFirstIndex = 0;
private int fLastIndex = 0; private int fLength = 0;
private Button fOkButton; private Button fOkButton;
private Label fErrorMessageLabel; private Label fErrorMessageLabel;
private Text fTypeText; private Text fTypeText;
private Text fFirstIndexText; private Text fFirstIndexText;
private Text fLastIndexText; private Text fLengthText;
public CastToArrayDialog( Shell parentShell, String initialType, int initialStart, int initialEnd ) public CastToArrayDialog( Shell parentShell, String initialType, int initialStart, int initialLength )
{ {
super( parentShell ); super( parentShell );
fType = ( initialType == null ) ? "" : initialType; fType = ( initialType == null ) ? "" : initialType;
fFirstIndex = initialStart; fFirstIndex = initialStart;
fLastIndex = initialEnd; fLength = initialLength;
} }
protected String getType() protected String getType()
@ -73,9 +73,9 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
return fFirstIndex; return fFirstIndex;
} }
protected int getLastIndex() protected int getLength()
{ {
return fLastIndex; return fLength;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -103,7 +103,7 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
fTypeText.setText( fType ); fTypeText.setText( fType );
fTypeText.selectAll(); fTypeText.selectAll();
fFirstIndexText.setText( String.valueOf( fFirstIndex ) ); fFirstIndexText.setText( String.valueOf( fFirstIndex ) );
fLastIndexText.setText( String.valueOf( fLastIndex ) ); fLengthText.setText( String.valueOf( fLength ) );
} }
} }
@ -150,7 +150,7 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
} }
} ); } );
Label label = ControlFactory.createLabel( composite, "First index:" ); Label label = ControlFactory.createLabel( composite, "Start index:" );
((GridData)label.getLayoutData()).horizontalSpan = 3; ((GridData)label.getLayoutData()).horizontalSpan = 3;
fFirstIndexText = ControlFactory.createTextField( composite ); fFirstIndexText = ControlFactory.createTextField( composite );
fFirstIndexText.addModifyListener( fFirstIndexText.addModifyListener(
@ -162,10 +162,10 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
} }
} ); } );
label = ControlFactory.createLabel( composite, "Last index:" ); label = ControlFactory.createLabel( composite, "Length:" );
((GridData)label.getLayoutData()).horizontalSpan = 3; ((GridData)label.getLayoutData()).horizontalSpan = 3;
fLastIndexText = ControlFactory.createTextField( composite ); fLengthText = ControlFactory.createTextField( composite );
fLastIndexText.addModifyListener( fLengthText.addModifyListener(
new ModifyListener() new ModifyListener()
{ {
public void modifyText( ModifyEvent e ) public void modifyText( ModifyEvent e )
@ -194,45 +194,38 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
} }
else else
{ {
int first = -1;
try try
{ {
first = Integer.parseInt( firstIndex ); Integer.parseInt( firstIndex );
} }
catch( NumberFormatException e ) catch( NumberFormatException e )
{
}
if ( first < 0 )
{ {
message = "Invalid first index."; message = "Invalid first index.";
enabled = false; enabled = false;
} }
else if ( enabled )
{ {
String lastIndex = fLastIndexText.getText().trim(); String lengthText = fLengthText.getText().trim();
if ( lastIndex.length() == 0 ) if ( lengthText.length() == 0 )
{ {
message = "The 'Last index' field must not be empty."; message = "The 'Last index' field must not be empty.";
enabled = false; enabled = false;
} }
else else
{ {
int last = -1; int length = -1;
try try
{ {
last = Integer.parseInt( lastIndex ); length = Integer.parseInt( lengthText );
} }
catch( NumberFormatException e ) catch( NumberFormatException e )
{
}
if ( last < 0 )
{ {
message = "Invalid last index."; message = "Invalid last index.";
enabled = false; enabled = false;
} }
else if ( last < first ) if ( enabled && length < 1 )
{ {
message = "The first index must not be greater than the last index."; message = "The length must be greater than 0.";
enabled = false; enabled = false;
} }
} }
@ -252,16 +245,16 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
{ {
fType = fTypeText.getText().trim(); fType = fTypeText.getText().trim();
String firstIndex = fFirstIndexText.getText().trim(); String firstIndex = fFirstIndexText.getText().trim();
String lastIndex = fLastIndexText.getText().trim(); String lengthText = fLengthText.getText().trim();
try try
{ {
fFirstIndex = Integer.parseInt( firstIndex ); fFirstIndex = Integer.parseInt( firstIndex );
fLastIndex = Integer.parseInt( lastIndex ); fLength = Integer.parseInt( lengthText );
} }
catch( NumberFormatException e ) catch( NumberFormatException e )
{ {
fFirstIndex = 0; fFirstIndex = 0;
fLastIndex = 0; fLength = 0;
} }
} }
else else
@ -370,12 +363,12 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
protected void doAction( ICastToArray castToArray ) throws DebugException protected void doAction( ICastToArray castToArray ) throws DebugException
{ {
String currentType = castToArray.getCurrentType().trim(); String currentType = castToArray.getCurrentType().trim();
CastToArrayDialog dialog = new CastToArrayDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType, 0, 0 ); CastToArrayDialog dialog = new CastToArrayDialog( CDebugUIPlugin.getActiveWorkbenchShell(), currentType, 0, 1 );
if ( dialog.open() == Window.OK ) if ( dialog.open() == Window.OK )
{ {
String newType = dialog.getType().trim(); String newType = dialog.getType().trim();
int firstIndex = dialog.getFirstIndex(); int firstIndex = dialog.getFirstIndex();
int lastIndex = dialog.getLastIndex(); int lastIndex = dialog.getLength();
castToArray.castToArray( newType, firstIndex, lastIndex ); castToArray.castToArray( newType, firstIndex, lastIndex );
} }
} }