f-spot r4346 - in trunk: . src src/Widgets



Author: rubenv
Date: Mon Sep 15 12:22:17 2008
New Revision: 4346
URL: http://svn.gnome.org/viewvc/f-spot?rev=4346&view=rev

Log:
2008-09-15  Ruben Vermeersch  <ruben savanne be>

	Add context sensitivity to the infobox/histogram.

	* src/MainWindow.cs: Notify the infobox of context changes.

	* src/Makefile.am: Add ViewContext.cs.

	* src/Preferences.cs: Remove the old preference keys.

	* src/Widgets/InfoBox.cs: Add smart context-sensitive
	displaying/undisplaying of infobox/histogram.

	* src/Widgets/Sidebar.cs: Remove the ViewContext enum...

	* src/Widgets/ViewContext.cs: ... and move it here (new file).

Added:
   trunk/src/Widgets/ViewContext.cs
Modified:
   trunk/ChangeLog
   trunk/src/MainWindow.cs
   trunk/src/Makefile.am
   trunk/src/Preferences.cs
   trunk/src/Widgets/InfoBox.cs
   trunk/src/Widgets/Sidebar.cs

Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs	(original)
+++ trunk/src/MainWindow.cs	Mon Sep 15 12:22:17 2008
@@ -355,8 +355,11 @@
 		sidebar.Show ();
 
 		info_box = new InfoBox ();
+		ViewModeChanged += info_box.HandleMainWindowViewModeChanged;
 		info_box.VersionIdChanged += delegate (InfoBox box, uint version_id) { UpdateForVersionIdChange (version_id);};
 		sidebar_vbox.PackEnd (info_box, false, false, 0);
+
+		info_box.Context = ViewContext.Library;
 		
 		tag_selection_widget.Selection.Changed += HandleTagSelectionChanged;
 		tag_selection_widget.DragDataGet += HandleTagSelectionDragDataGet;

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Sep 15 12:22:17 2008
@@ -266,6 +266,7 @@
 	$(srcdir)/Widgets/TagEntry.cs		\
 	$(srcdir)/Widgets/TagMenu.cs		\
 	$(srcdir)/Widgets/TrayView.cs		\
+	$(srcdir)/Widgets/ViewContext.cs		\
 	$(srcdir)/Widgets/Wipe.cs		\
 	$(srcdir)/XmpTagsImporter.cs		\
 	$(srcdir)/main.cs

Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs	(original)
+++ trunk/src/Preferences.cs	Mon Sep 15 12:22:17 2008
@@ -50,9 +50,6 @@
 		public const string SIDEBAR_POSITION = "/apps/f-spot/ui/sidebar_size";
 		public const string ZOOM = "/apps/f-spot/ui/zoom";
 
-		public const string INFOBOX_INFO_VISIBLE = "/apps/f-spot/ui/infobox_info_visible";
-		public const string INFOBOX_HISTOGRAM_VISIBLE = "/apps/f-spot/ui/infobox_histogram_visible";
-
 		public const string EXPORT_EMAIL_SIZE = "/apps/f-spot/export/email/size";
 		public const string EXPORT_EMAIL_ROTATE = "/apps/f-spot/export/email/auto_rotate";
 		public const string EXPORT_EMAIL_DELETE_TIMEOUT_SEC = "/apps/f-spot/export/email/delete_timeout_seconds";
@@ -147,10 +144,6 @@
 			case ZOOM:
 				return null;
 
-			case INFOBOX_INFO_VISIBLE:
-			case INFOBOX_HISTOGRAM_VISIBLE:
-				return true;
-
 			case IMPORT_GUI_ROLL_HISTORY:
 				return 10;
 

Modified: trunk/src/Widgets/InfoBox.cs
==============================================================================
--- trunk/src/Widgets/InfoBox.cs	(original)
+++ trunk/src/Widgets/InfoBox.cs	Mon Sep 15 12:22:17 2008
@@ -62,6 +62,7 @@
 		public delegate void VersionIdChangedHandler (InfoBox info_box, uint version_id);
 		public event VersionIdChangedHandler VersionIdChanged;
 	
+		private Expander info_expander;
 		private Expander histogram_expander;
 
 		private Gtk.Image histogram_image;
@@ -69,6 +70,20 @@
 
 		private Delay histogram_delay;
 
+		// Context switching (toggles visibility).
+		public event EventHandler ContextChanged;
+
+		private ViewContext view_context = ViewContext.Unknown;
+		public ViewContext Context {
+			get { return view_context; }
+			set {
+				view_context = value;
+				if (ContextChanged != null)
+					ContextChanged (this, null);
+			}
+		}
+
+		private readonly InfoBoxContextSwitchStrategy ContextSwitchStrategy;
 	
 		// Widgetry.	
 		private Label name_label;
@@ -126,9 +141,8 @@
 		{
 
 			histogram_expander = new Expander (Catalog.GetString ("Histogram"));
-			histogram_expander.Expanded = Preferences.Get<bool> (Preferences.INFOBOX_HISTOGRAM_VISIBLE);
 			histogram_expander.Activated += delegate (object sender, EventArgs e) { 
-				Preferences.Set (Preferences.INFOBOX_HISTOGRAM_VISIBLE, histogram_expander.Expanded);
+				ContextSwitchStrategy.SetHistogramVisible (Context, histogram_expander.Expanded);
 				UpdateHistogram ();
 			};
 			histogram_image = new Gtk.Image ();
@@ -144,10 +158,9 @@
 
 			Add (histogram_expander);
 
-			Expander info_expander = new Expander (Catalog.GetString ("Image Information"));
-			info_expander.Expanded = Preferences.Get<bool> (Preferences.INFOBOX_INFO_VISIBLE);
+			info_expander = new Expander (Catalog.GetString ("Image Information"));
 			info_expander.Activated += delegate (object sender, EventArgs e) {
-				Preferences.Set (Preferences.INFOBOX_INFO_VISIBLE, info_expander.Expanded);
+				ContextSwitchStrategy.SetInfoBoxVisible (Context, info_expander.Expanded);
 			};
 
 			Table info_table = new Table (6, 2, false);
@@ -475,13 +488,38 @@
 
 			return false;
 		}
