[Supertux-commit] r4899 - in branches/supertux-sharp/new-undo/supertux-editor: . PropertyEditors Tiles Undo

anmaster at millhouse.dreamhost.com anmaster at millhouse.dreamhost.com
Thu Mar 1 06:46:51 PST 2007


Author: anmaster
Date: 2007-03-01 06:46:45 -0800 (Thu, 01 Mar 2007)
New Revision: 4899

Modified:
   branches/supertux-sharp/new-undo/supertux-editor/PropertiesView.cs
   branches/supertux-sharp/new-undo/supertux-editor/PropertyEditors/ChooseResourceWidget.cs
   branches/supertux-sharp/new-undo/supertux-editor/ResizeDialog.cs
   branches/supertux-sharp/new-undo/supertux-editor/Tiles/TileBlock.cs
   branches/supertux-sharp/new-undo/supertux-editor/Undo/PropertyCommands.cs
Log:
Only one undo for ChooseResourceWidget as well.

Modified: branches/supertux-sharp/new-undo/supertux-editor/PropertiesView.cs
===================================================================
--- branches/supertux-sharp/new-undo/supertux-editor/PropertiesView.cs	2007-03-01 14:30:56 UTC (rev 4898)
+++ branches/supertux-sharp/new-undo/supertux-editor/PropertiesView.cs	2007-03-01 14:46:45 UTC (rev 4899)
@@ -229,7 +229,7 @@
 		}
 		errorLabel.Text = String.Empty;
 	}
