[Xfce4-commits] [xfce/exo] 01/01: exo-launch: pass flags to preferred application (Bug 9427), Add exo_str_is_flag to public API

noreply at xfce.org noreply at xfce.org
Mon Jul 17 11:53:20 CEST 2017


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/exo.

commit 21be6acf87c8575fdbe44dd0399583c115368c5c
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Mon Jul 17 05:53:13 2017 -0400

    exo-launch: pass flags to preferred application (Bug 9427), Add exo_str_is_flag to public API
---
 docs/reference/exo-sections.txt |  1 +
 exo-helper/exo-helper.c         | 14 +++++++++++++-
 exo-helper/main.c               |  1 +
 exo/exo-string.c                | 22 ++++++++++++++++++++++
 exo/exo-string.h                |  1 +
 exo/exo.symbols                 |  1 +
 6 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/docs/reference/exo-sections.txt b/docs/reference/exo-sections.txt
index 98bf661..e1ade8e 100644
--- a/docs/reference/exo-sections.txt
+++ b/docs/reference/exo-sections.txt
@@ -441,6 +441,7 @@ exo_execute_terminal_shell_on_screen
 exo_str_elide_underscores
 exo_str_is_equal
 exo_str_is_empty
+exo_str_is_flag
 exo_str_looks_like_an_uri
 exo_str_replace
 exo_strdup_strftime
diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c
index 6bfd202..44da82b 100644
--- a/exo-helper/exo-helper.c
+++ b/exo-helper/exo-helper.c
@@ -70,6 +70,7 @@ struct _ExoHelper
   gchar            *name;
   gchar           **commands;
   gchar           **commands_with_parameter;
+  gchar           **commands_with_flag;
   ExoHelperCategory category;
 };
 
@@ -102,6 +103,7 @@ exo_helper_finalize (GObject *object)
 {
   ExoHelper *helper = EXO_HELPER (object);
 
+  g_strfreev (helper->commands_with_flag);
   g_strfreev (helper->commands_with_parameter);
   g_strfreev (helper->commands);
   g_free (helper->name);
@@ -153,6 +155,7 @@ static ExoHelper*
 exo_helper_new (const gchar *id,
                 XfceRc      *rc)
 {
+  const gchar *commands_with_flag;
   const gchar *commands_with_parameter;
   const gchar *commands;
   const gchar *str;
@@ -197,6 +200,8 @@ exo_helper_new (const gchar *id,
   if (G_UNLIKELY (commands == NULL))
     goto failed;
 
+  commands_with_flag = exo_str_replace (commands, ";", " %s;");
+
   /* determine the commands (with parameter) */
   commands_with_parameter = xfce_rc_read_entry_untranslated (rc, "X-XFCE-CommandsWithParameter", NULL);
   if (G_UNLIKELY (commands_with_parameter == NULL))
@@ -224,6 +229,7 @@ exo_helper_new (const gchar *id,
 
   /* substitute the binary (if any) */
   helper->commands = substitute_binary (commands, binary);
+  helper->commands_with_flag = substitute_binary (commands_with_flag, binary);
   helper->commands_with_parameter = substitute_binary (commands_with_parameter, binary);
   g_free (binary);
 
@@ -381,7 +387,13 @@ exo_helper_execute (ExoHelper   *helper,
     real_parameter = parameter + 7;
 
   /* determine the command set to use */
-  commands = !exo_str_is_empty (real_parameter) ? helper->commands_with_parameter : helper->commands;
+  if (exo_str_is_flag (real_parameter)) {
+    commands = helper->commands_with_flag;
+  } else if (exo_str_is_empty (real_parameter)) {
+    commands = helper->commands;
+  } else {
+    commands = helper->commands_with_parameter;
+  }
 
   /* verify that we have atleast one command */
   if (G_UNLIKELY (*commands == NULL))
diff --git a/exo-helper/main.c b/exo-helper/main.c
index baa440f..13831c3 100644
--- a/exo-helper/main.c
+++ b/exo-helper/main.c
@@ -97,6 +97,7 @@ main (int argc, char **argv)
   g_option_context_add_group (opt_ctx, gtk_option_group);
 
   g_option_context_add_main_entries (opt_ctx, option_entries, NULL);
+  g_option_context_set_ignore_unknown_options (opt_ctx, TRUE);
   /* Note to Translators: Do not translate the TYPEs (WebBrowser, MailReader,
    * FileManager and TerminalEmulator), since the exo-helper utility will
    * not accept localized TYPEs.
diff --git a/exo/exo-string.c b/exo/exo-string.c
index b80cc42..646bdb8 100644
--- a/exo/exo-string.c
+++ b/exo/exo-string.c
@@ -437,5 +437,27 @@ exo_str_looks_like_an_uri (const gchar *str)
 
 
 
+/**
+ * exo_str_is_flag:
+ * @str : an input string.
+ *
+ * Check if @str looks like a commandline flag. This function simply
+ * checks if the string begins with a single dash.
+ *
+ * Returns: %TRUE if the @str looks like a flag, %FALSE otherwise.
+ *
+ * Since: 0.11.5
+ **/
+gboolean
+exo_str_is_flag (const gchar *str)
+{
+  if (G_UNLIKELY (str == NULL))
+    return FALSE;
+
+  return g_str_has_prefix (str, "-");
+}
+
+
+
 #define __EXO_STRING_C__
 #include <exo/exo-aliasdef.c>
diff --git a/exo/exo-string.h b/exo/exo-string.h
index 596ee3f..d1b0d8f 100644
--- a/exo/exo-string.h
+++ b/exo/exo-string.h
@@ -47,6 +47,7 @@ gchar               **exo_strndupv               (gchar          **strv,
 
 gboolean              exo_str_looks_like_an_uri  (const gchar     *str);
 
+gboolean              exo_str_is_flag            (const gchar     *str);
 
 
 /**
diff --git a/exo/exo.symbols b/exo/exo.symbols
index b340038..8a9aae1 100644
--- a/exo/exo.symbols
+++ b/exo/exo.symbols
@@ -270,6 +270,7 @@ exo_simple_job_launch G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
 #if IN_SOURCE(__EXO_STRING_C__)
 exo_str_elide_underscores G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
 exo_str_is_equal
+exo_str_is_flag
 exo_str_replace G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
 exo_strdup_strftime G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
 exo_strndupv G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list