Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Wed, 04 Mar 2015 11:40:45 UTC Commit: 232d4dacded6d98a827414d62fa9879f618fb4f1 https://github.com/geany/geany/commit/232d4dacded6d98a827414d62fa9879f618fb4...
Log Message: ----------- Add right-click launcher icon entry creating a new window
Normal clicking the launcher icon just brings the application to the foreground so there must be a way users can create a new instance of Geany.
Add an entry "New Window" to the context menu which is shown when right-clicking the Geany icon in the launcher (most applications have the "New Window" entry there).
In addition, fix "Open in new window" when using app bundle.
Since both of these functionalities create a new Geany instance, factor-out the instance creation code into a new utility function and use it in both cases.
Modified Paths: -------------- src/notebook.c src/osx.c src/utils.c src/utils.h
Modified: src/notebook.c 23 lines changed, 4 insertions(+), 19 deletions(-) =================================================================== @@ -419,29 +419,14 @@ static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data)
static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data) { - gchar *geany_path; GeanyDocument *doc = user_data; + gchar *doc_path;
g_return_if_fail(doc->is_valid);
- geany_path = g_find_program_in_path("geany"); - - if (geany_path) - { - gchar *doc_path = utils_get_locale_from_utf8(doc->file_name); - gchar *argv[] = {geany_path, "-i", doc_path, NULL}; - GError *err = NULL; - - if (!utils_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &err)) - { - g_printerr("Unable to open new window: %s", err->message); - g_error_free(err); - } - g_free(doc_path); - g_free(geany_path); - } - else - g_printerr("Unable to find 'geany'"); + doc_path = utils_get_locale_from_utf8(doc->file_name); + utils_start_new_geany_instance(doc_path); + g_free(doc_path); }
Modified: src/osx.c 15 lines changed, 14 insertions(+), 1 deletions(-) =================================================================== @@ -22,6 +22,7 @@
#include "osx.h"
+#include "utils.h" #include "ui_utils.h" #include "main.h"
@@ -79,9 +80,15 @@ static gboolean app_open_file_cb(GtkosxApplication *osx_app, gchar *path, gpoint }
+static void on_new_window(GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + utils_start_new_geany_instance(NULL); +} + + void osx_ui_init(void) { - GtkWidget *item; + GtkWidget *item, *menu; GtkosxApplication *osx_app = gtkosx_application_get();
item = ui_lookup_widget(main_widgets.window, "menubar1"); @@ -103,6 +110,12 @@ void osx_ui_init(void) G_CALLBACK(app_block_termination_cb), NULL); g_signal_connect(osx_app, "NSApplicationOpenFile", G_CALLBACK(app_open_file_cb), NULL); + + menu = gtk_menu_new(); + item = gtk_menu_item_new_with_label("New Window"); + g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(on_new_window), NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + gtkosx_application_set_dock_menu(osx_app, GTK_MENU_SHELL(menu)); }
#endif /* MAC_INTEGRATION */
Modified: src/utils.c 33 lines changed, 33 insertions(+), 0 deletions(-) =================================================================== @@ -2147,3 +2147,36 @@ const gchar *utils_resource_dir(GeanyResourceDirType type)
return resdirs[type]; } + + +void utils_start_new_geany_instance(gchar *doc_path) +{ + gchar **argv; + const gchar *command = is_osx_bundle() ? "open" : "geany"; + gchar *exec_path = g_find_program_in_path(command); + + if (exec_path) + { + GError *err = NULL; + + if (is_osx_bundle()) + { + gchar *osx_argv[] = {exec_path, "-n", "-a", "Geany", doc_path, NULL}; + argv = osx_argv; + } + else + { + gchar *unix_argv[] = {exec_path, "-i", doc_path, NULL}; + argv = unix_argv; + } + + if (!utils_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &err)) + { + g_printerr("Unable to open new window: %s", err->message); + g_error_free(err); + } + g_free(exec_path); + } + else + g_printerr("Unable to find 'geany'"); +}
Modified: src/utils.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -308,6 +308,8 @@ gchar *utils_get_user_config_dir(void);
const gchar *utils_resource_dir(GeanyResourceDirType type);
+void utils_start_new_geany_instance(gchar *doc_path); + #endif /* GEANY_PRIVATE */
G_END_DECLS
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).