[gnome-terminal] accels: Add find items to accel editor



commit 03265039060e7952669ea4d157780180b2a8d0a1
Author: Christian Persch <chpe gnome org>
Date:   Mon Feb 17 22:09:25 2014 +0100

    accels: Add find items to accel editor
    
    Also fix default accels.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723758

 src/org.gnome.Terminal.gschema.xml |   16 +++
 src/terminal-accels.c              |   12 ++
 src/terminal-search-dialog.h       |    8 ++-
 src/terminal-window.c              |  211 ++++++++++++++++++------------------
 4 files changed, 142 insertions(+), 105 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index 10705e3..94eeae9 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -383,6 +383,22 @@
       <default>'disabled'</default>
       <summary>Keyboard shortcut to reset and clear the terminal</summary>
     </key>
+    <key name="find" type="s">
+      <default>'&lt;Control&gt;&lt;Shift&gt;F'</default>
+      <summary>Keyboard shortcut to open the search dialog</summary>
+    </key>
+    <key name="find-next" type="s">
+      <default>'&lt;Control&gt;&lt;Shift&gt;G'</default>
+      <summary>Keyboard shortcut to find the next occurrence of the search term</summary>
+    </key>
+    <key name="find-previous" type="s">
+      <default>'&lt;Control&gt;&lt;Shift&gt;H'</default>
+      <summary>Keyboard shortcut to find the previous occurrence of the search term</summary>
+    </key>
+    <key name="find-clear" type="s">
+      <default>'&lt;Control&gt;&lt;Shift&gt;J'</default>
+      <summary>Keyboard shortcut to clear the find highlighting</summary>
+    </key>
     <key name="prev-tab" type="s">
       <default>'&lt;Control&gt;Page_Up'</default>
       <summary>Keyboard shortcut to switch to the previous tab</summary>
diff --git a/src/terminal-accels.c b/src/terminal-accels.c
index b782a4f..0d0a2ad 100644
--- a/src/terminal-accels.c
+++ b/src/terminal-accels.c
@@ -53,6 +53,10 @@
 #define KEY_CLOSE_WINDOW        "close-window"
 #define KEY_COPY                "copy"
 #define KEY_DETACH_TAB          "detach-tab"
+#define KEY_FIND                "find"
+#define KEY_FIND_CLEAR          "find-clear"
+#define KEY_FIND_PREV           "find-previous"
+#define KEY_FIND_NEXT           "find-next"
 #define KEY_FULL_SCREEN         "full-screen"
 #define KEY_HELP                "help"
 #define KEY_MOVE_TAB_LEFT       "move-tab-left"
@@ -124,6 +128,13 @@ static KeyEntry edit_entries[] = {
   ENTRY (N_("Paste"), KEY_PASTE, "paste", "s",  "'normal'"),
 };
 
