f-spot r4220 - in trunk: . src src/Extensions src/Widgets



Author: rubenv
Date: Fri Aug  1 11:04:17 2008
New Revision: 4220
URL: http://svn.gnome.org/viewvc/f-spot?rev=4220&view=rev

Log:
2008-08-01  Ruben Vermeersch  <ruben savanne be>

	* src/Extensions/ViewModeCondition.cs: Added. Allows showing sidebar pages
	conditionally, depending on whether the full library view, or just single
	view is in use.

	* src/FSpot.addin.xml: Add an extension point to hook in new sidebar
	pages, as requested by apart.

	* src/SingleView.cs:
	* src/MainWindow.cs: Get sidebar pages from the extension point, rather
	than hardcoding it in.

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

	* src/Widgets/Sidebar.cs: Add SidebarPageNode, an ExtensionNode to add
	sidebar pages.


Added:
   trunk/src/Extensions/ViewModeCondition.cs
Modified:
   trunk/ChangeLog
   trunk/src/FSpot.addin.xml
   trunk/src/MainWindow.cs
   trunk/src/Makefile.am
   trunk/src/SingleView.cs
   trunk/src/Widgets/Sidebar.cs

Added: trunk/src/Extensions/ViewModeCondition.cs
==============================================================================
--- (empty file)
+++ trunk/src/Extensions/ViewModeCondition.cs	Fri Aug  1 11:04:17 2008
@@ -0,0 +1,65 @@
+/*
+ * FSpot.Extensions.ViewModeCondition.cs
+ *
+ * Author(s)
+ * 	Ruben Vermeersch  <ruben savanne be>
+ *
+ * This is free software. See COPYING for details.
+ *
+ */
+
+using Mono.Addins;
+
+namespace FSpot.Extensions
+{
+	public enum ViewMode {
+		Unknown,
+		Single,
+		Library
+	}
+
+	// Defines a view mode condition, which determines which view mode is used.
+	//
+	// There are two valid values for the "mode" attribute, which 
+	// should be added to the Condition tag.
+	//   - single: Single view mode.
+	//   - library: Full F-Spot mode.
+	//
+	// This class contains a very nasty hack using a static initialization method
+	// to keep track of the current view mode. This is (unfortunately) needed
+	// because there is no way to get hold of a reference to the current window.
+	public class ViewModeCondition : ConditionType
+	{
+		private static event ViewModeChangedHandler ViewModeChanged;
+		private delegate void ViewModeChangedHandler ();
+
+		private static ViewMode Mode = ViewMode.Unknown;
+
+		public static void Initialize (ViewMode mode) {
+			Mode = mode;
+
+			if (ViewModeChanged != null)
+				ViewModeChanged ();
+		}
+		
+		public ViewModeCondition ()
+		{
+			ViewModeChanged += delegate { NotifyChanged (); };
+		}
+
+		public override bool Evaluate (NodeElement conditionNode)
+		{
+			string val = conditionNode.GetAttribute ("mode");
+			if (val.Length > 0) {
+				foreach (string mode in val.Split(',')) {
+					if (mode == "single" && Mode == ViewMode.Single) {
+						return true;
+					} else if (mode == "library" && Mode == ViewMode.Library) {
+						return true;
+					}
+				}
+			}
+			return false;
+		}
+	}
+}

Modified: trunk/src/FSpot.addin.xml
==============================================================================
--- trunk/src/FSpot.addin.xml	(original)
+++ trunk/src/FSpot.addin.xml	Fri Aug  1 11:04:17 2008
@@ -6,12 +6,17 @@
 
 	<Runtime>
 		<Import assembly="f-spot.exe" />
+		<Import assembly="FSpot.Widgets.dll" />
 	</Runtime>
 
 	<ExtensionPoint path = "/FSpot/Menus">
 		<ExtensionNode type="FSpot.Extensions.SubmenuNode"/>
 	</ExtensionPoint>
 
+	<ExtensionPoint path = "/FSpot/Sidebar">
+		<ExtensionNode type="FSpot.Widgets.SidebarPageNode"/>
+	</ExtensionPoint>
+
 	<ExtensionPoint path = "/FSpot/Services">
 		<ExtensionNode name="Service" type="FSpot.Extensions.ServiceNode"/>
 	</ExtensionPoint>
@@ -29,6 +34,7 @@
 	</Extension>
 
 	<ConditionType id="PhotoSelection" type="FSpot.Extensions.PhotoSelectionCondition" />
+	<ConditionType id="ViewMode" type="FSpot.Extensions.ViewModeCondition" />
 
 	<Extension path = "/FSpot/Menus/PhotoPopup">
 		<Command id = "CopyLocation" _label = "Copy Photo Locat_ion" command_type = "FSpot.Extensions.CopyLocation" />
@@ -44,4 +50,11 @@
 		<MenuGenerator id = "RemoveTag" _label = "Rem_ove Tag" icon = "gtk-remove" generator_type = "FSpot.Extensions.RemoveTag" />
 		<ComplexMenuItem id = "Rate" widget_type = "FSpot.Widgets.RatingMenuItem"  command_type = "FSpot.Extensions.Rate"/>
 	</Extension>	
