[gnome-terminal/wip/rishi/preserve-working-directory] profile: editor: Add setting to preserve the working directory
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/wip/rishi/preserve-working-directory] profile: editor: Add setting to preserve the working directory
- Date: Fri, 24 May 2019 15:15:13 +0000 (UTC)
commit fe2f99b58c6c68315f9c00f4d85a81e5a51fa182
Author: Debarshi Ray <debarshir gnome org>
Date: Fri May 24 17:14:19 2019 +0200
profile: editor: Add setting to preserve the working directory
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/126
src/org.gnome.Terminal.gschema.xml | 5 ++++
src/preferences.ui | 27 +++++++++++++----
src/profile-editor.c | 60 ++++++++++++++++++++++++++++++++++++++
src/terminal-schemas.h | 1 +
src/terminal-screen.c | 32 +++++++++++++++++---
5 files changed, 115 insertions(+), 10 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index e4e0c003..39ac8827 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -247,6 +247,11 @@
<summary>Whether to launch the command in the terminal as a login shell</summary>
<description>If true, the command inside the terminal will be launched as a login shell (argv[0] will
have a hyphen in front of it).</description>
</key>
+ <key name="preserve-working-directory" type="mb">
+ <default>nothing</default>
+ <summary>Whether to preserve the working directory when opening a new terminal</summary>
+ <description>If true, when opening a new terminal from a previous one the working directory of the
older terminal is carried over to the new one.</description>
+ </key>
<key name="use-custom-command" type="b">
<default>false</default>
<summary>Whether to run a custom command instead of the shell</summary>
diff --git a/src/preferences.ui b/src/preferences.ui
index f42b652c..a7bf9d36 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -1817,6 +1817,21 @@
<property name="border_width">12</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="preserve-working-directory-checkbutton">
+ <property name="label" translatable="yes">_Preserve working
directory</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">0</property>
+ <property name="left_attach">0</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
<child>
<object class="GtkCheckButton" id="login-shell-checkbutton">
<property name="label" translatable="yes">_Run command as a login
shell</property>
@@ -1827,7 +1842,7 @@
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="top_attach">0</property>
+ <property name="top_attach">1</property>
<property name="left_attach">0</property>
<property name="width">2</property>
</packing>
@@ -1842,7 +1857,7 @@
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="top_attach">1</property>
+ <property name="top_attach">2</property>
<property name="left_attach">0</property>
<property name="width">2</property>
</packing>
@@ -1857,7 +1872,7 @@
<property name="xalign">0</property>
</object>
<packing>
- <property name="top_attach">2</property>
+ <property name="top_attach">3</property>
<property name="left_attach">0</property>
</packing>
</child>
@@ -1868,7 +1883,7 @@
<property name="hexpand">True</property>
</object>
<packing>
- <property name="top_attach">2</property>
+ <property name="top_attach">3</property>
<property name="left_attach">1</property>
</packing>
</child>
@@ -1882,7 +1897,7 @@
<property name="xalign">0</property>
</object>
<packing>
- <property name="top_attach">3</property>
+ <property name="top_attach">4</property>
<property name="left_attach">0</property>
</packing>
</child>
@@ -1901,7 +1916,7 @@
</child>
</object>
<packing>
- <property name="top_attach">3</property>
+ <property name="top_attach">4</property>
<property name="left_attach">1</property>
</packing>
</child>
diff --git a/src/profile-editor.c b/src/profile-editor.c
index 1912c8cf..4612a2cf 100644
--- a/src/profile-editor.c
+++ b/src/profile-editor.c
@@ -639,6 +639,57 @@ init_encodings_combo (GtkWidget *widget)
"text", ENCODINGS_COLUMN_TEXT, NULL);
}
+static void
+init_preserve_working_directory (GSettings *profile)
+{
+ gs_unref_variant GVariant *preserve_working_directory_setting = NULL;
+ gs_unref_variant GVariant *preserve_working_directory_without_maybe = NULL;
+
+ preserve_working_directory_setting = g_settings_get_value (profile,
+
TERMINAL_PROFILE_PRESERVE_WORKING_DIRECTORY_KEY);
+ preserve_working_directory_without_maybe = g_variant_get_maybe (preserve_working_directory_setting);
+ g_message ("init: %p", preserve_working_directory_without_maybe);
+ if (preserve_working_directory_without_maybe == NULL)
+ {
+ GVariant *variant;
+ GVariant *variant_without_maybe;
+ gboolean use_custom_command;
+
+ use_custom_command = g_settings_get_boolean (profile, TERMINAL_PROFILE_USE_CUSTOM_COMMAND_KEY);
+ variant_without_maybe = g_variant_new_boolean (!use_custom_command);
+ variant = g_variant_new_maybe (G_VARIANT_TYPE_BOOLEAN, variant_without_maybe);
+ g_settings_set_value (profile, TERMINAL_PROFILE_PRESERVE_WORKING_DIRECTORY_KEY, variant);
+ }
+}
+
+/* static gboolean */
+/* preserve_working_directory_to_bool (GValue *value, */
+/* GVariant *variant, */
+/* gpointer user_data) */
+/* { */
+/* GSettings *profile = G_SETTINGS (user_data); */
+/* gs_unref_variant GVariant *variant_without_maybe = NULL; */
+/* gboolean preserve_working_directory; */
+
+/* variant_without_maybe = g_variant_get_maybe (variant); */
+/* if (variant_without_maybe == NULL) */
+/* preserve_working_directory = !g_settings_get_boolean (profile,
TERMINAL_PROFILE_USE_CUSTOM_COMMAND_KEY); */
+/* else */
+/* preserve_working_directory = g_variant_get_boolean (variant_without_maybe); */
+
+/* g_value_set_boolean (value, preserve_working_directory); */
+
+/* return TRUE; */
+/* } */
+
+/* static GVariant * */
+/* bool_to_preserve_working_directory (const GValue *value, */
+/* const GVariantType *expected_type, */
+/* gpointer user_data) */
+/* { */
+/* return g_variant_new_boolean (g_value_get_boolean (value)); */
+/* } */
+
static gboolean
s_to_rgba (GValue *value,
GVariant *variant,
@@ -1201,10 +1252,19 @@ profile_prefs_load (const char *uuid, GSettings *profile)
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET |
G_SETTINGS_BIND_INVERT_BOOLEAN);
+
+ init_preserve_working_directory (profile);
profile_prefs_settings_bind (profile, TERMINAL_PROFILE_USE_CUSTOM_COMMAND_KEY,
gtk_builder_get_object (builder,
"use-custom-command-checkbutton"),
"active", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+ profile_prefs_settings_bind (profile,
+ TERMINAL_PROFILE_PRESERVE_WORKING_DIRECTORY_KEY,
+ gtk_builder_get_object (builder,
+ "preserve-working-directory-checkbutton"),
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
profile_prefs_settings_bind (profile, TERMINAL_PROFILE_USE_THEME_COLORS_KEY,
gtk_builder_get_object (builder,
"use-theme-colors-checkbutton"),
diff --git a/src/terminal-schemas.h b/src/terminal-schemas.h
index ef30bd59..bd091051 100644
--- a/src/terminal-schemas.h
+++ b/src/terminal-schemas.h
@@ -59,6 +59,7 @@ G_BEGIN_DECLS
#define TERMINAL_PROFILE_LOGIN_SHELL_KEY "login-shell"
#define TERMINAL_PROFILE_NAME_KEY "name"
#define TERMINAL_PROFILE_PALETTE_KEY "palette"
+#define TERMINAL_PROFILE_PRESERVE_WORKING_DIRECTORY_KEY "preserve-working-directory"
#define TERMINAL_PROFILE_REWRAP_ON_RESIZE_KEY "rewrap-on-resize"
#define TERMINAL_PROFILE_SCROLLBACK_LINES_KEY "scrollback-lines"
#define TERMINAL_PROFILE_SCROLLBACK_UNLIMITED_KEY "scrollback-unlimited"
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 23134e80..41f9fbcc 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1372,6 +1372,33 @@ spawn_result_cb (VteTerminal *terminal,
}
}
+static gboolean
+terminal_screen_get_preserve_working_directory (TerminalScreen *screen)
+{
+ TerminalScreenPrivate *priv = screen->priv;
+ gs_unref_variant GVariant *preserve_working_directory_setting = NULL;
+ gs_unref_variant GVariant *preserve_working_directory_without_maybe = NULL;
+ gboolean preserve_working_directory;
+
+ preserve_working_directory_setting = g_settings_get_value (priv->profile,
+
TERMINAL_PROFILE_PRESERVE_WORKING_DIRECTORY_KEY);
+ preserve_working_directory_without_maybe = g_variant_get_maybe (preserve_working_directory_setting);
+ if (preserve_working_directory_without_maybe == NULL)
+ {
+ gboolean use_custom_command;
+
+ use_custom_command = g_settings_get_boolean (priv->profile, TERMINAL_PROFILE_USE_CUSTOM_COMMAND_KEY);
+ preserve_working_directory = !use_custom_command;
+ }
+ else
+ {
+ preserve_working_directory = g_variant_get_boolean (preserve_working_directory_without_maybe);
+ }
+
+ g_message ("screen: %d", preserve_working_directory);
+ return preserve_working_directory;
+}
+
static gboolean
terminal_screen_do_exec (TerminalScreen *screen,
FDSetupData *data /* adopting */,
@@ -1379,7 +1406,6 @@ terminal_screen_do_exec (TerminalScreen *screen,
{
TerminalScreenPrivate *priv = screen->priv;
VteTerminal *terminal = VTE_TERMINAL (screen);
- GSettings *profile;
char **env, **argv;
char *shell = NULL;
const char *working_dir;
@@ -1400,10 +1426,8 @@ terminal_screen_do_exec (TerminalScreen *screen,
"[screen %p] now launching the child process\n",
screen);
- profile = priv->profile;
-
if (priv->initial_working_directory &&
- !g_settings_get_boolean (profile, TERMINAL_PROFILE_USE_CUSTOM_COMMAND_KEY))
+ terminal_screen_get_preserve_working_directory (screen))
working_dir = priv->initial_working_directory;
else
working_dir = g_get_home_dir ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]