Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Created November 22, 2010 23:14
Show Gist options
  • Save codebrainz/710909 to your computer and use it in GitHub Desktop.
Save codebrainz/710909 to your computer and use it in GitHub Desktop.
Patch for notebook.c file in Geany to add an item to open the file in a new instance of Geany to the tabs' right-click menu when the tab contains a saved file.
--- geany-svn/src/notebook.c 2010-11-21 20:53:12.943333841 -0800
+++ geany-local/src/notebook.c 2010-11-21 20:54:20.836667216 -0800
@@ -193,10 +193,35 @@
}
+static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ gchar **argv;
+ gchar *doc_path;
+ gchar *geany_path;
+ GError *err = NULL;
+
+ doc_path = (gchar *)user_data;
+ geany_path = g_find_program_in_path("geany"); /* is it ok? */
+
+ argv = g_new0(gchar *, 4);
+ argv[0] = g_strdup(geany_path);
+ argv[1] = g_strdup("-i");
+ argv[2] = g_strdup(doc_path);
+ argv[3] = NULL;
+
+ if (!utils_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &err))
+ g_printerr("Unable to open new window: %s", err->message);
+
+ g_free(geany_path);
+ g_strfreev(argv);
+}
+
+
static void show_tab_bar_popup_menu(GdkEventButton *event)
{
GtkWidget *menu_item;
static GtkWidget *menu = NULL;
+ GeanyDocument *doc = NULL;
if (menu == NULL)
menu = gtk_menu_new();
@@ -207,6 +232,21 @@
ui_menu_add_document_items(GTK_MENU(menu), document_get_current(),
G_CALLBACK(tab_bar_menu_activate_cb));
+ /* load "Open in a New Window" item if current document has filename */
+ doc = document_get_current();
+ if (doc != NULL && doc->file_name != NULL)
+ {
+ menu_item = gtk_separator_menu_item_new();
+ gtk_widget_show(menu_item);
+ gtk_container_add(GTK_CONTAINER(menu), menu_item);
+
+ menu_item = gtk_menu_item_new_with_mnemonic("Open in a New _Window");
+ gtk_widget_show(menu_item);
+ gtk_container_add(GTK_CONTAINER(menu), menu_item);
+ g_signal_connect(menu_item, "activate",
+ G_CALLBACK(on_open_in_new_window_activate), doc->file_name);
+ }
+
menu_item = gtk_separator_menu_item_new();
gtk_widget_show(menu_item);
gtk_container_add(GTK_CONTAINER(menu), menu_item);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment