[glabels/vala] Added recent template selection to new label dialog.



commit cc9984979e3814edec9b0f5e1c9b6e29e0c33e81
Author: Jim Evins <evins snaught com>
Date:   Thu Apr 12 23:49:29 2012 -0400

    Added recent template selection to new label dialog.

 data/ui/new_label_dialog.ui   |  289 ++++++++++++++++++++++++++++++++---------
 glabels/Makefile.am           |    1 +
 glabels/font_history.vala     |   11 +-
 glabels/message_bar.vala      |  114 ++++++++++++++++
 glabels/new_label_dialog.vala |  238 +++++++++++++++++++++++++++++-----
 glabels/template_history.vala |   11 +-
 6 files changed, 558 insertions(+), 106 deletions(-)
---
diff --git a/data/ui/new_label_dialog.ui b/data/ui/new_label_dialog.ui
index 014a523..71740b2 100644
--- a/data/ui/new_label_dialog.ui
+++ b/data/ui/new_label_dialog.ui
@@ -1,50 +1,144 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.24"/>
+  <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkWindow" id="new_label_dialog">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">New Label</property>
     <property name="icon_name">preferences-desktop</property>
     <child>
-      <object class="GtkVBox" id="main_vbox">
+      <object class="GtkBox" id="main_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkToolbar" id="toolbar">
+          <object class="GtkNotebook" id="notebook1">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
+            <property name="can_focus">True</property>
+            <property name="tab_pos">left</property>
             <child>
-              <object class="GtkToolItem" id="toolbutton1">
+              <object class="GtkBox" id="recent_box">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="use_action_appearance">False</property>
+                <property name="border_width">6</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">3</property>
                 <child>
-                  <object class="GtkAlignment" id="alignment1">
+                  <object class="GtkBox" id="recent_info_box">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="top_padding">5</property>
-                    <property name="bottom_padding">5</property>
-                    <property name="left_padding">10</property>
-                    <property name="right_padding">5</property>
+                    <property name="orientation">vertical</property>
                     <child>
-                      <object class="GtkHBox" id="hbox1">
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="shadow_type">in</property>
+                    <child>
+                      <object class="GtkIconView" id="recent_icon_view">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="selection_mode">browse</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Recent</property>
+              </object>
+              <packing>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="search_box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">6</property>
+                    <child>
+                      <object class="GtkEntry" id="search_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">â</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="secondary_icon_stock">gtk-find</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="pack_type">end</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="search_info_box">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkHBox" id="hbox2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">6</property>
+                    <property name="spacing">10</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <object class="GtkVBox" id="vbox2">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="spacing">18</property>
                         <child>
-                          <object class="GtkAlignment" id="entry-alignment">
+                          <object class="GtkScrolledWindow" id="scrolledwindow1">
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">1</property>
-                            <property name="xscale">0</property>
+                            <property name="can_focus">True</property>
+                            <property name="shadow_type">in</property>
                             <child>
-                              <object class="GtkEntry" id="search_entry">
-                                <property name="width_request">210</property>
+                              <object class="GtkIconView" id="search_icon_view">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="invisible_char">â</property>
-                                <property name="secondary_icon_name">edit-find-symbolic</property>
-                                <property name="secondary_icon_activatable">False</property>
-                                <property name="secondary_icon_sensitive">False</property>
+                                <property name="selection_mode">browse</property>
                               </object>
                             </child>
                           </object>
@@ -55,78 +149,155 @@
                           </packing>
                         </child>
                       </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
                     </child>
                   </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
+                  </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">True</property>
-                <property name="homogeneous">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Search all</property>
+              </object>
+              <packing>
+                <property name="position">1</property>
+                <property name="tab_fill">False</property>
               </packing>
             </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkVBox" id="info_vbox">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="border_width">10</property>
             <child>
-              <object class="GtkHBox" id="hbox2">
+              <object class="GtkBox" id="custom_box">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="spacing">10</property>
+                <property name="border_width">6</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">3</property>
                 <child>
