Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Implementing Memory view formatting actions

Implementing Memory view formatting actions.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.13
diff -u -r1.13 ChangeLog
--- ChangeLog 23 Oct 2002 21:19:19 -0000 1.13
+++ ChangeLog 24 Oct 2002 23:14:57 -0000
@@ -1,3 +1,12 @@
+2002-10-24 Mikhail Khodjaiants
+ Implementing Memory view formatting actions.
+ * MemoryActionSelectionGroup.java: implementation of a toggle action group.
+ * MemorySizeAction.java: implementation of the "Memory Unit Size" menu item.
+ * MemoryView.java: add new actions to the view.
+ * MemoryViewer.java: support for new action.
+ * ICDebugHelpContextIds.java: help context id for the new action.
+ * ICDebugUIConstants.java: new menu group - "Format".
+
 2002-10-23 Mikhail Khodjaiants
  * DebuggerConsoleActionDelegate.java: The debugger/inferrior console should become visible when checking "Show Debug Console".
 
Index: src/org/eclipse/cdt/debug/internal/ui/actions/MemoryActionSelectionGroup.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/internal/ui/actions/MemoryActionSelectionGroup.java
diff -N src/org/eclipse/cdt/debug/internal/ui/actions/MemoryActionSelectionGroup.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/internal/ui/actions/MemoryActionSelectionGroup.java 24 Oct 2002 23:14:57 -0000
@@ -0,0 +1,73 @@
+/*
+ *(c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ *
+ */
+package org.eclipse.cdt.debug.internal.ui.actions;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.action.IAction;
+
+/**
+ * Enter type comment.
+ *
+ * @since: Oct 22, 2002
+ */
+public class MemoryActionSelectionGroup
+{
+ private List fActions;
+ private IAction fSelection = null;
+
+ /**
+  * Constructor for MemoryActionSelectionGroup.
+  */
+ public MemoryActionSelectionGroup()
+ {
+  fActions = new ArrayList();
+ }
+
+ public IAction getCurrentSelection()
+ {
+  return fSelection;
+ }

+ public void setCurrentSelection( IAction selection )
+ {
+  Iterator it = fActions.iterator();
+  while( it.hasNext() )
+  {
+   IAction action = "">+   if ( !action.equals( selection ) )
+   {
+    action.setChecked( false );
+   }
+  }
+  if ( fActions.contains( selection ) )
+  {
+   fSelection = selection;
+  }
+  else
+  {
+   fSelection = null;
+  }
+ }
+
+ public void addAction( IAction action )
+ {
+  fActions.add( action );
+ }

+ public void dispose()
+ {
+  fActions.clear();
+  fSelection = null;
+ }

+ public IAction[] getActions()
+ {
+  return (IAction[])fActions.toArray( new IAction[fActions.size()] );
+ }
+}
Index: src/org/eclipse/cdt/debug/internal/ui/actions/MemorySizeAction.java
===================================================================
RCS file: src/org/eclipse/cdt/debug/internal/ui/actions/MemorySizeAction.java
diff -N src/org/eclipse/cdt/debug/internal/ui/actions/MemorySizeAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/debug/internal/ui/actions/MemorySizeAction.java 24 Oct 2002 23:14:57 -0000
@@ -0,0 +1,86 @@
+/*
+ *(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.jface.action.Action;
+import org.eclipse.ui.texteditor.IUpdate;
+
+/**
+ * Enter type comment.
+ *
+ * @since: Oct 22, 2002
+ */
+public class MemorySizeAction extends Action implements IUpdate
+{
+ private MemoryActionSelectionGroup fGroup;
+ private MemoryViewer fMemoryViewer;
+ private int fId = 0;
+
+ /**
+  * Constructor for MemorySizeAction.
+  */
+ public MemorySizeAction( MemoryActionSelectionGroup group,
+        MemoryViewer viewer,
+        int id )
+ {
+  super( getLabel( id ) );
+  fGroup = group;
+  fMemoryViewer = viewer;
+  fId = id;
+  setChecked( false );
+ }
+
+ /* (non-Javadoc)
+  * @see org.eclipse.ui.texteditor.IUpdate#update()
+  */
+ public void update()
+ {
+  setEnabled( fMemoryViewer.canUpdate() );
+  setChecked( fMemoryViewer.getCurrentWordSize() == fId );
+/*
+  if ( isChecked() )
+  {
+   fGroup.setCurrentSelection( this );
+  }
+*/
+ }

+ private static String getLabel( int id )
+ {
+  String label = "";
+  switch( id )
+  {
+   case( IFormattedMemoryBlock.MEMORY_SIZE_BYTE ):
+    label = "1 byte";
+    break;
+   case( IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD ):
+    label = "2 bytes";
+    break;
+   case( IFormattedMemoryBlock.MEMORY_SIZE_WORD ):
+    label = "4 bytes";
+    break;
+   case( IFormattedMemoryBlock.MEMORY_SIZE_DOUBLE_WORD ):
+    label = "8 bytes";
+    break;
+  }
+  return label;
+ }
+
+ /* (non-Javadoc)
+  * @see org.eclipse.jface.action.IAction#run()
+  */
+ public void run()
+ {
+  fGroup.setCurrentSelection( this );
+ }

+ public String getActionId()
+ {
+  return "MemorySize" + fId;
+ }
+}
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java,v
retrieving revision 1.8
diff -u -r1.8 MemoryView.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java 22 Oct 2002 17:10:48 -0000 1.8
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java 24 Oct 2002 23:14:57 -0000
@@ -6,9 +6,12 @@
 package org.eclipse.cdt.debug.internal.ui.views.memory;
 
 import org.eclipse.cdt.debug.core.ICMemoryManager;
