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.
This commit is contained in:
parent
562885765d
commit
232d4dacde
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
15
src/osx.c
15
src/osx.c
@ -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 */
|
||||
|
33
src/utils.c
33
src/utils.c
@ -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'");
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user