Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added auto close setting to close window when that last tab is closed #613

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added auto close setting to close window when that last tab is closed
  • Loading branch information
tlemy committed Dec 11, 2023
commit e603dfc36cf344cfbb1841b9db40af656f749b4a
6 changes: 6 additions & 0 deletions data/org.x.editor.gschema.xml.in
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
21 changes: 21 additions & 0 deletions xed/xed-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,25 @@ on_enable_tab_scrolling_changed (GSettings *settings,
}
}

static void
on_auto_close_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
const GList *windows;
gboolean enable;

enable = g_settings_get_boolean (settings, key);
windows = xed_app_get_main_windows (XED_APP (g_application_get_default ()));

while (windows != NULL)
{
xed_window_set_auto_close (windows->data, enable);

windows = g_list_next (windows);
}
}

static void
on_max_recents_changed (GSettings *settings,
const gchar *key,
Expand Down Expand Up @@ -397,6 +416,8 @@ xed_settings_init (XedSettings *xs)
G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
g_signal_connect (xs->priv->editor, "changed::draw-whitespace-newline",
G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-close",
G_CALLBACK (on_auto_close_changed), xs);

/* ui changes */
g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling",
Expand Down
1 change: 1 addition & 0 deletions xed/xed-settings.h
Original file line number Diff line number Diff line change
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
22 changes: 22 additions & 0 deletions xed/xed-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,28 @@ xed_window_get_tab_from_location (XedWindow *window,
return ret;
}

/**
* xed_window_set_auto_close:
* @window: a #XedWindow
* @gboolean: a #gboolean
*
* Sets the auto_close switch.
* If the switch is set to true,
* the window closes once the last tab is closed.
*
* Return value: none
*/
void
xed_window_set_auto_close (XedWindow *window,
gboolean enable)
{
g_return_if_fail (XED_IS_WINDOW(window));

xed_debug (DEBUG_WINDOW);

g_settings_set_boolean (window->priv->editor_settings, XED_SETTINGS_AUTO_CLOSE, enable);
}

/**
* xed_window_get_message_bus:
* @window: a #XedWindow
Expand Down
1 change: 1 addition & 0 deletions xed/xed-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void xed_window_close_all_tabs (XedWindow *window);
void xed_window_close_tabs (XedWindow *window, const GList *tabs);
XedTab *xed_window_get_active_tab (XedWindow *window);
void xed_window_set_active_tab (XedWindow *window, XedTab *tab);
void xed_window_set_auto_close (XedWindow *window, gboolean enable);

/* Helper functions */
XedView *xed_window_get_active_view (XedWindow *window);
Expand Down