diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index f390b8b186..f51bd221ea 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -151,6 +151,11 @@ Remember the last focused document. Restore the focused document from a previous session when opening Code. + + '' + The default build directory's relative path. + The directory, relative to the project root, at which to open the terminal pane and where to run build commands by default. + false Request dark Gtk stylesheet variant diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index f5878982e6..eaacfe9226 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -49,7 +49,16 @@ namespace Scratch.Dialogs { var indent_width = new Gtk.SpinButton.with_range (1, 24, 1); Scratch.settings.bind ("indent-width", indent_width, "value", SettingsBindFlags.DEFAULT); + var buid_dir_label = new SettingsLabel (_("Default build directory")); + var build_dir_entry = new Gtk.Entry () { + placeholder_text = ".", + margin = 12, + halign = START + }; + + Scratch.settings.bind ("default-build-directory", build_dir_entry, "text", DEFAULT); var general_grid = new Gtk.Grid (); + general_grid.column_spacing = 12; general_grid.row_spacing = 6; general_grid.attach (new Granite.HeaderLabel (_("General")), 0, 0, 3); @@ -67,9 +76,13 @@ namespace Scratch.Dialogs { general_grid.attach (new SettingsSwitch ("strip-trailing-on-save"), 1, 6, 2); general_grid.attach (new SettingsLabel (_("Tab width:")), 0, 7); general_grid.attach (indent_width, 1, 7, 2); + general_grid.attach (new Granite.HeaderLabel (_("Projects")), 0, 8); + general_grid.attach (buid_dir_label, 0, 9); + general_grid.attach (build_dir_entry, 1, 9, 2); main_stack = new Gtk.Stack () { - margin = 12 + margin = 12, + vhomogeneous = true }; main_stack.add_titled (general_grid, "behavior", _("Behavior")); main_stack.add_titled (get_editor_box (), "interface", _("Interface")); diff --git a/src/FolderManager/ProjectFolderItem.vala b/src/FolderManager/ProjectFolderItem.vala index 60569b08f2..59396e0e60 100644 --- a/src/FolderManager/ProjectFolderItem.vala +++ b/src/FolderManager/ProjectFolderItem.vala @@ -120,9 +120,10 @@ namespace Scratch.FolderManager { _("Open in Terminal Pane"), MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL + "::" ); + var open_in_terminal_pane_item = new Gtk.MenuItem () { action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_IN_TERMINAL, - action_target = new Variant.string (file.file.get_path ()) + action_target = new Variant.string (Services.GitManager.get_instance ().get_default_build_dir (path)) }; open_in_terminal_pane_item.add (open_in_terminal_pane_label); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 220e3a07ef..f97d25d1b1 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -623,7 +623,8 @@ namespace Scratch { folder_manager_view.collapse_other_projects (); if (terminal.visible) { var open_in_terminal_action = Utils.action_from_group (ACTION_OPEN_IN_TERMINAL, actions); - open_in_terminal_action.activate (null); + var param = new Variant.string (Services.GitManager.get_instance ().get_default_build_dir (null)); + open_in_terminal_action.activate (param); } }); @@ -1308,9 +1309,9 @@ namespace Scratch { toggle_terminal_action.activate (null); } - //If param is null or empty, the active project path is returned or failing that + //If param is null or empty, the active project path build dir is returned or failing that //the active document path - var target_path = get_target_path_for_actions (param); + var target_path = get_target_path_for_actions (param, true); terminal.change_location (target_path); terminal.terminal.grab_focus (); } @@ -1341,7 +1342,7 @@ namespace Scratch { folder_manager_view.new_branch (get_target_path_for_actions (param)); } - private string? get_target_path_for_actions (Variant? path_variant) { + private string? get_target_path_for_actions (Variant? path_variant, bool use_build_dir = false) { string? path = ""; if (path_variant != null) { path = path_variant.get_string (); @@ -1349,6 +1350,10 @@ namespace Scratch { if (path == "") { // Happens when keyboard accelerator is used path = git_manager.active_project_path; + if (use_build_dir) { + path = git_manager.get_default_build_dir (path); + } + if (path == null) { var current_doc = get_current_document (); if (current_doc != null) { diff --git a/src/Services/GitManager.vala b/src/Services/GitManager.vala index 679e0e0c14..6001473cf4 100644 --- a/src/Services/GitManager.vala +++ b/src/Services/GitManager.vala @@ -98,5 +98,19 @@ namespace Scratch.Services { project_gitrepo_map.unset (root_path); } } + + // @project_path is the root of a project or null + public string get_default_build_dir (string? project_path) { + string build_path = project_path != null ? project_path : active_project_path; + var default_build_dir = Scratch.settings.get_string ("default-build-directory"); + var build_file = GLib.File.new_for_path (Path.build_filename (build_path, default_build_dir)); + if (build_file.query_exists ()) { + build_path = build_file.get_path (); + } else { + warning ("build path not found %s", build_file.get_path ()); + } + + return build_path; + } } }