[gnome-system-monitor] Focus the search bar again with Ctrl+F (bgo#711381)



commit a0ece20c315e2497416d73221c077eb0a26c8d02
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Feb 28 12:52:27 2014 +0200

    Focus the search bar again with Ctrl+F (bgo#711381)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711381
    
    Focus the search bar again if the search bar is shown and Ctrl+F is
    pressed, instead of having to press Ctrl+F twice to hide and show it
    again for another search.

 data/interface.ui   |    2 ++
 src/application.cpp |    8 ++++----
 src/application.h   |    1 +
 src/interface.cpp   |   27 +++++++++++++++++++++------
 4 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
index a672f14..cfddb20 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -44,8 +44,10 @@
         <child>
           <object class="GtkToggleButton" id="search_button">
             <property name="visible">True</property>
+            <property name="active">False</property>
             <property name="valign">center</property>
             <property name="action_name">win.search</property>
+            <property name="action_target">@b false</property>
             <style>
               <class name="image-button"/>
             </style>
diff --git a/src/application.cpp b/src/application.cpp
index 02d8e23..d05db25 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -395,14 +395,14 @@ void GsmApplication::on_startup()
     set_app_menu (menu);
 
     add_accelerator("<Primary>d", "win.show-dependencies", NULL);
-    add_accelerator("<Primary>s", "win.send-signal-stop", g_variant_new_int32(SIGSTOP));
-    add_accelerator("<Primary>c", "win.send-signal-cont", g_variant_new_int32(SIGCONT));
-    add_accelerator("<Primary>e", "win.send-signal-end", g_variant_new_int32(SIGTERM));
+    add_accelerator("<Primary>s", "win.send-signal-stop", g_variant_new_int32 (SIGSTOP));
+    add_accelerator("<Primary>c", "win.send-signal-cont", g_variant_new_int32 (SIGCONT));
+    add_accelerator("<Primary>e", "win.send-signal-end", g_variant_new_int32 (SIGTERM));
     add_accelerator("<Primary>k", "win.send-signal-kill", g_variant_new_int32 (SIGKILL));
     add_accelerator("<Primary>m", "win.memory-maps", NULL);
     add_accelerator("<Primary>o", "win.open-files", NULL);
     add_accelerator("<Alt>Return", "win.process-properties", NULL);
-    add_accelerator("<Primary>f", "win.search", NULL);
+    add_accelerator("<Primary>f", "win.search", g_variant_new_boolean (TRUE));
 
     Gtk::Window::set_default_icon_name ("utilities-system-monitor");
 
diff --git a/src/application.h b/src/application.h
index 5767a2b..fd94b28 100644
--- a/src/application.h
+++ b/src/application.h
@@ -166,6 +166,7 @@ public:
     GtkWidget        *end_process_button;
     GtkWidget        *search_button;
     GtkWidget        *search_entry;
+    GtkWidget        *search_bar;
     ProcConfig        config;
     LoadGraph        *cpu_graph;
     LoadGraph        *mem_graph;
diff --git a/src/interface.cpp b/src/interface.cpp
index efe041b..e43a55a 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -82,16 +82,16 @@ create_proc_view(GsmApplication *app, GtkBuilder * builder)
     app->popup_menu = gtk_menu_new_from_model (menu_model);
     gtk_menu_attach_to_widget (GTK_MENU (app->popup_menu), app->main_window, NULL);
     
-    GtkSearchBar *search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (builder, "proc_searchbar"));
+    app->search_bar = GTK_WIDGET (gtk_builder_get_object (builder, "proc_searchbar"));
     app->search_entry = GTK_WIDGET (gtk_builder_get_object (builder, "proc_searchentry"));
     
-    gtk_search_bar_connect_entry (search_bar, GTK_ENTRY (app->search_entry));
+    gtk_search_bar_connect_entry (GTK_SEARCH_BAR(app->search_bar), GTK_ENTRY (app->search_entry));
     g_signal_connect (app->main_window, "key-press-event",
-                      G_CALLBACK (cb_window_key_press_event), search_bar);
+                      G_CALLBACK (cb_window_key_press_event), app->search_bar);
                   
     g_signal_connect (app->search_entry, "changed", G_CALLBACK (search_text_changed), app);
 
-    g_object_bind_property (app->search_button, "active", search_bar, "search-mode-enabled", 
G_BINDING_BIDIRECTIONAL);
+    g_object_bind_property (app->search_bar, "search-mode-enabled", app->search_button, "active", 
(GBindingFlags)(G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE));
 }
 
 void
@@ -447,7 +447,22 @@ static void
 on_activate_toggle (GSimpleAction *action, GVariant *parameter, gpointer data)
 {
     GVariant *state = g_action_get_state (G_ACTION (action));
-    g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
+    g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));    
+    g_variant_unref (state);
+}
+
+static void
+on_activate_search (GSimpleAction *action, GVariant *parameter, gpointer data)
+{
+    GsmApplication *app = (GsmApplication *) data;
+    GVariant *state = g_action_get_state (G_ACTION (action));
+    gboolean is_search_shortcut = g_variant_get_boolean (parameter);
+    gboolean is_search_bar = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (app->search_bar));
+    if (is_search_shortcut && is_search_bar) {
+        gtk_widget_grab_focus (app->search_entry);
+    } else {
+        g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
+    }
     g_variant_unref (state);
 }
 
@@ -641,7 +656,7 @@ create_main_window (GsmApplication *app)
 
     GActionEntry win_action_entries[] = {
         { "about", on_activate_about, NULL, NULL, NULL },
-        { "search", on_activate_toggle, NULL, "false", NULL },
+        { "search", on_activate_search, "b", "false", NULL },
         { "send-signal-stop", on_activate_send_signal, "i", NULL, NULL },
         { "send-signal-cont", on_activate_send_signal, "i", NULL, NULL },
         { "send-signal-end", on_activate_send_signal, "i", NULL, NULL },


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