+static KeyEntry find_entries[] = {
+  ENTRY (N_("Find"),                 KEY_FIND,       "find", "s", "'find'"    ),
+  ENTRY (N_("Find Next"),            KEY_FIND_NEXT,  "find", "s", "'next'"    ),
+  ENTRY (N_("Find Previous"),        KEY_FIND_PREV,  "find", "s", "'previous'"),
+  ENTRY (N_("Clear Find Highlight"), KEY_FIND_CLEAR, "find", "s", "'clear'"   )
+};
+
 static KeyEntry view_entries[] = {
   ENTRY (N_("Hide and Show toolbar"), KEY_TOGGLE_MENUBAR, "show-menubar", NULL, NULL),
   ENTRY (N_("Full Screen"),           KEY_FULL_SCREEN,    "fullscreen",   NULL, NULL),
@@ -176,6 +187,7 @@ static KeyEntryList all_entries[] =
   { file_entries, G_N_ELEMENTS (file_entries), N_("File") },
   { edit_entries, G_N_ELEMENTS (edit_entries), N_("Edit") },
   { view_entries, G_N_ELEMENTS (view_entries), N_("View") },
+  { find_entries, G_N_ELEMENTS (find_entries), N_("Find") },
   { terminal_entries, G_N_ELEMENTS (terminal_entries), N_("Terminal") },
   { tabs_entries, G_N_ELEMENTS (tabs_entries), N_("Tabs") },
   { help_entries, G_N_ELEMENTS (help_entries), N_("Help") }
diff --git a/src/terminal-search-dialog.h b/src/terminal-search-dialog.h
index e35f843..256b27a 100644
--- a/src/terminal-search-dialog.h
+++ b/src/terminal-search-dialog.h
@@ -24,12 +24,18 @@
 
 G_BEGIN_DECLS
 
+#define TERMINAL_TYPE_SEARCH_DIALOG         (terminal_search_dialog_get_type ())
+#define TERMINAL_SEARCH_DIALOG(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_SEARCH_DIALOG, 
TerminalSearchDialog))
+#define TERMINAL_SEARCH_DIALOG_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_SEARCH_DIALOG, 
TerminalSearchDialogClass))
+#define TERMINAL_IS_SEARCH_DIALOG(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_SEARCH_DIALOG))
+#define TERMINAL_IS_SEARCH_DIALOG_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_SEARCH_DIALOG))
+#define TERMINAL_SEARCH_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_SEARCH_DIALOG, 
TerminalSearchDialogClass))
+
 typedef enum _TerminalSearchFlags {
   TERMINAL_SEARCH_FLAG_BACKWARDS       = 1 << 0,
   TERMINAL_SEARCH_FLAG_WRAP_AROUND     = 1 << 1
 } TerminalSearchFlags;
 
-
 GtkWidget      *terminal_search_dialog_new             (GtkWindow   *parent);
 
 void            terminal_search_dialog_present         (GtkWidget   *dialog);
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 249bea8..c35907b 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -179,14 +179,6 @@ static void view_zoom_out_callback            (GtkAction *action,
                                                TerminalWindow *window);
 static void view_zoom_normal_callback         (GtkAction *action,
                                                TerminalWindow *window);
