1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Live editing of the memory view.

This commit is contained in:
Mikhail Khodjaiants 2002-11-28 19:16:37 +00:00
parent edb4e2ef4e
commit 220d22f82b
7 changed files with 91 additions and 196 deletions

View file

@ -1,3 +1,12 @@
2002-11-28 Mikhail Khodjaiants
Live editing of the memory view.
* SaveMemoryChangesAction.java - removed
* MemoryPresentation.java
* MemoryControlArea.java
* MemoryText.java
* MemoryViewer.java
* MemoryView.java
2002-11-27 Mikhail Khodjaiants 2002-11-27 Mikhail Khodjaiants
Render debug target as suspended if no reason is specified. Render debug target as suspended if no reason is specified.
* CDTDebugModelPresentation.java * CDTDebugModelPresentation.java

View file

@ -1,54 +0,0 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
import org.eclipse.cdt.debug.internal.ui.views.memory.MemoryViewer;
import org.eclipse.ui.actions.SelectionProviderAction;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.texteditor.IUpdate;
/**
* Enter type comment.
*
* @since: Oct 30, 2002
*/
public class SaveMemoryChangesAction extends SelectionProviderAction implements IUpdate
{
private MemoryViewer fMemoryViewer;
/**
* Constructor for SaveMemoryChangesAction.
* @param provider
* @param text
*/
public SaveMemoryChangesAction( MemoryViewer viewer )
{
super( viewer, "Save Changes" );
fMemoryViewer = viewer;
CDebugImages.setLocalImageDescriptors( this, CDebugImages.IMG_LCL_MEMORY_SAVE );
setDescription( "Save Changes" );
setToolTipText( "Save Changes" );
WorkbenchHelp.setHelp( this, ICDebugHelpContextIds.MEMORY_SAVE_ACTION );
}
/* (non-Javadoc)
* @see org.eclipse.ui.texteditor.IUpdate#update()
*/
public void update()
{
setEnabled( fMemoryViewer.canSave() );
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.IAction#run()
*/
public void run()
{
fMemoryViewer.saveChanges();
}
}

View file

@ -425,26 +425,6 @@ public class MemoryControlArea extends Composite
} }
} }
protected void saveChanges()
{
if ( getMemoryBlock() != null )
{
try
{
getMemoryBlock().saveChanges();
String title = getTitle();
if ( title.charAt( 0 ) == '*' )
{
setTitle( title.substring( 1 ) );
}
}
catch( DebugException e )
{
CDebugUIPlugin.errorDialog( "Unable to save memory changes.", e.getStatus() );
}
}
}
private void updateToolTipText() private void updateToolTipText()
{ {
setTabItemToolTipText( fAddressText.getText().trim() ); setTabItemToolTipText( fAddressText.getText().trim() );

View file

@ -6,7 +6,6 @@
package org.eclipse.cdt.debug.internal.ui.views.memory; package org.eclipse.cdt.debug.internal.ui.views.memory;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -18,6 +17,7 @@ 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;
import org.eclipse.swt.widgets.Display;
/** /**
* *
@ -379,45 +379,7 @@ public class MemoryPresentation
return false; return false;
} }
protected MemoryText.TextReplacement[] textChanged( int offset, char newChar, char[] replacedText ) protected int getDataItemIndex( int offset )
{
ArrayList list = new ArrayList();
if ( getMemoryBlock() != null )
{
int index = getDataItemIndex( offset );
if ( index != -1 )
{
char[] chars = getDataItemChars( index );
if ( isInDataArea( offset ) )
{
int charIndex = getOffsetInDataItem( offset, index );
chars[charIndex] = newChar;
}
if ( isInAsciiArea( offset ) )
{
chars = CDebugUtils.getByteText( (byte)newChar );
}
try
{
String text = new String( chars );
getMemoryBlock().setItemValue( index, text );
list.add( new MemoryText.TextReplacement( getDataItemOffset( index ), text ) );
if ( displayASCII() )
{
// Ascii is enabled only when the word size is one byte
list.add( getAsciiTextReplacement( index, chars ) );
}
}
catch( DebugException e )
{
// ignore
}
}
}
return (MemoryText.TextReplacement[])list.toArray( new MemoryText.TextReplacement[list.size()] );
}
private int getDataItemIndex( int offset )
{ {
int row = offset / getRowLength(); int row = offset / getRowLength();
int pos = offset % getRowLength() - getAddressLength() - INTERVAL_BETWEEN_ADDRESS_AND_DATA; int pos = offset % getRowLength() - getAddressLength() - INTERVAL_BETWEEN_ADDRESS_AND_DATA;
@ -473,19 +435,6 @@ public class MemoryPresentation
return -1; return -1;
} }
private MemoryText.TextReplacement getAsciiTextReplacement( int itemIndex, char[] chars )
{
int row = itemIndex / getNumberOfDataItemsInRow();
int col = itemIndex % getNumberOfDataItemsInRow();
int offset = row * getRowLength() +
getAddressLength() + INTERVAL_BETWEEN_ADDRESS_AND_DATA +
getNumberOfDataItemsInRow() * (getDataItemLength() + INTERVAL_BETWEEN_DATA_ITEMS) +
INTERVAL_BETWEEN_DATA_AND_ASCII + col;
byte newValue = CDebugUtils.textToByte( chars );
char ch = ( Character.isISOControl( (char)newValue ) || newValue < 0 ) ? getPaddingCharacter() : (char)newValue;
return new MemoryText.TextReplacement( offset, new String( new char[]{ ch } ) );
}
public void dispose() public void dispose()
{ {
if ( fAddressZones != null ) if ( fAddressZones != null )
@ -498,15 +447,6 @@ public class MemoryPresentation
} }
} }
protected boolean isDirty()
{
if ( getMemoryBlock() != null )
{
return getMemoryBlock().isDirty();
}
return false;
}
private String getDataItemPresentation( String item ) private String getDataItemPresentation( String item )
{ {
switch( getDataFormat() ) switch( getDataFormat() )
@ -571,4 +511,52 @@ public class MemoryPresentation
} }
return false; return false;
} }
protected String getNewItemValue( int offset, char newChar )
{
if ( getMemoryBlock() != null )
{
int index = getDataItemIndex( offset );
if ( index != -1 )
{
char[] chars = getDataItemChars( index );
if ( isInDataArea( offset ) )
{
int charIndex = getOffsetInDataItem( offset, index );
chars[charIndex] = newChar;
}
if ( isInAsciiArea( offset ) )
{
chars = CDebugUtils.getByteText( (byte)newChar );
}
return new String( chars );
}
}
return null;
}
protected void setItemValue( int offset, char ch )
{
if ( getMemoryBlock() != null )
{
int index = getDataItemIndex( offset );
if ( index != -1 )
{
String newValue = getNewItemValue( offset, ch );
if ( newValue != null )
{
try
{
getMemoryBlock().setItemValue( index, newValue );
return;
}
catch( DebugException e )
{
Display.getDefault().beep();
}
}
}
}
Display.getDefault().beep();
}
} }

View file

@ -33,38 +33,6 @@ import org.eclipse.swt.widgets.Control;
*/ */
public class MemoryText public class MemoryText
{ {
/**
*
* The instance of this class specifies the text replacement
* that has to be applied to the StyledText widget.
*
* @since Oct 29, 2002
*/
public static class TextReplacement
{
private int fStart;
private String fText;
/**
* Constructor for TextReplacement.
*/
public TextReplacement( int start, String text )
{
fStart = start;
fText = text;
}
public int getStart()
{
return fStart;
}
public String getText()
{
return fText;
}
}
private StyledText fText = null; private StyledText fText = null;
private MemoryPresentation fPresentation = null; private MemoryPresentation fPresentation = null;
private boolean fUpdating = false; private boolean fUpdating = false;
@ -118,16 +86,19 @@ public class MemoryText
return; return;
if ( event.length != 1 ) if ( event.length != 1 )
return; return;
TextReplacement[] trs = fPresentation.textChanged( event.start,
fText.getText().charAt( event.start ),
event.replacedText.toCharArray() );
int caretOffset = fText.getCaretOffset(); int caretOffset = fText.getCaretOffset();
update( trs ); fText.getCaret().setVisible( false );
char ch = fText.getText().charAt( event.start );
restoreText( event.start, event.length, event.replacedText );
fPresentation.setItemValue( event.start, ch );
fText.setCaretOffset( caretOffset ); fText.setCaretOffset( caretOffset );
fText.getCaret().setVisible( true );
} }
public void refresh() public void refresh()
{ {
int offset = fText.getCaretOffset();
fText.getCaret().setVisible( false );
fText.setFont( new Font( fText.getDisplay(), getFontData() ) ); fText.setFont( new Font( fText.getDisplay(), getFontData() ) );
fText.setBackground( getBackgroundColor() ); fText.setBackground( getBackgroundColor() );
fText.setForeground( getForegroundColor() ); fText.setForeground( getForegroundColor() );
@ -151,7 +122,8 @@ public class MemoryText
getBackgroundColor() ) ); getBackgroundColor() ) );
} }
fText.redraw(); fText.redraw();
updateTitle(); fText.setCaretOffset( offset );
fText.getCaret().setVisible( true );
} }
private void refresh( Point[] zones, String[] items ) private void refresh( Point[] zones, String[] items )
@ -170,7 +142,6 @@ public class MemoryText
*/ */
fText.redrawRange( zones[i].x, zones[i].y - zones[i].x + 1, false ); fText.redrawRange( zones[i].x, zones[i].y - zones[i].x + 1, false );
} }
updateTitle();
} }
protected void handleVerifyKey( VerifyEvent event ) protected void handleVerifyKey( VerifyEvent event )
@ -295,7 +266,7 @@ public class MemoryText
{ {
return fText; return fText;
} }
/*
protected void update( TextReplacement[] trs ) protected void update( TextReplacement[] trs )
{ {
fUpdating = true; fUpdating = true;
@ -304,18 +275,24 @@ public class MemoryText
fText.replaceTextRange( trs[i].getStart(), fText.replaceTextRange( trs[i].getStart(),
trs[i].getText().length(), trs[i].getText().length(),
trs[i].getText() ); trs[i].getText() );
/*
fText.setStyleRange( new StyleRange( trs[i].getStart(), fText.setStyleRange( new StyleRange( trs[i].getStart(),
trs[i].getText().length(), trs[i].getText().length(),
getDirtyColor(), getDirtyColor(),
getBackgroundColor() ) ); getBackgroundColor() ) );
*/
fText.redrawRange( trs[i].getStart(), trs[i].getText().length(), false ); fText.redrawRange( trs[i].getStart(), trs[i].getText().length(), false );
} }
saveChanges();
fUpdating = false; fUpdating = false;
updateTitle(); updateTitle();
} }
*/
private void restoreText( int start, int length, String text )
{
fUpdating = true;
fText.replaceTextRange( start, length, text );
fUpdating = false;
}
/*
private void updateTitle() private void updateTitle()
{ {
if ( fText.getParent() instanceof MemoryControlArea ) if ( fText.getParent() instanceof MemoryControlArea )
@ -332,4 +309,13 @@ public class MemoryText
((MemoryControlArea)fText.getParent()).setTitle( title ); ((MemoryControlArea)fText.getParent()).setTitle( title );
} }
} }
private void saveChanges()
{
if ( fText.getParent() instanceof MemoryControlArea )
{
((MemoryControlArea)fText.getParent()).saveChanges();
}
}
*/
} }

