[Xfce4-commits] <postler:master> Implement a search option bar, shown while searching

Christian Dywan noreply at xfce.org
Sat Jun 5 17:42:01 CEST 2010


Updating branch refs/heads/master
         to ad7ddb7bbd5e9b806624245377b16069d51bcace (commit)
       from b295c4e6dfd9229c63ddd234b508e6141c93efe6 (commit)

commit ad7ddb7bbd5e9b806624245377b16069d51bcace
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Jun 4 23:32:59 2010 +0200

    Implement a search option bar, shown while searching

 postler/postler-bureau.vala   |   64 +++++++++++++++++++++++++++++++++++++----
 postler/postler-messages.vala |    9 +++--
 2 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index e27c334..ab1c712 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -18,6 +18,7 @@ public class Postler.Bureau : Gtk.Window {
     Gtk.VBox shelf;
     Gtk.Toolbar toolbar;
     Gtk.Entry search;
+    Gtk.Toolbar search_options;
     Postler.Folders folders;
     Postler.Messages messages;
     Postler.Content content;
@@ -74,6 +75,11 @@ public class Postler.Bureau : Gtk.Window {
                 <toolitem action="About"/>
                 <separator expand="true"/>
             </toolbar>
+            <toolbar name="search_options">
+                <toolitem action="SearchSubject"/>
+                <toolitem action="SearchSender"/>
+                <toolitem action="SearchRecipient"/>
+            </toolbar>
         </ui>
     """;
 
@@ -106,6 +112,36 @@ public class Postler.Bureau : Gtk.Window {
         search.grab_focus ();
     }
 
+    void action_search_options () {
+        search.activate ();
+    }
+
+    void search_entry_activated () {
+        var action = actions.get_action ("SearchSubject") as Gtk.RadioAction;
+        if (search.text == "") {
+            search_options.hide ();
+            action.set_current_value (0);
+            messages.search ("");
+            return;
+        }
+
+        switch (action.get_current_value ()) {
+        case 0:
+            messages.search (search.text, "subject");
+            break;
+        case 1:
+            messages.search (search.text, "from");
+            break;
+        case 2:
+            messages.search (search.text, "to");
+            break;
+        default:
+            assert_not_reached ();
+        }
+        messages.grab_focus ();
+        search_options.show ();
+    }
+
     void action_view_source () {
         Postler.App.spawn_module ("source", content.last_location);
     }
@@ -170,6 +206,15 @@ public class Postler.Bureau : Gtk.Window {
           false }
     };
 
+    const Gtk.RadioActionEntry[] radio_entries = {
+        { "SearchSubject", null, N_("Subject"), "",
+          N_("Search messages by subject"), 0 },
+        { "SearchSender", null, N_("Sender"), "",
+          N_("Search messages by sender"), 1 },
+        { "SearchRecipient", null, N_("Recipient"), "",
+          N_("Search messages by recipient"), 2 }
+    };
+
     static string icon_name_for_mime_type (string mime_type, Gtk.Widget widget) {
         var icon_theme = Gtk.IconTheme.get_for_screen (widget.get_screen ());
         var parts = mime_type.split ("/", 2);
@@ -202,6 +247,7 @@ public class Postler.Bureau : Gtk.Window {
         actions.set_translation_domain (Config.GETTEXT_PACKAGE);
         actions.add_actions (action_entries, this);
         actions.add_toggle_actions  (toggle_entries, this);
+        actions.add_radio_actions  (radio_entries, 0, action_search_options);
         actions.add_action (new Postler.MenuAction ("View",
             _("_View"), _("View"), Gtk.STOCK_PREFERENCES));
         ui.insert_action_group (actions, 0);
@@ -246,10 +292,7 @@ public class Postler.Bureau : Gtk.Window {
         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);
-            messages.grab_focus ();
-        } );
+        search.activate.connect (search_entry_activated);
         search.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_CLEAR);
         search.icon_release.connect ((position, event) => {
             search.text = "";
@@ -265,6 +308,13 @@ public class Postler.Bureau : Gtk.Window {
         shelf.pack_start (hpaned, true, true, 0);
         var vpaned = new Gtk.VPaned ();
         hpaned.pack2 (vpaned, false, true);
+        var messages_box = new Gtk.VBox (false, 0);
+        vpaned.pack1 (messages_box, false, true);
+        search_options = ui.get_widget ("/search_options") as Gtk.Toolbar;
+        actions.get_action ("SearchSubject").is_important = true;
+        actions.get_action ("SearchSender").is_important = true;
+        actions.get_action ("SearchRecipient").is_important = true;
+        messages_box.pack_start (search_options, false, false, 0);
         messages = new Postler.Messages ();
         messages.notify["selected-location"].connect ((object, pspec) => {
             Postler.Messages messages = object as Postler.Messages;
@@ -272,7 +322,7 @@ public class Postler.Bureau : Gtk.Window {
             actions.get_action ("MessageDelete").sensitive = state;
         });
         scrolled = new Postler.ScrolledWindow (messages);
-        vpaned.pack1 (scrolled, false, true);
+        messages_box.pack_start (scrolled, true, true, 0);
         content = new Postler.Content ();
         actions.get_action ("MessageReply").sensitive = false;
         actions.get_action ("MessageReplyAll").sensitive = false;
@@ -327,7 +377,9 @@ public class Postler.Bureau : Gtk.Window {
         scrolled = new Postler.ScrolledWindow (message_parts);
         content_box.pack_start (scrolled, false, false, 0);
         shelf.show_all ();
-        scrolled.hide ();
+
+        search_options.hide ();
+        message_parts.parent.parent.hide ();
 
         folders.set_headers_visible (false);
         messages.set_headers_visible (false);
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 3f97c50..c0e09e1 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -238,12 +238,12 @@ public class Postler.Messages : Gtk.TreeView {
         return status;
     }
 
-    public void search (string filter) {
+    public void search (string filter, string header="subject") {
         last_filter = filter;
-        populate (last_location, filter.down ());
+        populate (last_location, filter.down (), header);
     }
 
-    public bool populate (string? location, string filter="") {
+    public bool populate (string? location, string filter="", string header="subject") {
         clear ();
         sort.reset_default_sort_func ();
         if (location == null)
@@ -261,7 +261,7 @@ public class Postler.Messages : Gtk.TreeView {
             to_or_from = "from";
 
         try {
-            string filter_header = "subject";
+            string filter_header;
             string real_filter = "";
             string[] folders = {};
 
@@ -277,6 +277,7 @@ public class Postler.Messages : Gtk.TreeView {
                 folders += toplevel + "/" + search_account + "/INBOX/cur";
                 folders += toplevel + "/" + search_account + "/INBOX/new";
             } catch (GLib.KeyFileError keyfile_error) {
+                filter_header = header;
                 real_filter = last_filter;
                 folders += location + "/cur";
                 folders += location + "/new";



More information about the Xfce4-commits mailing list