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

Store and restore active-project-path explicitly #1472

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5ad6921
Add "active-project-path" setting.
Oct 9, 2024
4eb0372
Dont change active project just because a document changes
Oct 9, 2024
67f238c
Remove some unused code relating to active_project
Oct 9, 2024
c2f4940
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Oct 13, 2024
c05ab29
Do not override active project with default on startup
Oct 13, 2024
5b4db0e
Show global search dialog if scope unspecified
Oct 13, 2024
ad9cc13
Distinguish global search path from default action target
Oct 14, 2024
916e10d
Allow global search when no active project
Oct 14, 2024
ca34ddd
Set active project after load folder is none already set
Oct 14, 2024
baf705e
FileView: Use git_manager property
Oct 14, 2024
5d350e7
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Oct 30, 2024
43c1023
Allow no project to be restored. Only user sets active project.
Oct 30, 2024
0bca777
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Nov 6, 2024
3794a65
Merge branch 'master' into jeremypw/sync-activeproject-startup
zeebok Dec 1, 2024
24da045
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Dec 7, 2024
f01dfde
On close other folders make remaining active
Dec 7, 2024
48320f3
Set active project context menu item for git repos
Dec 7, 2024
2fa14e9
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 8, 2025
d8e21e4
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 11, 2025
b8efe29
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 12, 2025
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
5 changes: 5 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
<summary>Remember the last focused document.</summary>
<description>Restore the focused document from a previous session when opening Code.</description>
</key>
<key name="active-project-path" type="s">
<default>''</default>
<summary>The active project path.</summary>
<description>The path to the folder containing the active project.</description>
</key>
<key name="default-build-directory" type="s">
<default>''</default>
<summary>The default build directory's relative path.</summary>
Expand Down
45 changes: 30 additions & 15 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
public const string ACTION_CHANGE_BRANCH = "change-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 @@ -46,7 +47,8 @@ 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_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"},
{ ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"}
};

private GLib.Settings settings;
Expand All @@ -60,11 +62,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
public ActionGroup toplevel_action_group { get; private set; }
public string icon_name { get; set; }
public string title { get; set; }
public string active_project_path {
get {
return git_manager.active_project_path;
}
}

public FileView (Scratch.Services.PluginsManager plugins_manager) {
plugins = plugins_manager;
Expand Down Expand Up @@ -119,10 +116,30 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
if (project_folder_item != folder_root) {
toplevel_action_group.activate_action (MainWindow.ACTION_CLOSE_PROJECT_DOCS, new Variant.string (project_folder_item.path));
root.remove (project_folder_item);
Scratch.Services.GitManager.get_instance ().remove_project (project_folder_item);
git_manager.remove_project (project_folder_item);
}
}

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

write_settings ();
}

private void action_set_active_project (SimpleAction action, GLib.Variant? parameter) {
warning ("set active project");
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 ();
}

Expand Down Expand Up @@ -176,14 +193,9 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
selected = null;
}

public void collapse_other_projects (string? keep_open_path = null) {
public void collapse_other_projects () {
unowned string path;
if (keep_open_path == null) {
path = git_manager.active_project_path;
} else {
path = keep_open_path;
git_manager.active_project_path = path;
}
path = git_manager.active_project_path;

foreach (var child in root.children) {
var project_folder = ((ProjectFolderItem) child);
Expand Down Expand Up @@ -528,10 +540,13 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
rename_items_with_same_name (child_folder);
}
}
Scratch.Services.GitManager.get_instance ().remove_project (folder_root);

git_manager.remove_project (folder_root);
write_settings ();
});

// Do not assume this is the active folder

write_settings ();
}

Expand Down
32 changes: 22 additions & 10 deletions src/FolderManager/ProjectFolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,28 @@ namespace Scratch.FolderManager {
warning (e.message);
}