-	
+
 	private void OnEntryChanged(object o, EventArgs args)
 	{
 		try {

Modified: branches/supertux-sharp/new-undo/supertux-editor/PropertyEditors/ChooseResourceWidget.cs
===================================================================
--- branches/supertux-sharp/new-undo/supertux-editor/PropertyEditors/ChooseResourceWidget.cs	2007-03-01 14:30:56 UTC (rev 4898)
+++ branches/supertux-sharp/new-undo/supertux-editor/PropertyEditors/ChooseResourceWidget.cs	2007-03-01 14:46:45 UTC (rev 4899)
@@ -6,22 +6,17 @@
 using LispReader;
 using Undo;
 
-public sealed class ChooseResourceWidget : CustomSettingsWidget
-{
+public sealed class ChooseResourceWidget : CustomSettingsWidget {
 	private Entry entry;
-	// HACK: Workaround for entry.Text = path.Replace("\\", "/"); resulting in
-	// OnEntryChanged being called twice
-	private bool isChoose;
 
-	public override Widget Create(object caller)
-	{
+	public override Widget Create(object caller) {
 		HBox box = new HBox();
 		entry = new Entry();
 		string val = (string) field.GetValue(Object);
-		if(val != null)
+		if (val != null)
 			entry.Text = val;
 
-		entry.Changed += OnEntryChanged;
+		entry.FocusOutEvent += OnEntryChangeDone;
 		box.PackStart(entry, true, true, 0);
 
 		Button chooseButton = new Button("...");
@@ -35,9 +30,8 @@
 		return box;
 	}
 
-	private void OnChoose(object o, EventArgs args)
-	{
-		FileChooserDialog dialog = new FileChooserDialog("Choose resource", null, FileChooserAction.Open, new object[] {});
+	private void OnChoose(object o, EventArgs args) {
+		FileChooserDialog dialog = new FileChooserDialog("Choose resource", null, FileChooserAction.Open, new object[] { });
 		dialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
 		dialog.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Ok);
 		dialog.DefaultResponse = Gtk.ResponseType.Ok;
@@ -45,20 +39,18 @@
 		dialog.Action = FileChooserAction.Open;
 		dialog.SetFilename(Settings.Instance.SupertuxData + entry.Text);
 		int result = dialog.Run();
-		if(result != (int) ResponseType.Ok) {
+		if (result != (int) ResponseType.Ok) {
 			dialog.Destroy();
 			return;
 		}
 		string path;
-		if(dialog.Filename.StartsWith(Settings.Instance.SupertuxData))
+		if (dialog.Filename.StartsWith(Settings.Instance.SupertuxData))
 			path = dialog.Filename.Substring(Settings.Instance.SupertuxData.Length,
-			                                       dialog.Filename.Length - Settings.Instance.SupertuxData.Length);
+																						 dialog.Filename.Length - Settings.Instance.SupertuxData.Length);
 		else
 			path = System.IO.Path.GetFileName(dialog.Filename);
-		isChoose = true;
 		// Fixes backslashes on windows:
 		entry.Text = path.Replace("\\", "/");
-		isChoose = false;
 		PropertyChangeCommand command = new PropertyChangeCommand(
 			"Changed value of " + field.Name,
 			field,
@@ -69,21 +61,19 @@
 		dialog.Destroy();
 	}
 
-	private void OnEntryChanged(object o, EventArgs arg)
-	{
-		if (!isChoose) {
-			try {
-				Entry entry = (Entry) o;
-				PropertyChangeCommand command = new PropertyChangeCommand(
-					"Changed value of " + field.Name,
-					field,
-					_object,
-					entry.Text);
-				command.Do();
-				UndoManager.AddCommand(command);
-			} catch (Exception e) {
-				ErrorDialog.Exception(e);
-			}
+	private void OnEntryChangeDone(object o, FocusOutEventArgs args) {
+		try {
+			Entry entry = (Entry) o;
+			if ((string)field.GetValue(_object) == entry.Text) return;
+			PropertyChangeCommand command = new PropertyChangeCommand(
+				"Changed value of " + field.Name,
+				field,
+				_object,
+				entry.Text);
+			command.Do();
+			UndoManager.AddCommand(command);
+		} catch (Exception e) {
+			ErrorDialog.Exception(e);
 		}
 	}
 }

Modified: branches/supertux-sharp/new-undo/supertux-editor/ResizeDialog.cs
===================================================================
--- branches/supertux-sharp/new-undo/supertux-editor/ResizeDialog.cs	2007-03-01 14:30:56 UTC (rev 4898)
+++ branches/supertux-sharp/new-undo/supertux-editor/ResizeDialog.cs	2007-03-01 14:46:45 UTC (rev 4899)
@@ -43,7 +43,7 @@
 	{
 		try {
 			uint newWidth = UInt32.Parse(WidthEntry.Text);
-			uint newHeight = UInt32.Parse(HeightEntry.Text);	
+			uint newHeight = UInt32.Parse(HeightEntry.Text);
 			//application.TakeUndoSnapshot( "Sector resized to " + newWidth + "x" + newHeight);
 			SectorSizeChangeCommand command = new SectorSizeChangeCommand(
 				"Sector resized to " + newWidth + "x" + newHeight,

Modified: branches/supertux-sharp/new-undo/supertux-editor/Tiles/TileBlock.cs
===================================================================
--- branches/supertux-sharp/new-undo/supertux-editor/Tiles/TileBlock.cs	2007-03-01 14:30:56 UTC (rev 4898)
+++ branches/supertux-sharp/new-undo/supertux-editor/Tiles/TileBlock.cs	2007-03-01 14:46:45 UTC (rev 4899)
@@ -157,7 +157,7 @@
 	internal StateData SaveState() {
 		return new StateData(Width, Height, Elements);
 	}
-	
+
 	/// <summary>
 	/// Data for undoing
 	/// </summary>
@@ -166,6 +166,6 @@
 		width = state.width;
 		height = state.height;
 		Elements = new List<int>(state.Elements);
-	}	
+	}
 
 }

Modified: branches/supertux-sharp/new-undo/supertux-editor/Undo/PropertyCommands.cs
===================================================================
--- branches/supertux-sharp/new-undo/supertux-editor/Undo/PropertyCommands.cs	2007-03-01 14:30:56 UTC (rev 4898)
+++ branches/supertux-sharp/new-undo/supertux-editor/Undo/PropertyCommands.cs	2007-03-01 14:46:45 UTC (rev 4899)
@@ -43,4 +43,4 @@
 			this.newData = newData;
 		}
 	}
-}
\ No newline at end of file
+}



More information about the supertux-commit mailing list