mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 15:05:36 +02:00
Adding editing features to the memory view.
This commit is contained in:
parent
873f660e03
commit
113211c2e4
2 changed files with 71 additions and 19 deletions
|
@ -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.
|
||||
* MemoryNumberOfColumnAction.java: the action class
|
||||
* MemoryViewer.java: support of the action
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.List;
|
|||
import org.eclipse.cdt.debug.core.ICMemoryManager;
|
||||
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
|
||||
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.debug.core.DebugException;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
@ -260,7 +259,7 @@ public class MemoryPresentation
|
|||
{
|
||||
return getAddressLength() +
|
||||
INTERVAL_BETWEEN_ADDRESS_AND_DATA +
|
||||
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) * getNumberOfDataItems() +
|
||||
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) * getNumberOfDataItemsInRow() +
|
||||
( ( displayASCII() ) ? INTERVAL_BETWEEN_DATA_AND_ASCII +
|
||||
getDataBytesPerRow() : 0 ) + 1;
|
||||
}
|
||||
|
@ -287,7 +286,7 @@ public class MemoryPresentation
|
|||
int pos = offset % getRowLength();
|
||||
int asciiColumn = getAddressLength() +
|
||||
INTERVAL_BETWEEN_ADDRESS_AND_DATA +
|
||||
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItems() +
|
||||
(getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS ) * getNumberOfDataItemsInRow() +
|
||||
INTERVAL_BETWEEN_DATA_AND_ASCII;
|
||||
return ( pos >= asciiColumn && pos < getRowLength() - 1 );
|
||||
}
|
||||
|
@ -300,7 +299,7 @@ public class MemoryPresentation
|
|||
{
|
||||
int pos = offset % getRowLength();
|
||||
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 )
|
||||
return isInDataItem( pos - dataBegin );
|
||||
}
|
||||
|
@ -309,7 +308,7 @@ public class MemoryPresentation
|
|||
|
||||
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) )
|
||||
return false;
|
||||
|
@ -327,7 +326,7 @@ public class MemoryPresentation
|
|||
return 0;
|
||||
}
|
||||
|
||||
private int getNumberOfDataItems()
|
||||
private int getNumberOfDataItemsInRow()
|
||||
{
|
||||
if ( getMemoryBlock() != null )
|
||||
return getMemoryBlock().getNumberOfColumns();
|
||||
|
@ -449,19 +448,25 @@ public class MemoryPresentation
|
|||
|
||||
protected void textChanged( int offset, char newChar, char[] replacedText )
|
||||
{
|
||||
byte b = 0;
|
||||
if ( getMemoryBlock() != null )
|
||||
{
|
||||
int index = -1;
|
||||
if ( isInDataArea( offset ) )
|
||||
{
|
||||
index = getDataItemIndex( 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
|
||||
{
|
||||
getMemoryBlock().setValue( offset, new byte[] { b } );
|
||||
getMemoryBlock().setItemValue( index, new String( chars ) );
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue