[gnome-terminal] all: Add pref for position of newly added tabs
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] all: Add pref for position of newly added tabs
- Date: Wed, 20 Nov 2019 22:13:55 +0000 (UTC)
commit 56cd640a2d7f861d537aa8dff65d12f312a1fb98
Author: Egmont Koblinger <egmont gmail com>
Date: Wed Nov 20 23:12:53 2019 +0100
all: Add pref for position of newly added tabs
Add a setting and prefs UI for where to put newly opened tabs, instead
of always adding them to the end.
https://bugzilla.gnome.org/show_bug.cgi?id=709109
src/org.gnome.Terminal.gschema.xml | 10 ++++++++
src/preferences.ui | 50 ++++++++++++++++++++++++++++++++++++++
src/terminal-enums.h | 5 ++++
src/terminal-mdi-container.c | 5 ++--
src/terminal-mdi-container.h | 6 +++--
src/terminal-notebook.c | 4 +--
src/terminal-prefs.c | 8 ++++++
src/terminal-schemas.h | 1 +
src/terminal-window.c | 27 ++++++++++++++++++--
src/terminal-window.h | 2 ++
10 files changed, 110 insertions(+), 8 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index b8d13b64..be6205d6 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -29,6 +29,11 @@
<value nick='tab' value='1'/>
</enum>
+ <enum id='org.gnome.Terminal.NewTabPosition'>
+ <value nick='last' value='0'/>
+ <value nick='next' value='1'/>
+ </enum>
+
<enum id='org.gnome.Terminal.ScrollbarPolicy'>
<value nick='always' value='0'/>
<!-- <value nick='automatic' value='1'/> -->
@@ -684,6 +689,11 @@
<summary>Which theme variant to use</summary>
</key>
+ <key name="new-tab-position" enum="org.gnome.Terminal.NewTabPosition">
+ <default>'last'</default>
+ <summary>Whether new tabs should open next to the current one or at the last position</summary>
+ </key>
+
<!-- Note that changing the following settings will only take effect
when gnome-terminal-server is restarted.
-->
diff --git a/src/preferences.ui b/src/preferences.ui
index fe4d6247..a6cf07d2 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -20,6 +20,24 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="new-tab-position-liststore">
+ <columns>
+ <!-- column-name label -->
+ <column type="gchararray"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes" comments="New tab opens at the last position">Last</col>
+ <col id="1">last</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes" comments="New tab opens next to current tab">Next</col>
+ <col id="1">next</col>
+ </row>
+ </data>
+ </object>
<object class="GtkListStore" id="theme-variant-liststore">
<columns>
<!-- column-name label -->
@@ -434,6 +452,38 @@
<property name="left_attach">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="new-tab-position-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">New tab _position:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">new-tab-position-combobox</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="new-tab-position-combobox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="model">new-tab-position-liststore</property>
+ <property name="id_column">1</property>
+ <child>
+ <object class="GtkCellRendererText" id="renderer3a"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="left_attach">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/terminal-enums.h b/src/terminal-enums.h
index 3bae788b..93f1460c 100644
--- a/src/terminal-enums.h
+++ b/src/terminal-enums.h
@@ -29,6 +29,11 @@ typedef enum {
TERMINAL_NEW_TERMINAL_MODE_TAB
} TerminalNewTerminalMode;
+typedef enum {
+ TERMINAL_NEW_TAB_POSITION_LAST,
+ TERMINAL_NEW_TAB_POSITION_NEXT
+} TerminalNewTabPosition;
+
typedef enum
{
TERMINAL_EXIT_CLOSE,
diff --git a/src/terminal-mdi-container.c b/src/terminal-mdi-container.c
index 66d506ed..76464a92 100644
--- a/src/terminal-mdi-container.c
+++ b/src/terminal-mdi-container.c
@@ -97,12 +97,13 @@ terminal_mdi_container_default_init (TerminalMdiContainerInterface *iface)
void
terminal_mdi_container_add_screen (TerminalMdiContainer *container,
- TerminalScreen *screen)
+ TerminalScreen *screen,
+ int position)
{
g_return_if_fail (TERMINAL_IS_MDI_CONTAINER (container));
g_return_if_fail (TERMINAL_IS_SCREEN (screen));
- TERMINAL_MDI_CONTAINER_GET_IFACE (container)->add_screen (container, screen);
+ TERMINAL_MDI_CONTAINER_GET_IFACE (container)->add_screen (container, screen, position);
}
void
diff --git a/src/terminal-mdi-container.h b/src/terminal-mdi-container.h
index c64154c6..829521f0 100644
--- a/src/terminal-mdi-container.h
+++ b/src/terminal-mdi-container.h
@@ -37,7 +37,8 @@ struct _TerminalMdiContainerInterface {
/* vfuncs */
void (* add_screen) (TerminalMdiContainer *container,
- TerminalScreen *screen);
+ TerminalScreen *screen,
+ int position);
void (* remove_screen) (TerminalMdiContainer *container,
TerminalScreen *screen);
TerminalScreen * (* get_active_screen) (TerminalMdiContainer *container);
@@ -69,7 +70,8 @@ struct _TerminalMdiContainerInterface {
GType terminal_mdi_container_get_type (void);
void terminal_mdi_container_add_screen (TerminalMdiContainer *container,
- TerminalScreen *screen);
+ TerminalScreen *screen,
+ int position);
void terminal_mdi_container_remove_screen (TerminalMdiContainer *container,
TerminalScreen *screen);
diff --git a/src/terminal-notebook.c b/src/terminal-notebook.c
index 9add96b8..356a3898 100644
--- a/src/terminal-notebook.c
+++ b/src/terminal-notebook.c
@@ -119,12 +119,12 @@ remove_reorder_bindings (GtkBindingSet *binding_set,
static void
terminal_notebook_add_screen (TerminalMdiContainer *container,
- TerminalScreen *screen)
+ TerminalScreen *screen,
+ int position)
{
TerminalNotebook *notebook = TERMINAL_NOTEBOOK (container);
GtkNotebook *gtk_notebook = GTK_NOTEBOOK (notebook);
GtkWidget *screen_container, *tab_label;
- const int position = -1;
g_warn_if_fail (gtk_widget_get_parent (GTK_WIDGET (screen)) == NULL);
diff --git a/src/terminal-prefs.c b/src/terminal-prefs.c
index 88f7635b..05d2cf84 100644
--- a/src/terminal-prefs.c
+++ b/src/terminal-prefs.c
@@ -725,6 +725,7 @@ terminal_prefs_show_preferences (GSettings *profile, const char *widget_name)
GtkWidget *disable_shortcuts_button;
GtkWidget *theme_variant_label, *theme_variant_combo;
GtkWidget *new_terminal_mode_label, *new_terminal_mode_combo;
+ GtkWidget *new_tab_position_combo;
GtkWidget *close_button, *help_button;
GtkWidget *content_box, *general_frame, *keybindings_frame;
GSettings *settings;
@@ -760,6 +761,7 @@ terminal_prefs_show_preferences (GSettings *profile, const char *widget_name)
"disable-mnemonics-checkbutton", &disable_mnemonics_button,
"disable-shortcuts-checkbutton", &disable_shortcuts_button,
"disable-menu-accel-checkbutton", &disable_menu_accel_button,
+ "new-tab-position-combobox", &new_tab_position_combo,
"accelerators-treeview", &tree_view,
"the-stack", &data->stack,
"the-listbox", &data->listbox,
@@ -831,6 +833,12 @@ terminal_prefs_show_preferences (GSettings *profile, const char *widget_name)
gtk_widget_set_visible (new_terminal_mode_combo, FALSE);
}
+ g_settings_bind (settings,
+ TERMINAL_SETTING_NEW_TAB_POSITION_KEY,
+ new_tab_position_combo,
+ "active-id",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
if (shell_shows_menubar) {
gtk_widget_set_visible (disable_mnemonics_button, FALSE);
} else {
diff --git a/src/terminal-schemas.h b/src/terminal-schemas.h
index 4051a29b..05e9f819 100644
--- a/src/terminal-schemas.h
+++ b/src/terminal-schemas.h
@@ -82,6 +82,7 @@ G_BEGIN_DECLS
#define TERMINAL_SETTING_ENABLE_SHORTCUTS_KEY "shortcuts-enabled"
#define TERMINAL_SETTING_HEADERBAR_KEY "headerbar"
#define TERMINAL_SETTING_NEW_TERMINAL_MODE_KEY "new-terminal-mode"
+#define TERMINAL_SETTING_NEW_TAB_POSITION_KEY "new-tab-position"
#define TERMINAL_SETTING_SCHEMA_VERSION "schema-version"
#define TERMINAL_SETTING_SHELL_INTEGRATION_KEY "shell-integration-enabled"
#define TERMINAL_SETTING_TAB_POLICY_KEY "tab-policy"
diff --git a/src/terminal-window.c b/src/terminal-window.c
index c184bab8..032978e5 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -2442,6 +2442,13 @@ screen_close_request_cb (TerminalMdiContainer *container,
terminal_window_remove_screen (window, screen);
}
+int
+terminal_window_get_active_screen_num (TerminalWindow *window)
+{
+ TerminalWindowPrivate *priv = window->priv;
+ return terminal_mdi_container_get_active_screen_num (priv->mdi_container);
+}
+
void
terminal_window_add_screen (TerminalWindow *window,
TerminalScreen *screen,
@@ -2454,12 +2461,28 @@ terminal_window_add_screen (TerminalWindow *window,
if (gtk_widget_is_toplevel (old_window) &&
TERMINAL_IS_WINDOW (old_window) &&
TERMINAL_WINDOW (old_window)== window)
- return;
+ return;
if (TERMINAL_IS_WINDOW (old_window))
terminal_window_remove_screen (TERMINAL_WINDOW (old_window), screen);
- terminal_mdi_container_add_screen (priv->mdi_container, screen);
+ if (position == -1) {
+ GSettings *global_settings = terminal_app_get_global_settings (terminal_app_get ());
+ TerminalNewTabPosition position_pref = g_settings_get_enum (global_settings,
+ TERMINAL_SETTING_NEW_TAB_POSITION_KEY);
+ switch (position_pref) {
+ case TERMINAL_NEW_TAB_POSITION_NEXT:
+ position = terminal_window_get_active_screen_num (window) + 1;
+ break;
+
+ default:
+ case TERMINAL_NEW_TAB_POSITION_LAST:
+ position = -1;
+ break;
+ }
+ }
+
+ terminal_mdi_container_add_screen (priv->mdi_container, screen, position);
}
void
diff --git a/src/terminal-window.h b/src/terminal-window.h
index a76469a3..7691c5a4 100644
--- a/src/terminal-window.h
+++ b/src/terminal-window.h
@@ -52,6 +52,8 @@ TerminalWindow* terminal_window_new (GApplication *app);
GtkUIManager *terminal_window_get_ui_manager (TerminalWindow *window);
+int terminal_window_get_active_screen_num (TerminalWindow *window);
+
void terminal_window_add_screen (TerminalWindow *window,
TerminalScreen *screen,
int position);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]