lists.geany.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
List overview
Plugins-Commits
April 2019
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
plugins-commits@lists.geany.org
1 participants
50 discussions
Start a n
N
ew thread
[geany/geany-plugins] 1c11ac: Make the "Delete" entry in the popup insensitive for non-empty directories
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 15 Oct 2018 19:26:14 UTC Commit: 1c11acbbaa5c9cc357528959d550f8e711d92b86
https://github.com/geany/geany-plugins/commit/1c11acbbaa5c9cc357528959d550f…
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
).
1
0
0
0
[geany/geany-plugins] 48a871: Make it more clear what's going on with "sentinel"
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 15 Oct 2018 14:18:13 UTC Commit: 48a8717d27e76dfc1fc0c0e900950126132a65ac
https://github.com/geany/geany-plugins/commit/48a8717d27e76dfc1fc0c0e900950…
Log Message: ----------- Make it more clear what's going on with "sentinel" The "sentinel" entry is a dummy entry for an empty directory - make this more clear in the code and explicitly disable tag manager attempts to parse such entries. Modified Paths: -------------- projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c Modified: projectorganizer/src/prjorg-project.c 12 lines changed, 8 insertions(+), 4 deletions(-) =================================================================== @@ -114,11 +114,12 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns, if (!patterns_match(ignored_dirs_patterns, utf8_name)) { - list = g_slist_prepend(list, g_build_path(G_DIR_SEPARATOR_S, utf8_filename, PROJORG_SENTINEL_FILENAME, NULL)); lst = get_file_list(utf8_filename, patterns, ignored_dirs_patterns, ignored_file_patterns, visited_paths); if (lst) list = g_slist_concat(list, lst); + else + list = g_slist_prepend(list, g_build_path(G_DIR_SEPARATOR_S, utf8_filename, PROJORG_DIR_ENTRY, NULL)); } } else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) @@ -285,16 +286,19 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) g_hash_table_iter_init(&iter, root->file_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - TMSourceFile *sf; + TMSourceFile *sf = NULL; gchar *utf8_path = key; gchar *locale_path = utils_get_locale_from_utf8(utf8_path); + gchar *basename = g_path_get_basename(locale_path); - sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); - if (sf && !document_find_by_filename(utf8_path)) + if (g_strcmp0(PROJORG_DIR_ENTRY, basename) != 0) + sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); + if (sf && !document_find_by_filename(utf8_path) ) g_ptr_array_add(source_files, sf); g_hash_table_insert(file_table, g_strdup(utf8_path), sf); g_free(locale_path); + g_free(basename); } g_hash_table_destroy(root->file_table); root->file_table = file_table; Modified: projectorganizer/src/prjorg-project.h 5 lines changed, 4 insertions(+), 1 deletions(-) =================================================================== @@ -63,6 +63,9 @@ void prjorg_project_remove_single_tm_file(gchar *utf8_filename); gboolean prjorg_project_is_in_project(const gchar *utf8_filename); -#define PROJORG_SENTINEL_FILENAME "..." +/* In the code we create a list of all files but we want to keep empty directories + * in the list for which we create a fake file name with the PROJORG_DIR_ENTRY + * value. */ +#define PROJORG_DIR_ENTRY "..." #endif Modified: projectorganizer/src/prjorg-sidebar.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -1072,7 +1072,7 @@ static void create_branch(gint level, GSList *leaf_list, GtkTreeIter *parent, gchar **path_arr = elem->data; GIcon *icon = NULL; - if (g_strcmp0(PROJORG_SENTINEL_FILENAME, path_arr[level]) == 0) + if (g_strcmp0(PROJORG_DIR_ENTRY, path_arr[level]) == 0) continue; gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 3527ca: g_free() related cleanups
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 15 Oct 2018 16:43:27 UTC Commit: 3527cae32c2f409af826411befd9bc3197d02f02
https://github.com/geany/geany-plugins/commit/3527cae32c2f409af826411befd9b…
Log Message: ----------- g_free() related cleanups g_free() is safe to call on NULL so we can call g_free() at the same level where the pointer got (optionally) created. Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c Modified: projectorganizer/src/prjorg-sidebar.c 27 lines changed, 13 insertions(+), 14 deletions(-) =================================================================== @@ -381,7 +381,7 @@ static gchar* parent_dir_for_create() static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { - gchar *dir, *name, *path; + gchar *dir, *name; dir = parent_dir_for_create(); if (dir == NULL) @@ -392,8 +392,7 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp if (name != NULL) { - path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); - g_free(name); + gchar *path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); if (create_file(path)) { @@ -405,13 +404,14 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create new file %s"), path); g_free(path); } + g_free(name); g_free(dir); } static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { - gchar *dir, *name, *path; + gchar *dir, *name; dir = parent_dir_for_create(); if (dir == NULL) @@ -422,8 +422,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo if (name != NULL) { - path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); - g_free(name); + gchar *path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); if (create_dir(path)) { @@ -434,6 +433,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create directory %s"), path); g_free(path); } + g_free(name); g_free(dir); } @@ -443,7 +443,7 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe GtkTreeSelection *treesel; GtkTreeModel *model; GtkTreeIter iter, parent; - gchar *name, *dir, *newname, *oldpath, *newpath; + gchar *name, *dir; treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) @@ -457,13 +457,13 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); if (name != NULL) { - newname = dialogs_show_input(_("Rename"), GTK_WINDOW(geany->main_widgets->window), + gchar *newname = dialogs_show_input(_("Rename"), GTK_WINDOW(geany->main_widgets->window), _("New name:"), name); if (newname != NULL) { - oldpath = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); - newpath = g_build_path(G_DIR_SEPARATOR_S, dir, newname, NULL); + gchar *oldpath = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + gchar *newpath = g_build_path(G_DIR_SEPARATOR_S, dir, newname, NULL); if (rename_file_or_dir(oldpath, newpath)) { prjorg_project_rescan(); @@ -474,11 +474,11 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe oldpath, newpath); g_free(oldpath); g_free(newpath); - g_free(newname); } - g_free(name); + g_free(newname); } g_free(dir); + g_free(name); } @@ -488,7 +488,6 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe GtkTreeModel *model; GtkTreeIter iter; gchar *name; - gchar *path; treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) @@ -498,7 +497,7 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe if (dialogs_show_question(_("Do you really want to delete '%s'"), name)) { - path = build_path(&iter); + gchar *path = build_path(&iter); //TODO: recurse into directories -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] b56579: Remove unnecessary config writes
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Mon, 15 Oct 2018 14:37:14 UTC Commit: b56579a8bd18a79050ed0f411db9e8c6c8f7a424
https://github.com/geany/geany-plugins/commit/b56579a8bd18a79050ed0f411db9e…
Log Message: ----------- Remove unnecessary config writes File operations don't change the project file in any way. Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c Modified: projectorganizer/src/prjorg-sidebar.c 4 lines changed, 0 insertions(+), 4 deletions(-) =================================================================== @@ -400,7 +400,6 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp open_file(path); prjorg_project_rescan(); prjorg_sidebar_update(TRUE); - project_write_config(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create new file %s"), path); @@ -430,7 +429,6 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo { prjorg_project_rescan(); prjorg_sidebar_update(TRUE); - project_write_config(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create directory %s"), path); @@ -470,7 +468,6 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe { prjorg_project_rescan(); prjorg_sidebar_update(TRUE); - project_write_config(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot rename %s to %s"), @@ -514,7 +511,6 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe prjorg_project_rescan(); prjorg_sidebar_update(TRUE); - project_write_config(); } g_free(name); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] e08e6b: Remove debug prints
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Sun, 14 Oct 2018 18:37:12 UTC Commit: e08e6ba85038a65c2560ecfa9f18fad0511a0c13
https://github.com/geany/geany-plugins/commit/e08e6ba85038a65c2560ecfa9f18f…
Log Message: ----------- Remove debug prints Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c Modified: projectorganizer/src/prjorg-sidebar.c 10 lines changed, 0 insertions(+), 10 deletions(-) =================================================================== @@ -369,7 +369,6 @@ static gchar* parent_dir_for_create() path = build_path(&iter); if (!g_file_test(path, G_FILE_TEST_IS_DIR)) { - g_print("%s is not dir\n", path); g_free(path); path = NULL; if (gtk_tree_model_iter_parent(model, &parent, &iter)) @@ -388,16 +387,13 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp if (dir == NULL) return; - g_print("Creating file in %s\n", dir); - name = dialogs_show_input(_("New File"), GTK_WINDOW(geany->main_widgets->window), _("Name:"), _("newfile.txt")); if (name != NULL) { path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); g_free(name); - g_print("new file: %s", path); if (create_file(path)) { @@ -422,16 +418,13 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo if (dir == NULL) return; - g_print("Creating dir in %s\n", dir); - name = dialogs_show_input(_("New Directory"), GTK_WINDOW(geany->main_widgets->window), _("Name:"), _("newdir")); if (name != NULL) { path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); g_free(name); - g_print("new dir: %s", path); if (create_dir(path)) { @@ -454,8 +447,6 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe GtkTreeIter iter, parent; gchar *name, *dir, *newname, *oldpath, *newpath; - g_print("Renaming"); - treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) return; @@ -511,7 +502,6 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe if (dialogs_show_question(_("Do you really want to delete '%s'"), name)) { path = build_path(&iter); - printf("deleting '%s'\n", path); //TODO: recurse into directories -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 884f90: Use locale encoding for file operations instead of utf8
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Sun, 14 Oct 2018 19:19:46 UTC Commit: 884f90dce152f192f766f1d7990c82d7b9219a93
https://github.com/geany/geany-plugins/commit/884f90dce152f192f766f1d7990c8…
Log Message: ----------- Use locale encoding for file operations instead of utf8 Modified Paths: -------------- projectorganizer/src/prjorg-utils.c Modified: projectorganizer/src/prjorg-utils.c 43 lines changed, 24 insertions(+), 19 deletions(-) =================================================================== @@ -124,26 +124,36 @@ void close_file(gchar *utf8_name) gboolean create_file(gchar *utf8_name) { - int fd; - GError *err; - - fd = g_open(utf8_name, O_CREAT|O_EXCL, 0660); // rw-rw---- - if (fd == -1) // not created? - return FALSE; - g_close(fd, &err); - return TRUE; + gchar *name = utils_get_locale_from_utf8(utf8_name); + gint fd = g_open(name, O_CREAT|O_EXCL, 0660); // rw-rw---- + gboolean success = FALSE; + + if (fd != -1) + { + GError *err; + success = TRUE; + g_close(fd, &err); + } + g_free(name); + return success; } gboolean create_dir(char *utf8_name) { - return g_mkdir_with_parents(utf8_name, 0770) == 0; // rwxrwx--- + gchar *name = utils_get_locale_from_utf8(utf8_name); + gboolean ret = g_mkdir_with_parents(name, 0770) == 0; // rwxrwx--- + g_free(name); + return ret; } gboolean remove_file_or_dir(char *utf8_name) { - return g_remove(utf8_name) == 0; + gchar *name = utils_get_locale_from_utf8(utf8_name); + gboolean ret = g_remove(utf8_name) == 0; + g_free(name); + return ret; } @@ -157,19 +167,14 @@ static gboolean document_rename(GeanyDocument *document, gchar *utf8_name) gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname) { - GeanyDocument *doc; - gchar *oldname; - gchar *newname; - int res; - - doc = document_find_by_filename(utf8_oldname); + GeanyDocument *doc = document_find_by_filename(utf8_oldname); if (doc) return document_rename(doc, utf8_newname); else { - oldname = utils_get_locale_from_utf8(utf8_oldname); - newname = utils_get_locale_from_utf8(utf8_newname); - res = g_rename(oldname, newname); + gchar *oldname = utils_get_locale_from_utf8(utf8_oldname); + gchar *newname = utils_get_locale_from_utf8(utf8_newname); + gint res = g_rename(oldname, newname); g_free(oldname); g_free(newname); return res == 0; -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 63f980: Eliminate begin/end braces around 1-line blocks to match used code style
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Sun, 14 Oct 2018 18:32:36 UTC Commit: 63f9808599c9203b38062c6af894a3cd3c21a04b
https://github.com/geany/geany-plugins/commit/63f9808599c9203b38062c6af894a…
Log Message: ----------- Eliminate begin/end braces around 1-line blocks to match used code style Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c Modified: projectorganizer/src/prjorg-sidebar.c 24 lines changed, 0 insertions(+), 24 deletions(-) =================================================================== @@ -373,9 +373,7 @@ static gchar* parent_dir_for_create() g_free(path); path = NULL; if (gtk_tree_model_iter_parent(model, &parent, &iter)) - { path = build_path(&parent); - } } } return path; @@ -388,9 +386,7 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp dir = parent_dir_for_create(); if (dir == NULL) - { return; - } g_print("Creating file in %s\n", dir); @@ -411,9 +407,7 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp project_write_config(); } else - { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create new file %s"), path); - } g_free(path); } g_free(dir); @@ -426,9 +420,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo dir = parent_dir_for_create(); if (dir == NULL) - { return; - } g_print("Creating dir in %s\n", dir); @@ -448,9 +440,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo project_write_config(); } else - { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create directory %s"), path); - } g_free(path); } g_free(dir); @@ -468,18 +458,12 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) - { return; - } if (!gtk_tree_model_iter_parent(model, &parent, &iter)) - { return; - } dir = build_path(&parent); if (dir == NULL) - { return; - } gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); if (name != NULL) @@ -498,10 +482,8 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe project_write_config(); } else - { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot rename %s to %s"), oldpath, newpath); - } g_free(oldpath); g_free(newpath); g_free(newname); @@ -522,9 +504,7 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) - { return; - } gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); @@ -536,13 +516,9 @@ static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe //TODO: recurse into directories if (remove_file_or_dir(path)) - { close_file(path); - } else - { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot delete file %s"), path); - } g_free(path); Modified: projectorganizer/src/prjorg-utils.c 5 lines changed, 0 insertions(+), 5 deletions(-) =================================================================== @@ -129,9 +129,7 @@ gboolean create_file(gchar *utf8_name) fd = g_open(utf8_name, O_CREAT|O_EXCL, 0660); // rw-rw---- if (fd == -1) // not created? - { return FALSE; - } g_close(fd, &err); return TRUE; } @@ -149,7 +147,6 @@ gboolean remove_file_or_dir(char *utf8_name) } - static gboolean document_rename(GeanyDocument *document, gchar *utf8_name) { // IMHO: this is wrong. If save as fails Geany's state becomes inconsistent. @@ -167,9 +164,7 @@ gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname) doc = document_find_by_filename(utf8_oldname); if (doc) - { return document_rename(doc, utf8_newname); - } else { oldname = utils_get_locale_from_utf8(utf8_oldname); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] ca1912: Add file operations to Project Organizer.
by Daniel Guerrero
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Daniel Guerrero <dgm(a)aquilessolutions.com> Committer: Daniel Guerrero <dgm(a)aquilessolutions.com> Date: Fri, 10 Aug 2018 15:07:25 UTC Commit: ca1912d6c5ebf671af36851b63c2508da6b464e0
https://github.com/geany/geany-plugins/commit/ca1912d6c5ebf671af36851b63c25…
Log Message: ----------- Add file operations to Project Organizer. Add file and directory creation, renaming and removal operations to the Project Organizer sidebar. Modified Paths: -------------- projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c projectorganizer/src/prjorg-utils.h Modified: projectorganizer/src/prjorg-project.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -114,6 +114,7 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns, if (!patterns_match(ignored_dirs_patterns, utf8_name)) { + list = g_slist_prepend(list, g_build_path(G_DIR_SEPARATOR_S, utf8_filename, PROJORG_SENTINEL_FILENAME, NULL)); lst = get_file_list(utf8_filename, patterns, ignored_dirs_patterns, ignored_file_patterns, visited_paths); if (lst) Modified: projectorganizer/src/prjorg-project.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -63,4 +63,6 @@ void prjorg_project_remove_single_tm_file(gchar *utf8_filename); gboolean prjorg_project_is_in_project(const gchar *utf8_filename); +#define PROJORG_SENTINEL_FILENAME "..." + #endif Modified: projectorganizer/src/prjorg-sidebar.c 253 lines changed, 253 insertions(+), 0 deletions(-) =================================================================== @@ -105,6 +105,11 @@ static struct GtkWidget *find_tag; GtkWidget *expand; GtkWidget *remove_external_dir; + + GtkWidget *create_file; + GtkWidget *create_dir; + GtkWidget *rename; + GtkWidget *delete; } s_popup_menu; @@ -350,6 +355,206 @@ static void on_remove_external_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_U } +// returned string must be freed +static gchar* parent_dir_for_create() +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *path = NULL; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + path = build_path(&iter); + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + { + g_print("%s is not dir\n", path); + g_free(path); + path = NULL; + if (gtk_tree_model_iter_parent(model, &parent, &iter)) + { + path = build_path(&parent); + } + } + } + return path; +} + + +static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *dir, *name, *path; + + dir = parent_dir_for_create(); + if (NULL == dir) + { + return; + } + + g_print("Creating file in %s\n", dir); + + name = dialogs_show_input(_("New File"), GTK_WINDOW(geany->main_widgets->window), + _("Name:"), _("newfile.txt")); + + if (NULL != name) + { + path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + g_free(name); + g_print("new file: %s", path); + + if (create_file(path)) + { + open_file(path); + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + project_write_config(); + } + else + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create new file %s"), path); + } + g_free(path); + } + g_free(dir); +} + + +static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *dir, *name, *path; + + dir = parent_dir_for_create(); + if (NULL == dir) + { + return; + } + + g_print("Creating dir in %s\n", dir); + + name = dialogs_show_input(_("New Directory"), GTK_WINDOW(geany->main_widgets->window), + _("Name:"), _("newdir")); + + if (NULL != name) + { + path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + g_free(name); + g_print("new dir: %s", path); + + if (create_dir(path)) + { + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + project_write_config(); + } + else + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create directory %s"), path); + } + g_free(path); + } + g_free(dir); +} + + +static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *name, *dir, *newname, *oldpath, *newpath; + + g_print("Renaming"); + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + return; + } + if (!gtk_tree_model_iter_parent(model, &parent, &iter)) + { + return; + } + dir = build_path(&parent); + if (NULL == dir) + { + return; + } + + gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); + if (NULL != name) + { + newname = dialogs_show_input(_("Rename"), GTK_WINDOW(geany->main_widgets->window), + _("New name:"), name); + + if (NULL != newname) + { + oldpath = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + newpath = g_build_path(G_DIR_SEPARATOR_S, dir, newname, NULL); + if (rename_file_or_dir(oldpath, newpath)) + { + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + project_write_config(); + } + else + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot rename %s to %s"), + oldpath, newpath); + } + g_free(oldpath); + g_free(newpath); + g_free(newname); + } + g_free(name); + } + g_free(dir); +} + + +static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter; + gchar *name; + gchar *path; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + return; + } + + gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); + + if (dialogs_show_question(_("Do you really want to delete '%s'"), name)) + { + path = build_path(&iter); + printf("deleting '%s'\n", path); + + //TODO: recurse into directories + + if (remove_file_or_dir(path)) + { + close_file(path); + } + else + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot delete file %s"), path); + } + + g_free(path); + + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + project_write_config(); + } + + g_free(name); +} + + static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboolean full_path, GPatternSpec *pattern) { GtkTreeModel *model = GTK_TREE_MODEL(s_file_store); @@ -900,6 +1105,10 @@ static void create_branch(gint level, GSList *leaf_list, GtkTreeIter *parent, GtkTreeIter iter; gchar **path_arr = elem->data; GIcon *icon = NULL; + + if (0 == g_strcmp0(PROJORG_SENTINEL_FILENAME, path_arr[level])) + continue; + gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); if (content_type) @@ -1468,6 +1677,50 @@ void prjorg_sidebar_init(void) g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_remove_external_dir), NULL); s_popup_menu.remove_external_dir = item; + + + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + + image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("New File")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_create_file), NULL); + s_popup_menu.create_file = item; + + image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("New Directory")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_create_dir), NULL); + s_popup_menu.create_dir = item; + + image = gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("Rename")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_rename), NULL); + s_popup_menu.rename = item; + + image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("Delete")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_delete), NULL); + s_popup_menu.delete = item; + + + item = gtk_separator_menu_item_new(); gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); Modified: projectorganizer/src/prjorg-utils.c 78 lines changed, 78 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,11 @@ #include <string.h> #include <glib.h> +#include <glib/gstdio.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + #include <geanyplugin.h> #include "prjorg-utils.h" @@ -104,6 +109,79 @@ void open_file(gchar *utf8_name) } +void close_file(gchar *utf8_name) +{ + GeanyDocument *doc; + + doc = document_find_by_filename(utf8_name); + if (doc) + { + document_set_text_changed(doc, FALSE); + document_close(doc); + } +} + + +gboolean create_file(gchar *utf8_name) +{ + int fd; + GError *err; + + fd = g_open(utf8_name, O_CREAT|O_EXCL, 0660); // rw-rw---- + if (-1 == fd) // not created? + { + return FALSE; + } + g_close(fd, &err); + return TRUE; +} + + +gboolean create_dir(char *utf8_name) +{ + return 0 == g_mkdir_with_parents(utf8_name, 0770); // rwxrwx--- +} + + +gboolean remove_file_or_dir(char *utf8_name) +{ + return 0 == g_remove(utf8_name); +} + + + +static gboolean document_rename(GeanyDocument *document, gchar *utf8_name) +{ + // IMHO: this is wrong. If save as fails Geany's state becomes inconsistent. + document_rename_file(document, utf8_name); + return document_save_file_as(document, utf8_name); +} + + +gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname) +{ + GeanyDocument *doc; + gchar *oldname; + gchar *newname; + int res; + + doc = document_find_by_filename(utf8_oldname); + if (doc) + { + return document_rename(doc, utf8_newname); + } + else + { + oldname = utils_get_locale_from_utf8(utf8_oldname); + newname = utils_get_locale_from_utf8(utf8_newname); + res = g_rename(oldname, newname); + g_free(oldname); + g_free(newname); + return 0 == res; + } +} + + gchar *get_selection(void) { GeanyDocument *doc = document_get_current(); Modified: projectorganizer/src/prjorg-utils.h 7 lines changed, 7 insertions(+), 0 deletions(-) =================================================================== @@ -25,6 +25,13 @@ gboolean patterns_match(GSList *patterns, const gchar *str); GSList *get_precompiled_patterns(gchar **patterns); void open_file(gchar *utf8_name); +void close_file(gchar *utf8_name); + +gboolean create_file(char *utf8_name); +gboolean create_dir(char *utf8_name); +gboolean remove_file_or_dir(char *utf8_name); +gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname); + gchar *get_selection(void); gchar *get_project_base_path(void); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 61f4a5: Eliminate Yoda style conditions to match the style of the rest of the code
by Jiří Techet
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: Jiří Techet <techet(a)gmail.com> Committer: Jiří Techet <techet(a)gmail.com> Date: Sun, 14 Oct 2018 17:54:59 UTC Commit: 61f4a51d69a31d62d05d7328e2a86f8888bd5c95
https://github.com/geany/geany-plugins/commit/61f4a51d69a31d62d05d7328e2a86…
Log Message: ----------- Eliminate Yoda style conditions to match the style of the rest of the code Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c Modified: projectorganizer/src/prjorg-sidebar.c 16 lines changed, 8 insertions(+), 8 deletions(-) =================================================================== @@ -387,7 +387,7 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp gchar *dir, *name, *path; dir = parent_dir_for_create(); - if (NULL == dir) + if (dir == NULL) { return; } @@ -397,7 +397,7 @@ static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gp name = dialogs_show_input(_("New File"), GTK_WINDOW(geany->main_widgets->window), _("Name:"), _("newfile.txt")); - if (NULL != name) + if (name != NULL) { path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); g_free(name); @@ -425,7 +425,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo gchar *dir, *name, *path; dir = parent_dir_for_create(); - if (NULL == dir) + if (dir == NULL) { return; } @@ -435,7 +435,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo name = dialogs_show_input(_("New Directory"), GTK_WINDOW(geany->main_widgets->window), _("Name:"), _("newdir")); - if (NULL != name) + if (name != NULL) { path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); g_free(name); @@ -476,18 +476,18 @@ static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointe return; } dir = build_path(&parent); - if (NULL == dir) + if (dir == NULL) { return; } gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); - if (NULL != name) + if (name != NULL) { newname = dialogs_show_input(_("Rename"), GTK_WINDOW(geany->main_widgets->window), _("New name:"), name); - if (NULL != newname) + if (newname != NULL) { oldpath = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); newpath = g_build_path(G_DIR_SEPARATOR_S, dir, newname, NULL); @@ -1106,7 +1106,7 @@ static void create_branch(gint level, GSList *leaf_list, GtkTreeIter *parent, gchar **path_arr = elem->data; GIcon *icon = NULL; - if (0 == g_strcmp0(PROJORG_SENTINEL_FILENAME, path_arr[level])) + if (g_strcmp0(PROJORG_SENTINEL_FILENAME, path_arr[level]) == 0) continue; gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); Modified: projectorganizer/src/prjorg-utils.c 8 lines changed, 4 insertions(+), 4 deletions(-) =================================================================== @@ -128,7 +128,7 @@ gboolean create_file(gchar *utf8_name) GError *err; fd = g_open(utf8_name, O_CREAT|O_EXCL, 0660); // rw-rw---- - if (-1 == fd) // not created? + if (fd == -1) // not created? { return FALSE; } @@ -139,13 +139,13 @@ gboolean create_file(gchar *utf8_name) gboolean create_dir(char *utf8_name) { - return 0 == g_mkdir_with_parents(utf8_name, 0770); // rwxrwx--- + return g_mkdir_with_parents(utf8_name, 0770) == 0; // rwxrwx--- } gboolean remove_file_or_dir(char *utf8_name) { - return 0 == g_remove(utf8_name); + return g_remove(utf8_name) == 0; } @@ -177,7 +177,7 @@ gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname) res = g_rename(oldname, newname); g_free(oldname); g_free(newname); - return 0 == res; + return res == 0; } } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 8ec8bb: Merge pull request #783 from techee/projorg_file_ops
by elextr
01 Apr '19
01 Apr '19
Branch: refs/heads/master Author: elextr <elextr(a)gmail.com> Committer: GitHub <noreply(a)github.com> Date: Mon, 01 Apr 2019 01:03:26 UTC Commit: 8ec8bb339a6e130c858401d9de4bf265a1a28b3e
https://github.com/geany/geany-plugins/commit/8ec8bb339a6e130c858401d9de4bf…
Log Message: ----------- Merge pull request #783 from techee/projorg_file_ops Add file operations to Project Organizer v2 Modified Paths: -------------- projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c projectorganizer/src/prjorg-utils.h Modified: projectorganizer/src/prjorg-project.c 11 lines changed, 8 insertions(+), 3 deletions(-) =================================================================== @@ -118,6 +118,8 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns, ignored_file_patterns, visited_paths); if (lst) list = g_slist_concat(list, lst); + else + list = g_slist_prepend(list, g_build_path(G_DIR_SEPARATOR_S, utf8_filename, PROJORG_DIR_ENTRY, NULL)); } } else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) @@ -284,16 +286,19 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) g_hash_table_iter_init(&iter, root->file_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - TMSourceFile *sf; + TMSourceFile *sf = NULL; gchar *utf8_path = key; gchar *locale_path = utils_get_locale_from_utf8(utf8_path); + gchar *basename = g_path_get_basename(locale_path); - sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); - if (sf && !document_find_by_filename(utf8_path)) + if (g_strcmp0(PROJORG_DIR_ENTRY, basename) != 0) + sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); + if (sf && !document_find_by_filename(utf8_path) ) g_ptr_array_add(source_files, sf); g_hash_table_insert(file_table, g_strdup(utf8_path), sf); g_free(locale_path); + g_free(basename); } g_hash_table_destroy(root->file_table); root->file_table = file_table; Modified: projectorganizer/src/prjorg-project.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -63,4 +63,9 @@ void prjorg_project_remove_single_tm_file(gchar *utf8_filename); gboolean prjorg_project_is_in_project(const gchar *utf8_filename); +/* In the code we create a list of all files but we want to keep empty directories + * in the list for which we create a fake file name with the PROJORG_DIR_ENTRY + * value. */ +#define PROJORG_DIR_ENTRY "..." + #endif Modified: projectorganizer/src/prjorg-sidebar.c 231 lines changed, 231 insertions(+), 0 deletions(-) =================================================================== @@ -105,6 +105,11 @@ static struct GtkWidget *find_tag; GtkWidget *expand; GtkWidget *remove_external_dir; + + GtkWidget *create_file; + GtkWidget *create_dir; + GtkWidget *rename; + GtkWidget *delete; } s_popup_menu; @@ -350,6 +355,169 @@ static void on_remove_external_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_U } +// returned string must be freed +static gchar* parent_dir_for_create() +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *path = NULL; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + path = build_path(&iter); + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + { + g_free(path); + path = NULL; + if (gtk_tree_model_iter_parent(model, &parent, &iter)) + path = build_path(&parent); + } + } + return path; +} + + +static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *dir, *name; + + dir = parent_dir_for_create(); + if (dir == NULL) + return; + + name = dialogs_show_input(_("New File"), GTK_WINDOW(geany->main_widgets->window), + _("File name:"), _("newfile.txt")); + + if (name != NULL) + { + gchar *path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + + if (create_file(path)) + { + open_file(path); + //TODO: don't rescan the whole project, only change the affected file + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + } + else + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create file '%s'."), path); + g_free(path); + } + g_free(name); + g_free(dir); +} + + +static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *dir, *name; + + dir = parent_dir_for_create(); + if (dir == NULL) + return; + + name = dialogs_show_input(_("New Directory"), GTK_WINDOW(geany->main_widgets->window), + _("Directory name:"), _("newdir")); + + if (name != NULL) + { + gchar *path = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + + if (create_dir(path)) + { + //TODO: don't rescan the whole project, only change the affected directory + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + } + else + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot create directory '%s'."), path); + g_free(path); + } + g_free(name); + g_free(dir); +} + + +static void on_rename(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *name, *dir; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) + return; + if (!gtk_tree_model_iter_parent(model, &parent, &iter)) + return; + dir = build_path(&parent); + if (dir == NULL) + return; + + gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); + if (name != NULL) + { + gchar *newname = dialogs_show_input(_("Rename"), GTK_WINDOW(geany->main_widgets->window), + _("New name:"), name); + + if (newname != NULL) + { + gchar *oldpath = g_build_path(G_DIR_SEPARATOR_S, dir, name, NULL); + gchar *newpath = g_build_path(G_DIR_SEPARATOR_S, dir, newname, NULL); + if (rename_file_or_dir(oldpath, newpath)) + { + //TODO: don't rescan the whole project, only change the affected file + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + } + else + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot rename '%s' to '%s'."), + oldpath, newpath); + g_free(oldpath); + g_free(newpath); + } + g_free(newname); + } + g_free(dir); + g_free(name); +} + + +static void on_delete(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter; + gchar *name; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (!gtk_tree_selection_get_selected(treesel, &model, &iter)) + return; + + gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); + + if (dialogs_show_question(_("Are you sure you want to delete '%s'?"), name)) + { + gchar *path = build_path(&iter); + + if (remove_file_or_dir(path)) + close_file(path); + else + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Cannot delete file '%s'."), path); + + g_free(path); + + //TODO: don't rescan the whole project, only change the affected file + prjorg_project_rescan(); + prjorg_sidebar_update(TRUE); + } + + g_free(name); +} + + static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboolean full_path, GPatternSpec *pattern) { GtkTreeModel *model = GTK_TREE_MODEL(s_file_store); @@ -789,6 +957,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)); @@ -798,6 +968,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; @@ -900,6 +1087,10 @@ static void create_branch(gint level, GSList *leaf_list, GtkTreeIter *parent, GtkTreeIter iter; gchar **path_arr = elem->data; GIcon *icon = NULL; + + if (g_strcmp0(PROJORG_DIR_ENTRY, path_arr[level]) == 0) + continue; + gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); if (content_type) @@ -1472,6 +1663,46 @@ void prjorg_sidebar_init(void) gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("New File...")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_create_file), NULL); + s_popup_menu.create_file = item; + + image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("New Directory...")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_create_dir), NULL); + s_popup_menu.create_dir = item; + + image = gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("Rename...")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_rename), NULL); + s_popup_menu.rename = item; + + image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); + gtk_widget_show(image); + item = gtk_image_menu_item_new_with_mnemonic(_("Delete")); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_delete), NULL); + s_popup_menu.delete = item; + + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = gtk_image_menu_item_new_with_mnemonic(_("H_ide Sidebar")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU)); Modified: projectorganizer/src/prjorg-utils.c 77 lines changed, 77 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,11 @@ #include <string.h> #include <glib.h> +#include <glib/gstdio.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + #include <geanyplugin.h> #include "prjorg-utils.h" @@ -104,6 +109,78 @@ void open_file(gchar *utf8_name) } +void close_file(gchar *utf8_name) +{ + GeanyDocument *doc = document_find_by_filename(utf8_name); + + if (doc) + { + document_set_text_changed(doc, FALSE); + document_close(doc); + } +} + + +gboolean create_file(gchar *utf8_name) +{ + gchar *name = utils_get_locale_from_utf8(utf8_name); + gint fd = g_open(name, O_CREAT|O_EXCL, 0660); // rw-rw---- + gboolean success = FALSE; + + if (fd != -1) + { + GError *err; + success = TRUE; + g_close(fd, &err); + } + g_free(name); + return success; +} + + +gboolean create_dir(char *utf8_name) +{ + gchar *name = utils_get_locale_from_utf8(utf8_name); + gboolean ret = g_mkdir_with_parents(name, 0770) == 0; // rwxrwx--- + g_free(name); + return ret; +} + + +gboolean remove_file_or_dir(char *utf8_name) +{ + gchar *name = utils_get_locale_from_utf8(utf8_name); + gboolean ret = g_remove(utf8_name) == 0; + g_free(name); + return ret; +} + + +static gboolean document_rename(GeanyDocument *document, gchar *utf8_name) +{ + // IMHO: this is wrong. If save as fails Geany's state becomes inconsistent. + document_rename_file(document, utf8_name); + return document_save_file_as(document, utf8_name); +} + + +gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname) +{ + GeanyDocument *doc = document_find_by_filename(utf8_oldname); + if (doc) + return document_rename(doc, utf8_newname); + else + { + gchar *oldname = utils_get_locale_from_utf8(utf8_oldname); + gchar *newname = utils_get_locale_from_utf8(utf8_newname); + gint res = g_rename(oldname, newname); + g_free(oldname); + g_free(newname); + return res == 0; + } +} + + gchar *get_selection(void) { GeanyDocument *doc = document_get_current(); Modified: projectorganizer/src/prjorg-utils.h 7 lines changed, 7 insertions(+), 0 deletions(-) =================================================================== @@ -25,6 +25,13 @@ gboolean patterns_match(GSList *patterns, const gchar *str); GSList *get_precompiled_patterns(gchar **patterns); void open_file(gchar *utf8_name); +void close_file(gchar *utf8_name); + +gboolean create_file(char *utf8_name); +gboolean create_dir(char *utf8_name); +gboolean remove_file_or_dir(char *utf8_name); +gboolean rename_file_or_dir(gchar *utf8_oldname, gchar *utf8_newname); + gchar *get_selection(void); gchar *get_project_base_path(void); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
← Newer
1
2
3
4
5
Older →
Jump to page:
1
2
3
4
5
Results per page:
10
25
50
100
200