+
+		// Context switching
+
+		private void HandleContextChanged (object sender, EventArgs args)
+		{
+			bool infobox_visible = ContextSwitchStrategy.InfoBoxVisible (Context);
+			info_expander.Expanded = infobox_visible;
+
+			bool histogram_visible = ContextSwitchStrategy.HistogramVisible (Context);
+			histogram_expander.Expanded = histogram_visible;
+			if (histogram_visible)
+				UpdateHistogram ();
+		}
 	
+		public void HandleMainWindowViewModeChanged (object o, EventArgs args)
+		{
+			MainWindow.ModeType mode = MainWindow.Toplevel.ViewMode;
+			if (mode == MainWindow.ModeType.IconView)
+				Context = ViewContext.Library;
+			else if (mode == MainWindow.ModeType.PhotoView)
+				Context = ViewContext.Edit;
+		}
 	
 		// Constructor.
 	
 		public InfoBox () : base (false, 0)
 		{
+			ContextSwitchStrategy = new MRUInfoBoxContextSwitchStrategy ();
+			ContextChanged += HandleContextChanged;
+
 			SetupWidgets ();
+
 			update_delay = new Delay (Update);
 			update_delay.Start ();
 
@@ -491,4 +529,52 @@
             Hide ();
 		}
 	}
+
+	// Decides whether infobox / histogram should be shown for each context. Implemented
+	// using the Strategy pattern, to make it swappable easily, in case the
+	// default MRUInfoBoxContextSwitchStrategy is not sufficiently usable.
+	public abstract class InfoBoxContextSwitchStrategy {
+		public abstract bool InfoBoxVisible (ViewContext context);
+		public abstract bool HistogramVisible (ViewContext context);
+
+		public abstract void SetInfoBoxVisible (ViewContext context, bool visible);
+		public abstract void SetHistogramVisible (ViewContext context, bool visible);
+	}
+
+	// Values are stored as strings, because bool is not nullable through Preferences.
+	public class MRUInfoBoxContextSwitchStrategy : InfoBoxContextSwitchStrategy {
+		public const string PREF_PREFIX = Preferences.APP_FSPOT + "ui";
+
+		private string PrefKeyForContext (ViewContext context, string item) {
+			return String.Format ("{0}/{1}_visible/{2}", PREF_PREFIX, item, context);
+		}
+
+		private bool VisibilityForContext (ViewContext context, string item) {
+			string visible = Preferences.Get<string> (PrefKeyForContext (context, item));
+			if (visible == null)
+				return true;
+			else
+				return visible == "1";
+		}
+
+		private void SetVisibilityForContext (ViewContext context, string item, bool visible) {
+			Preferences.Set (PrefKeyForContext (context, item), visible ? "1" : "0");
+		}
+
+		public override bool InfoBoxVisible (ViewContext context) {
+			return VisibilityForContext (context, "infobox");
+		}
+
+		public override bool HistogramVisible (ViewContext context) {
+			return VisibilityForContext (context, "histogram");
+		}
+
+		public override void SetInfoBoxVisible (ViewContext context, bool visible) {
+			SetVisibilityForContext (context, "infobox", visible);
+		}
+
+		public override void SetHistogramVisible (ViewContext context, bool visible) {
+			SetVisibilityForContext (context, "histogram", visible);
+		}
+	}
 }

Modified: trunk/src/Widgets/Sidebar.cs
==============================================================================
--- trunk/src/Widgets/Sidebar.cs	(original)
+++ trunk/src/Widgets/Sidebar.cs	Mon Sep 15 12:22:17 2008
@@ -18,16 +18,6 @@
 using System.Collections.Generic;
 
 namespace FSpot.Widgets {
-	// This nasty enum serves to differentiate between the different view
-	// modes. As we have both SingleView and normal F-Spot, there is no 
-	// uniform way of naming these contexts.
-	public enum ViewContext {
-		Unknown,
-		Single,
-		Library,
-		Edit
-	}
-
 	[ExtensionNode ("SidebarPage")]
 	public class SidebarPageNode : ExtensionNode {
 		[NodeAttribute (Required=true)]

Added: trunk/src/Widgets/ViewContext.cs
==============================================================================
--- (empty file)
+++ trunk/src/Widgets/ViewContext.cs	Mon Sep 15 12:22:17 2008
@@ -0,0 +1,20 @@
+/*
+ * Widgets.ViewContext.cs
+ *
+ * Author(s)
+ *	Ruben Vermeersch <ruben savanne be>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+namespace FSpot.Widgets {
+	// This nasty enum serves to differentiate between the different view
+	// modes. As we have both SingleView and normal F-Spot, there is no
+	// uniform way of naming these contexts.
+	public enum ViewContext {
+		Unknown,
+		Single,
+		Library,
+		Edit
+	}
+}



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