Created
July 28, 2015 01:03
-
-
Save codebrainz/9dd84b5a7c08e710085c to your computer and use it in GitHub Desktop.
Fix "Open in New Window" feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/utils.c b/src/utils.c | |
index c5edd5a..37ae12a 100644 | |
--- a/src/utils.c | |
+++ b/src/utils.c | |
@@ -2154,30 +2154,35 @@ const gchar *utils_resource_dir(GeanyResourceDirType type) | |
void utils_start_new_geany_instance(const gchar *doc_path) | |
{ | |
- const gchar *const *argv; | |
const gchar *command = is_osx_bundle() ? "open" : "geany"; | |
gchar *exec_path = g_find_program_in_path(command); | |
if (exec_path) | |
{ | |
GError *err = NULL; | |
+ GPtrArray *args = g_ptr_array_sized_new (6); | |
+ g_ptr_array_add (args, exec_path); | |
if (is_osx_bundle()) | |
{ | |
- const gchar *const osx_argv[] = {exec_path, "-n", "-a", "Geany", doc_path, NULL}; | |
- argv = osx_argv; | |
+ g_ptr_array_add (args, (gpointer) "-n"); | |
+ g_ptr_array_add (args, (gpointer) "-a"); | |
+ g_ptr_array_add (args, (gpointer) "Geany"); | |
+ g_ptr_array_add (args, (gpointer) doc_path); | |
} | |
else | |
{ | |
- const gchar *const unix_argv[] = {exec_path, "-i", doc_path, NULL}; | |
- argv = unix_argv; | |
+ g_ptr_array_add (args, (gpointer) "-i"); | |
+ g_ptr_array_add (args, (gpointer) doc_path); | |
} | |
+ g_ptr_array_add (args, NULL); | |
- if (!utils_spawn_async(NULL, (gchar**) argv, NULL, 0, NULL, NULL, NULL, &err)) | |
+ if (!utils_spawn_async(NULL, (gchar**) args->pdata, NULL, 0, NULL, NULL, NULL, &err)) | |
{ | |
g_printerr("Unable to open new window: %s", err->message); | |
g_error_free(err); | |
} | |
+ g_ptr_array_free (args, TRUE); | |
g_free(exec_path); | |
} | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/utils.c b/src/utils.c | |
index c5edd5a..8638b13 100644 | |
--- a/src/utils.c | |
+++ b/src/utils.c | |
@@ -2154,24 +2154,29 @@ const gchar *utils_resource_dir(GeanyResourceDirType type) | |
void utils_start_new_geany_instance(const gchar *doc_path) | |
{ | |
- const gchar *const *argv; | |
const gchar *command = is_osx_bundle() ? "open" : "geany"; | |
gchar *exec_path = g_find_program_in_path(command); | |
if (exec_path) | |
{ | |
GError *err = NULL; | |
+ const gchar *argv[6]; // max args + 1 | |
+ gint argc = 0; | |
+ argv[argc++] = exec_path; | |
if (is_osx_bundle()) | |
{ | |
- const gchar *const osx_argv[] = {exec_path, "-n", "-a", "Geany", doc_path, NULL}; | |
- argv = osx_argv; | |
+ argv[argc++] = "-n"; | |
+ argv[argc++] = "-a"; | |
+ argv[argc++] = "Geany"; | |
+ argv[argc++] = doc_path; | |
} | |
else | |
{ | |
- const gchar *const unix_argv[] = {exec_path, "-i", doc_path, NULL}; | |
- argv = unix_argv; | |
+ argv[argc++] = "-i"; | |
+ argv[argc++] = doc_path; | |
} | |
+ argv[argc++] = NULL; | |
if (!utils_spawn_async(NULL, (gchar**) argv, NULL, 0, NULL, NULL, NULL, &err)) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last increment (argc++) is superflous but otherwise looks fine.