+import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
 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.MemorySizeAction;
 import org.eclipse.cdt.debug.internal.ui.actions.RefreshMemoryAction;
 import org.eclipse.cdt.debug.internal.ui.actions.ShowAsciiAction;
 import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
@@ -23,6 +26,7 @@
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
@@ -36,6 +40,7 @@
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.texteditor.IUpdate;
 
 /**
  *
@@ -50,6 +55,7 @@
            IDebugExceptionHandler
 {
  private IDebugModelPresentation fModelPresentation = null;
+ private MemoryActionSelectionGroup fMemorySizeGroup = null;
 
  /* (non-Javadoc)
   * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(Composite)
@@ -94,6 +100,9 @@
   setAction( "ShowAscii", action ); file://$NON-NLS-1$
   add( (ShowAsciiAction)action );
 
+  fMemorySizeGroup = new MemoryActionSelectionGroup();
+  createSizeActionGroup( fMemorySizeGroup );
+
   // set initial content here, as viewer has to be set
   setInitialContent();
  }
@@ -113,15 +122,30 @@
  {
   menu.add( new Separator( ICDebugUIConstants.EMPTY_MEMORY_GROUP ) );
   menu.add( new Separator( ICDebugUIConstants.MEMORY_GROUP ) );
-  menu.add( getAction( "AutoRefreshMemory" ) ); file://$NON-NLS-1$
-  menu.add( getAction( "RefreshMemory" ) ); file://$NON-NLS-1$
-  menu.add( getAction( "ClearMemory" ) ); file://$NON-NLS-1$
+
+  menu.add( new Separator( ICDebugUIConstants.EMPTY_FORMAT_GROUP ) );
+  menu.add( new Separator( ICDebugUIConstants.FORMAT_GROUP ) );
 
   menu.add( new Separator( IDebugUIConstants.EMPTY_RENDER_GROUP ) );
   menu.add( new Separator( IDebugUIConstants.RENDER_GROUP ) );
-  menu.add( getAction( "ShowAscii" ) ); file://$NON-NLS-1$
 
   menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) );
+
+  menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "AutoRefreshMemory" ) ); file://$NON-NLS-1$
+  menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "RefreshMemory" ) ); file://$NON-NLS-1$
+  menu.appendToGroup( ICDebugUIConstants.MEMORY_GROUP, getAction( "ClearMemory" ) ); file://$NON-NLS-1$
+
+  MenuManager subMenu = new MenuManager( "Memory Unit Size         " );
+  {
+   IAction[] actions = fMemorySizeGroup.getActions();
+   for ( int i = 0; i < actions.length; ++i )
+   {
+    subMenu.add( actions[i] );
+   }
+  }
+  menu.appendToGroup( ICDebugUIConstants.FORMAT_GROUP, subMenu );
+
+  menu.appendToGroup( IDebugUIConstants.RENDER_GROUP, getAction( "ShowAscii" ) ); file://$NON-NLS-1$
  }
 
  /* (non-Javadoc)
@@ -173,10 +197,14 @@
   */
  public void dispose()
  {
+  removeActionGroup( fMemorySizeGroup );
+  fMemorySizeGroup.dispose();
+
   remove( (ShowAsciiAction)getAction( "ShowAscii" ) );
   remove( (ClearMemoryAction)getAction( "ClearMemory" ) );
   remove( (RefreshMemoryAction)getAction( "RefreshMemory" ) );
   remove( (AutoRefreshMemoryAction)getAction( "AutoRefreshMemory" ) );
+
   getSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
   CDebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( this );
   super.dispose();
@@ -255,6 +283,31 @@
   for ( int i = 0; i < items.length; ++i )
   {
    super.createContextMenu( ((MemoryControlArea)items[i].getControl()).getMemoryText().getControl() );
+  }
+ }

