[gnome-builder] terminal: apply prepend/append path to build terminal
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] terminal: apply prepend/append path to build terminal
- Date: Wed, 19 Jan 2022 21:59:47 +0000 (UTC)
commit 6634e127754664debb74b051e0d9fbc86baa9819
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 19 13:59:27 2022 -0800
terminal: apply prepend/append path to build terminal
We need access to the configuration object to be able to do this, so plumb
it through and update associated actions to use the new variant. We leave
the old variant still for cases where that might be needed as fallbacks.
Fixes #1605
src/libide/terminal/ide-terminal-launcher.c | 42 +++++++++++++++++++++-
src/libide/terminal/ide-terminal-launcher.h | 2 ++
.../terminal/gbp-terminal-workspace-addin.c | 25 ++++++++++---
src/plugins/terminal/gtk/menus.ui | 2 +-
4 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/terminal/ide-terminal-launcher.c b/src/libide/terminal/ide-terminal-launcher.c
index b6f1c8189..3b4f59baf 100644
--- a/src/libide/terminal/ide-terminal-launcher.c
+++ b/src/libide/terminal/ide-terminal-launcher.c
@@ -39,6 +39,7 @@ typedef enum
LAUNCHER_KIND_RUNTIME,
LAUNCHER_KIND_RUNNER,
LAUNCHER_KIND_LAUNCHER,
+ LAUNCHER_KIND_CONFIG,
} LauncherKind;
struct _IdeTerminalLauncher
@@ -50,6 +51,7 @@ struct _IdeTerminalLauncher
gchar **args;
IdeRuntime *runtime;
IdeContext *context;
+ IdeConfig *config;
IdeSubprocessLauncher *launcher;
LauncherKind kind;
};
@@ -316,6 +318,7 @@ static void
spawn_runtime_launcher (IdeTerminalLauncher *self,
IdeTask *task,
IdeRuntime *runtime,
+ IdeConfig *config,
gint pty_fd)
{
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
@@ -369,6 +372,9 @@ spawn_runtime_launcher (IdeTerminalLauncher *self,
ide_subprocess_launcher_setenv (launcher, "SHELL", shell, TRUE);
+ if (config != NULL)
+ ide_config_apply_path (config, launcher);
+
if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, &error)))
ide_task_return_error (task, g_steal_pointer (&error));
else
@@ -493,7 +499,11 @@ ide_terminal_launcher_spawn_async (IdeTerminalLauncher *self,
switch (self->kind)
{
case LAUNCHER_KIND_RUNTIME:
- spawn_runtime_launcher (self, task, self->runtime, pty_fd);
+ spawn_runtime_launcher (self, task, self->runtime, NULL, pty_fd);
+ break;
+
+ case LAUNCHER_KIND_CONFIG:
+ spawn_runtime_launcher (self, task, self->runtime, self->config, pty_fd);
break;
case LAUNCHER_KIND_RUNNER:
@@ -549,6 +559,7 @@ ide_terminal_launcher_finalize (GObject *object)
g_clear_pointer (&self->title, g_free);
g_clear_object (&self->launcher);
g_clear_object (&self->runtime);
+ g_clear_object (&self->config);
G_OBJECT_CLASS (ide_terminal_launcher_parent_class)->finalize (object);
}
@@ -797,6 +808,35 @@ ide_terminal_launcher_new_for_debug (void)
return g_steal_pointer (&self);
}
+/**
+ * ide_terminal_launcher_new_for_config:
+ * @config: an #IdeConfig
+ *
+ * Create a new #IdeTerminalLauncher that will spawn a terminal in the runtime
+ * of the configuration with various build options applied.
+ *
+ * Returns: (transfer full): a newly created #IdeTerminalLauncher
+ */
+IdeTerminalLauncher *
+ide_terminal_launcher_new_for_config (IdeConfig *config)
+{
+ IdeTerminalLauncher *self;
+ IdeRuntime *runtime;
+
+ g_return_val_if_fail (IDE_IS_CONFIG (config), NULL);
+
+ runtime = ide_config_get_runtime (config);
+
+ self = g_object_new (IDE_TYPE_TERMINAL_LAUNCHER, NULL);
+ self->runtime = g_object_ref (runtime);
+ self->config = g_object_ref (config);
+ self->kind = LAUNCHER_KIND_CONFIG;
+
+ ide_terminal_launcher_set_title (self, ide_runtime_get_name (runtime));
+
+ return g_steal_pointer (&self);
+}
+
/**
* ide_terminal_launcher_new_for_runtime:
* @runtime: an #IdeRuntime
diff --git a/src/libide/terminal/ide-terminal-launcher.h b/src/libide/terminal/ide-terminal-launcher.h
index 33c2fda43..22edaf991 100644
--- a/src/libide/terminal/ide-terminal-launcher.h
+++ b/src/libide/terminal/ide-terminal-launcher.h
@@ -34,6 +34,8 @@ IDE_AVAILABLE_IN_3_34
IdeTerminalLauncher *ide_terminal_launcher_new (IdeContext *context);
IDE_AVAILABLE_IN_3_34
IdeTerminalLauncher *ide_terminal_launcher_new_for_launcher (IdeSubprocessLauncher *launcher);
+IDE_AVAILABLE_IN_42
+IdeTerminalLauncher *ide_terminal_launcher_new_for_config (IdeConfig *config);
IDE_AVAILABLE_IN_3_34
IdeTerminalLauncher *ide_terminal_launcher_new_for_debug (void);
IDE_AVAILABLE_IN_3_34
diff --git a/src/plugins/terminal/gbp-terminal-workspace-addin.c
b/src/plugins/terminal/gbp-terminal-workspace-addin.c
index 16ef146cb..3f95c1b41 100644
--- a/src/plugins/terminal/gbp-terminal-workspace-addin.c
+++ b/src/plugins/terminal/gbp-terminal-workspace-addin.c
@@ -135,6 +135,7 @@ new_terminal_activate (GSimpleAction *action,
IdeTerminalPage *page;
IdeSurface *surface;
IdeRuntime *runtime = NULL;
+ IdeContext *context;
const gchar *name;
GtkWidget *current_frame = NULL;
IdePage *current_page;
@@ -154,9 +155,23 @@ new_terminal_activate (GSimpleAction *action,
current_frame = gtk_widget_get_ancestor (GTK_WIDGET (current_page), IDE_TYPE_FRAME);
}
+ context = ide_workspace_get_context (self->workspace);
name = g_action_get_name (G_ACTION (action));
- if (ide_str_equal0 (name, "new-terminal-in-runtime"))
+ /* Only allow plain terminals unless this is a project */
+ if (!ide_context_has_project (context) &&
+ !ide_str_equal0 (name, "debug-terminal"))
+ name = "new-terminal";
+
+ if (ide_str_equal0 (name, "new-terminal-in-config"))
+ {
+ IdeConfigManager *config_manager = ide_config_manager_from_context (context);
+ IdeConfig *config = ide_config_manager_get_current (config_manager);
+
+ cwd = find_builddir (self->workspace);
+ launcher = ide_terminal_launcher_new_for_config (config);
+ }
+ else if (ide_str_equal0 (name, "new-terminal-in-runtime"))
{
runtime = find_runtime (self->workspace);
cwd = find_builddir (self->workspace);
@@ -180,7 +195,6 @@ new_terminal_activate (GSimpleAction *action,
}
else
{
- IdeContext *context = ide_widget_get_context (GTK_WIDGET (self->workspace));
launcher = ide_terminal_launcher_new (context);
}
}
@@ -343,6 +357,7 @@ on_run_manager_stopped (GbpTerminalWorkspaceAddin *self,
static const GActionEntry terminal_actions[] = {
{ "new-terminal-workspace", new_terminal_workspace },
{ "new-terminal", new_terminal_activate },
+ { "new-terminal-in-config", new_terminal_activate },
{ "new-terminal-in-runner", new_terminal_activate },
{ "new-terminal-in-runtime", new_terminal_activate },
{ "new-terminal-in-dir", new_terminal_activate },
@@ -358,7 +373,7 @@ static const DzlShortcutEntry gbp_terminal_shortcut_entries[] = {
N_("General"),
N_("Terminal") },
- { "org.gnome.builder.workspace.new-terminal-in-runtime",
+ { "org.gnome.builder.workspace.new-terminal-in-config",
0, NULL,
N_("Workspace shortcuts"),
N_("General"),
@@ -389,10 +404,10 @@ gbp_terminal_workspace_addin_setup_shortcuts (GbpTerminalWorkspaceAddin *self,
"win.new-terminal");
dzl_shortcut_controller_add_command_action (controller,
- "org.gnome.builder.workspace.new-terminal-in-runtime",
+ "org.gnome.builder.workspace.new-terminal-in-config",
I_("<primary><alt><shift>t"),
DZL_SHORTCUT_PHASE_DISPATCH,
- "win.new-terminal-in-runtime");
+ "win.new-terminal-in-config");
dzl_shortcut_controller_add_command_action (controller,
"org.gnome.builder.workspace.new-terminal-in-runner",
diff --git a/src/plugins/terminal/gtk/menus.ui b/src/plugins/terminal/gtk/menus.ui
index 7def307df..28eaa3757 100644
--- a/src/plugins/terminal/gtk/menus.ui
+++ b/src/plugins/terminal/gtk/menus.ui
@@ -14,7 +14,7 @@
<attribute name="id">new-build-terminal</attribute>
<attribute name="after">new-terminal</attribute>
<attribute name="label" translatable="yes">New _Build Terminal</attribute>
- <attribute name="action">win.new-terminal-in-runtime</attribute>
+ <attribute name="action">win.new-terminal-in-config</attribute>
<attribute name="accel"><ctrl><shift><alt>t</attribute>
</item>
<item>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]