Skip to content

Commit

Permalink
added auto close setting to close window when that last tab is closed (
Browse files Browse the repository at this point in the history
…#613)

* added auto close setting to close window when that last tab is closed
  • Loading branch information
tlemy committed Mar 7, 2024
1 parent a453117 commit 2168e89
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
6 changes: 6 additions & 0 deletions data/org.x.editor.gschema.xml.in
Expand Up @@ -197,6 +197,12 @@
<description>Whether xed should render newline characters</description>
</key>

<key name="auto-close" type="b">
<default>false</default>
<summary>Close window when closing last tab</summary>
<description>Whether the window will close once the last tab is closed.</description>
</key>

</schema>

<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.x.editor.preferences.ui" path="/org/x/editor/preferences/ui/">
Expand Down
6 changes: 5 additions & 1 deletion help/C/index.docbook
Expand Up @@ -999,11 +999,15 @@
<para>This refers to the tabs at the top of the window for selecting the document being edited. If this option is enabled, and the mouse point is over the document tab area, rolling the mouse wheel will cycle through the different document tabs.</para>
</sect3>

<sect3 id="xed-prefs-autoclose">
<title>Auto close</title>
<para>If this option is enabled, once the last tab is closed, the window will close.</para>
</sect3>
</sect2>

<sect2 id="xed-prefs-save">
<title>Save Preferences </title>

<sect3 id="xed-prefs-filesave">
<title>File saving</title>
<variablelist>
Expand Down
55 changes: 55 additions & 0 deletions xed/resources/ui/xed-preferences-dialog.ui
Expand Up @@ -932,6 +932,61 @@
<property name="position">11</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label24">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Auto close</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.1000000000000001"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">12</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box30">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">32</property>
<property name="margin_right">32</property>
<child>
<object class="GtkLabel" id="auto_close_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Close window when closing last tab</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="auto_close_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">13</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
15 changes: 15 additions & 0 deletions xed/xed-commands-file.c
Expand Up @@ -1716,6 +1716,21 @@ _xed_cmd_file_close_tab (XedTab *tab,
{
xed_window_close_tab (window, tab);
}

if (window->priv->num_tabs == 0)
{
gboolean enable_auto_close;

enable_auto_close =
g_settings_get_boolean (window->priv->editor_settings, XED_SETTINGS_AUTO_CLOSE);

if (!enable_auto_close)
{
return;
}

gtk_widget_destroy (GTK_WIDGET (window));
}
}

void
Expand Down
11 changes: 11 additions & 0 deletions xed/xed-preferences-dialog.c
Expand Up @@ -126,6 +126,9 @@ struct _XedPreferencesDialog
/* Tab scrolling */
GtkWidget *tab_scrolling_switch;

/* Auto close*/
GtkWidget *auto_close_switch;

/* Style scheme */
GtkWidget *prefer_dark_theme_switch;
GtkWidget *schemes_list;
Expand Down Expand Up @@ -192,6 +195,7 @@ xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, split_words_revealer);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, split_words_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, tab_scrolling_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, auto_close_switch);

/* Save page widgets */
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, backup_copy_switch);
Expand Down Expand Up @@ -433,6 +437,13 @@ setup_editor_page (XedPreferencesDialog *dlg)
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);

/* Auto close */
g_settings_bind (dlg->editor_settings,
XED_SETTINGS_AUTO_CLOSE,
dlg->auto_close_switch,
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);

xapp_preferences_window_add_page (XAPP_PREFERENCES_WINDOW (dlg), dlg->editor_page, "editor", _("Editor"));
}

Expand Down
1 change: 1 addition & 0 deletions xed/xed-settings.h
Expand Up @@ -99,6 +99,7 @@ void xed_settings_set_list (GSettings *settings,
#define XED_SETTINGS_SYNTAX_HIGHLIGHTING "syntax-highlighting"
#define XED_SETTINGS_SEARCH_HIGHLIGHTING "search-highlighting"
#define XED_SETTINGS_ENABLE_TAB_SCROLLING "enable-tab-scrolling"
#define XED_SETTINGS_AUTO_CLOSE "auto-close"
#define XED_SETTINGS_TOOLBAR_VISIBLE "toolbar-visible"
#define XED_SETTINGS_MENUBAR_VISIBLE "menubar-visible"
#define XED_SETTINGS_STATUSBAR_VISIBLE "statusbar-visible"
Expand Down

0 comments on commit 2168e89

Please sign in to comment.