var open_in_terminal_pane_item = new GLib.MenuItem (
_("Open in Terminal Pane"),
GLib.Action.print_detailed_name (
MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL,
new Variant.string (
Services.GitManager.get_instance ().get_default_build_dir (path)
MenuItem set_active_folder_item;
if (is_git_repo) {
set_active_folder_item = new GLib.MenuItem (
_("Set as Active Project"),
GLib.Action.print_detailed_name (
FileView.ACTION_PREFIX + FileView.ACTION_SET_ACTIVE_PROJECT,
new Variant.string (file.path)
)
)
);
open_in_terminal_pane_item.set_attribute_value (
);
} else {
set_active_folder_item = new GLib.MenuItem (
_("Open in Terminal Pane"),
GLib.Action.print_detailed_name (
MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL,
new Variant.string (
Services.GitManager.get_instance ().get_default_build_dir (path)
)
)
);
}

set_active_folder_item.set_attribute_value (
"accel",
Utils.get_accel_for_action (
GLib.Action.print_detailed_name (
Expand All @@ -154,7 +166,7 @@ namespace Scratch.FolderManager {
);

var external_actions_section = new GLib.Menu ();
external_actions_section.append_item (open_in_terminal_pane_item);
external_actions_section.append_item (set_active_folder_item);
external_actions_section.append_item (create_submenu_for_open_in (file_type));

var folder_actions_section = new GLib.Menu ();
Expand Down
34 changes: 29 additions & 5 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ namespace Scratch {
public Scratch.Application app { get; private set; }
public bool restore_docs { get; construct; }
public RestoreOverride restore_override { get; construct set; }
public string default_globalsearch_path {
owned get {
if (document_view.current_document != null) {
if (document_view.current_document.project_path != "") {
return document_view.current_document.project_path;
}
}

return git_manager.active_project_path;
}
}

public Scratch.Widgets.DocumentView document_view;

Expand Down Expand Up @@ -618,7 +629,6 @@ namespace Scratch {
title = _("%s - %s").printf (doc.get_basename (), base_title);

toolbar.set_document_focus (doc);
git_manager.active_project_path = doc.source_view.project.path;
folder_manager_view.select_path (doc.file.get_path ());

// Must follow setting focus document for editorconfig plug
Expand Down Expand Up @@ -1200,8 +1210,10 @@ namespace Scratch {
}

private void action_find_global (SimpleAction action, Variant? param) {
var selected_text = "";
var search_path = "";

var current_doc = get_current_document ();
string selected_text = "";
if (current_doc != null) {
selected_text = current_doc.get_selected_text (false);
}
Expand All @@ -1221,7 +1233,19 @@ namespace Scratch {
term = search_bar.search_entry.text;
}

folder_manager_view.search_global (get_target_path_for_actions (param), term);
if (param != null && param.get_string () != "") {
search_path = param.get_string ();
} else {
search_path = default_globalsearch_path;
}

if (search_path != "") {
folder_manager_view.search_global (search_path, term);
} else {
// Fallback to standard search
warning ("Unable to perform global search - search document instead");
action_fetch (action, param);
}
}

private void update_find_actions () {
Expand All @@ -1232,9 +1256,9 @@ namespace Scratch {
Utils.action_from_group (ACTION_SHOW_FIND, actions).set_enabled (is_current_doc);
Utils.action_from_group (ACTION_FIND_NEXT, actions).set_enabled (is_current_doc);
Utils.action_from_group (ACTION_FIND_PREVIOUS, actions).set_enabled (is_current_doc);
var can_global_search = is_current_doc || git_manager.active_project_path != null;
Utils.action_from_group (ACTION_FIND_GLOBAL, actions).set_enabled (can_global_search);

var is_active_project = git_manager.active_project_path != "";
Utils.action_from_group (ACTION_FIND_GLOBAL, actions).set_enabled (is_active_project);
return Source.REMOVE;
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ namespace Scratch.Services {
}
}

public string project_path {
owned get {
if (source_view.project != null) {
return source_view.project.path;
} else {
return "";
}
}
}

private string _title = "";
public string title {
get { return _title; }
Expand Down
6 changes: 3 additions & 3 deletions src/Services/GitManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ namespace Scratch.Services {
return instance;
}

private GitManager () {
construct {
// Used to populate the ChooseProject popover in sorted order
project_liststore = new ListStore (typeof (FolderManager.ProjectFolderItem));
settings.bind ("active-project-path", this, "active-project-path", DEFAULT);
}

public MonitoredRepository? add_project (FolderManager.ProjectFolderItem root_folder) {
Expand All @@ -72,8 +73,7 @@ namespace Scratch.Services {
);
}

//Ensure active_project_path always set
active_project_path = root_path;
// No longer need to set default project (restored from settings or left unset)
return project_gitrepo_map.@get (root_path);
}

Expand Down
Loading
Loading