From d3ebea609384d276469cb98fa2c004287a5a3695 Mon Sep 17 00:00:00 2001
From: Mikhail Khodjaiants <mikhailkhod@googlemail.com>
Date: Mon, 11 Nov 2002 20:16:03 +0000
Subject: [PATCH] Fix for PR 25988: The 'Padding Character' preference of the
 Memory view doesn't work.

---
 debug/org.eclipse.cdt.debug.ui/ChangeLog      |  5 ++++
 .../preferences/MemoryViewPreferencePage.java | 14 +++++++++-
 .../ui/views/memory/MemoryControlArea.java    | 28 +++++++++++++++----
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog
index e8f81d6ed0a..d79c685ea0f 100644
--- a/debug/org.eclipse.cdt.debug.ui/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog
@@ -1,3 +1,8 @@
+2002-11-11 Mikhail Khodjaiants
+	Fix for PR 25988: The 'Padding Character' preference of the Memory view doesn't work.
+	* MemoryControlArea.java
+	* MemoryViewPreferencePage.java
+
 2002-11-05 Mikhail Khodjaiants
 	Implementation of the "Add Global Variables" action of the Expressions view.
 	Action images:
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/MemoryViewPreferencePage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/MemoryViewPreferencePage.java
index 4ec0ab1414f..c0ab3564e9a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/MemoryViewPreferencePage.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/MemoryViewPreferencePage.java
@@ -96,7 +96,8 @@ public class MemoryViewPreferencePage extends FieldEditorPreferencePage
 //		addField( dirty );
 		addField( font );
 
-		StringFieldEditor paddingChar = new StringFieldEditor( ICDebugPreferenceConstants.PREF_MEMORY_PADDING_CHAR, "Padding Character:", 1, getFieldEditorParent() );
+//		StringFieldEditor paddingChar = new StringFieldEditor( ICDebugPreferenceConstants.PREF_MEMORY_PADDING_CHAR, "Padding Character:", 1, getFieldEditorParent() );
+		StringFieldEditor paddingChar = createPaddingCharacterField();
 		paddingChar.setTextLimit( 1 );
 		addField( paddingChar );
 	}
@@ -136,4 +137,15 @@ public class MemoryViewPreferencePage extends FieldEditorPreferencePage
 		CDebugUIPlugin.getDefault().savePluginPreferences();
 		return ok;
 	}
+	
+	private StringFieldEditor createPaddingCharacterField()
+	{
+		return new StringFieldEditor( ICDebugPreferenceConstants.PREF_MEMORY_PADDING_CHAR, "Padding Character:", 1, getFieldEditorParent() )
+					{
+						protected boolean doCheckState() 
+						{
+							return ( getTextControl().getText().length() == 1 );
+						}
+					};
+	}
 }
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java
index e514dc70af7..cba8c4dee7f 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java
@@ -13,6 +13,7 @@ import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants;
 import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CTabFolder;
@@ -72,11 +73,10 @@ public class MemoryControlArea extends Composite
 
 	private MemoryPresentation createPresentation()
 	{
-/*
 		IPreferenceStore pstore = CDebugUIPlugin.getDefault().getPreferenceStore();
 		char[] paddingCharStr = pstore.getString( ICDebugPreferenceConstants.PREF_MEMORY_PADDING_CHAR ).toCharArray();
-		char paddingChar = ( paddingCharStr.length > 0 ) ? paddingCharStr[0] : '.';
-*/
+		setPaddingChar( ( paddingCharStr.length > 0 ) ? paddingCharStr[0] : '.' );
+
 		return new MemoryPresentation();
 	}
 
@@ -164,10 +164,11 @@ public class MemoryControlArea extends Composite
 		{
 			fMemoryText.setDirtyColor();
 		}
-		else
+		else if ( event.getProperty().equals( ICDebugPreferenceConstants.PREF_MEMORY_PADDING_CHAR ) )
 		{
-//			updatePresentation( event );
-//			fMemoryText.refresh();
+			String paddingCharString = (String)event.getNewValue();
+			setPaddingChar( ( paddingCharString.length() > 0 ) ? paddingCharString.charAt( 0 ) : '.' );
+			refresh();
 		}
 	}
 	
@@ -307,6 +308,21 @@ public class MemoryControlArea extends Composite
 	public void setPaddingChar( char paddingChar )
 	{
 		fPaddingChar = paddingChar;
+		if ( getMemoryBlock() != null )
+		{
+			try
+			{
+				getMemoryBlock().reformat( getMemoryBlock().getFormat(),
+										   getMemoryBlock().getWordSize(),
+										   getMemoryBlock().getNumberOfRows(),
+										   getMemoryBlock().getNumberOfColumns(),
+										   fPaddingChar );
+			}
+			catch( DebugException e )
+			{
+				// ignore
+			}
+		}
 	}
 
 	public void setWordSize( int wordSize )
