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 13 commits into
base: master
Choose a base branch
from
Open
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