View file

@ -15,7 +15,6 @@ import org.eclipse.cdt.debug.internal.ui.actions.MemoryFormatAction;
import org.eclipse.cdt.debug.internal.ui.actions.MemoryNumberOfColumnAction; import org.eclipse.cdt.debug.internal.ui.actions.MemoryNumberOfColumnAction;
import org.eclipse.cdt.debug.internal.ui.actions.MemorySizeAction; import org.eclipse.cdt.debug.internal.ui.actions.MemorySizeAction;
import org.eclipse.cdt.debug.internal.ui.actions.RefreshMemoryAction; import org.eclipse.cdt.debug.internal.ui.actions.RefreshMemoryAction;
import org.eclipse.cdt.debug.internal.ui.actions.SaveMemoryChangesAction;
import org.eclipse.cdt.debug.internal.ui.actions.ShowAsciiAction; import org.eclipse.cdt.debug.internal.ui.actions.ShowAsciiAction;
import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants; import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
@ -100,11 +99,6 @@ public class MemoryView extends AbstractDebugEventHandlerView
setAction( "ClearMemory", action ); //$NON-NLS-1$ setAction( "ClearMemory", action ); //$NON-NLS-1$
add( (ClearMemoryAction)action ); add( (ClearMemoryAction)action );
action = new SaveMemoryChangesAction( (MemoryViewer)getViewer() );
action.setEnabled( false );
setAction( "SaveMemoryChanges", action ); //$NON-NLS-1$
add( (SaveMemoryChangesAction)action );
action = new ShowAsciiAction( (MemoryViewer)getViewer() ); action = new ShowAsciiAction( (MemoryViewer)getViewer() );
action.setEnabled( false ); action.setEnabled( false );
action.setChecked( CDebugUIPlugin.getDefault().getPreferenceStore().getBoolean( ICDebugPreferenceConstants.PREF_MEMORY_SHOW_ASCII ) ); action.setChecked( CDebugUIPlugin.getDefault().getPreferenceStore().getBoolean( ICDebugPreferenceConstants.PREF_MEMORY_SHOW_ASCII ) );
@ -151,7 +145,6 @@ public class MemoryView extends AbstractDebugEventHandlerView
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "AutoRefreshMemory" ) ); //$NON-NLS-1$ menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "AutoRefreshMemory" ) ); //$NON-NLS-1$
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "RefreshMemory" ) ); //$NON-NLS-1$ menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "RefreshMemory" ) ); //$NON-NLS-1$
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "ClearMemory" ) ); //$NON-NLS-1$ menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "ClearMemory" ) ); //$NON-NLS-1$
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "SaveMemoryChanges" ) ); //$NON-NLS-1$
MenuManager subMenu = new MenuManager( "Format" ); MenuManager subMenu = new MenuManager( "Format" );
{ {
@ -196,7 +189,6 @@ public class MemoryView extends AbstractDebugEventHandlerView
tbm.add( getAction( "AutoRefreshMemory" ) ); //$NON-NLS-1$ tbm.add( getAction( "AutoRefreshMemory" ) ); //$NON-NLS-1$
tbm.add( getAction( "RefreshMemory" ) ); //$NON-NLS-1$ tbm.add( getAction( "RefreshMemory" ) ); //$NON-NLS-1$
tbm.add( getAction( "ClearMemory" ) ); //$NON-NLS-1$ tbm.add( getAction( "ClearMemory" ) ); //$NON-NLS-1$
tbm.add( getAction( "SaveMemoryChanges" ) ); //$NON-NLS-1$
tbm.add( new Separator( IDebugUIConstants.RENDER_GROUP ) ); tbm.add( new Separator( IDebugUIConstants.RENDER_GROUP ) );
tbm.add( getAction( "ShowAscii" ) ); //$NON-NLS-1$ tbm.add( getAction( "ShowAscii" ) ); //$NON-NLS-1$
@ -244,7 +236,6 @@ public class MemoryView extends AbstractDebugEventHandlerView
fMemoryNumberOfColumnsGroup.dispose(); fMemoryNumberOfColumnsGroup.dispose();
remove( (ShowAsciiAction)getAction( "ShowAscii" ) ); remove( (ShowAsciiAction)getAction( "ShowAscii" ) );
remove( (SaveMemoryChangesAction)getAction( "SaveMemoryChanges" ) );
remove( (ClearMemoryAction)getAction( "ClearMemory" ) ); remove( (ClearMemoryAction)getAction( "ClearMemory" ) );
remove( (RefreshMemoryAction)getAction( "RefreshMemory" ) ); remove( (RefreshMemoryAction)getAction( "RefreshMemory" ) );
remove( (AutoRefreshMemoryAction)getAction( "AutoRefreshMemory" ) ); remove( (AutoRefreshMemoryAction)getAction( "AutoRefreshMemory" ) );

View file

@ -218,11 +218,6 @@ public class MemoryViewer extends ContentViewer
((MemoryControlArea)fTabFolder.getSelection().getControl()).clear(); ((MemoryControlArea)fTabFolder.getSelection().getControl()).clear();
} }
public void saveChanges()
{
((MemoryControlArea)fTabFolder.getSelection().getControl()).saveChanges();
}
public void refreshMemoryBlock() public void refreshMemoryBlock()
{ {
((MemoryControlArea)fTabFolder.getSelection().getControl()).refreshMemoryBlock(); ((MemoryControlArea)fTabFolder.getSelection().getControl()).refreshMemoryBlock();