Skip to content

Commit 20b82ba

Browse files
committed
Lose FileView.ACTION_SET_PROJECT_ACTIVE call MainWindow action directly
1 parent 6d25e42 commit 20b82ba

4 files changed

Lines changed: 17 additions & 26 deletions

File tree

src/FolderManager/FileView.vala

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
3636
public const string ACTION_CHECKOUT_REMOTE_BRANCH = "checkout-remote-branch";
3737
public const string ACTION_CLOSE_FOLDER = "close-folder";
3838
public const string ACTION_CLOSE_OTHER_FOLDERS = "close-other-folders";
39-
public const string ACTION_SET_PROJECT_ACTIVE = "set-project-active";
4039

4140
private const ActionEntry[] ACTION_ENTRIES = {
4241
{ ACTION_LAUNCH_APP_WITH_FILE_PATH, action_launch_app_with_file_path, "as" },
@@ -48,8 +47,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
4847
{ ACTION_NEW_FILE, add_new_file, "s" },
4948
{ ACTION_NEW_FOLDER, add_new_folder, "s"},
5049
{ ACTION_CLOSE_FOLDER, action_close_folder, "s"},
51-
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"},
52-
{ ACTION_SET_PROJECT_ACTIVE, action_set_project_active, "s"}
50+
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"}
5351
};
5452

5553
private GLib.Settings settings;
@@ -127,27 +125,11 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
127125
set_project_active (path);
128126
}
129127

130-
private void action_set_project_active (SimpleAction action, GLib.Variant? parameter) {
131-
var path = parameter.get_string ();
132-
if (path == null || path == "") {
133-
return;
134-
}
135-
136-
var folder_root = find_path (root, path) as ProjectFolderItem;
137-
if (folder_root == null) {
138-
return;
139-
}
140-
141-
set_project_active (path);
142-
}
143-
144128
private void set_project_active (string path) {
145129
toplevel_action_group.activate_action (
146130
MainWindow.ACTION_SET_ACTIVE_PROJECT,
147131
new Variant.string (path)
148132
);
149-
150-
write_settings ();
151133
}
152134

153135
public async void restore_saved_state () {
@@ -254,6 +236,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
254236
return null;
255237
}
256238

239+
public bool project_is_open (string project_path) {
240+
return get_project_for_file (GLib.File.new_for_path (project_path)) != null;
241+
}
242+
257243
public ProjectFolderItem? get_project_for_file (GLib.File file) {
258244
foreach (var item in root.children) {
259245
if (item is ProjectFolderItem) {
@@ -588,10 +574,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
588574
}
589575
}
590576
Scratch.Services.GitManager.get_instance ().remove_project (folder_root);
591-
write_settings ();
577+
save_opened_folders ();
592578
});
593579

594-
write_settings ();
580+
save_opened_folders ();
595581
add_folder.callback ();
596582
return Source.REMOVE;
597583
});
@@ -606,7 +592,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
606592
return false;
607593
}
608594

609-
private void write_settings () {
595+
private void save_opened_folders () {
610596
string[] to_save = {};
611597

612598
foreach (var main_folder in root.children) {

src/FolderManager/FolderItem.vala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ namespace Scratch.FolderManager {
6161
}
6262
}
6363

64-
6564
public void load_children () {
6665
if (loading_required) {
6766
foreach (var child in file.children) {

src/FolderManager/ProjectFolderItem.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace Scratch.FolderManager {
146146
set_active_folder_item = new GLib.MenuItem (
147147
_("Set as Active Project"),
148148
GLib.Action.print_detailed_name (
149-
FileView.ACTION_PREFIX + FileView.ACTION_SET_PROJECT_ACTIVE,
149+
MainWindow.ACTION_PREFIX + MainWindow.ACTION_SET_ACTIVE_PROJECT,
150150
new Variant.string (file.path)
151151
)
152152
);

src/MainWindow.vala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,14 @@ namespace Scratch {
14521452

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

14581464
var new_build_dir = Services.GitManager.get_instance ().get_default_build_dir (null);
14591465
terminal.change_location (new_build_dir);

0 commit comments

Comments
 (0)