[mistelix] Recent Files menu



commit ecff63cfbb6053b0cab1c346bfdcf63aa29a291e
Author: Jordi Mas <jmas softcatala org>
Date:   Fri Jul 31 15:36:33 2009 +0200

    Recent Files menu

 src/Core/RecentFilesStorage.cs              |   15 +++++++++++
 src/DataModel/ObservableList.cs             |   10 +++++++
 src/Makefile.am                             |    5 ++-
 src/Widgets/AuthoringPaneView.cs            |    2 +-
 src/Widgets/{GtkMenu.cs => ExtendedMenu.cs} |    5 ++-
 src/Widgets/ProjectElementView.cs           |    4 +-
 src/Widgets/SlideShowImageView.cs           |    4 +-
 src/mistelix.cs                             |   37 +++++++++++++++++++++++++++
 src/mistelix.glade                          |   18 ++++++++++---
 9 files changed, 87 insertions(+), 13 deletions(-)
---
diff --git a/src/Core/RecentFilesStorage.cs b/src/Core/RecentFilesStorage.cs
index 3b52977..77d95cd 100644
--- a/src/Core/RecentFilesStorage.cs
+++ b/src/Core/RecentFilesStorage.cs
@@ -65,6 +65,21 @@ namespace Mistelix.Core
 			get { return items; }
 		}
 
+		public void Sort ()
+		{
+			items.List.Sort (CompareItems);
+		}
+
+		static int CompareItems (RecentFile recent_a, RecentFile recent_b)
+		{
+			int rslt = DateTime.Compare (recent_a.timestamp, recent_b.timestamp);
+
+			if (rslt == 0)
+				return rslt;
+
+			return rslt > 0 ? -1 : 0;
+		}
+
 		void OnCollectionChanged (object sender, ObservableList <RecentFile>.CollectionChangedEventArgs e)
 		{
 			if (ListUpdated != null)
diff --git a/src/DataModel/ObservableList.cs b/src/DataModel/ObservableList.cs
index c42a58b..91e9de5 100644
--- a/src/DataModel/ObservableList.cs
+++ b/src/DataModel/ObservableList.cs
@@ -74,6 +74,11 @@ namespace Mistelix.DataModel
 			get { return list.Count; }
 		}
 
