[Xfce4-commits] <postler:master> Implement 'Find' as an entry in the toolbar

Christian Dywan noreply at xfce.org
Sat May 29 04:18:02 CEST 2010


Updating branch refs/heads/master
         to 070767e4257ba1baec646517ea4d0ded95d043c9 (commit)
       from 2f3988646324e0688a278d0bcedb63a7f15b7eb3 (commit)

commit 070767e4257ba1baec646517ea4d0ded95d043c9
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat May 29 02:14:45 2010 +0200

    Implement 'Find' as an entry in the toolbar

 postler/postler-bureau.vala   |   23 ++++++++++++++++++++---
 postler/postler-messages.vala |   15 ++++++++++++++-
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 239243c..526bc2d 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -16,7 +16,8 @@ public class Postler.Bureau : Gtk.Window {
     Gtk.ActionGroup actions;
 
     Gtk.VBox shelf;
-    Gtk.Widget toolbar;
+    Gtk.Toolbar toolbar;
+    Gtk.Entry search;
     Postler.Folders folders;
     Postler.Messages messages;
     Postler.Content content;
@@ -40,6 +41,8 @@ public class Postler.Bureau : Gtk.Window {
                 <menu action="Edit">
                     <menuitem action="HideRead"/>
                     <separator/>
+                    <menuitem action="Search"/>
+                    <separator/>
                     <menuitem action="Preferences"/>
                 </menu>
                 <menu action="Help">
@@ -64,6 +67,7 @@ public class Postler.Bureau : Gtk.Window {
                 </toolitem>
                 <separator/>
                 <toolitem action="About"/>
+                <separator expand="true"/>
             </toolbar>
         </ui>
     """;
@@ -93,6 +97,10 @@ public class Postler.Bureau : Gtk.Window {
         /* TODO */
     }
 
+    void action_search () {
+        search.grab_focus ();
+    }
+
     void action_preferences () {
         /* TODO */
     }
@@ -136,6 +144,8 @@ public class Postler.Bureau : Gtk.Window {
         { "Quit", Gtk.STOCK_QUIT, null, "<Ctrl>q",
           N_("Quit the application"), action_quit },
         { "Edit", null, N_("_Edit") },
+        { "Search", Gtk.STOCK_FIND, null, "<Ctrl>s",
+          N_("Search the selected folder"), action_search },
         { "Preferences", Gtk.STOCK_PREFERENCES, null, "<Ctrl><Alt>p",
           N_("Configure the application preferences"), action_preferences },
         { "Help", null, N_("_Help") },
@@ -180,9 +190,16 @@ public class Postler.Bureau : Gtk.Window {
         /* The menubar is nice for globalmenu, but otherwise redundant */
         menubar.set_no_show_all (true);
         shelf.pack_start (menubar, false, false, 0);
-        toolbar = ui.get_widget ("/toolbar");
+        toolbar = ui.get_widget ("/toolbar") as Gtk.Toolbar;
         actions.get_action ("MessageNew").is_important = true;
-        /* TODO: Put a search entry in the toolbar */
+        var toolitem = new Gtk.ToolItem ();
+        toolbar.insert (toolitem, -1);
+        search = new Gtk.Entry ();
+        /* FIXME: icons are available since GTK+ 2.16 */
+        search.set_icon_from_stock (Gtk.EntryIconPosition.PRIMARY, Gtk.STOCK_FIND);
+        search.activate.connect ((search) => {messages.search (search.text); } );
+        toolitem.add (search);
+        toolitem.show_all ();
         shelf.pack_start (toolbar, false, false, 0);
         var hpaned = new Gtk.HPaned ();
         folders = new Postler.Folders ();
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 960ccc0..b8c6264 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -19,6 +19,9 @@ public class Postler.Messages : Gtk.TreeView {
     public bool hide_read { get; set; }
     public string? selected_location { get; set; }
 
+    string last_location;
+    string last_filter;
+
     enum Columns {
         FLAGGED,
         STATUS,
@@ -134,11 +137,18 @@ public class Postler.Messages : Gtk.TreeView {
         return GLib.Time.local (timestamp).format ("%x %X");
     }
 
-    public bool populate (string? location) {
+    public void search (string filter) {
+        last_filter = filter;
+        populate (last_location, last_filter);
+    }
+
+    public bool populate (string? location, string? filter=null) {
         clear ();
         sort.reset_default_sort_func ();
         if (location == null)
             return true;
+        if (filter != null)
+            last_filter = filter;
         try {
             string[] folders = { "cur", "new" };
             foreach (var folder in folders) {
@@ -219,6 +229,8 @@ public class Postler.Messages : Gtk.TreeView {
 
                     string charset = null;
                     string real_subject = parse_encoded (subject, out charset);
+                    if (last_filter != null && !(last_filter in real_subject))
+                        continue;
                     store.insert_with_values (out account_iter, null, -1,
                         Columns.FLAGGED, flagged,
                         Columns.STATUS, status,
@@ -244,6 +256,7 @@ public class Postler.Messages : Gtk.TreeView {
                     scroll_to_cell (sort.get_path (sort_iter), null, false, 0, 0);
                 }
             }
+            last_location = location;
         } catch (GLib.Error error) {
             GLib.critical (_("Failed to read folder \"%s\": %s"),
                 location, error.message);



More information about the Xfce4-commits mailing list