Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1446cec
Save terminal-pane state explicitly - destroy signal unsuitable
jeremypw May 27, 2025
3737cda
Use common action to set active project
jeremypw May 27, 2025
68eb0fb
Disambiguate action name
jeremypw May 29, 2025
c303756
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw May 29, 2025
d738599
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jun 5, 2025
debbf2d
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jun 10, 2025
dd04b48
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jun 16, 2025
1b24dfe
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jun 20, 2025
8b9c7b3
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jun 28, 2025
6d25e42
Match self in get_project_for_file
jeremypw Jun 28, 2025
20b82ba
Lose FileView.ACTION_SET_PROJECT_ACTIVE call MainWindow action directly
jeremypw Jun 28, 2025
4e451de
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jul 2, 2025
eb54627
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Jul 16, 2025
0751854
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Aug 9, 2025
b505e03
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Aug 18, 2025
a985df6
Merge branch 'master' into jeremypw/terminal-pane/save-state
jeremypw Oct 18, 2025
367b672
Revert renaming function
jeremypw Nov 5, 2025
7635580
Merge branch 'master' into jeremypw/terminal-pane/save-state
zeebok Jan 25, 2026
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
39 changes: 16 additions & 23 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
public const string ACTION_CHECKOUT_REMOTE_BRANCH = "checkout-remote-branch";
public const string ACTION_CLOSE_FOLDER = "close-folder";
public const string ACTION_CLOSE_OTHER_FOLDERS = "close-other-folders";
public const string ACTION_SET_ACTIVE_PROJECT = "set-active-project";

private const ActionEntry[] ACTION_ENTRIES = {
{ ACTION_LAUNCH_APP_WITH_FILE_PATH, action_launch_app_with_file_path, "as" },
Expand All @@ -48,8 +47,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
{ ACTION_NEW_FILE, add_new_file, "s" },
{ ACTION_NEW_FOLDER, add_new_folder, "s"},
{ ACTION_CLOSE_FOLDER, action_close_folder, "s"},
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"},
{ ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"}
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"}
};

private GLib.Settings settings;
Expand Down Expand Up @@ -115,32 +113,23 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
foreach (var child in root.children) {
var project_folder_item = (ProjectFolderItem) child;
if (project_folder_item != folder_root) {
toplevel_action_group.activate_action (MainWindow.ACTION_CLOSE_PROJECT_DOCS, new Variant.string (project_folder_item.path));
toplevel_action_group.activate_action (
MainWindow.ACTION_CLOSE_PROJECT_DOCS,
new Variant.string (project_folder_item.path)
);
root.remove (project_folder_item);
git_manager.remove_project (project_folder_item);
}
}

//Make remaining project the active one
git_manager.active_project_path = path;

write_settings ();
set_project_active (path);
}