+		public List <T> List {
+			get { return list; }
+		}
+
+
 		public T this [int index] {
 			get { return list [index]; }
 			set { 
@@ -117,6 +122,11 @@ namespace Mistelix.DataModel
 				CollectionChanged (this, new CollectionChangedEventArgs (ChangeType.ElementRemoved, item));
 		}
 
+		public void Sort (IComparer <T> comparer)
+		{
+			list.Sort (comparer);
+		}
+
 		IEnumerator <T> IEnumerable <T>.GetEnumerator ()
 		{
 			return list.GetEnumerator ();
diff --git a/src/Makefile.am b/src/Makefile.am
index 4f47677..bd51e77 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,7 +26,7 @@ MISTELIX_CSDISTFILES =				\
 	$(srcdir)/Widgets/ProjectElementView.cs	\
 	$(srcdir)/Widgets/PixbufImageSurface.cs	\
 	$(srcdir)/Widgets/SlideShowView.cs	\
-	$(srcdir)/Widgets/GtkMenu.cs	\
+	$(srcdir)/Widgets/ExtendedMenu.cs	\
 	$(srcdir)/Dialogs/GtkDialog.cs	\
 	$(srcdir)/Dialogs/AddSlideDialog.cs	\
 	$(srcdir)/Dialogs/AddVideoDialog.cs	\
@@ -81,7 +81,8 @@ MISTELIX_CSDISTFILES =				\
 	$(srcdir)/Backends/ThumbnailCache/Provider.cs \
 	$(srcdir)/Backends/ThumbnailCache/Factory.cs \
 	$(srcdir)/Backends/ThumbnailCache/Gnome.cs \
-	$(srcdir)/Backends/ThumbnailCache/None.cs
+	$(srcdir)/Backends/ThumbnailCache/None.cs \
+	$(srcdir)/Widgets/DataMenuItem.cs
 
 ASSEMBLIES = \
 	 $(MISTELIX_LIBS)    		\
diff --git a/src/Widgets/AuthoringPaneView.cs b/src/Widgets/AuthoringPaneView.cs
index d2c96cb..2b47b8c 100644
--- a/src/Widgets/AuthoringPaneView.cs
+++ b/src/Widgets/AuthoringPaneView.cs
@@ -228,7 +228,7 @@ namespace Mistelix.Widgets
 
 			if (args.Event.Button == 3) {
 				active_item = b;
-				GtkMenu menu = new GtkMenu ();
+				ExtendedMenu menu = new ExtendedMenu ();
 				menu.AddItem (Catalog.GetString ("Element properties"), OnShowElementProperties);
 				menu.AddItem (Catalog.GetString ("Delete element from project"), OnDeleteElement);
 				menu.Popup (args);
diff --git a/src/Widgets/GtkMenu.cs b/src/Widgets/ExtendedMenu.cs
similarity index 96%
rename from src/Widgets/GtkMenu.cs
rename to src/Widgets/ExtendedMenu.cs
index 7e1d2c3..ce9841e 100644
--- a/src/Widgets/GtkMenu.cs
+++ b/src/Widgets/ExtendedMenu.cs
@@ -27,10 +27,11 @@ using Gtk;
 namespace Mistelix.Widgets
 {
 	// Extended GTKMenu functionality
-	public class GtkMenu : Gtk.Menu
+	public class ExtendedMenu : Gtk.Menu
 	{			
-		public GtkMenu ()
+		public ExtendedMenu ()
 		{
+
 		}
 
 		public Gtk.MenuItem AddItem (string label, EventHandler ev)
diff --git a/src/Widgets/ProjectElementView.cs b/src/Widgets/ProjectElementView.cs
index f527794..114ff86 100644
--- a/src/Widgets/ProjectElementView.cs
+++ b/src/Widgets/ProjectElementView.cs
@@ -290,12 +290,12 @@ namespace Mistelix.Widgets
 		[GLib.ConnectBefore]
 		void OnButtonPressed (object o, ButtonPressEventArgs args)
 		{
-			GtkMenu menu;
+			ExtendedMenu menu;
 
 			if (args.Event.Button != 3)
 				return;
 
-			menu = new GtkMenu ();
+			menu = new ExtendedMenu ();
 			menu.AddItem (Catalog.GetString ("Open element"), OnOpenElement);
 			menu.AddItem (Catalog.GetString ("Delete element from project"), OnDeleteElements);
 			menu.Popup (args);
diff --git a/src/Widgets/SlideShowImageView.cs b/src/Widgets/SlideShowImageView.cs
index 50ba46f..4fa072d 100644
--- a/src/Widgets/SlideShowImageView.cs
+++ b/src/Widgets/SlideShowImageView.cs
@@ -456,13 +456,13 @@ namespace Mistelix.Widgets
 		[GLib.ConnectBefore]
 		void OnButtonPressed (object o, ButtonPressEventArgs args)
 		{
-			GtkMenu menu;
+			ExtendedMenu menu;
 			ExtensionNodeList nodelist;
 
 			if (args.Event.Button != 3)
 				return;
 
-			menu = new GtkMenu ();
+			menu = new ExtendedMenu ();
 
 			nodelist = EffectManager.List;
 			if (nodelist.Count > 0) {
diff --git a/src/mistelix.cs b/src/mistelix.cs
index 40a6402..df9beb1 100644
--- a/src/mistelix.cs
+++ b/src/mistelix.cs
@@ -64,6 +64,8 @@ namespace Mistelix
 		[Glade.Widget] Gtk.MenuItem add_videos;
 		[Glade.Widget] Gtk.VBox rightpaned_vbox;
 		[Glade.Widget] Gtk.VBox buttons_vbox;
+		[Glade.Widget] Gtk.MenuItem recent_menuitem;
+		ExtendedMenu recent_submenu;
 
 		AuthoringPaneView authoring_view;
 		Project project;
@@ -120,6 +122,9 @@ namespace Mistelix
 
 			CreateViews ();
 
+			recent_submenu = new ExtendedMenu ();
+			recent_menuitem.Submenu = recent_submenu;
+
 			app_window.IconName = "mistelix";
 			hpaned.Position = 30; // H (right), controls position of top "Project elements" button bar
 			vpaned.Position = 700; // W (left)
@@ -580,6 +585,38 @@ namespace Mistelix
 			OpenProject (args.Project);
 		}
 
+		void OnRecentFiles (object sender,EventArgs args)
+		{
+			recent_submenu = new ExtendedMenu ();
+			recent_menuitem.Submenu = recent_submenu;
+
+			recent_files.Sort ();
+			for (int i = 0; i < recent_files.Items.Count; i++)
+			{
+				string label;
+				MenuItemData item;
+
+				label = recent_files.Items[i].filename;
+				label = label.Replace ("_", "__");
+				item = new MenuItemData (label);
+				item.Data = recent_files.Items[i];
+
+				recent_submenu.Append (item);
+				item.Show ();
+				item.Activated += OnRecentMenuItem;
+			}
+		}
+
+		void OnRecentMenuItem (object sender, EventArgs args)
+		{
+			RecentFile recent;
+			MenuItemData menu_item;
+
+			menu_item = (MenuItemData) sender;
+			recent = (RecentFile) menu_item.Data;
+			OpenProject (recent.filename);
+		}
+
 		[DllImport ("libc")] // Linux
 		private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
 
diff --git a/src/mistelix.glade b/src/mistelix.glade
index 6800327..d7d076d 100644
--- a/src/mistelix.glade
+++ b/src/mistelix.glade
@@ -49,7 +49,7 @@
 		      <signal name="activate" handler="OnNewProject" last_modification_time="Sat, 11 Oct 2008 15:55:34 GMT"/>
 
 		      <child internal-child="image">
-			<widget class="GtkImage" id="image39">
+			<widget class="GtkImage" id="image45">
 			  <property name="visible">True</property>
 			  <property name="stock">gtk-new</property>
 			  <property name="icon_size">1</property>
@@ -70,7 +70,7 @@
 		      <signal name="activate" handler="OnOpenProject" last_modification_time="Sat, 11 Oct 2008 15:55:34 GMT"/>
 
 		      <child internal-child="image">
-			<widget class="GtkImage" id="image40">
+			<widget class="GtkImage" id="image46">
 			  <property name="visible">True</property>
 			  <property name="stock">gtk-open</property>
 			  <property name="icon_size">1</property>
@@ -91,7 +91,7 @@
 		      <signal name="activate" handler="OnSaveProject" last_modification_time="Sat, 11 Oct 2008 15:55:34 GMT"/>
 
 		      <child internal-child="image">
-			<widget class="GtkImage" id="image41">
+			<widget class="GtkImage" id="image47">
 			  <property name="visible">True</property>
 			  <property name="stock">gtk-save</property>
 			  <property name="icon_size">1</property>
@@ -112,7 +112,7 @@
 		      <signal name="activate" handler="OnSaveAs" last_modification_time="Tue, 30 Jun 2009 05:18:51 GMT"/>
 
 		      <child internal-child="image">
-			<widget class="GtkImage" id="image42">
+			<widget class="GtkImage" id="image48">
 			  <property name="visible">True</property>
 			  <property name="stock">gtk-save-as</property>
 			  <property name="icon_size">1</property>
@@ -126,6 +126,15 @@
 		  </child>
 
 		  <child>
+		    <widget class="GtkMenuItem" id="recent_menuitem">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Recent _Files</property>
+		      <property name="use_underline">True</property>
+		      <signal name="activate" handler="OnRecentFiles" last_modification_time="Thu, 30 Jul 2009 16:02:26 GMT"/>
+		    </widget>
+		  </child>
+
+		  <child>
 		    <widget class="GtkSeparatorMenuItem" id="separador1">
 		      <property name="visible">True</property>
 		    </widget>
@@ -2072,6 +2081,7 @@
 		  <property name="relief">GTK_RELIEF_NORMAL</property>
 		  <property name="focus_on_click">True</property>
 		  <signal name="clicked" handler="OnOpenFolder" last_modification_time="Sat, 06 Dec 2008 17:28:30 GMT"/>
+
 		  <child>
 		    <widget class="GtkAlignment" id="alignment3">
 		      <property name="visible">True</property>



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