[gnome-terminal] Offer to open the profile preference from the info bar



commit a66cffeb8e66ee7d701bcaaef14bb5e713a60817
Author: Christian Persch <chpe gnome org>
Date:   Sun Feb 21 22:00:49 2010 +0100

    Offer to open the profile preference from the info bar
    
    When spawning the child process fails, add a button to the info bar that
    directly opens the profile editor on the command setting page.

 src/profile-editor.c  |   56 ++++++++++++++++++++++++++++++++++++++++++++----
 src/profile-editor.h  |    3 +-
 src/terminal-app.c    |   13 +++++++----
 src/terminal-app.h    |    3 +-
 src/terminal-screen.c |   23 ++++++++++++++++---
 src/terminal-window.c |    3 +-
 6 files changed, 84 insertions(+), 17 deletions(-)
---
diff --git a/src/profile-editor.c b/src/profile-editor.c
index 19f092f..11f8e81 100644
--- a/src/profile-editor.c
+++ b/src/profile-editor.c
@@ -687,9 +687,50 @@ profile_editor_destroyed (GtkWidget       *editor,
   g_object_set_data (G_OBJECT (editor), "builder", NULL);
 }
 
+static void
+terminal_profile_editor_focus_widget (GtkWidget *editor,
+                                      const char *widget_name)
+{
+  GtkBuilder *builder;
+  GtkWidget *widget, *page;
+
+  if (widget_name == NULL)
+    return;
+
+  builder = g_object_get_data (G_OBJECT (editor), "builder");
+  widget = GTK_WIDGET (gtk_builder_get_object (builder, widget_name));
+  if (widget == NULL)
+    return;
+
+  page = widget;
+  while (page && page->parent && !GTK_IS_NOTEBOOK (page->parent))
+    page = page->parent;
+
+  if (page != NULL && GTK_IS_NOTEBOOK (page->parent)) {
+    GtkNotebook *notebook;
+
+    notebook = GTK_NOTEBOOK (page->parent);
+    gtk_notebook_set_current_page (notebook, gtk_notebook_page_num (notebook, page));
+  }
+
+  if (GTK_WIDGET_IS_SENSITIVE (widget))
+    gtk_widget_grab_focus (widget);
+}
+
+/**
+ * terminal_profile_edit:
+ * @profile: a #TerminalProfile
+ * @transient_parent: a #GtkWindow, or %NULL
+ * @widget_name: a widget name in the profile editor's UI, or %NULL
+ *
+ * Shows the profile editor with @profile, anchored to @transient_parent.
+ * If @widget_name is non-%NULL, focuses the corresponding widget and
+ * switches the notebook to its containing page.
+ */
 void
 terminal_profile_edit (TerminalProfile *profile,
-                       GtkWindow       *transient_parent)
+                       GtkWindow       *transient_parent,
+                       const char      *widget_name)
 {
   char *path;
   GtkBuilder *builder;
@@ -700,6 +741,8 @@ terminal_profile_edit (TerminalProfile *profile,
   editor = g_object_get_data (G_OBJECT (profile), "editor-window");
   if (editor)
     {
+      terminal_profile_editor_focus_widget (editor, widget_name);
+
       gtk_window_set_transient_for (GTK_WINDOW (editor),
                                     GTK_WINDOW (transient_parent));
       gtk_window_present (GTK_WINDOW (editor));
@@ -801,11 +844,12 @@ terminal_profile_edit (TerminalProfile *profile,
 #define CONNECT(name, prop) CONNECT_WITH_FLAGS (name, prop, 0)
 #define SET_ENUM_VALUE(name, value) g_object_set_data (gtk_builder_get_object (builder, name), "enum-value", GINT_TO_POINTER (value))
 
-  g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "custom-command-entry")),
-                    "changed",
+  w = GTK_WIDGET (gtk_builder_get_object (builder, "custom-command-entry"));
+  custom_command_entry_changed_cb (GTK_ENTRY (w));
+  g_signal_connect (w, "changed",
                     G_CALLBACK (custom_command_entry_changed_cb), NULL);
-  g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "profile-name-entry")),
-                    "changed",
+  w = GTK_WIDGET (gtk_builder_get_object (builder, "profile-name-entry"));
+  g_signal_connect (w, "changed",
                     G_CALLBACK (visible_name_entry_changed_cb), editor);
 
   g_signal_connect (gtk_builder_get_object  (builder, "reset-compat-defaults-button"),
@@ -866,6 +910,8 @@ terminal_profile_edit (TerminalProfile *profile,
                     G_CALLBACK (profile_forgotten_cb),
                     editor);
 
+  terminal_profile_editor_focus_widget (editor, widget_name);
+
   gtk_window_set_transient_for (GTK_WINDOW (editor),
                                 GTK_WINDOW (transient_parent));
   gtk_window_present (GTK_WINDOW (editor));
diff --git a/src/profile-editor.h b/src/profile-editor.h
index 0478f48..2ed92b6 100644
--- a/src/profile-editor.h
+++ b/src/profile-editor.h
@@ -26,7 +26,8 @@
 G_BEGIN_DECLS
 
 void terminal_profile_edit (TerminalProfile *profile,
-                            GtkWindow       *transient_parent);
+                            GtkWindow       *transient_parent,
+                            const char      *widget_name);
 
 G_END_DECLS
 
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 66c220b..39ea6bc 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -686,7 +686,8 @@ profile_list_edit_button_clicked_cb (GtkWidget *button,
   gtk_tree_model_get (model, &iter, (int) COL_PROFILE, &selected_profile, (int) -1);
 
   terminal_app_edit_profile (app, selected_profile,
-                             GTK_WINDOW (app->manage_profiles_dialog));
+                             GTK_WINDOW (app->manage_profiles_dialog),
+                             NULL);
   g_object_unref (selected_profile);
 }
 