private void action_set_active_project (SimpleAction action, GLib.Variant? parameter) {
var path = parameter.get_string ();
if (path == null || path == "") {
return;
}

var folder_root = find_path (root, path) as ProjectFolderItem;
if (folder_root == null) {
return;
}

git_manager.active_project_path = path;

write_settings ();
private void set_project_active (string path) {
toplevel_action_group.activate_action (
MainWindow.ACTION_SET_ACTIVE_PROJECT,
new Variant.string (path)
);
}

public async void restore_saved_state () {
Expand Down Expand Up @@ -251,11 +240,15 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
return null;
}

public bool project_is_open (string project_path) {
return get_project_for_file (GLib.File.new_for_path (project_path)) != null;
}

public ProjectFolderItem? get_project_for_file (GLib.File file) {
foreach (var item in root.children) {
if (item is ProjectFolderItem) {
var folder = (ProjectFolderItem)item;
if (folder.contains_file (file)) {
if (folder.file.file.equal (file) || folder.contains_file (file)) {
return folder;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace Scratch.FolderManager {
}
}


public void load_children () {
if (loading_required) {
foreach (var child in file.children) {
Expand Down
2 changes: 1 addition & 1 deletion src/FolderManager/ProjectFolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace Scratch.FolderManager {
set_active_folder_item = new GLib.MenuItem (
_("Set as Active Project"),
GLib.Action.print_detailed_name (
FileView.ACTION_PREFIX + FileView.ACTION_SET_ACTIVE_PROJECT,
MainWindow.ACTION_PREFIX + MainWindow.ACTION_SET_ACTIVE_PROJECT,
new Variant.string (file.path)
)
);
Expand Down
32 changes: 23 additions & 9 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace Scratch {
public const string ACTION_TOGGLE_OUTLINE = "action-toggle-outline";
public const string ACTION_TOGGLE_TERMINAL = "action-toggle-terminal";
public const string ACTION_OPEN_IN_TERMINAL = "action-open-in-terminal";
public const string ACTION_SET_ACTIVE_PROJECT = "action-set-active-project";
public const string ACTION_NEXT_TAB = "action-next-tab";
public const string ACTION_PREVIOUS_TAB = "action-previous-tab";
public const string ACTION_CLEAR_LINES = "action-clear-lines";
Expand Down Expand Up @@ -169,6 +170,7 @@ namespace Scratch {
{ ACTION_TOGGLE_SIDEBAR, action_toggle_sidebar, null, "true" },
{ ACTION_TOGGLE_TERMINAL, action_toggle_terminal, null, "false"},
{ ACTION_OPEN_IN_TERMINAL, action_open_in_terminal, "s"},
{ ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"},
{ ACTION_TOGGLE_OUTLINE, action_toggle_outline, null, "false" },
{ ACTION_NEXT_TAB, action_next_tab },
{ ACTION_PREVIOUS_TAB, action_previous_tab },
Expand Down Expand Up @@ -633,14 +635,6 @@ namespace Scratch {
}
});

sidebar.choose_project_button.project_chosen.connect (() => {
folder_manager_view.collapse_other_projects ();
if (terminal.visible) {
var open_in_terminal_action = Utils.action_from_group (ACTION_OPEN_IN_TERMINAL, actions);
var param = new Variant.string (Services.GitManager.get_instance ().get_default_build_dir (null));
open_in_terminal_action.activate (param);
}
});

set_widgets_sensitive (false);
}
Expand Down Expand Up @@ -865,6 +859,8 @@ namespace Scratch {
// Plugin panes size
Scratch.saved_state.set_int ("hp1-size", hp1.get_position ());
Scratch.saved_state.set_int ("vp-size", vp.get_position ());

terminal.save_settings ();
}

// SIGTERM/SIGINT Handling
Expand Down Expand Up @@ -1450,7 +1446,7 @@ namespace Scratch {

private void action_open_in_terminal (SimpleAction action, Variant? param) {
// Ensure terminal is visible
if (terminal == null || !terminal.visible) {
if (!terminal.visible) {
var toggle_terminal_action = Utils.action_from_group (ACTION_TOGGLE_TERMINAL, actions);
toggle_terminal_action.activate (null);
}
Expand All @@ -1462,6 +1458,24 @@ namespace Scratch {
terminal.terminal.grab_focus ();
}

private void action_set_active_project (SimpleAction action, Variant? param) {
var project_path = param.get_string ();
if (folder_manager_view.project_is_open (project_path)) {
git_manager.active_project_path = project_path;
folder_manager_view.collapse_other_projects ();
//The opened folders are not changed so no need to update "opened-folders" setting
} else {
warning ("Attempt to set folder path %s which is not opened as active project ignored", project_path);
//TODO Handle this by opening the folder
}

var new_build_dir = Services.GitManager.get_instance ().get_default_build_dir (null);
terminal.change_location (new_build_dir);
if (terminal.visible) {
terminal.terminal.grab_focus ();
}
}

private void action_toggle_outline (SimpleAction action) {
action.set_state (!action.get_state ().get_boolean ());
document_view.outline_visible = action.get_state ().get_boolean ();
Expand Down
12 changes: 10 additions & 2 deletions src/Widgets/ChooseProjectButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
private Gtk.Label label_widget;
private Gtk.ListBox project_listbox;

public ActionGroup toplevel_action_group { get; construct; }
public signal void project_chosen ();

construct {
realize.connect (() => {
toplevel_action_group = get_action_group (Scratch.MainWindow.ACTION_GROUP);
assert_nonnull (toplevel_action_group);
});

var img = new Gtk.Image () {
gicon = new ThemedIcon ("git-symbolic"),
icon_size = Gtk.IconSize.SMALL_TOOLBAR
Expand Down Expand Up @@ -146,8 +152,10 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {

project_listbox.row_activated.connect ((row) => {
var project_entry = ((ProjectRow) row);
git_manager.active_project_path = project_entry.project_path;
project_chosen ();
toplevel_action_group.activate_action (
Scratch.MainWindow.ACTION_SET_ACTIVE_PROJECT,
new Variant.string (project_entry.project_path)
);
});

toggled.connect (() => {
Expand Down
9 changes: 4 additions & 5 deletions src/Widgets/Terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ public class Code.Terminal : Gtk.Box {
scrolled_window.add (terminal);

add (scrolled_window);

destroy.connect (() => {
Scratch.saved_state.set_string ("last-opened-path", get_shell_location ());
});

show_all ();
}

Expand Down Expand Up @@ -298,6 +293,10 @@ public class Code.Terminal : Gtk.Box {
} //No suitable system keys
}

public void save_settings () {
Scratch.saved_state.set_string ("last-opened-path", get_shell_location ());
}

public void increment_size () {
terminal.font_scale = (terminal.font_scale + 0.1).clamp (MIN_SCALE, MAX_SCALE);
}
Expand Down