[Xfce4-commits] [apps/xfce4-terminal] 01/01: Expose default terminal directory setting to Preferences

noreply at xfce.org noreply at xfce.org
Tue Sep 12 01:54:20 CEST 2017


This is an automated email from the git hooks/post-receive script.

f   2   4   0   4       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-terminal.

commit 8060658be0227dc64bf25bec64770dd755026ad1
Author: Igor <f2404 at yandex.ru>
Date:   Mon Sep 11 19:51:07 2017 -0400

    Expose default terminal directory setting to Preferences
    
    New terminals (tabs or windows) will use it as their working directory if
    it's set; current working directory will be used otherwise.
    Note: MiscDefaultWorkingDir has been renamed to DefaultWorkingDir;
    UseDefaultWorkingDir checkbox added.
---
 terminal/terminal-preferences-dialog.c | 11 ++++++-
 terminal/terminal-preferences.c        | 33 ++++++++++++-------
 terminal/terminal-preferences.glade    | 44 +++++++++++++++++++++++++
 terminal/terminal-window.c             | 59 +++++++++++++++++++---------------
 4 files changed, 109 insertions(+), 38 deletions(-)

diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index 7fa4bbe..86970e5 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -140,7 +140,7 @@ terminal_preferences_dialog_init (TerminalPreferencesDialog *dialog)
   gchar            *current;
   GtkTreeIter       current_iter;
   const gchar      *props_active[] = { "title-mode", "command-login-shell",
-                                       "run-custom-command",
+                                       "run-custom-command", "use-default-working-dir",
                                        "scrolling-on-output", "scrolling-on-keystroke",
                                        "scrolling-bar", "scrolling-unlimited",
                                        "misc-cursor-shape", "misc-cursor-blinks",
@@ -250,6 +250,7 @@ error:
   BIND_PROPERTIES ("font-name", "font-name");
   BIND_PROPERTIES ("title-initial", "text");
   BIND_PROPERTIES ("custom-command", "text");
+  BIND_PROPERTIES ("default-working-dir", "text");
   BIND_PROPERTIES ("word-chars", "text");
   BIND_PROPERTIES ("scrolling-lines", "value");
   BIND_PROPERTIES ("tab-activity-timeout", "value");
@@ -264,6 +265,14 @@ error:
                           object2, "sensitive",
                           G_BINDING_SYNC_CREATE);
 
+  /* working directory button */
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "use-default-working-dir");
+  object2 = gtk_builder_get_object (GTK_BUILDER (dialog), "default-working-dir");
+  terminal_return_if_fail (G_IS_OBJECT (object) && G_IS_OBJECT (object2));
+  g_object_bind_property (object, "active",
+                          object2, "sensitive",
+                          G_BINDING_SYNC_CREATE);
+
   /* unlimited scrollback button */
   object = gtk_builder_get_object (GTK_BUILDER (dialog), "scrolling-unlimited");
   object2 = gtk_builder_get_object (GTK_BUILDER (dialog), "scrolling-lines");
diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index 8a8fdb6..7accf1d 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -103,7 +103,8 @@ enum
   PROP_MISC_HIGHLIGHT_URLS,
   PROP_MISC_MIDDLE_CLICK_OPENS_URI,
   PROP_MISC_COPY_ON_SELECT,
-  PROP_MISC_DEFAULT_WORKING_DIR,
+  PROP_USE_DEFAULT_WORKING_DIR,
+  PROP_DEFAULT_WORKING_DIR,
   PROP_MISC_REWRAP_ON_RESIZE,
   PROP_MISC_USE_SHIFT_ARROWS_TO_SCROLL,
   PROP_MISC_SLIM_TABS,
