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

Continous saving of current tabs and tab-zooms #742

Merged
merged 17 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion data/io.elementary.terminal.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</key>
<key name="remember-tabs" type="b">
<default>true</default>
<summary>Whether open tabs should be remembered on closing (subject to privacy setting).</summary>
<summary>Whether open tabs should be remembered (subject to privacy setting).</summary>
<description>
Defines whether the terminal should remember the last open tabs and restore
them when the terminal is reopened. If the global privacy setting is on, the tabs
Expand Down
45 changes: 28 additions & 17 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace Terminal {
private HashTable<string, TerminalWidget> restorable_terminals;
private bool is_fullscreen = false;
private bool on_drag = false;
private string[] saved_tabs;
private string[] saved_zooms;

private const int NORMAL = 0;
private const int MAXIMIZED = 1;
Expand Down Expand Up @@ -550,15 +548,6 @@ namespace Terminal {
}

private void restore_saved_state (bool restore_pos = true) {
if (Granite.Services.System.history_is_enabled () &&
Application.settings.get_boolean ("remember-tabs")) {

saved_tabs = Terminal.Application.saved_state.get_strv ("tabs");
saved_zooms = Terminal.Application.saved_state.get_strv ("tab-zooms");
} else {
saved_tabs = {};
saved_zooms = {};
}

var rect = Gdk.Rectangle ();
Terminal.Application.saved_state.get ("window-size", "(ii)", out rect.width, out rect.height);
Expand Down Expand Up @@ -594,6 +583,7 @@ namespace Terminal {
var terminal_widget = get_term_widget (tab);
terminals.append (terminal_widget);
terminal_widget.window = this;
save_opened_terminals ();
}

private void on_tab_removed (Granite.Widgets.Tab tab) {
Expand All @@ -604,6 +594,7 @@ namespace Terminal {
} else {
terminals.remove (terminal_widget);
check_for_tabs_with_same_name ();
save_opened_terminals ();
}
}

Expand Down Expand Up @@ -639,7 +630,13 @@ namespace Terminal {
}

private void on_tab_reordered (Granite.Widgets.Tab tab, int new_pos) {
var terminal_widget = get_term_widget (tab);

current_terminal.grab_focus ();

terminals.remove (terminal_widget);
terminals.insert (terminal_widget, new_pos);

save_opened_terminals ();
jeremypw marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -652,6 +649,8 @@ namespace Terminal {
notebook.current = tab;
term.grab_focus ();
check_for_tabs_with_same_name ();

save_opened_terminals ();
}

private void on_tab_moved (Granite.Widgets.Tab tab, int x, int y) {
Expand Down Expand Up @@ -831,14 +830,14 @@ namespace Terminal {
if (Granite.Services.System.history_is_enabled () &&
Application.settings.get_boolean ("remember-tabs")) {

tabs = saved_tabs;
tabs = Terminal.Application.saved_state.get_strv ("tabs");
var n_tabs = tabs.length;

if (n_tabs == 0) {
tabs += Environment.get_home_dir ();
zooms += default_zoom;
} else {
foreach (unowned string zoom_s in saved_zooms) {
foreach (unowned string zoom_s in Terminal.Application.saved_state.get_strv ("tab-zooms")) {
var zoom = double.parse (zoom_s); // Locale independent

if (zooms.length < n_tabs) {
Expand Down Expand Up @@ -875,8 +874,6 @@ namespace Terminal {
}
}

Terminal.Application.saved_state.set_strv ("tabs", {});

focus = focus.clamp (0, tabs.length - 1);

/* This must not be in an Idle loop to avoid duplicate tabs being opened (issue #245) */
Expand Down Expand Up @@ -939,7 +936,7 @@ namespace Terminal {
});

terminal_widget.window_title_changed.connect (check_for_tabs_with_same_name);
terminal_widget.cwd_changed.connect (check_for_tabs_with_same_name);
terminal_widget.cwd_changed.connect (cwd_changed);

terminal_widget.set_font (term_font);

Expand Down Expand Up @@ -978,6 +975,8 @@ namespace Terminal {
terminal_widget.run_program (program, location);
}

save_opened_terminals ();

return terminal_widget;
}

Expand Down Expand Up @@ -1205,10 +1204,12 @@ namespace Terminal {

private void action_zoom_in_font () {
current_terminal.increment_size ();
save_opened_terminals ();
}

private void action_zoom_out_font () {
current_terminal.decrement_size ();
save_opened_terminals ();
}

private void action_zoom_default_font () {
Expand Down Expand Up @@ -1344,9 +1345,15 @@ namespace Terminal {
return;
}

private void cwd_changed () {
check_for_tabs_with_same_name ();
jeremypw marked this conversation as resolved.
Show resolved Hide resolved
save_opened_terminals ();
}

private void save_opened_terminals () {
string[] opened_tabs = {};
string[] zooms = {};
int focused_tab = 0;

Application.saved_state.set_double ("zoom", current_terminal.font_scale);

Expand All @@ -1362,6 +1369,10 @@ namespace Terminal {
}
}
});

if (notebook.current != null) {
focused_tab = notebook.get_tab_position (notebook.current);
}
}

Terminal.Application.saved_state.set_strv (
Expand All @@ -1376,7 +1387,7 @@ namespace Terminal {

Terminal.Application.saved_state.set_int (
"focused-tab",
notebook.current != null ? notebook.get_tab_position (notebook.current) : 0
focused_tab
);
}

Expand Down
Loading