Skip to content

Ensure terminal pane shell location correct when opened #1574

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 19 additions & 26 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 @@ -247,11 +236,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 Expand Up @@ -581,10 +574,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
}
}
Scratch.Services.GitManager.get_instance ().remove_project (folder_root);
write_settings ();
save_opened_folders ();
});

write_settings ();
save_opened_folders ();
add_folder.callback ();
return Source.REMOVE;
});
Expand All @@ -599,7 +592,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
return false;
}

private void write_settings () {
private void save_opened_folders () {
string[] to_save = {};

foreach (var main_folder in root.children) {
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 @@ -109,6 +109,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 @@ -167,6 +168,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 @@ -631,14 +633,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 @@ -863,6 +857,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 @@ -1442,7 +1438,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 @@ -1454,6 +1450,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 @@ -22,9 +22,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 @@ -128,8 +134,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
8 changes: 4 additions & 4 deletions src/Widgets/Terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ public class Code.Terminal : Gtk.Box {

add (scrolled_window);

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

show_all ();
}

Expand Down Expand Up @@ -204,6 +200,10 @@ public class Code.Terminal : Gtk.Box {
this.terminal.set_colors (foreground_color, background_color, palette);
}

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