mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 19:25:38 +02:00
Implementation of the "Format/Decimal" and "Format/Unsigned Decimal" actions of the Memory view.
This commit is contained in:
parent
74a706751c
commit
281b81b6c2
7 changed files with 163 additions and 8 deletions
|
@ -1,3 +1,12 @@
|
|||
2002-11-03 Mikhail Khodjaiants
|
||||
Implementation of the "Format/Decimal" and "Format/Unsigned Decimal" actions of the Memory view.
|
||||
* MemoryFormataction.java
|
||||
* MemorySizeAction.java
|
||||
* MemoryNumberOfColumnsAction.java
|
||||
* MemoryPresentation.java
|
||||
* MemoryViewer.java
|
||||
* MemoryView.java
|
||||
|
||||
2002-11-01 Mikhail Khodjaiants
|
||||
Implementing decimal format support of the Memory view.
|
||||
* MemoryPresentation.java
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.memory.MemoryViewer;
|
||||
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
||||
/**
|
||||
*
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since Nov 3, 2002
|
||||
*/
|
||||
public class MemoryFormatAction extends Action implements IUpdate
|
||||
{
|
||||
private MemoryActionSelectionGroup fGroup;
|
||||
private MemoryViewer fMemoryViewer;
|
||||
private int fFormat = 0;
|
||||
|
||||
/**
|
||||
* Constructor for MemoryFormatAction.
|
||||
*/
|
||||
public MemoryFormatAction( MemoryActionSelectionGroup group,
|
||||
MemoryViewer viewer,
|
||||
int format )
|
||||
{
|
||||
super( getLabel( format ) );
|
||||
fGroup = group;
|
||||
fMemoryViewer = viewer;
|
||||
fFormat = format;
|
||||
setChecked( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.texteditor.IUpdate#update()
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
setEnabled( fMemoryViewer.canChangeFormat( fFormat ) );
|
||||
setChecked( fMemoryViewer.getCurrentFormat() == fFormat );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.action.IAction#run()
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
fMemoryViewer.setFormat( fFormat );
|
||||
fGroup.setCurrentSelection( this );
|
||||
}
|
||||
catch( DebugException e )
|
||||
{
|
||||
CDebugUIPlugin.errorDialog( "Unable to change format.", e.getStatus() );
|
||||
setChecked( false );
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLabel( int id )
|
||||
{
|
||||
String label = "";
|
||||
switch( id )
|
||||
{
|
||||
case( IFormattedMemoryBlock.MEMORY_FORMAT_HEX ):
|
||||
label = "Hexadecimal";
|
||||
break;
|
||||
case( IFormattedMemoryBlock.MEMORY_FORMAT_SIGNED_DECIMAL ):
|
||||
label = "Signed Decimal";
|
||||
break;
|
||||
case( IFormattedMemoryBlock.MEMORY_FORMAT_UNSIGNED_DECIMAL ):
|
||||
label = "Unsigned Decimal";
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getActionId()
|
||||
{
|
||||
return "MemoryFormat" + fFormat;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,8 @@
|
|||
*/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.internal.ui.actions.MemoryActionSelectionGroup;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.memory.MemoryViewer;
|
||||
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
@ -64,7 +62,7 @@ public class MemoryNumberOfColumnAction extends Action implements IUpdate
|
|||
}
|
||||
catch( DebugException e )
|
||||
{
|
||||
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
|
||||
CDebugUIPlugin.errorDialog( "Unable to change the column number.", e.getStatus() );
|
||||
setChecked( false );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.eclipse.cdt.debug.internal.ui.actions;
|
|||
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.memory.MemoryViewer;
|
||||
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
@ -80,7 +79,7 @@ public class MemorySizeAction extends Action implements IUpdate
|
|||
}
|
||||
catch( DebugException e )
|
||||
{
|
||||
CDebugUIPlugin.errorDialog( e.getMessage(), (IStatus)null );
|
||||
CDebugUIPlugin.errorDialog( "Unable to change memory unit size.", e.getStatus() );
|
||||
setChecked( false );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -525,6 +525,8 @@ public class MemoryPresentation
|
|||
{
|
||||
switch( wordSize )
|
||||
{
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_BYTE:
|
||||
return ( signed ) ? 4 : 3;
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD:
|
||||
return ( signed ) ? 6 : 5;
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_WORD:
|
||||
|
@ -545,13 +547,17 @@ public class MemoryPresentation
|
|||
private String convertToDecimal( int wordSize, String item, boolean signed )
|
||||
{
|
||||
String result = "";
|
||||
boolean le = getMemoryBlock().isLittleEndian();
|
||||
switch( wordSize )
|
||||
{
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_BYTE:
|
||||
result = Long.toString( ( signed ) ? CDebugUtils.toByte( item.toCharArray(), le ) : CDebugUtils.toUnsignedByte( item.toCharArray(), le ) );
|
||||
break;
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD:
|
||||
result = Long.toString( CDebugUtils.toShort( item.toCharArray(), signed ) );
|
||||
result = Long.toString( ( signed ) ? CDebugUtils.toShort( item.toCharArray(), le ) : CDebugUtils.toUnsignedShort( item.toCharArray(), le ) );
|
||||
break;
|
||||
case IFormattedMemoryBlock.MEMORY_SIZE_WORD:
|
||||
result = Long.toString( CDebugUtils.toInt( item.toCharArray(), signed ) );
|
||||
result = Long.toString( ( signed ) ? CDebugUtils.toInt( item.toCharArray(), le ) : CDebugUtils.toUnsignedInt( item.toCharArray(), le ) );
|
||||
break;
|
||||
}
|
||||
return CDebugUtils.prependString( result, getDataItemLength(), ' ' );
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
|
|||
import org.eclipse.cdt.debug.internal.ui.actions.AutoRefreshMemoryAction;
|
||||
import org.eclipse.cdt.debug.internal.ui.actions.ClearMemoryAction;
|
||||
import org.eclipse.cdt.debug.internal.ui.actions.MemoryActionSelectionGroup;
|
||||
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.MemorySizeAction;
|
||||
import org.eclipse.cdt.debug.internal.ui.actions.RefreshMemoryAction;
|
||||
|
@ -57,6 +58,7 @@ public class MemoryView extends AbstractDebugEventHandlerView
|
|||
IDebugExceptionHandler
|
||||
{
|
||||
private IDebugModelPresentation fModelPresentation = null;
|
||||
private MemoryActionSelectionGroup fMemoryFormatGroup = null;
|
||||
private MemoryActionSelectionGroup fMemorySizeGroup = null;
|
||||
private MemoryActionSelectionGroup fMemoryNumberOfColumnsGroup = null;
|
||||
|
||||
|
@ -108,6 +110,9 @@ public class MemoryView extends AbstractDebugEventHandlerView
|
|||
setAction( "ShowAscii", action ); //$NON-NLS-1$
|
||||
add( (ShowAsciiAction)action );
|
||||
|
||||
fMemoryFormatGroup = new MemoryActionSelectionGroup();
|
||||
createFormatActionGroup( fMemoryFormatGroup );
|
||||
|
||||
fMemorySizeGroup = new MemoryActionSelectionGroup();
|
||||
createSizeActionGroup( fMemorySizeGroup );
|
||||
|
||||
|
@ -147,7 +152,17 @@ public class MemoryView extends AbstractDebugEventHandlerView
|
|||
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "ClearMemory" ) ); //$NON-NLS-1$
|
||||
menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "SaveMemoryChanges" ) ); //$NON-NLS-1$
|
||||
|
||||
MenuManager subMenu = new MenuManager( "Memory Unit Size " );
|
||||
MenuManager subMenu = new MenuManager( "Format" );
|
||||
{
|
||||
IAction[] actions = fMemoryFormatGroup.getActions();
|
||||
for ( int i = 0; i < actions.length; ++i )
|
||||
{
|
||||
subMenu.add( actions[i] );
|
||||
}
|
||||
}
|
||||
menu.appendToGroup( ICDebugUIConstants.FORMAT_GROUP, subMenu );
|
||||
|
||||
subMenu = new MenuManager( "Memory Unit Size " );
|
||||
{
|
||||
IAction[] actions = fMemorySizeGroup.getActions();
|
||||
for ( int i = 0; i < actions.length; ++i )
|
||||
|
@ -220,6 +235,8 @@ public class MemoryView extends AbstractDebugEventHandlerView
|
|||
*/
|
||||
public void dispose()
|
||||
{
|
||||
removeActionGroup( fMemoryFormatGroup );
|
||||
fMemoryFormatGroup.dispose();
|
||||
removeActionGroup( fMemorySizeGroup );
|
||||
fMemorySizeGroup.dispose();
|
||||
removeActionGroup( fMemoryNumberOfColumnsGroup );
|
||||
|
@ -312,6 +329,21 @@ public class MemoryView extends AbstractDebugEventHandlerView
|
|||
}
|
||||
}
|
||||
|
||||
private void createFormatActionGroup( MemoryActionSelectionGroup group )
|
||||
{
|
||||
int[] formats = new int[] { IFormattedMemoryBlock.MEMORY_FORMAT_HEX,
|
||||
IFormattedMemoryBlock.MEMORY_FORMAT_SIGNED_DECIMAL,
|
||||
IFormattedMemoryBlock.MEMORY_FORMAT_UNSIGNED_DECIMAL };
|
||||
for ( int i = 0; i < formats.length; ++i )
|
||||
{
|
||||
MemoryFormatAction action = new MemoryFormatAction( group, (MemoryViewer)getViewer(), formats[i] );
|
||||
action.setEnabled( false );
|
||||
setAction( action.getActionId(), action ); //$NON-NLS-1$
|
||||
add( action );
|
||||
group.addAction( action );
|
||||
}
|
||||
}
|
||||
|
||||
private void createSizeActionGroup( MemoryActionSelectionGroup group )
|
||||
{
|
||||
int[] ids = new int[] { IFormattedMemoryBlock.MEMORY_SIZE_BYTE,
|
||||
|
|
|
@ -170,6 +170,12 @@ public class MemoryViewer extends ContentViewer
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean canChangeFormat( int format )
|
||||
{
|
||||
IFormattedMemoryBlock block = ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock();
|
||||
return ( block != null && block.canChangeFormat( format ) );
|
||||
}
|
||||
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return ( ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock() != null );
|
||||
|
@ -226,6 +232,22 @@ public class MemoryViewer extends ContentViewer
|
|||
return ((MemoryControlArea)fTabFolder.getSelection().getControl()).getPresentation().canDisplayAscii();
|
||||
}
|
||||
|
||||
public int getCurrentFormat()
|
||||
{
|
||||
IFormattedMemoryBlock block = ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock();
|
||||
return ( block != null ) ? block.getFormat() : 0;
|
||||
}
|
||||
|
||||
public void setFormat( int format ) throws DebugException
|
||||
{
|
||||
IFormattedMemoryBlock block = ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock();
|
||||
if ( block != null )
|
||||
{
|
||||
block.reformat( format, block.getWordSize(), block.getNumberOfRows(), block.getNumberOfColumns() );
|
||||
((MemoryControlArea)fTabFolder.getSelection().getControl()).refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentWordSize()
|
||||
{
|
||||
IFormattedMemoryBlock block = ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock();
|
||||
|
|
Loading…
Add table
Reference in a new issue