-                  <placeholder/>
+                  <object class="GtkBox" id="custom_info_box">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="shadow_type">in</property>
+                    <child>
+                      <object class="GtkIconView" id="custom_icon_view">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="selection_mode">browse</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
                 </child>
                 <child>
-                  <object class="GtkVBox" id="vbox2">
+                  <object class="GtkHBox" id="hbox3">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="spacing">18</property>
+                    <property name="spacing">9</property>
                     <child>
-                      <object class="GtkScrolledWindow" id="scrolledwindow1">
+                      <object class="GtkButton" id="custom_add_button">
+                        <property name="label">gtk-add</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkIconView" id="icon_view">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="selection_mode">browse</property>
-                          </object>
-                        </child>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_stock">True</property>
                       </object>
                       <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
                         <property name="position">0</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkButton" id="custom_edit_button">
+                        <property name="label">gtk-edit</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="custom_delete_button">
+                        <property name="label">gtk-delete</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="padding">6</property>
+                    <property name="position">2</property>
                   </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Custom</property>
+              </object>
+              <packing>
+                <property name="position">2</property>
+                <property name="tab_fill">False</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index e9285ce..5530527 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -42,6 +42,7 @@ glabels_4_SOURCES = \
 	merge_none.vala \
 	merge_record.vala \
 	merge_text.vala \
+	message_bar.vala \
 	mini_preview.vala \
 	new_label_dialog.vala \
 	object_editor.vala \
