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

Merged
merged 28 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 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
f859d51
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 23, 2025
8285e1b
Do not signal project-chosen twice for each change
Jan 27, 2025
7f6edde
Do not call same code twice for each time a tab closes
Jan 27, 2025
4629cdc
ProjectChooser: signal only on manual change
Jan 29, 2025
750f2cf
Update popover only when activated;
Jan 29, 2025
c6d81f0
Merge branch 'master' into jeremypw/sync-activeproject-startup
zeebok Feb 4, 2025
1a54316
Remove debug code
Feb 4, 2025
04f487b
Merge branch 'master' into jeremypw/sync-activeproject-startup
Feb 5, 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
14 changes: 2 additions & 12 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
public bool ignore_next_select { get; set; default = false; }
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 @@ -193,14 +188,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
1 change: 0 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,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
5 changes: 3 additions & 2 deletions src/Services/GitManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Scratch.Services {
public class GitManager : Object {
public ListStore project_liststore { get; private set; }
public string active_project_path { get; set; default = "";}
public string active_project_path { get; set;}

static Gee.HashMap<string, MonitoredRepository> project_gitrepo_map;
static GitManager? instance;
Expand All @@ -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 Down
20 changes: 12 additions & 8 deletions src/Widgets/ChooseProjectButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
popover = project_popover;

var git_manager = Scratch.Services.GitManager.get_instance ();
set_active_path (git_manager.active_project_path);
git_manager.notify["active-project-path"].connect (() => {
set_active_path (git_manager.active_project_path);
});

git_manager.project_liststore.items_changed.connect ((src, pos, n_removed, n_added) => {
var rows = project_listbox.get_children ();
for (int index = (int)pos; index < pos + n_removed; index++) {
Expand All @@ -115,10 +120,6 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
set_active_path (git_manager.active_project_path);
});

git_manager.notify["active-project-path"].connect (() => {
set_active_path (git_manager.active_project_path);
});

project_listbox.remove.connect ((row) => {
var project_row = row as ProjectRow;
var current_project = Scratch.Services.GitManager.get_instance ().active_project_path;
Expand All @@ -140,12 +141,15 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
});
}

// Determine which docs are actually visible, terminal path, expanded folder etc
private void set_active_path (string active_path) {
foreach (var child in project_listbox.get_children ()) {
var project_entry = ((ProjectRow) child);
if (active_path.has_prefix (project_entry.project_path + Path.DIR_SEPARATOR_S)) {
project_listbox.row_activated (project_entry);
break;
var project_row = ((ProjectRow) child);
if (active_path.has_prefix (project_row.project_path)) {
project_row.active = true;
project_row.activate ();
} else {
project_row.active = false;
}
}
}
Expand Down