@@ -711,7 +712,8 @@ profile_list_row_activated_cb (GtkTreeView       *tree_view,
   gtk_tree_model_get (model, &iter, (int) COL_PROFILE, &selected_profile, (int) -1);
 
   terminal_app_edit_profile (app, selected_profile,
-                             GTK_WINDOW (app->manage_profiles_dialog));
+                             GTK_WINDOW (app->manage_profiles_dialog),
+                             NULL);
   g_object_unref (selected_profile);
 }
 
@@ -1139,7 +1141,7 @@ new_profile_response_cb (GtkWidget *new_profile_dialog,
                              list,
                              NULL);
 
-      terminal_profile_edit (new_profile, transient_parent);
+      terminal_profile_edit (new_profile, transient_parent, NULL);
 
     cleanup:
       g_free (name);
@@ -1876,9 +1878,10 @@ terminal_app_new_terminal (TerminalApp     *app,
 void
 terminal_app_edit_profile (TerminalApp     *app,
                            TerminalProfile *profile,
-                           GtkWindow       *transient_parent)
+                           GtkWindow       *transient_parent,
+                           const char      *widget_name)
 {
-  terminal_profile_edit (profile, transient_parent);
+  terminal_profile_edit (profile, transient_parent, widget_name);
 }
 
 void
diff --git a/src/terminal-app.h b/src/terminal-app.h
index 1c82f50..300d91a 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -96,7 +96,8 @@ gboolean terminal_app_handle_options (TerminalApp *app,
 
 void terminal_app_edit_profile (TerminalApp     *app,
                                 TerminalProfile *profile,
-                                GtkWindow       *transient_parent);
+                                GtkWindow       *transient_parent,
+                                const char      *widget_name);
 
 void terminal_app_new_profile (TerminalApp     *app,
                                TerminalProfile *default_base_profile,
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 0e78097..b0f12aa 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1411,20 +1411,34 @@ get_child_environment (TerminalScreen *screen,
 
 #if GTK_CHECK_VERSION (2, 18, 0)
 
+enum {
+  RESPONSE_RETRY,
+  RESPONSE_EDIT_PROFILE
+};
+
 static void
 info_bar_response_cb (GtkWidget *info_bar,
                       int response,
                       TerminalScreen *screen)
 {
-  gtk_widget_destroy (info_bar);
-
   switch (response) {
     case GTK_RESPONSE_CANCEL:
+      gtk_widget_destroy (info_bar);
       g_signal_emit (screen, signals[CLOSE_SCREEN], 0);
       break;
-    case GTK_RESPONSE_ACCEPT:
+    case RESPONSE_RETRY:
+      gtk_widget_destroy (info_bar);
       terminal_screen_launch_child_on_idle (screen);
       break;
+    case RESPONSE_EDIT_PROFILE:
+      terminal_app_edit_profile (terminal_app_get (),
+                                 terminal_screen_get_profile (screen),
+                                 GTK_WINDOW (terminal_screen_get_window (screen)),
+                                 "custom-command-entry");
+      break;
+    default:
+      gtk_widget_destroy (info_bar);
+      break;
   }
 }
 
@@ -1478,7 +1492,8 @@ terminal_screen_launch_child_cb (TerminalScreen *screen)
     GtkWidget *info_bar;
 
     info_bar = terminal_info_bar_new (GTK_MESSAGE_ERROR,
-                                      _("Retry"), GTK_RESPONSE_ACCEPT,
+                                      _("_Profile Preferences"), RESPONSE_EDIT_PROFILE,
+                                      _("_Retry"), RESPONSE_RETRY,
                                       NULL);
     terminal_info_bar_format_text (TERMINAL_INFO_BAR (info_bar),
                                    _("There was an error creating the child process for this terminal"));
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 3479ca2..fa4ca84 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3299,7 +3299,8 @@ edit_current_profile_callback (GtkAction *action,
   
   terminal_app_edit_profile (terminal_app_get (),
                              terminal_screen_get_profile (priv->active_screen),
-                             GTK_WINDOW (window));
+                             GTK_WINDOW (window),
+                             NULL);
 }
 
 static void



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