+
+	<Extension path = "/FSpot/Sidebar">
+		<SidebarPage sidebar_page_type = "FSpot.Widgets.MetadataDisplayPage" />
+		<Condition id="ViewMode" mode="library">
+			<SidebarPage sidebar_page_type = "FSpot.Widgets.EditorPage" />
+		</Condition>
+	</Extension>
 </Addin>

Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs	(original)
+++ trunk/src/MainWindow.cs	Fri Aug  1 11:04:17 2008
@@ -2,6 +2,7 @@
 using Gtk;
 using GtkSharp;
 using Glade;
+using Mono.Addins;
 using Mono.Unix;
 using System;
 using System.Text;
@@ -16,6 +17,7 @@
 using Banshee.Kernel;
 
 using FSpot;
+using FSpot.Extensions;
 using FSpot.Query;
 using FSpot.Widgets;
 using FSpot.Utils;
@@ -306,8 +308,8 @@
 
 		sidebar.AppendPage (tag_selection_scrolled, Catalog.GetString ("Tags"), "gtk-new");
 
-		sidebar.AppendPage (new MetadataDisplayPage ());
-//		sidebar.AppendPage (new EditorPage ());
+		ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Library);
+		AddinManager.AddExtensionNodeHandler ("/FSpot/Sidebar", OnSidebarExtensionChanged);
  		
 		sidebar.CloseRequested += HideSidebar;
 		sidebar.Show ();
@@ -491,6 +493,12 @@
 		Banshee.Kernel.Scheduler.Resume ();
 	}
 
+	private void OnSidebarExtensionChanged (object s, ExtensionNodeEventArgs args) {
+		// FIXME: No sidebar page removal yet!
+		if (args.Change == ExtensionChange.Add)
+			sidebar.AppendPage ((args.ExtensionNode as SidebarPageNode).GetSidebarPage ());
+	}
+
 	private Photo CurrentPhoto {
 		get {
 			int active = ActiveIndex ();

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Fri Aug  1 11:04:17 2008
@@ -112,6 +112,7 @@
 	$(srcdir)/Extensions/PhotoSelectionCondition.cs	\
 	$(srcdir)/Extensions/PopupCommands.cs	\
 	$(srcdir)/Extensions/ServiceNode.cs	\
+	$(srcdir)/Extensions/ViewModeCondition.cs	\
 	$(srcdir)/Fader.cs			\
 	$(srcdir)/FileImportBackend.cs		\
 	$(srcdir)/FileBrowsableItem.cs		\
@@ -293,6 +294,7 @@
 	-r:FSpot.Utils.dll
 
 WIDGETS_ASSEMBLIES =				\
+	$(LINK_MONO_ADDINS)			\
 	-pkg:gtk-sharp-2.0			\
 	-pkg:gnome-sharp-2.0			\
 	-r:Mono.Posix				\

Modified: trunk/src/SingleView.cs
==============================================================================
--- trunk/src/SingleView.cs	(original)
+++ trunk/src/SingleView.cs	Fri Aug  1 11:04:17 2008
@@ -1,8 +1,10 @@
 using Gtk;
 using Gdk;
 using System;
+using Mono.Addins;
 using Mono.Unix;
 
+using FSpot.Extensions;
 using FSpot.Utils;
 using FSpot.UI.Dialog;
 using FSpot.Widgets;
@@ -119,7 +121,8 @@
 			info_vbox.Add (sidebar);
 			sidebar.AppendPage (directory_scrolled, Catalog.GetString ("Folder"), "gtk-directory");
 
-			sidebar.AppendPage (new MetadataDisplayPage ());
+			ViewModeCondition.Initialize (FSpot.Extensions.ViewMode.Single);
+			AddinManager.AddExtensionNodeHandler ("/FSpot/Sidebar", OnSidebarExtensionChanged);
  		
 			sidebar.CloseRequested += HandleHideSidePane;
 			sidebar.Show ();
@@ -174,6 +177,12 @@
 			export.Activated += HandleExportActivated ;
 		}
 
+		private void OnSidebarExtensionChanged (object s, ExtensionNodeEventArgs args) {
+			// FIXME: No sidebar page removal yet!
+			if (args.Change == ExtensionChange.Add)
+				sidebar.AppendPage ((args.ExtensionNode as SidebarPageNode).GetSidebarPage ());
+		}
+
 		void HandleExportActivated (object o, EventArgs e)
 		{
 			FSpot.Extensions.ExportMenuItemNode.SelectedImages = delegate () {return new FSpot.PhotoArray (directory_view.Selection.Items); };

Modified: trunk/src/Widgets/Sidebar.cs
==============================================================================
--- trunk/src/Widgets/Sidebar.cs	(original)
+++ trunk/src/Widgets/Sidebar.cs	Fri Aug  1 11:04:17 2008
@@ -10,10 +10,22 @@
  */
 
 using Gtk;
+using Mono.Addins;
 using System;
 using System.Collections.Generic;
 
 namespace FSpot.Widgets {
+	[ExtensionNode ("SidebarPage")]
+	public class SidebarPageNode : ExtensionNode {
+		[NodeAttribute (Required=true)]
+		protected string sidebar_page_type;
+
+		public SidebarPage GetSidebarPage () {
+			return (SidebarPage) Addin.CreateInstance (sidebar_page_type);
+		}
+	}
+
+
 	public class SidebarPage {
 		// The widget shown on the sidebar page.
 		private readonly Widget widget;



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