f-spot r3728 - in trunk/src: . UI.Dialog



Author: sdelcroix
Date: Mon Mar  3 11:56:46 2008
New Revision: 3728
URL: http://svn.gnome.org/viewvc/f-spot?rev=3728&view=rev

Log:
SizeAttribute for GladeDialog

Added:
   trunk/src/UI.Dialog/SizeAttribute.cs
Modified:
   trunk/src/GladeDialog.cs
   trunk/src/ImportCommand.cs
   trunk/src/Makefile.am

Modified: trunk/src/GladeDialog.cs
==============================================================================
--- trunk/src/GladeDialog.cs	(original)
+++ trunk/src/GladeDialog.cs	Mon Mar  3 11:56:46 2008
@@ -1,3 +1,17 @@
+/*
+ * FSpot.GladeDialog.cs
+ *
+ * Author(s):
+ *	Larry Ewing  <lewing novell com>
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software, See COPYING for details
+ */
+
+using System;
+using FSpot.UI.Dialog;
+using Gtk;
+
 namespace FSpot {
 	public class GladeDialog {
 		protected string dialog_name;
@@ -6,7 +20,6 @@
 		
 		protected GladeDialog ()
 		{
-
 		}
 
 		public GladeDialog (string name)
@@ -19,15 +32,42 @@
 			this.dialog_name = name;		
 			xml = new Glade.XML (null, "f-spot.glade", name, "f-spot");
 			xml.Autoconnect (this);
+
+			Attribute[] attributeArray = Attribute.GetCustomAttributes (this.GetType ());
+			foreach(Attribute attrib in attributeArray) 
+			{
+				if (attrib is SizeAttribute)
+				{
+					SizeAttribute a = attrib as SizeAttribute;
+ 					if ((int) FSpot.Preferences.Get (a.WidthKey) > 0)
+ 						Dialog.Resize ((int) Preferences.Get (a.WidthKey), (int) Preferences.Get(a.HeightKey));
+				}
+			}
 		}
 
 		public Gtk.Dialog Dialog {
 			get {
 				if (dialog == null)
 					dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
-				
 				return dialog;
 			}
 		}
+
+		protected void SaveSettings ()
+		{
+			Attribute[] attributeArray = Attribute.GetCustomAttributes (this.GetType ());
+			foreach(Attribute attrib in attributeArray) 
+			{
+				if (attrib is SizeAttribute)
+				{
+					SizeAttribute a = attrib as SizeAttribute;
+					int width, height;
+					Dialog.GetSize (out width, out height);
+
+					Preferences.Set (a.WidthKey, width);
+					Preferences.Set (a.HeightKey, height);
+				}
+			}	
+		}
 	}
 }

Modified: trunk/src/ImportCommand.cs
==============================================================================
--- trunk/src/ImportCommand.cs	(original)
+++ trunk/src/ImportCommand.cs	Mon Mar  3 11:56:46 2008
@@ -26,6 +26,7 @@
 using FSpot.Utils;
 using FSpot.UI.Dialog;
 
+[Size (Preferences.IMPORT_WINDOW_WIDTH, Preferences.IMPORT_WINDOW_HEIGHT)]
 public class ImportCommand : FSpot.GladeDialog
 {
 	internal class SourceItem : ImageMenuItem
@@ -589,9 +590,6 @@
 		this.Dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
 		this.Dialog.Response += HandleDialogResponse;
 
- 		if ((int) FSpot.Preferences.Get (FSpot.Preferences.IMPORT_WINDOW_WIDTH) > 0)
- 			this.Dialog.Resize ((int) FSpot.Preferences.Get (FSpot.Preferences.IMPORT_WINDOW_WIDTH), (int) FSpot.Preferences.Get(FSpot.Preferences.IMPORT_WINDOW_HEIGHT));
-
  		if ((int) FSpot.Preferences.Get (FSpot.Preferences.IMPORT_WINDOW_PANE_POSITION) > 0)
 			import_hpaned.Position = (int) FSpot.Preferences.Get (FSpot.Preferences.IMPORT_WINDOW_PANE_POSITION);
 
@@ -693,11 +691,7 @@
 				}
 			}
 
-			int width, height;
-			this.Dialog.GetSize (out width, out height);
-
-			FSpot.Preferences.Set (FSpot.Preferences.IMPORT_WINDOW_WIDTH, width);
-			FSpot.Preferences.Set (FSpot.Preferences.IMPORT_WINDOW_HEIGHT, height);
+			SaveSettings ();
 			FSpot.Preferences.Set (FSpot.Preferences.IMPORT_WINDOW_PANE_POSITION, import_hpaned.Position);
 
 			this.Dialog.Destroy ();

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Mar  3 11:56:46 2008
@@ -226,6 +226,7 @@
 	$(srcdir)/UI.Dialog/AboutDialog.cs	\
 	$(srcdir)/UI.Dialog/EditExceptionDialog.cs	\
 	$(srcdir)/UI.Dialog/HigMessageDialog.cs	\
+	$(srcdir)/UI.Dialog/SizeAttribute.cs	\
 	$(srcdir)/Updater.cs			\
 	$(srcdir)/UriCollection.cs		\
 	$(srcdir)/Util.cs			\

Added: trunk/src/UI.Dialog/SizeAttribute.cs
==============================================================================
--- (empty file)
+++ trunk/src/UI.Dialog/SizeAttribute.cs	Mon Mar  3 11:56:46 2008
@@ -0,0 +1,31 @@
+/*
+ * FSpot.UI.Dialog.SizeAttribute.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details
+ */
+using System;
+
+namespace FSpot.UI.Dialog
+{
+	[AttributeUsage (AttributeTargets.Class)]
+	public class SizeAttribute : Attribute
+	{
+		string width_key;
+		public string WidthKey {
+			get { return width_key; }
+		}
+		string height_key;
+		public string HeightKey {
+			get { return height_key; }
+		}
+
+		public SizeAttribute (string width_key, string height_key)
+		{
+			this.width_key = width_key;
+			this.height_key = height_key;
+		}
+	}
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]