Skip to content

Commit 48320f3

Browse files
Jeremy WoottenJeremy Wootten
authored andcommitted
Set active project context menu item for git repos
1 parent f01dfde commit 48320f3

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

src/FolderManager/FileView.vala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
3535
public const string ACTION_CHANGE_BRANCH = "change-branch";
3636
public const string ACTION_CLOSE_FOLDER = "close-folder";
3737
public const string ACTION_CLOSE_OTHER_FOLDERS = "close-other-folders";
38+
public const string ACTION_SET_ACTIVE_PROJECT = "set-active-project";
3839

3940
private const ActionEntry[] ACTION_ENTRIES = {
4041
{ ACTION_LAUNCH_APP_WITH_FILE_PATH, action_launch_app_with_file_path, "as" },
@@ -46,7 +47,8 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
4647
{ ACTION_NEW_FILE, add_new_file, "s" },
4748
{ ACTION_NEW_FOLDER, add_new_folder, "s"},
4849
{ ACTION_CLOSE_FOLDER, action_close_folder, "s"},
49-
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"}
50+
{ ACTION_CLOSE_OTHER_FOLDERS, action_close_other_folders, "s"},
51+
{ ACTION_SET_ACTIVE_PROJECT, action_set_active_project, "s"}
5052
};
5153

5254
private GLib.Settings settings;
@@ -124,6 +126,23 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
124126
write_settings ();
125127
}
126128

129+
private void action_set_active_project (SimpleAction action, GLib.Variant? parameter) {
130+
warning ("set active project");
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+
git_manager.active_project_path = path;
142+
143+
write_settings ();
144+
}
145+
127146
public void restore_saved_state () {
128147
foreach (unowned string path in settings.get_strv ("opened-folders")) {
129148
add_folder (new File (path), false);

src/FolderManager/ProjectFolderItem.vala

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,28 @@ namespace Scratch.FolderManager {
134134
warning (e.message);
135135
}
136136

137-
var open_in_terminal_pane_item = new GLib.MenuItem (
138-
_("Open in Terminal Pane"),
139-
GLib.Action.print_detailed_name (
140-
MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL,
141-
new Variant.string (
142-
Services.GitManager.get_instance ().get_default_build_dir (path)
137+
MenuItem set_active_folder_item;
138+
if (is_git_repo) {
139+
set_active_folder_item = new GLib.MenuItem (
140+
_("Set as Active Project"),
141+
GLib.Action.print_detailed_name (
142+
FileView.ACTION_PREFIX + FileView.ACTION_SET_ACTIVE_PROJECT,
143+
new Variant.string (file.path)
143144
)
144-
)
145-
);
146-
open_in_terminal_pane_item.set_attribute_value (
145+
);
146+
} else {
147+
set_active_folder_item = new GLib.MenuItem (
148+
_("Open in Terminal Pane"),
149+
GLib.Action.print_detailed_name (
150+
MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL,
151+
new Variant.string (
152+
Services.GitManager.get_instance ().get_default_build_dir (path)
153+
)
154+
)
155+
);
156+
}
157+
158+
set_active_folder_item.set_attribute_value (
147159
"accel",
148160
Utils.get_accel_for_action (
149161
GLib.Action.print_detailed_name (
@@ -154,7 +166,7 @@ namespace Scratch.FolderManager {
154166
);
155167

156168
var external_actions_section = new GLib.Menu ();
157-
external_actions_section.append_item (open_in_terminal_pane_item);
169+
external_actions_section.append_item (set_active_folder_item);
158170
external_actions_section.append_item (create_submenu_for_open_in (file_type));
159171

160172
var folder_actions_section = new GLib.Menu ();

0 commit comments

Comments
 (0)