[gnome-builder] shellcmd: add close-on-exit option for shell commands
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] shellcmd: add close-on-exit option for shell commands
- Date: Sun, 11 Aug 2019 04:15:43 +0000 (UTC)
commit 12dd01994bab1518da156332a77243dddd371f09
Author: Christian Hergert <chergert redhat com>
Date: Sat Aug 10 21:15:36 2019 -0700
shellcmd: add close-on-exit option for shell commands
src/plugins/shellcmd/gbp-shellcmd-command-editor.c | 3 ++
.../shellcmd/gbp-shellcmd-command-editor.ui | 30 ++++++++++++
src/plugins/shellcmd/gbp-shellcmd-command.c | 54 +++++++++++++++++++--
src/plugins/shellcmd/gbp-shellcmd-command.h | 55 ++++++++++++----------
4 files changed, 111 insertions(+), 31 deletions(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-editor.c
b/src/plugins/shellcmd/gbp-shellcmd-command-editor.c
index 7f75535aa..be3c82781 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-editor.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-editor.c
@@ -46,6 +46,7 @@ struct _GbpShellcmdCommandEditor
GtkRadioButton *host;
GtkRadioButton *build;
GtkRadioButton *run;
+ GtkSwitch *close_on_exit;
};
G_DEFINE_TYPE (GbpShellcmdCommandEditor, gbp_shellcmd_command_editor, GTK_TYPE_BIN)
@@ -188,6 +189,7 @@ gbp_shellcmd_command_editor_class_init (GbpShellcmdCommandEditorClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/plugins/shellcmd/gbp-shellcmd-command-editor.ui");
gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, build);
gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, change);
+ gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, close_on_exit);
gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, command);
gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, delete);
gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandEditor, directory);
@@ -208,6 +210,7 @@ gbp_shellcmd_command_editor_init (GbpShellcmdCommandEditor *self)
self->bindings = dzl_binding_group_new ();
dzl_binding_group_bind (self->bindings, "title", self->title, "text", G_BINDING_BIDIRECTIONAL);
+ dzl_binding_group_bind (self->bindings, "close-on-exit", self->close_on_exit, "active",
G_BINDING_BIDIRECTIONAL);
dzl_binding_group_bind (self->bindings, "command", self->command, "text", G_BINDING_BIDIRECTIONAL);
dzl_binding_group_bind (self->bindings, "shortcut", self->shortcut, "accelerator",
G_BINDING_BIDIRECTIONAL);
dzl_binding_group_bind (self->bindings, "cwd", self->directory, "text", G_BINDING_BIDIRECTIONAL);
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-editor.ui
b/src/plugins/shellcmd/gbp-shellcmd-command-editor.ui
index 92fd99127..b6df4cc99 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-editor.ui
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-editor.ui
@@ -116,6 +116,36 @@
</style>
</object>
</child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Close on Exit</property>
+ <property name="margin-top">10</property>
+ <property name="visible">true</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="close_on_exit">
+ <property name="halign">start</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">If enabled, the terminal page will close after the
command executes.</property>
+ <property name="visible">true</property>
+ <property name="wrap">true</property>
+ <property name="width-chars">10</property>
+ <property name="max-width-chars">10</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="scale" value="0.8333"/>
+ </attributes>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Keyboard Shortcut</property>
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command.c b/src/plugins/shellcmd/gbp-shellcmd-command.c
index 699f9d998..c91dd60f6 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command.c
@@ -47,15 +47,18 @@ struct _GbpShellcmdCommand
gchar *command;
gchar *cwd;
IdeEnvironment *environment;
+
+ guint close_on_exit : 1;
};
enum {
PROP_0,
- PROP_ID,
+ PROP_CLOSE_ON_EXIT,
PROP_COMMAND,
PROP_CWD,
PROP_ENV,
PROP_ENVIRONMENT,
+ PROP_ID,
PROP_LOCALITY,
PROP_SHORTCUT,
PROP_SUBTITLE,
@@ -126,6 +129,10 @@ gbp_shellcmd_command_get_property (GObject *object,
g_value_set_string (value, gbp_shellcmd_command_get_id (self));
break;
+ case PROP_CLOSE_ON_EXIT:
+ g_value_set_boolean (value, gbp_shellcmd_command_get_close_on_exit (self));
+ break;
+
case PROP_COMMAND:
g_value_set_string (value, gbp_shellcmd_command_get_command (self));
break;
@@ -173,6 +180,10 @@ gbp_shellcmd_command_set_property (GObject *object,
self->id = g_value_dup_string (value);
break;
+ case PROP_CLOSE_ON_EXIT:
+ gbp_shellcmd_command_set_close_on_exit (self, g_value_get_boolean (value));
+ break;
+
case PROP_COMMAND:
gbp_shellcmd_command_set_command (self, g_value_get_string (value));
break;
@@ -222,6 +233,13 @@ gbp_shellcmd_command_class_init (GbpShellcmdCommandClass *klass)
NULL,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_CLOSE_ON_EXIT] =
+ g_param_spec_boolean ("close-on-exit",
+ "Close on Exit",
+ "If the terminal should automatically close after running",
+ FALSE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_COMMAND] =
g_param_spec_string ("command",
"Command",
@@ -452,7 +470,7 @@ gbp_shellcmd_command_run_host (GbpShellcmdCommand *self,
tlauncher = ide_terminal_launcher_new_for_launcher (launcher);
page = g_object_new (IDE_TYPE_TERMINAL_PAGE,
- "close-on-exit", FALSE,
+ "close-on-exit", self->close_on_exit,
"launcher", tlauncher,
"manage-spawn", TRUE,
"respawn-on-exit", FALSE,
@@ -509,7 +527,7 @@ gbp_shellcmd_command_run_app (GbpShellcmdCommand *self,
tlauncher = ide_terminal_launcher_new_for_launcher (launcher);
page = g_object_new (IDE_TYPE_TERMINAL_PAGE,
- "close-on-exit", FALSE,
+ "close-on-exit", self->close_on_exit,
"launcher", tlauncher,
"manage-spawn", TRUE,
"respawn-on-exit", FALSE,
@@ -585,7 +603,7 @@ gbp_shellcmd_command_run_runner (GbpShellcmdCommand *self,
ide_pipeline_get_builddir (pipeline));
page = g_object_new (IDE_TYPE_TERMINAL_PAGE,
- "close-on-exit", FALSE,
+ "close-on-exit", self->close_on_exit,
"launcher", launcher,
"manage-spawn", TRUE,
"respawn-on-exit", FALSE,
@@ -660,7 +678,7 @@ gbp_shellcmd_command_run_build (GbpShellcmdCommand *self,
tlauncher = ide_terminal_launcher_new_for_launcher (launcher);
page = g_object_new (IDE_TYPE_TERMINAL_PAGE,
- "close-on-exit", FALSE,
+ "close-on-exit", self->close_on_exit,
"launcher", tlauncher,
"manage-spawn", TRUE,
"respawn-on-exit", FALSE,
@@ -1043,12 +1061,14 @@ gbp_shellcmd_command_copy (GbpShellcmdCommand *self)
ret = g_object_new (GBP_TYPE_SHELLCMD_COMMAND, NULL);
ret->locality = self->locality;
+ ret->priority = self->priority;
ret->id = g_strdup (self->id);
ret->shortcut = g_strdup (self->shortcut);
ret->title = g_strdup (self->title);
ret->subtitle = g_strdup (self->subtitle);
ret->command = g_strdup (self->command);
ret->cwd = g_strdup (self->cwd);
+ ret->close_on_exit = self->close_on_exit;
if (self->environment != NULL)
{
@@ -1068,3 +1088,27 @@ gbp_shellcmd_command_set_priority (GbpShellcmdCommand *self,
self->priority = priority;
}
+
+gboolean
+gbp_shellcmd_command_get_close_on_exit (GbpShellcmdCommand *self)
+{
+ g_return_val_if_fail (GBP_IS_SHELLCMD_COMMAND (self), FALSE);
+
+ return self->close_on_exit;
+}
+
+void
+gbp_shellcmd_command_set_close_on_exit (GbpShellcmdCommand *self,
+ gboolean close_on_exit)
+{
+ g_return_if_fail (GBP_IS_SHELLCMD_COMMAND (self));
+
+ close_on_exit = !!close_on_exit;
+
+ if (close_on_exit != self->close_on_exit)
+ {
+ self->close_on_exit = close_on_exit;
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CLOSE_ON_EXIT]);
+ gbp_shellcmd_command_changed (self);
+ }
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command.h b/src/plugins/shellcmd/gbp-shellcmd-command.h
index e0bc60fdf..d81ba8566 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-command.h
@@ -37,31 +37,34 @@ typedef enum
G_DECLARE_FINAL_TYPE (GbpShellcmdCommand, gbp_shellcmd_command, GBP, SHELLCMD_COMMAND, IdeObject)
-GbpShellcmdCommand *gbp_shellcmd_command_from_key_file (GKeyFile *key_file,
- const gchar *group,
- GError **error);
-void gbp_shellcmd_command_to_key_file (GbpShellcmdCommand *self,
- GKeyFile *key_file);
-GbpShellcmdCommand *gbp_shellcmd_command_copy (GbpShellcmdCommand *self);
-const gchar *gbp_shellcmd_command_get_id (GbpShellcmdCommand *self);
-GbpShellcmdCommandLocality gbp_shellcmd_command_get_locality (GbpShellcmdCommand *self);
-void gbp_shellcmd_command_set_locality (GbpShellcmdCommand *self,
- GbpShellcmdCommandLocality locality);
-const gchar *gbp_shellcmd_command_get_command (GbpShellcmdCommand *self);
-void gbp_shellcmd_command_set_command (GbpShellcmdCommand *self,
- const gchar *command);
-const gchar *gbp_shellcmd_command_get_cwd (GbpShellcmdCommand *self);
-void gbp_shellcmd_command_set_cwd (GbpShellcmdCommand *self,
- const gchar *cwd);
-IdeEnvironment *gbp_shellcmd_command_get_environment (GbpShellcmdCommand *self);
-void gbp_shellcmd_command_set_priority (GbpShellcmdCommand *self,
- gint priority);
-const gchar *gbp_shellcmd_command_get_shortcut (GbpShellcmdCommand *self);
-void gbp_shellcmd_command_set_shortcut (GbpShellcmdCommand *self,
- const gchar *shortcut);
-void gbp_shellcmd_command_set_subtitle (GbpShellcmdCommand *self,
- const gchar *subtitle);
-void gbp_shellcmd_command_set_title (GbpShellcmdCommand *self,
- const gchar *title);
+GbpShellcmdCommand *gbp_shellcmd_command_from_key_file (GKeyFile *key_file,
+ const gchar *group,
+ GError **error);
+void gbp_shellcmd_command_to_key_file (GbpShellcmdCommand *self,
+ GKeyFile *key_file);
+GbpShellcmdCommand *gbp_shellcmd_command_copy (GbpShellcmdCommand *self);
+const gchar *gbp_shellcmd_command_get_id (GbpShellcmdCommand *self);
+GbpShellcmdCommandLocality gbp_shellcmd_command_get_locality (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_locality (GbpShellcmdCommand *self,
+ GbpShellcmdCommandLocality locality);
+const gchar *gbp_shellcmd_command_get_command (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_command (GbpShellcmdCommand *self,
+ const gchar *command);
+const gchar *gbp_shellcmd_command_get_cwd (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_cwd (GbpShellcmdCommand *self,
+ const gchar *cwd);
+IdeEnvironment *gbp_shellcmd_command_get_environment (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_priority (GbpShellcmdCommand *self,
+ gint priority);
+const gchar *gbp_shellcmd_command_get_shortcut (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_shortcut (GbpShellcmdCommand *self,
+ const gchar *shortcut);
+void gbp_shellcmd_command_set_subtitle (GbpShellcmdCommand *self,
+ const gchar *subtitle);
+void gbp_shellcmd_command_set_title (GbpShellcmdCommand *self,
+ const gchar *title);
+gboolean gbp_shellcmd_command_get_close_on_exit (GbpShellcmdCommand *self);
+void gbp_shellcmd_command_set_close_on_exit (GbpShellcmdCommand *self,
+ gboolean
close_on_exit);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]