diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in index 9418cda9..5ab827e9 100644 --- a/data/org.x.editor.gschema.xml.in +++ b/data/org.x.editor.gschema.xml.in @@ -197,6 +197,12 @@ Whether xed should render newline characters + + false + Close window when closing last tab + Whether the window will close once the last tab is closed. + + diff --git a/help/C/index.docbook b/help/C/index.docbook index a21976ce..299f918b 100644 --- a/help/C/index.docbook +++ b/help/C/index.docbook @@ -999,11 +999,15 @@ 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. + + Auto close + If this option is enabled, once the last tab is closed, the window will close. + Save Preferences - + File saving diff --git a/xed/resources/ui/xed-preferences-dialog.ui b/xed/resources/ui/xed-preferences-dialog.ui index 2929d33d..776bd121 100644 --- a/xed/resources/ui/xed-preferences-dialog.ui +++ b/xed/resources/ui/xed-preferences-dialog.ui @@ -932,6 +932,61 @@ 11 + + + True + False + Auto close + 0 + + + + + + + False + True + 12 + + + + + True + False + 32 + 32 + + + True + False + Close window when closing last tab + 0 + + + False + True + 0 + + + + + True + True + + + False + True + end + 1 + + + + + False + True + 13 + + diff --git a/xed/xed-commands-file.c b/xed/xed-commands-file.c index a07a5868..4f5185d0 100644 --- a/xed/xed-commands-file.c +++ b/xed/xed-commands-file.c @@ -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 diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c index fe44e451..ca51e545 100644 --- a/xed/xed-preferences-dialog.c +++ b/xed/xed-preferences-dialog.c @@ -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; @@ -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); @@ -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")); } diff --git a/xed/xed-settings.h b/xed/xed-settings.h index 71790c8e..0b2c3cd0 100644 --- a/xed/xed-settings.h +++ b/xed/xed-settings.h @@ -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"