@@ -576,6 +577,26 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
+   * TerminalPreferences:use-default-working-dir:
+   **/
+  preferences_props[PROP_USE_DEFAULT_WORKING_DIR] =
+      g_param_spec_boolean ("use-default-working-dir",
+                            NULL,
+                            "UseDefaultWorkingDir",
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  /**
+   * TerminalPreferences:default-working-dir:
+   **/
+  preferences_props[PROP_DEFAULT_WORKING_DIR] =
+      g_param_spec_string ("default-working-dir",
+                           NULL,
+                           "DefaultWorkingDir",
+                           "",
+                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  /**
    * TerminalPreferences:dropdown-animation-time:
    **/
   preferences_props[PROP_DROPDOWN_ANIMATION_TIME] =
@@ -951,16 +972,6 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   /**
-   * TerminalPreferences:misc-default-working-dir:
-   **/
-  preferences_props[PROP_MISC_DEFAULT_WORKING_DIR] =
-      g_param_spec_string ("misc-default-working-dir",
-                           NULL,
-                           "MiscDefaultWorkingDir",
-                           "",
-                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
-  /**
    * TerminalPreferences:misc-rewrap-on-resize:
    **/
   preferences_props[PROP_MISC_REWRAP_ON_RESIZE] =
diff --git a/terminal/terminal-preferences.glade b/terminal/terminal-preferences.glade
index 72aea9b..af31000 100644
--- a/terminal/terminal-preferences.glade
+++ b/terminal/terminal-preferences.glade
@@ -474,6 +474,50 @@
                                 <property name="position">2</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkBox" id="hbox10">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="tooltip_text" translatable="yes">Select this option to make new terminals (tabs or windows) use custom working directory. Otherwise, current working directory will be used.</property>
+                                <property name="spacing">12</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="use-default-working-dir">
+                                    <property name="label" translatable="yes">_Working directory:</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="halign">start</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="default-working-dir">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="hexpand">True</property>
+                                    <property name="invisible_char">•</property>
+                                    <property name="primary_icon_activatable">False</property>
+                                    <property name="secondary_icon_activatable">False</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">3</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index 72c15b8..e62cd3c 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -1554,26 +1554,40 @@ terminal_window_action_set_encoding (GtkAction      *action,
 
 
 
+static gchar *
+terminal_window_get_working_directory (TerminalWindow *window)
+{
+  gchar    *default_dir;
+  gboolean  use_default_dir;
+
+  g_object_get (G_OBJECT (window->priv->preferences),
+                "use-default-working-dir", &use_default_dir,
+                "default-working-dir", &default_dir,
+                NULL);
+
+  if (use_default_dir && g_strcmp0 (default_dir, "") != 0)
+    return default_dir;
+
+  if (G_LIKELY (window->priv->active != NULL))
+    return g_strdup (terminal_screen_get_working_directory (window->priv->active));
+
+  return NULL;
+}
+
+
+
 static void
 terminal_window_action_new_tab (GtkAction      *action,
                                 TerminalWindow *window)
 {
-  const gchar    *directory = NULL;
-  gchar          *default_dir;
-  TerminalScreen *terminal;
-
-  terminal = TERMINAL_SCREEN (g_object_new (TERMINAL_TYPE_SCREEN, NULL));
-  g_object_get (G_OBJECT (window->priv->preferences), "misc-default-working-dir", &default_dir, NULL);
-
-  if (g_strcmp0 (default_dir, "") != 0)
-    directory = default_dir;
-  else if (G_LIKELY (window->priv->active != NULL))
-    directory = terminal_screen_get_working_directory (window->priv->active);
+  TerminalScreen *terminal = TERMINAL_SCREEN (g_object_new (TERMINAL_TYPE_SCREEN, NULL));
+  gchar          *directory = terminal_window_get_working_directory (window);
 
   if (directory != NULL)
-    terminal_screen_set_working_directory (terminal, directory);
-
-  g_free (default_dir);
+    {
+      terminal_screen_set_working_directory (terminal, directory);
+      g_free (directory);
+    }
 
   terminal_window_add (window, terminal);
   terminal_screen_launch_child (terminal);
@@ -1585,20 +1599,13 @@ static void
 terminal_window_action_new_window (GtkAction      *action,
                                    TerminalWindow *window)
 {
-  const gchar *directory = NULL;
-  gchar       *default_dir;
-
-  g_object_get (G_OBJECT (window->priv->preferences), "misc-default-working-dir", &default_dir, NULL);
-
-  if (g_strcmp0 (default_dir, "") != 0)
-    directory = default_dir;
-  else if (G_LIKELY (window->priv->active != NULL))
-    directory = terminal_screen_get_working_directory (window->priv->active);
+  gchar *directory = terminal_window_get_working_directory (window);
 
   if (directory != NULL)
-    g_signal_emit (G_OBJECT (window), window_signals[NEW_WINDOW], 0, directory);
-
-  g_free (default_dir);
+    {
+      g_signal_emit (G_OBJECT (window), window_signals[NEW_WINDOW], 0, directory);
+      g_free (directory);
+    }
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list