diff --git a/glabels/font_history.vala b/glabels/font_history.vala
index 15ee153..0afa47c 100644
--- a/glabels/font_history.vala
+++ b/glabels/font_history.vala
@@ -52,14 +52,13 @@ namespace glabels
 		{
 			string[] old_families;
 			string[] new_families;
-			int      i, j;
 
 			old_families = history.get_strv( "recent-fonts" );
 
 			new_families = new string[1];
-			new_families += family;
+			new_families[0] = family;
 
-			for ( i = 0, j = 1; (j < (max_n-1)) && (i < old_families.length); i++ )
+			for ( int i = 0; (i < (max_n-1)) && (i < old_families.length); i++ )
 			{
 				if ( family != old_families[i] )
 				{
@@ -72,13 +71,11 @@ namespace glabels
 
 		public List<string> get_family_list()
 		{
-			string[]     families;
 			List<string> family_list = new List<string>();
-			int          i;
 
-			families = history.get_strv( "recent-fonts" );
+			string[] families = history.get_strv( "recent-fonts" );
 
-			for ( i = 0; i < families.length; i++ )
+			for ( int i = 0; i < families.length; i++ )
 			{
 				if ( font_families.is_family_installed( families[i] ) )
 				{
diff --git a/glabels/message_bar.vala b/glabels/message_bar.vala
new file mode 100644
index 0000000..95ed02a
--- /dev/null
+++ b/glabels/message_bar.vala
@@ -0,0 +1,114 @@
+/*  message_bar.vala
+ *
+ *  Copyright (C) 2012  Jim Evins <evins snaught com>
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+using GLib;
+
+namespace glabels
+{
+
+	class MessageBar : Gtk.InfoBar
+	{
+		Gtk.Image  image;
+		Gtk.Label  label;
+
+		string     primary_text;
+		string     secondary_text;
+
+
+		public MessageBar( Gtk.MessageType type,
+		                   Gtk.ButtonsType buttons,
+		                   string          message_format,
+		                   ... )
+		{
+			set_message_type( type );
+
+			image = new Gtk.Image();
+			switch( type )
+			{
+			case Gtk.MessageType.INFO:
+				image.set_from_stock( Gtk.Stock.DIALOG_INFO, Gtk.IconSize.DIALOG );
+				break;
+			case Gtk.MessageType.WARNING:
+				image.set_from_stock( Gtk.Stock.DIALOG_WARNING, Gtk.IconSize.DIALOG );
+				break;
+			case Gtk.MessageType.QUESTION:
+				image.set_from_stock( Gtk.Stock.DIALOG_QUESTION, Gtk.IconSize.DIALOG );
+				break;
+			case Gtk.MessageType.ERROR:
+				image.set_from_stock( Gtk.Stock.DIALOG_ERROR, Gtk.IconSize.DIALOG );
+				break;
+			default:
+				break;
+			}
+
+			var args = va_list();
+			primary_text = message_format.vprintf( args );
+			label = new Gtk.Label( primary_text );
+
+			Gtk.Container container = get_content_area() as Gtk.Container;
+			Gtk.HBox hbox = new Gtk.HBox( false, 6 );
+			container.add( hbox );
+
+			hbox.pack_start( image, false, false, 0 );
+			hbox.pack_start( label, false, false, 0 );
+
+			hbox.show_all();
+
+			switch (buttons)
+			{
+			case Gtk.ButtonsType.OK:
+				add_button( Gtk.Stock.OK, Gtk.ResponseType.ACCEPT );
+				break;
+			case Gtk.ButtonsType.CLOSE:
+				add_button( Gtk.Stock.CLOSE, Gtk.ResponseType.ACCEPT );
+				break;
+			case Gtk.ButtonsType.CANCEL:
+				add_button( Gtk.Stock.CANCEL, Gtk.ResponseType.REJECT );
+				break;
+			case Gtk.ButtonsType.YES_NO:
+				add_button( Gtk.Stock.YES, Gtk.ResponseType.ACCEPT );
+				add_button( Gtk.Stock.NO,  Gtk.ResponseType.REJECT );
+				break;
+			case Gtk.ButtonsType.OK_CANCEL:
+				add_button( Gtk.Stock.OK,     Gtk.ResponseType.ACCEPT );
+				add_button( Gtk.Stock.CANCEL, Gtk.ResponseType.REJECT );
+				break;
+			default:
+				break;
+			}
+
+		}
+
+
+		public void format_secondary_text( string message_format, ... )
+		{
+			var args = va_list();
+			secondary_text = message_format.vprintf( args );
+
+			string markup = "<span weight=\"bold\" size=\"larger\">%s</span>\n%s".printf( primary_text,
+				                                                                          secondary_text );
+
+			label.set_markup( markup );
+		}
+
+	}
+
+}
\ No newline at end of file
diff --git a/glabels/new_label_dialog.vala b/glabels/new_label_dialog.vala
index a7a66a5..4dd11ea 100644
--- a/glabels/new_label_dialog.vala
+++ b/glabels/new_label_dialog.vala
@@ -26,17 +26,34 @@ namespace glabels
 
 	class NewLabelDialog : Gtk.Dialog
 	{
-		private Prefs prefs;
+		private Prefs               prefs;
+		private TemplateHistory     template_history;
 
+		private Gtk.Box             recent_box;
+		private Gtk.Box             recent_info_box;
+		private MessageBar          recent_info_bar;
+		private Gtk.IconView        recent_icon_view;
 
-		private Gtk.IconView  icon_view;
-
+		private Gtk.Box             search_box;
+		private Gtk.Box             search_info_box;
+		private MessageBar          search_info_bar;
 		private Gtk.Entry           search_entry;
-		private string              search_string = "";
-		private Gtk.TreeModelFilter search_filtered_model;
+		private Gtk.IconView        search_icon_view;
 
-		private Gtk.ListStore model;
+		private Gtk.Box             custom_box;
+		private Gtk.Box             custom_info_box;
+		private MessageBar          custom_info_bar;
+		private Gtk.IconView        custom_icon_view;
+		private Gtk.Button          custom_add_button;
+		private Gtk.Button          custom_edit_button;
+		private Gtk.Button          custom_delete_button;
 
+		private Gtk.ListStore       recent_model;
+
+		private string              search_string = "";
+		private Gtk.TreeModelFilter search_filtered_model;
+		private bool                search_filtered_model_empty;
+		private Gtk.ListStore       search_model;
 
 		public string? template_name { get; private set; }
 
@@ -56,7 +73,7 @@ namespace glabels
 			try
 			{
 				string file = GLib.Path.build_filename( Config.DATADIR, Config.GLABELS_BRANCH, "ui", "new_label_dialog.ui" );
-				string[] objects = { "main_vbox", null };
+				string[] objects = { "main_box", null };
 				builder.add_objects_from_file( file, objects );
 			}
 			catch ( Error err )
@@ -64,26 +81,152 @@ namespace glabels
 				error( "Error: %s", err.message );
 			}
 
-			Gtk.VBox main_vbox = builder.get_object( "main_vbox" ) as Gtk.VBox;
-			((Gtk.Box)get_content_area()).pack_start( main_vbox );
+			Gtk.Box main_box = builder.get_object( "main_box" ) as Gtk.Box;
+			((Gtk.Box)get_content_area()).pack_start( main_box );
+
+			/* Recent templates widgets */
+			recent_box           = builder.get_object( "recent_box" )           as Gtk.Box;
+			recent_info_box      = builder.get_object( "recent_info_box" )      as Gtk.Box;
+			recent_icon_view     = builder.get_object( "recent_icon_view" )     as Gtk.IconView;
+
+			/* Search widgets */
+			search_box           = builder.get_object( "search_box" )           as Gtk.Box;
+			search_info_box      = builder.get_object( "search_info_box" )      as Gtk.Box;
+			search_entry         = builder.get_object( "search_entry" )         as Gtk.Entry;
+			search_icon_view     = builder.get_object( "search_icon_view" )     as Gtk.IconView;
+
+			/* Custom templates widgets */
+			custom_box           = builder.get_object( "custom_box" )           as Gtk.Box;
+			custom_info_box      = builder.get_object( "custom_info_box" )      as Gtk.Box;
+			custom_icon_view     = builder.get_object( "custom_icon_view" )     as Gtk.IconView;
+			custom_add_button    = builder.get_object( "custom_add_button" )    as Gtk.Button;
+			custom_edit_button   = builder.get_object( "custom_edit_button" )   as Gtk.Button;
+			custom_delete_button = builder.get_object( "custom_delete_button" ) as Gtk.Button;
+
+
+			/* Recent page preparation */
+			recent_info_bar = new MessageBar( Gtk.MessageType.INFO,
+			                                  Gtk.ButtonsType.NONE,
+			                                  _("No recent templates found.") );
+			recent_info_bar.format_secondary_text( _("Try selecting a template in the \"Search all\" tab.") );
+			recent_info_box.pack_start( recent_info_bar, false, false, 0 );
+			recent_info_bar.show();
+			recent_info_bar.set_no_show_all( true );
+			setup_recent_model();
+
+			/* Search page preparation */
+			search_info_bar = new MessageBar( Gtk.MessageType.INFO,
+			                                  Gtk.ButtonsType.NONE,
+			                                  _("No match.") );
+			search_info_bar.format_secondary_text( _("Try modifying the search") );
+			search_info_box.pack_start( search_info_bar, false, false, 0 );
+			search_info_bar.hide();
+			search_info_bar.set_no_show_all( true );
+			setup_search_model();
+
+			/* Custom page preparation */
+			custom_info_bar = new MessageBar( Gtk.MessageType.INFO,
+			                                  Gtk.ButtonsType.NONE,
+			                                  _("No custom templates found.") );
+			custom_info_bar.format_secondary_text( _("You may create new templates or try searching for pre-defined templates in the \"Search all\" tab.") );
+			custom_info_box.pack_start( custom_info_bar, false, false, 0 );
+			custom_info_bar.show();
+
+			/* Connect signals. */
+			search_entry.changed.connect( on_search_entry_changed );
+			search_entry.icon_release.connect( on_search_entry_clear );
+			recent_icon_view.selection_changed.connect( on_recent_icon_view_selection_changed );
+			recent_icon_view.button_release_event.connect( on_recent_icon_view_button_release_event );
+			search_icon_view.selection_changed.connect( on_search_icon_view_selection_changed );
+			search_icon_view.button_release_event.connect( on_search_icon_view_button_release_event );
+		}
+
+
+		private void setup_recent_model()
+		{
+			template_history = new TemplateHistory( 5 );
+
+			/* Create and set icon view model. */
+			recent_model = new Gtk.ListStore( 3, typeof(string), typeof(Gdk.Pixbuf), typeof(string) );
+
+			recent_icon_view.set_model( recent_model );
+			recent_icon_view.set_text_column( 0 );
+			recent_icon_view.set_pixbuf_column( 1 );
+			recent_icon_view.set_tooltip_column( 2 );
+
+			/* Set "follow-state" property of pixbuf renderer. (pre-light) */
+			List<weak Gtk.CellRenderer> renderer_list = recent_icon_view.cell_area.get_cells();
+			foreach ( Gtk.CellRenderer renderer in renderer_list )
+			{
+				if ( renderer is Gtk.CellRendererPixbuf )
+				{
+					((Gtk.CellRendererPixbuf)renderer).follow_state = true;
+				}
+			}
+
+			/* Intialize model. */
+			foreach ( string name in template_history.get_template_list() )
+			{
+				libglabels.Template template = libglabels.Db.lookup_template_from_name( name );
+
+				Gtk.TreeIter iter;
+				recent_model.append( out iter );
+
+				string tooltip = build_tooltip( template );
+
+				recent_model.set( iter,
+				                  0, template.name,
+				                  1, template.preview_pixbuf,
+				                  2, tooltip,
+				                  -1);
+
+				recent_info_bar.hide();
+			}
+
+			template_history.changed.connect( on_template_history_changed );
+		}
+
 
-			search_entry = builder.get_object( "search_entry" ) as Gtk.Entry;
-			icon_view    = builder.get_object( "icon_view" )    as Gtk.IconView;
+		private void on_template_history_changed()
+		{
+			recent_model.clear();
+
+			/* Re-intialize model. */
+			foreach ( string name in template_history.get_template_list() )
+			{
+				libglabels.Template template = libglabels.Db.lookup_template_from_name( name );
+
+				Gtk.TreeIter iter;
+				recent_model.append( out iter );
+
+				string tooltip = build_tooltip( template );
+
+				recent_model.set( iter,
+				                  0, template.name,
+				                  1, template.preview_pixbuf,
+				                  2, tooltip,
+				                  -1);
+
+				recent_info_bar.hide();
+			}
+		}
 
 
+		private void setup_search_model()
+		{
 			/* Create and set icon view model. */
-			model = new Gtk.ListStore( 3, typeof(string), typeof(Gdk.Pixbuf), typeof(string) );
+			search_model = new Gtk.ListStore( 3, typeof(string), typeof(Gdk.Pixbuf), typeof(string) );
 
-			search_filtered_model = new Gtk.TreeModelFilter( model, null );
+			search_filtered_model = new Gtk.TreeModelFilter( search_model, null );
 			search_filtered_model.set_visible_func( search_filter_func );
 
-			icon_view.set_model( search_filtered_model );
-			icon_view.set_text_column( 0 );
-			icon_view.set_pixbuf_column( 1 );
-			icon_view.set_tooltip_column( 2 );
+			search_icon_view.set_model( search_filtered_model );
+			search_icon_view.set_text_column( 0 );
+			search_icon_view.set_pixbuf_column( 1 );
+			search_icon_view.set_tooltip_column( 2 );
 
 			/* Set "follow-state" property of pixbuf renderer. (pre-light) */
-			List<weak Gtk.CellRenderer> renderer_list = icon_view.cell_area.get_cells();
+			List<weak Gtk.CellRenderer> renderer_list = search_icon_view.cell_area.get_cells();
 			foreach ( Gtk.CellRenderer renderer in renderer_list )
 			{
 				if ( renderer is Gtk.CellRendererPixbuf )
@@ -96,22 +239,16 @@ namespace glabels
 			foreach ( libglabels.Template template in libglabels.Db.templates )
 			{
 				Gtk.TreeIter iter;
-				model.append( out iter );
+				search_model.append( out iter );
 
 				string tooltip = build_tooltip( template );
 
-				model.set( iter,
-				           0, template.name,
-				           1, template.preview_pixbuf,
-				           2, tooltip,
-				           -1);
+				search_model.set( iter,
+				                  0, template.name,
+				                  1, template.preview_pixbuf,
+				                  2, tooltip,
+				                  -1);
 			}
-
-			/* Connect signals. */
-			search_entry.changed.connect( on_search_entry_changed );
-			search_entry.icon_release.connect( on_search_entry_clear );
-			icon_view.selection_changed.connect( on_icon_view_selection_changed );
-			icon_view.button_release_event.connect( on_icon_view_button_release_event );
 		}
 
 
@@ -136,6 +273,7 @@ namespace glabels
 		{
 			if ( search_string == "" )
 			{
+				search_filtered_model_empty = false;
 				return true;
 			}
 
@@ -148,6 +286,7 @@ namespace glabels
 
 			if ( needle in haystack )
 			{
+				search_filtered_model_empty = false;
 				return true;
 			}
 
@@ -186,13 +325,46 @@ namespace glabels
 				search_entry.secondary_icon_sensitive   = true;
 			}
 
+			search_filtered_model_empty = true;
 			search_filtered_model.refilter();
+
+			if ( search_filtered_model_empty )
+			{
+				search_info_bar.show();
+			}
+			else
+			{
+				search_info_bar.hide();
+			}
+		}
+
+
+		private void on_recent_icon_view_selection_changed()
+		{
+			List<Gtk.TreePath> list = recent_icon_view.get_selected_items();
+
+			Gtk.TreeIter iter;
+			if ( recent_model.get_iter( out iter, list.first().data ) )
+			{
+				Value value;
+				recent_model.get_value( iter, 0, out value );
+
+				template_name = value.get_string();
+			}
+		}
+
+
+		private bool on_recent_icon_view_button_release_event( Gdk.EventButton event )
+		{
+			response( Gtk.ResponseType.OK );
+			template_history.changed.disconnect( on_template_history_changed );
+			return true;
 		}
 
 
-		private void on_icon_view_selection_changed()
+		private void on_search_icon_view_selection_changed()
 		{
-			List<Gtk.TreePath> list = icon_view.get_selected_items();
+			List<Gtk.TreePath> list = search_icon_view.get_selected_items();
 
 			Gtk.TreeIter iter;
 			if ( search_filtered_model.get_iter( out iter, list.first().data ) )
@@ -205,7 +377,7 @@ namespace glabels
 		}
 
 
-		private bool on_icon_view_button_release_event( Gdk.EventButton event )
+		private bool on_search_icon_view_button_release_event( Gdk.EventButton event )
 		{
 			response( Gtk.ResponseType.OK );
 			return true;
diff --git a/glabels/template_history.vala b/glabels/template_history.vala
index 11d9c91..c609a80 100644
--- a/glabels/template_history.vala
+++ b/glabels/template_history.vala
@@ -48,14 +48,13 @@ namespace glabels
 		{
 			string[] old_templates;
 			string[] new_templates;
-			int      i, j;
 
 			old_templates = history.get_strv( "recent-templates" );
 
 			new_templates = new string[1];
-			new_templates += template_name;
+			new_templates[0] = template_name;
 
-			for ( i = 0, j = 1; (j < (max_n-1)) && (i < old_templates.length); i++ )
+			for ( int i = 0; (i < (max_n-1)) && (i < old_templates.length); i++ )
 			{
 				if ( template_name != old_templates[i] )
 				{
@@ -68,13 +67,11 @@ namespace glabels
 
 		public List<string> get_template_list()
 		{
-			string[]     templates;
 			List<string> template_list = new List<string>();
-			int          i;
 
-			templates = history.get_strv( "recent-templates" );
+			string[] templates = history.get_strv( "recent-templates" );
 
-			for ( i = 0; i < templates.length; i++ )
+			for ( int i = 0; i < templates.length; i++ )
 			{
 				template_list.append( templates[i] );
 			}



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