-static void search_find_callback              (GtkAction *action,
-                                               TerminalWindow *window);
-static void search_find_next_callback         (GtkAction *action,
-                                               TerminalWindow *window);
-static void search_find_prev_callback         (GtkAction *action,
-                                               TerminalWindow *window);
-static void search_clear_highlight_callback   (GtkAction *action,
-                                               TerminalWindow *window);
 static void terminal_set_title_callback       (GtkAction *action,
                                                TerminalWindow *window);
 static void terminal_add_encoding_callback    (GtkAction *action,
@@ -213,6 +205,8 @@ static gboolean find_larger_zoom_factor  (double  current,
 static gboolean find_smaller_zoom_factor (double  current,
                                           double *found);
 static void terminal_window_update_zoom_sensitivity (TerminalWindow *window);
+static void terminal_window_update_search_sensitivity (TerminalScreen *screen,
+                                                       TerminalWindow *window);
 
 static void terminal_window_show (GtkWidget *widget);
 
@@ -946,6 +940,108 @@ action_edit_profile_cb (GSimpleAction *action,
 }
 
 static void
+find_response_cb (GtkWidget *dialog,
+                  int        response,
+                  gpointer   user_data)
+{
+  TerminalWindow *window = TERMINAL_WINDOW (user_data);
+  TerminalWindowPrivate *priv = window->priv;
+  TerminalSearchFlags flags;
+  GRegex *regex;
+
+  if (response != GTK_RESPONSE_ACCEPT)
+    return;
+
+  if (G_UNLIKELY (!priv->active_screen))
+    return;
+
+  regex = terminal_search_dialog_get_regex (dialog);
+  flags = terminal_search_dialog_get_search_flags (dialog);
+
+  vte_terminal_search_set_gregex (VTE_TERMINAL (priv->active_screen), regex);
+  vte_terminal_search_set_wrap_around (VTE_TERMINAL (priv->active_screen),
+                                      (flags & TERMINAL_SEARCH_FLAG_WRAP_AROUND));
+
+  if (flags & TERMINAL_SEARCH_FLAG_BACKWARDS)
+    vte_terminal_search_find_previous (VTE_TERMINAL (priv->active_screen));
+  else
+    vte_terminal_search_find_next (VTE_TERMINAL (priv->active_screen));
+
+  terminal_window_update_search_sensitivity (priv->active_screen, window);
+}
+
+static void
+action_find_cb (GSimpleAction *action,
+                GVariant *parameter,
+                gpointer user_data)
+{
+  TerminalWindow *window = user_data;
+  TerminalWindowPrivate *priv = window->priv;
+  const char *mode;
+
+  if (G_UNLIKELY (!priv->active_screen))
+    return;
+
+  g_variant_get (parameter, "&s", &mode);
+
+  if (g_str_equal (mode, "find")) {
+    if (!priv->search_find_dialog) {
+      GtkWidget *dialog;
+
+      dialog = priv->search_find_dialog = terminal_search_dialog_new (GTK_WINDOW (window));
+
+      g_signal_connect (dialog, "destroy",
+                        G_CALLBACK (gtk_widget_destroyed), &priv->search_find_dialog);
+      g_signal_connect (dialog, "response",
+                        G_CALLBACK (find_response_cb), window);
+      /* prevent destruction */
+      g_signal_connect (dialog, "delete-event", G_CALLBACK (gtk_true), NULL);
+    }
+
+    terminal_search_dialog_present (priv->search_find_dialog);
+  } else if (g_str_equal (mode, "next")) {
+    vte_terminal_search_find_next (VTE_TERMINAL (priv->active_screen));
+  } else if (g_str_equal (mode, "previous")) {
+    vte_terminal_search_find_previous (VTE_TERMINAL (priv->active_screen));
+  } else if (g_str_equal (mode, "clear")) {
+    vte_terminal_search_set_gregex (VTE_TERMINAL (priv->active_screen), NULL);
+  } else
+    return;
+}
+
+static void
+search_find_callback (GtkAction *action,
+                     TerminalWindow *window)
+{
+  g_action_activate (g_action_map_lookup_action (G_ACTION_MAP (window), "find"),
+                     g_variant_new ("s", "find"));
+}
+
+static void
+search_find_next_callback (GtkAction *action,
+                          TerminalWindow *window)
+{
+  g_action_activate (g_action_map_lookup_action (G_ACTION_MAP (window), "find"),
+                     g_variant_new ("s", "next"));
+}
+
+static void
+search_find_prev_callback (GtkAction *action,
+                          TerminalWindow *window)
+{
+  g_action_activate (g_action_map_lookup_action (G_ACTION_MAP (window), "find"),
+                     g_variant_new ("s", "previous"));
+}
+
+static void
+search_clear_highlight_callback (GtkAction *action,
+                                TerminalWindow *window)
+{
+  g_action_activate (g_action_map_lookup_action (G_ACTION_MAP (window), "find"),
+                     g_variant_new ("s", "clear"));
+}
+
+static void
 action_toggle_state_cb (GSimpleAction *saction,
                         GVariant *parameter,
                         gpointer user_data)
@@ -2328,6 +2424,7 @@ terminal_window_init (TerminalWindow *window)
     { "set-title",           action_set_title_cb,      NULL,   NULL, NULL },
     { "zoom",                action_zoom_cb,           "i",    NULL, NULL },
     { "detach-tab",          action_detach_tab_cb,     NULL,   NULL, NULL },
+    { "find",                action_find_cb,           "s",    NULL, NULL },
     { "help",                action_help_cb,           NULL,   NULL, NULL },
     { "about",               action_about_cb,          NULL,   NULL, NULL },
     { "preferences",         action_preferences_cb,    NULL,   NULL, NULL },
@@ -2409,10 +2506,10 @@ terminal_window_init (TerminalWindow *window)
       { "SearchFind", "edit-find", N_("_Find…"), "<shift><control>F",
        NULL,
        G_CALLBACK (search_find_callback) },
-      { "SearchFindNext", NULL, N_("Find Ne_xt"), "<shift><control>H",
+      { "SearchFindNext", NULL, N_("Find Ne_xt"), "<shift><control>G",
        NULL,
        G_CALLBACK (search_find_next_callback) },
-      { "SearchFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>G",
+      { "SearchFindPrevious", NULL, N_("Find Pre_vious"), "<shift><control>H",
        NULL,
        G_CALLBACK (search_find_prev_callback) },
       { "SearchClearHighlight", NULL, N_("_Clear Highlight"), "<shift><control>J",
@@ -3672,100 +3769,6 @@ view_fullscreen_toggled_callback (GtkToggleAction *action,
 }
 
 static void
-search_find_response_callback (GtkWidget *dialog,
-                              int        response,
-                              gpointer   user_data)
-{
-  TerminalWindow *window = TERMINAL_WINDOW (user_data);
-  TerminalWindowPrivate *priv = window->priv;
-  TerminalSearchFlags flags;
-  GRegex *regex;
-
-  if (response != GTK_RESPONSE_ACCEPT)
-    return;
-
-  if (G_UNLIKELY (!priv->active_screen))
-    return;
-
-  regex = terminal_search_dialog_get_regex (dialog);
-  g_return_if_fail (regex != NULL);
-
-  flags = terminal_search_dialog_get_search_flags (dialog);
-
-  vte_terminal_search_set_gregex (VTE_TERMINAL (priv->active_screen), regex);
-  vte_terminal_search_set_wrap_around (VTE_TERMINAL (priv->active_screen),
-                                      (flags & TERMINAL_SEARCH_FLAG_WRAP_AROUND));
-
-  if (flags & TERMINAL_SEARCH_FLAG_BACKWARDS)
-    vte_terminal_search_find_previous (VTE_TERMINAL (priv->active_screen));
-  else
-    vte_terminal_search_find_next (VTE_TERMINAL (priv->active_screen));
-
-  terminal_window_update_search_sensitivity (priv->active_screen, window);
-}
-
-static gboolean
-search_dialog_delete_event_cb (GtkWidget   *widget,
-                              GdkEventAny *event,
-                              gpointer     user_data)
-{
-       /* prevent destruction */
-       return TRUE;
-}
-
-static void
-search_find_callback (GtkAction *action,
-                     TerminalWindow *window)
-{
-  TerminalWindowPrivate *priv = window->priv;
-
-  if (!priv->search_find_dialog) {
-    GtkWidget *dialog;
-
-    dialog = priv->search_find_dialog = terminal_search_dialog_new (GTK_WINDOW (window));
-
-    g_signal_connect (dialog, "destroy",
-                     G_CALLBACK (gtk_widget_destroyed), &priv->search_find_dialog);
-    g_signal_connect (dialog, "response",
-                     G_CALLBACK (search_find_response_callback), window);
-    g_signal_connect (dialog, "delete-event",
-                    G_CALLBACK (search_dialog_delete_event_cb), NULL);
-  }
-
-  terminal_search_dialog_present (priv->search_find_dialog);
-}
-
-static void
-search_find_next_callback (GtkAction *action,
-                          TerminalWindow *window)
-{
-  if (G_UNLIKELY (!window->priv->active_screen))
-    return;
-
-  vte_terminal_search_find_next (VTE_TERMINAL (window->priv->active_screen));
-}
-
-static void
-search_find_prev_callback (GtkAction *action,
-                          TerminalWindow *window)
-{
-  if (G_UNLIKELY (!window->priv->active_screen))
-    return;
-
-  vte_terminal_search_find_previous (VTE_TERMINAL (window->priv->active_screen));
-}
-
-static void
-search_clear_highlight_callback (GtkAction *action,
-                                TerminalWindow *window)
-{
-  if (G_UNLIKELY (!window->priv->active_screen))
-    return;
-
-  vte_terminal_search_set_gregex (VTE_TERMINAL (window->priv->active_screen), NULL);
-}
-
-static void
 terminal_add_encoding_callback (GtkAction *action,
                                 TerminalWindow *window)
 {


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