1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 23:45:23 +02:00

Adding editing features to the memory view.

This commit is contained in:
Mikhail Khodjaiants 2002-10-28 02:53:58 +00:00
parent 873f660e03
commit 113211c2e4
2 changed files with 71 additions and 19 deletions

View file

@ -1,4 +1,7 @@
2002-10-24 Mikhail Khodjaiants 2002-10-27 Mikhail Khodjaiants
* MemoryPresentation.java: adding editing features to the memory view.
2002-10-25 Mikhail Khodjaiants
Implementation of the 'Number Of Columns' action. Implementation of the 'Number Of Columns' action.
* MemoryNumberOfColumnAction.java: the action class * MemoryNumberOfColumnAction.java: the action class
* MemoryViewer.java: support of the action * MemoryViewer.java: support of the action

View file

@ -13,7 +13,6 @@ import java.util.List;
import org.eclipse.cdt.debug.core.ICMemoryManager; import org.eclipse.cdt.debug.core.ICMemoryManager;
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock; import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
import org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow; import org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils; import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
@ -260,7 +259,7 @@ public class MemoryPresentation
{ {
return getAddressLength() + return getAddressLength() +
INTERVAL_BETWEEN_ADDRESS_AND_DATA + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) * getNumberOfDataItems() + (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) * getNumberOfDataItemsInRow() +
( ( displayASCII() ) ? INTERVAL_BETWEEN_DATA_AND_ASCII + ( ( displayASCII() ) ? INTERVAL_BETWEEN_DATA_AND_ASCII +
getDataBytesPerRow() : 0 ) + 1; getDataBytesPerRow() : 0 ) + 1;
} }
@ -287,7 +286,7 @@ public class MemoryPresentation
int pos = offset % getRowLength(); int pos = offset % getRowLength();
int asciiColumn = getAddressLength() + int asciiColumn = getAddressLength() +
INTERVAL_BETWEEN_ADDRESS_AND_DATA + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItems() + (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItemsInRow() +
INTERVAL_BETWEEN_DATA_AND_ASCII; INTERVAL_BETWEEN_DATA_AND_ASCII;
return ( pos >= asciiColumn && pos < getRowLength() - 1 ); return ( pos >= asciiColumn && pos < getRowLength() - 1 );
} }
@ -300,7 +299,7 @@ public class MemoryPresentation
{ {
int pos = offset % getRowLength(); int pos = offset % getRowLength();
int dataBegin = getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA; int dataBegin = getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA;
int dataEnd = dataBegin + ((getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItems()); int dataEnd = dataBegin + ((getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItemsInRow());
if ( pos >= dataBegin && pos < dataEnd ) if ( pos >= dataBegin && pos < dataEnd )
return isInDataItem( pos - dataBegin ); return isInDataItem( pos - dataBegin );
} }
@ -309,7 +308,7 @@ public class MemoryPresentation
private boolean isInDataItem( int pos ) private boolean isInDataItem( int pos )
{ {
for ( int i = 0; i < getNumberOfDataItems(); ++i ) for ( int i = 0; i < getNumberOfDataItemsInRow(); ++i )
{ {
if ( pos < i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) ) if ( pos < i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) )
return false; return false;
@ -327,7 +326,7 @@ public class MemoryPresentation
return 0; return 0;
} }
private int getNumberOfDataItems() private int getNumberOfDataItemsInRow()
{ {
if ( getMemoryBlock() != null ) if ( getMemoryBlock() != null )
return getMemoryBlock().getNumberOfColumns(); return getMemoryBlock().getNumberOfColumns();
@ -449,19 +448,25 @@ public class MemoryPresentation
protected void textChanged( int offset, char newChar, char[] replacedText ) protected void textChanged( int offset, char newChar, char[] replacedText )
{ {
byte b = 0; if ( getMemoryBlock() != null )
{
int index = -1;
if ( isInDataArea( offset ) ) if ( isInDataArea( offset ) )
{ {
index = getDataItemIndex( offset );
} }
if ( isInAsciiArea( offset ) ) if ( isInAsciiArea( offset ) )
{ {
b = CDebugUtils.charToByte( newChar ); index = offset;
} }
if ( getMemoryBlock() != null ) if ( index != -1 )
{ {
char[] chars = getDataItemChars( index );
int itemOffset = getDataItemOffset( index );
chars[offset - itemOffset] = newChar;
try try
{ {
getMemoryBlock().setValue( offset, new byte[] { b } ); getMemoryBlock().setItemValue( index, new String( chars ) );
} }
catch( DebugException e ) catch( DebugException e )
{ {
@ -470,3 +475,47 @@ public class MemoryPresentation
} }
} }
} }
private int getDataItemIndex( int offset )
{
int row = offset / getRowLength();
int pos = offset % getRowLength();
for ( int i = 0; i < getNumberOfDataItemsInRow(); ++i )
{
if ( pos < i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) )
return -1;
if ( pos >= i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) &&
pos < (i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS)) + getDataItemLength() )
return i + (row * getNumberOfDataItemsInRow());
}
return -1;
}
private int getDataItemOffset( int index )
{
int row = index / getNumberOfDataItemsInRow();
int pos = index % getDataItemLength();
return row * getRowLength() +
getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
pos * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS);
}
private char[] getDataItemChars( int index )
{
if ( getMemoryBlock() != null )
{
int rowNumber = index / (getMemoryBlock().getNumberOfColumns() * getMemoryBlock().getWordSize());
int pos = index % (getMemoryBlock().getNumberOfColumns() * getMemoryBlock().getWordSize());
IFormattedMemoryBlockRow[] rows = getMemoryBlock().getRows();
if ( rowNumber < rows.length )
{
String[] data = rows[rowNumber].getData();
if ( pos < data.length )
{
return data[pos].toCharArray();
}
}
}
return new char[0];
}
}