mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-22 00:15:25 +02:00
Implementing editing features of the memory view.
This commit is contained in:
parent
347a692269
commit
e4a57a52b7
7 changed files with 107 additions and 33 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-10-28 Mikhail Khodjaiants
|
||||
Implementing editing features of the memory view.
|
||||
* IFormattedMemoryBlockRow.java
|
||||
* CFormattedMemoryBlock.java
|
||||
|
||||
2002-10-27 Mikhail Khodjaiants
|
||||
* IFormattedMemoryBlock.java: added the 'setItemValue' method.
|
||||
* CFormattedMemoryBlock.java: implementation of the 'setItemValue' method.
|
||||
|
|
|
@ -34,4 +34,6 @@ public interface IFormattedMemoryBlockRow
|
|||
* @return the ASCII dump for this row
|
||||
*/
|
||||
String getASCII();
|
||||
|
||||
Integer[] getDirtyItems();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.eclipse.cdt.debug.internal.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
|
@ -38,6 +38,7 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
private long fAddress;
|
||||
private String[] fData;
|
||||
private String fAscii;
|
||||
private boolean[] fDirtyItems;
|
||||
|
||||
/**
|
||||
* Constructor for CFormattedMemoryBlockRow.
|
||||
|
@ -47,6 +48,8 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
fAddress = address;
|
||||
fData = data;
|
||||
fAscii = ascii;
|
||||
fDirtyItems = new boolean[fData.length];
|
||||
Arrays.fill( fDirtyItems, false );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -72,6 +75,26 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
{
|
||||
return fData;
|
||||
}
|
||||
|
||||
protected void setData( int colIndex, String newValue )
|
||||
{
|
||||
if ( colIndex < fData.length )
|
||||
{
|
||||
fData[colIndex] = newValue;
|
||||
fDirtyItems[colIndex] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer[] getDirtyItems()
|
||||
{
|
||||
ArrayList list = new ArrayList( fDirtyItems.length );
|
||||
for ( int i = 0; i < fDirtyItems.length; ++i )
|
||||
{
|
||||
if ( fDirtyItems[i] )
|
||||
list.add( new Integer( i ) );
|
||||
}
|
||||
return (Integer[])list.toArray( new Integer[list.size()] );
|
||||
}
|
||||
}
|
||||
|
||||
private String fAddressExpression;
|
||||
|
@ -84,7 +107,6 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
private char fPaddingChar = '.';
|
||||
private List fRows = null;
|
||||
private Long[] fChangedAddresses = new Long[0];
|
||||
private HashSet fDirtyBytes;
|
||||
|
||||
/**
|
||||
* Constructor for CFormattedMemoryBlock.
|
||||
|
@ -123,7 +145,6 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
fNumberOfColumns = numberOfColumns;
|
||||
fDisplayAscii = true;
|
||||
fPaddingChar = paddingChar;
|
||||
fDirtyBytes = new HashSet();
|
||||
getCDISession().getEventManager().addEventListener( this );
|
||||
}
|
||||
|
||||
|
@ -164,7 +185,7 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
*/
|
||||
public boolean displayASCII()
|
||||
{
|
||||
return fDisplayAscii;
|
||||
return ( getWordSize() == IFormattedMemoryBlock.MEMORY_SIZE_BYTE && fDisplayAscii );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -347,8 +368,6 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
fCDIMemoryBlock = null;
|
||||
}
|
||||
getCDISession().getEventManager().removeEventListener( this );
|
||||
fDirtyBytes.clear();
|
||||
fDirtyBytes = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -436,7 +455,6 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
private void handleChangedEvent( ICDIMemoryChangedEvent event )
|
||||
{
|
||||
resetRows();
|
||||
resetDirtyBytes();
|
||||
setChangedAddresses( event.getAddresses() );
|
||||
fireChangeEvent( DebugEvent.CONTENT );
|
||||
}
|
||||
|
@ -477,10 +495,15 @@ public class CFormattedMemoryBlock extends CDebugElement
|
|||
*/
|
||||
public void setItemValue( int index, String newValue ) throws DebugException
|
||||
{
|
||||
}
|
||||
|
||||
private void resetDirtyBytes()
|
||||
{
|
||||
fDirtyBytes.clear();
|
||||
int rowIndex = index / getNumberOfColumns();
|
||||
if ( rowIndex < getRows().length )
|
||||
{
|
||||
CFormattedMemoryBlockRow row = (CFormattedMemoryBlockRow)getRows()[rowIndex];
|
||||
int colIndex = index % getNumberOfColumns();
|
||||
if ( colIndex < row.getData().length )
|
||||
{
|
||||
row.setData( colIndex, newValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2002-10-28 Mikhail Khodjaiants
|
||||
Implementing editing features of the memory view.
|
||||
* MemoryPresentation.java
|
||||
* MemoryControlArea.java
|
||||
* MemoryText.java
|
||||
|
||||
2002-10-27 Mikhail Khodjaiants
|
||||
* MemoryPresentation.java: adding editing features to the memory view.
|
||||
|
||||
|
|
|
@ -181,6 +181,7 @@ public class MemoryControlArea extends Composite
|
|||
{
|
||||
fAddressText.setText( ( getPresentation() != null ) ? getPresentation().getAddressExpression() : "" );
|
||||
fMemoryText.refresh();
|
||||
fMemoryView.updateObjects();
|
||||
}
|
||||
|
||||
protected void setMemoryManager( ICMemoryManager mm )
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package org.eclipse.cdt.debug.internal.ui.views.memory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -13,6 +14,7 @@ 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;
|
||||
|
@ -35,7 +37,6 @@ public class MemoryPresentation
|
|||
|
||||
private List fAddressZones;
|
||||
private List fChangedZones;
|
||||
private List fDirtyZones;
|
||||
|
||||
private boolean fDisplayAscii = true;
|
||||
|
||||
|
@ -46,7 +47,6 @@ public class MemoryPresentation
|
|||
{
|
||||
fAddressZones = new LinkedList();
|
||||
fChangedZones = new LinkedList();
|
||||
fDirtyZones = new LinkedList();
|
||||
}
|
||||
|
||||
public IFormattedMemoryBlock getMemoryBlock()
|
||||
|
@ -123,7 +123,31 @@ public class MemoryPresentation
|
|||
|
||||
public Point[] getDirtyZones()
|
||||
{
|
||||
return (Point[])fDirtyZones.toArray( new Point[fDirtyZones.size()] );
|
||||
ArrayList dirtyZones = new ArrayList();
|
||||
if ( fBlock != null )
|
||||
{
|
||||
IFormattedMemoryBlockRow[] rows = fBlock.getRows();
|
||||
for ( int i = 0; i < rows.length; ++i )
|
||||
{
|
||||
int rowOffset = i * getRowLength();
|
||||
Integer[] dirtyItems = rows[i].getDirtyItems();
|
||||
for ( int j = 0; j < dirtyItems.length; ++j )
|
||||
{
|
||||
int offset = rowOffset +
|
||||
getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
|
||||
dirtyItems[j].intValue() * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS);
|
||||
dirtyZones.add( new Point( offset, offset + getDataItemLength() ) );
|
||||
if ( displayASCII() )
|
||||
{
|
||||
offset = rowOffset +
|
||||
getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
|
||||
getNumberOfDataItemsInRow() * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS);
|
||||
dirtyZones.add( new Point( offset, offset + (getDataItemLength() / 2) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (Point[])dirtyZones.toArray( new Point[dirtyZones.size()] );
|
||||
}
|
||||
|
||||
public String getStartAddress()
|
||||
|
@ -159,9 +183,9 @@ public class MemoryPresentation
|
|||
result.append( items[i] );
|
||||
result.append( getInterval( INTERVAL_BETWEEN_DATA_ITEMS ) );
|
||||
}
|
||||
result.append( getInterval( INTERVAL_BETWEEN_DATA_AND_ASCII ) );
|
||||
if ( displayASCII() )
|
||||
{
|
||||
result.append( getInterval( INTERVAL_BETWEEN_DATA_AND_ASCII ) );
|
||||
result.append( row.getASCII() );
|
||||
}
|
||||
result.append( '\n' );
|
||||
|
@ -450,20 +474,19 @@ public class MemoryPresentation
|
|||
{
|
||||
if ( getMemoryBlock() != null )
|
||||
{
|
||||
int index = -1;
|
||||
if ( isInDataArea( offset ) )
|
||||
{
|
||||
index = getDataItemIndex( offset );
|
||||
}
|
||||
if ( isInAsciiArea( offset ) )
|
||||
{
|
||||
index = offset;
|
||||
}
|
||||
int index = getDataItemIndex( offset );
|
||||
if ( index != -1 )
|
||||
{
|
||||
char[] chars = getDataItemChars( index );
|
||||
int itemOffset = getDataItemOffset( index );
|
||||
chars[offset - itemOffset] = newChar;
|
||||
if ( isInDataArea( offset ) )
|
||||
{
|
||||
int charIndex = getOffsetInDataItem( offset, index );
|
||||
chars[charIndex] = newChar;
|
||||
}
|
||||
if ( isInAsciiArea( offset ) )
|
||||
{
|
||||
chars = CDebugUtils.getByteText( (byte)newChar );
|
||||
}
|
||||
try
|
||||
{
|
||||
getMemoryBlock().setItemValue( index, new String( chars ) );
|
||||
|
@ -479,7 +502,7 @@ public class MemoryPresentation
|
|||
private int getDataItemIndex( int offset )
|
||||
{
|
||||
int row = offset / getRowLength();
|
||||
int pos = offset % getRowLength();
|
||||
int pos = offset % getRowLength() - getAddressLength() - INTERVAL_BETWEEN_ADDRESS_AND_DATA;
|
||||
for ( int i = 0; i < getNumberOfDataItemsInRow(); ++i )
|
||||
{
|
||||
if ( pos < i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) )
|
||||
|
@ -488,13 +511,17 @@ public class MemoryPresentation
|
|||
pos < (i * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS)) + getDataItemLength() )
|
||||
return i + (row * getNumberOfDataItemsInRow());
|
||||
}
|
||||
if ( displayASCII() && pos >= getNumberOfDataItemsInRow() * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) + INTERVAL_BETWEEN_DATA_AND_ASCII )
|
||||
{
|
||||
return ((pos - ((getNumberOfDataItemsInRow() * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) + INTERVAL_BETWEEN_DATA_AND_ASCII))) * 2 / getDataItemLength()) + row * getNumberOfDataItemsInRow();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getDataItemOffset( int index )
|
||||
{
|
||||
int row = index / getNumberOfDataItemsInRow();
|
||||
int pos = index % getDataItemLength();
|
||||
int pos = index % getNumberOfDataItemsInRow();
|
||||
return row * getRowLength() +
|
||||
getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
|
||||
pos * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS);
|
||||
|
@ -504,8 +531,8 @@ public class MemoryPresentation
|
|||
{
|
||||
if ( getMemoryBlock() != null )
|
||||
{
|
||||
int rowNumber = index / (getMemoryBlock().getNumberOfColumns() * getMemoryBlock().getWordSize());
|
||||
int pos = index % (getMemoryBlock().getNumberOfColumns() * getMemoryBlock().getWordSize());
|
||||
int rowNumber = index / getMemoryBlock().getNumberOfColumns();
|
||||
int pos = index % getMemoryBlock().getNumberOfColumns();
|
||||
IFormattedMemoryBlockRow[] rows = getMemoryBlock().getRows();
|
||||
if ( rowNumber < rows.length )
|
||||
{
|
||||
|
@ -518,4 +545,13 @@ public class MemoryPresentation
|
|||
}
|
||||
return new char[0];
|
||||
}
|
||||
|
||||
private int getOffsetInDataItem( int offset, int index )
|
||||
{
|
||||
if ( isInDataArea( offset ) )
|
||||
{
|
||||
return offset - getDataItemOffset( index );
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,11 +83,12 @@ public class MemoryText
|
|||
{
|
||||
if ( event.length != 1 )
|
||||
return;
|
||||
int caretOffset = fText.getCaretOffset();
|
||||
fPresentation.textChanged( event.start,
|
||||
fText.getText().charAt( event.start ),
|
||||
event.replacedText.toCharArray() );
|
||||
Point[] zones = fPresentation.getDirtyZones();
|
||||
refresh( zones, fPresentation.getText( zones ) );
|
||||
refresh();
|
||||
fText.setCaretOffset( caretOffset );
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
|
|
Loading…
Add table
Reference in a new issue