Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Mon, 15 Oct 2018 19:26:14 UTC Commit: 1c11acbbaa5c9cc357528959d550f8e711d92b86 https://github.com/geany/geany-plugins/commit/1c11acbbaa5c9cc357528959d550f8...
Log Message: ----------- Make the "Delete" entry in the popup insensitive for non-empty directories
Also remove the TODO comment as we probably shouldn't allow non-empty directory deletion because it's dangerous. Because of file pattern filtering, directories may seem empty in the sidebar even though they contain files. This could confuse users thinking they are looking at empty directories they and could delete those by accident.
Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c
Modified: projectorganizer/src/prjorg-sidebar.c 21 lines changed, 19 insertions(+), 2 deletions(-) =================================================================== @@ -499,8 +499,6 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe { gchar *path = build_path(&iter);
- //TODO: recurse into directories - if (remove_file_or_dir(path)) close_file(path); else @@ -955,6 +953,8 @@ static gboolean on_button_release(G_GNUC_UNUSED GtkWidget * widget, GdkEventButt GtkTreeSelection *treesel; GtkTreeModel *model; GtkTreeIter iter; + gboolean delete_enabled = TRUE; + gchar *path;
treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view));
@@ -964,6 +964,23 @@ static gboolean on_button_release(G_GNUC_UNUSED GtkWidget * widget, GdkEventButt gtk_widget_set_sensitive(s_popup_menu.expand, gtk_tree_model_iter_has_child(model, &iter)); gtk_widget_set_sensitive(s_popup_menu.remove_external_dir, topmost_selected(model, &iter, FALSE));
+ path = build_path(&iter); + SETPTR(path, utils_get_locale_from_utf8(path)); + if (g_file_test(path, G_FILE_TEST_IS_DIR)) + { + GDir *dir = g_dir_open(path, 0, NULL); + + delete_enabled = FALSE; + if (dir) + { + delete_enabled = g_dir_read_name(dir) == NULL; + g_dir_close(dir); + } + } + g_free(path); + + gtk_widget_set_sensitive(s_popup_menu.delete, delete_enabled); + gtk_menu_popup(GTK_MENU(s_popup_menu.widget), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE;
Modified: projectorganizer/src/prjorg-utils.c 3 lines changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -111,9 +111,8 @@ void open_file(gchar *utf8_name)
void close_file(gchar *utf8_name) { - GeanyDocument *doc; + GeanyDocument *doc = document_find_by_filename(utf8_name);
- doc = document_find_by_filename(utf8_name); if (doc) { document_set_text_changed(doc, FALSE);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org