+ private void createSizeActionGroup( MemoryActionSelectionGroup group )
+ {
+  int[] ids = new int[] { IFormattedMemoryBlock.MEMORY_SIZE_BYTE,
+        IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD,   
+        IFormattedMemoryBlock.MEMORY_SIZE_WORD,   
+        IFormattedMemoryBlock.MEMORY_SIZE_DOUBLE_WORD };   
+  for ( int i = 0; i < ids.length; ++i )
+  {
+   MemorySizeAction action = "" MemorySizeAction( group, (MemoryViewer)getViewer(), ids[i] );
+   action.setEnabled( false );
+   setAction( action.getActionId(), action ); file://$NON-NLS-1$
+   add( action );
+   group.addAction( action );
+  }
+ }

+ private void removeActionGroup(  MemoryActionSelectionGroup group )
+ {
+  IAction[] actions = group.getActions();
+  for ( int i = 0; i < actions.length; ++i )
+  {
+   remove( (IUpdate)actions[i] );
   }
  }
 }
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java,v
retrieving revision 1.9
diff -u -r1.9 MemoryViewer.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java 22 Oct 2002 17:10:48 -0000 1.9
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java 24 Oct 2002 23:14:57 -0000
@@ -209,4 +209,10 @@
  {
   return ((MemoryControlArea)fTabFolder.getSelection().getControl()).getPresentation().canDisplayAscii();
  }

+ public int getCurrentWordSize()
+ {
+  IFormattedMemoryBlock block = ((MemoryControlArea)fTabFolder.getSelection().getControl()).getMemoryBlock();
+  return ( block != null ) ? block.getWordSize() : 0;
+ }
 }
Index: src/org/eclipse/cdt/debug/ui/ICDebugUIConstants.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/ICDebugUIConstants.java,v
retrieving revision 1.5
diff -u -r1.5 ICDebugUIConstants.java
--- src/org/eclipse/cdt/debug/ui/ICDebugUIConstants.java 18 Oct 2002 22:02:51 -0000 1.5
+++ src/org/eclipse/cdt/debug/ui/ICDebugUIConstants.java 24 Oct 2002 23:14:57 -0000
@@ -59,4 +59,15 @@
   * Identifier for a memory group in a menu (value <code>"memoryGroup"</code>).
   */
  public static final String MEMORY_GROUP = "memoryGroup"; file://$NON-NLS-1$
+
+ /**
+  * Identifier for an empty group preceeding a
+  * format group in a menu (value <code>"emptyFormatGroup"</code>).
+  */
+ public static final String EMPTY_FORMAT_GROUP = "emptyFormatGroup"; file://$NON-NLS-1$

+ /**
+  * Identifier for a format group in a menu (value <code>"formatGroup"</code>).
+  */
+ public static final String FORMAT_GROUP = "formatGroup"; file://$NON-NLS-1$
 }


Back to the top