Revision: 1228 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1228&view=re... Author: dimitrov-adrian Date: 2010-04-10 17:37:43 +0000 (Sat, 10 Apr 2010)
Log Message: ----------- Treebrowser: make right click menu dynamic
Modified Paths: -------------- trunk/geany-plugins/treebrowser/ChangeLog trunk/geany-plugins/treebrowser/src/treebrowser.c
Modified: trunk/geany-plugins/treebrowser/ChangeLog =================================================================== --- trunk/geany-plugins/treebrowser/ChangeLog 2010-04-10 16:59:27 UTC (rev 1227) +++ trunk/geany-plugins/treebrowser/ChangeLog 2010-04-10 17:37:43 UTC (rev 1228) @@ -27,6 +27,7 @@ some string changed in prefs dialog added option to close document if it is deleted from treebrowser highlighing addressbar if typed directory not exists + make right click menu dynamic
31-03-2010 Adrian Dimitrov dimitrov.adrian@gmail.com
Modified: trunk/geany-plugins/treebrowser/src/treebrowser.c =================================================================== --- trunk/geany-plugins/treebrowser/src/treebrowser.c 2010-04-10 16:59:27 UTC (rev 1227) +++ trunk/geany-plugins/treebrowser/src/treebrowser.c 2010-04-10 17:37:43 UTC (rev 1228) @@ -389,6 +389,13 @@ * ------------------*/
static void +on_menu_close(GtkMenuItem *menuitem, gchar *uri) +{ + if (g_file_test(uri, G_FILE_TEST_EXISTS)) + document_close(document_find_by_filename(uri)); +} + +static void on_menu_go_up(GtkMenuItem *menuitem, gpointer *user_data) { treebrowser_chroot(g_path_get_dirname(addressbar_last_address)); @@ -401,60 +408,39 @@ }
static void -on_menu_open_externally(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_open_externally(GtkMenuItem *menuitem, gchar *uri) { - - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - GtkTreeIter iter; - GtkTreeModel *model; - gchar *uri; - gchar *cmd, *locale_cmd, *dir; GString *cmd_str = g_string_new(CONFIG_OPEN_EXTERNAL_CMD); GError *error = NULL;
- if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - gtk_tree_model_get(model, &iter, TREEBROWSER_COLUMN_URI, &uri, -1); + dir = g_file_test(uri, G_FILE_TEST_IS_DIR) ? g_strdup(uri) : g_path_get_dirname(uri);
- dir = g_file_test(uri, G_FILE_TEST_IS_DIR) ? g_strdup(uri) : g_path_get_dirname(uri); + utils_string_replace_all(cmd_str, "%f", uri); + utils_string_replace_all(cmd_str, "%d", dir);
- utils_string_replace_all(cmd_str, "%f", uri); - utils_string_replace_all(cmd_str, "%d", dir); - - cmd = g_string_free(cmd_str, FALSE); - locale_cmd = utils_get_locale_from_utf8(cmd); - if (! g_spawn_command_line_async(locale_cmd, &error)) - { - gchar *c = strchr(cmd, ' '); - if (c != NULL) - *c = '\0'; - ui_set_statusbar(TRUE, - _("Could not execute configured external command '%s' (%s)."), - cmd, error->message); - g_error_free(error); - } - g_free(locale_cmd); - g_free(cmd); - g_free(dir); + cmd = g_string_free(cmd_str, FALSE); + locale_cmd = utils_get_locale_from_utf8(cmd); + if (! g_spawn_command_line_async(locale_cmd, &error)) + { + gchar *c = strchr(cmd, ' '); + if (c != NULL) + *c = '\0'; + ui_set_statusbar(TRUE, + _("Could not execute configured external command '%s' (%s)."), + cmd, error->message); + g_error_free(error); } + g_free(locale_cmd); + g_free(cmd); + g_free(dir); }
static void -on_menu_set_as_root(GtkMenuItem *menuitem, const gchar *type) +on_menu_set_as_root(GtkMenuItem *menuitem, gchar *uri) { - - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - GtkTreeIter iter; - GtkTreeModel *model; - gchar *uri; - - if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - gtk_tree_model_get(model, &iter, TREEBROWSER_COLUMN_URI, &uri, -1); - if (g_file_test(uri, G_FILE_TEST_IS_DIR)) - treebrowser_chroot(uri); - } + if (g_file_test(uri, G_FILE_TEST_IS_DIR)) + treebrowser_chroot(uri); }
static void @@ -610,12 +596,24 @@ }
static GtkWidget* -create_popup_menu(gpointer *user_data) +create_popup_menu(gchar *name, gchar *uri) { + gboolean is_exists = g_file_test(uri, G_FILE_TEST_EXISTS); + gboolean is_dir = is_exists ? g_file_test(uri, G_FILE_TEST_IS_DIR) : FALSE; GtkWidget *item, *menu;
menu = gtk_menu_new();
+ if (document_find_by_filename(uri) != NULL) + { + item = ui_image_menu_item_new(GTK_STOCK_CLOSE, g_strdup_printf(_("Close: %s"), name)); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_close), uri); + + item = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu), item); + } + item = ui_image_menu_item_new(GTK_STOCK_GO_UP, _("Go up")); gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_go_up), NULL); @@ -624,16 +622,21 @@ gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_current_path), NULL);
- item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Open externally")); - gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_open_externally), NULL); + if (is_exists) + { + item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Open externally")); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_open_externally), uri); + }
- item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Set as root")); - gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_set_as_root), NULL); + if (is_dir) + { + item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Set as root")); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_set_as_root), uri); + }
item = gtk_separator_menu_item_new(); - gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
item = ui_image_menu_item_new(GTK_STOCK_ADD, _("Create new directory")); @@ -644,16 +647,18 @@ gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_object), "file");
- item = ui_image_menu_item_new(GTK_STOCK_SAVE_AS, _("Rename")); - gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_rename), NULL); + if (is_exists) + { + item = ui_image_menu_item_new(GTK_STOCK_SAVE_AS, _("Rename")); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_rename), NULL);
- item = ui_image_menu_item_new(GTK_STOCK_DELETE, _("Delete")); - gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_delete), NULL); + item = ui_image_menu_item_new(GTK_STOCK_DELETE, _("Delete")); + gtk_container_add(GTK_CONTAINER(menu), item); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_delete), NULL); + }
item = gtk_separator_menu_item_new(); - gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
item = ui_image_menu_item_new(GTK_STOCK_REFRESH, _("Refresh")); @@ -673,7 +678,6 @@ g_signal_connect(item, "activate", G_CALLBACK(on_menu_collapse_all), NULL);
item = gtk_separator_menu_item_new(); - gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
menu_showbars = gtk_check_menu_item_new_with_mnemonic(_("Show bars")); @@ -754,14 +758,23 @@ * ------------------ */
static gboolean -on_treeview_mouseclick(GtkWidget *widget, GdkEventButton *event, gpointer user_data) +on_treeview_mouseclick(GtkWidget *widget, GdkEventButton *event, GtkTreeSelection *selection) { + GtkTreeIter iter; + GtkTreeModel *model; + gchar *name = NULL, *uri = NULL; + + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + gtk_tree_model_get(GTK_TREE_MODEL(treestore), &iter, + TREEBROWSER_COLUMN_NAME, &name, + TREEBROWSER_COLUMN_URI, &uri, + -1); + } + if (event->button == 3) { - static GtkWidget *popup_menu = NULL; - if (popup_menu == NULL) - popup_menu = create_popup_menu(user_data); - gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL, event->button, event->time); + gtk_menu_popup(GTK_MENU(create_popup_menu(name, uri)), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE; } return FALSE;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.