Revision: 1190 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1190&view=re... Author: dimitrov-adrian Date: 2010-03-20 12:09:27 +0000 (Sat, 20 Mar 2010)
Log Message: ----------- Code improvment, most of code is rewriten
Modified Paths: -------------- trunk/geany-plugins/treebrowser/src/treebrowser.c
Modified: trunk/geany-plugins/treebrowser/src/treebrowser.c =================================================================== --- trunk/geany-plugins/treebrowser/src/treebrowser.c 2010-03-20 11:49:51 UTC (rev 1189) +++ trunk/geany-plugins/treebrowser/src/treebrowser.c 2010-03-20 12:09:27 UTC (rev 1190) @@ -1,25 +1,34 @@ // treebrowser.c // // Copyright 2010 Adrian Dimitrov dimitrov.adrian@gmail.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -// MA 02110-1301, USA.
-/* Development release ChangeLog +/* + * TODO + * --------------------------- + * configuration dialog + * trackick path to current focused document + * Windows compitable + * Language files + * (DONE) oneclick document opening + * (DONE) filter separating ex.: "*.c;*.cpp;*.h" + * fix possible memory leaks (using g_free... where is need) + * + * + * Development release ChangeLog * ----------------------------- + * (19-03-2010) + * clear up the syntax and function names + * fixed many bugs with renaming/creating/deleting objects + * added multiple filtering criterias + * added oneclick document opening * + * (18-03-2010) + * add option to reverse filematch filter + * + * (17-03-2010) + * migrated to dialogs_show_msgbox and dialogs_show_question + * fix problem with path initialization + * * (16-03-2010) * fix compilation warning messages * fix some crytical errors @@ -28,18 +37,15 @@ * fix patch applyed from Enrico about initial directories * * (20-02-2010) - * v0.1.1 * made strings suitable for localization * fixed problem with default chroot * added option to disable chrooting on double click on directory * * (17-02-2010) - * v0.1 * added options to add/remove/rename directories and files * code cleanup * * (14-02-2010) - * v0.0.1 * initial, with base options * */ @@ -50,29 +56,36 @@ #include "Scintilla.h"
/* These items are set by Geany before plugin_init() is called. */ -GeanyPlugin *geany_plugin; -GeanyData *geany_data; -GeanyFunctions *geany_functions; +GeanyPlugin *geany_plugin; +GeanyData *geany_data; +GeanyFunctions *geany_functions;
-static gint page_number = 0; +static gint page_number = 0; static GtkTreeStore *treestore; -static GtkWidget *treeview; -static GtkWidget *vbox; -static GtkWidget *vbox_bars; -static GtkWidget *addressbar; -static gchar *addressbar_last_address = NULL; +static GtkWidget *treeview; +static GtkWidget *vbox; +static GtkWidget *vbox_bars; static GtkWidget *filter; +static GtkWidget *addressbar; +static gchar *addressbar_last_address = NULL;
static GtkTreeViewColumn *treeview_column_icon, *treeview_column_text; static GtkCellRenderer *render_icon, *render_text;
-// config -static gint CONFIG_DIRECTORY_DEEP = 1; -static gboolean CONFIG_SHOW_HIDDEN_FILES = FALSE; -static gboolean CONFIG_SHOW_BARS = TRUE; -static gboolean CONFIG_CHROOT_ON_DCLICK = FALSE; +// +// CONFIG VARS +// +static gint CONFIG_INITIAL_DIR_DEEP = 1; +static gboolean CONFIG_REVERSE_FILTER = FALSE; +static gboolean CONFIG_ONE_CLICK_CHDOC = FALSE; +static gboolean CONFIG_SHOW_HIDDEN_FILES = FALSE; +static gboolean CONFIG_SHOW_BARS = TRUE; +static gboolean CONFIG_CHROOT_ON_DCLICK = FALSE; +static gboolean CONFIG_FOLLOW_CURRENT_DOC = FALSE;
-// treeview struct +// +// TREEVIEW STRUCT +// enum { TREEBROWSER_COLUMNC = 3, @@ -85,151 +98,296 @@ TREEBROWSER_RENDER_TEXT = 1 };
- +// +// PLUGIN INFO +// PLUGIN_VERSION_CHECK(147) -PLUGIN_SET_INFO(_("Tree Browser"), _("Treeview filebrowser plugin."), "0.1" , " e01 (Enzo_01@abv.bg)") +PLUGIN_SET_INFO(_("Tree Browser"), _("Treeview filebrowser plugin."), "0.1" , "Adrian Dimitrov (dimitrov.adrian@gmail.com)")
-// predefines -#define foreach_slist_free(node, list) \ - for (node = list, list = NULL; g_slist_free_1(list), node != NULL; list = node, node = node->next) +// +// PREDEFINES +// +#define foreach_slist_free(node, list) for (node = list, list = NULL; g_slist_free_1(list), node != NULL; list = node, node = node->next)
-// prototypes -static void msgbox(gchar *message); -static gboolean dialogs_yesno(gchar* message); -static gboolean check_filtered(const gchar* base_name); -static gchar* get_default_dir(void); -static void on_renamed(GtkCellRenderer *renderer, const gchar *path_string, const gchar *newname, gpointer data); -static GtkWidget* create_popup_menu(gpointer *user_data); -static GtkWidget* create_view_and_model (void); -static int gtk_tree_store_iter_clear_nodes(GtkTreeIter iter, gboolean delete_root); -static void treebrowser_browse(gchar *directory, GtkTreeIter parent, gboolean isRoot, gint deep_limit); -static void fs_remove(gchar *root, gboolean delete_root); -static void treebrowser_track_path(gchar *directory); -static void treebrowser_chroot(gchar *directory); -static void showbars(gboolean state); -static void on_menu_showhide_bars(GtkMenuItem *menuitem, gpointer *user_data); -static void on_menu_external_open(GtkMenuItem *menuitem, gpointer *user_data); -static void on_menu_go_parent(GtkMenuItem *menuitem, gpointer *user_data); -static void on_menu_set_as_root(GtkMenuItem *menuitem, gpointer *user_data); -static void on_menu_refresh(GtkMenuItem *menuitem, gpointer *user_data); -static void on_row_expanded(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data); -static void on_row_collapsed(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data); -static void on_addressbar_activate(GtkEntry *entry, gpointer user_data); -static void on_addressbar_icon (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data); -static void on_filter_activate(GtkEntry *entry, gpointer user_data); -static gboolean* treebrowser_track_path_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data); -// end of prototypes
+// +// PROTOTYPES +// +static void treebrowser_browse(gchar *directory, gpointer parent, gint deep_limit); +static void gtk_tree_store_iter_clear_nodes(gpointer iter, gboolean delete_root);
-static void -msgbox(gchar *message) + +// +// TREEBROWSER CORE FUNCTIONS +// + +static gboolean +check_filtered(const gchar *base_name) { - GtkWidget *window; - GtkWidget *dialog; + gchar **filters; + gint i;
- dialog = gtk_message_dialog_new(GTK_WINDOW (window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "%s", - message); + if (gtk_entry_get_text_length(GTK_ENTRY(filter)) < 1) + return TRUE;
- gtk_dialog_run(GTK_DIALOG (dialog)); - gtk_widget_destroy(dialog); + filters = g_strsplit(gtk_entry_get_text(GTK_ENTRY(filter)), ";", 0); + + for (i = 0; filters[i]; i++) + if (utils_str_equal(base_name, "*") || g_pattern_match_simple(filters[i], base_name)) + return CONFIG_REVERSE_FILTER ? FALSE : TRUE; + + return CONFIG_REVERSE_FILTER ? TRUE : FALSE; }
+static gchar* +get_default_dir(void) +{ + gchar *dir; + GeanyProject *project = geany->app->project; + GeanyDocument *doc = document_get_current();
-static gboolean -dialogs_yesno(gchar *message) + if (doc != NULL && doc->file_name != NULL && g_path_is_absolute(doc->file_name)) + return utils_get_locale_from_utf8(g_path_get_dirname(doc->file_name)); + + if (project) + dir = project->base_path; + else + dir = geany->prefs->default_open_path; + + if (NZV(dir)) + return utils_get_locale_from_utf8(dir); + + return g_get_current_dir(); +} + +static void +treebrowser_chroot(gchar *directory) { - GtkWidget *window, *dialog; - dialog = gtk_message_dialog_new(GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "%s", - message); + gtk_entry_set_text(GTK_ENTRY(addressbar), directory);
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES) + if (! g_file_test(directory, G_FILE_TEST_IS_DIR)) { - gtk_widget_destroy(dialog); - return TRUE; + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Directory '%s' not exists."), directory); + return; } - gtk_widget_destroy(dialog); - return FALSE; + + gtk_tree_store_clear(treestore); + addressbar_last_address = directory; + treebrowser_browse(directory, NULL, CONFIG_INITIAL_DIR_DEEP); }
+static void +treebrowser_browse(gchar *directory, gpointer parent, gint deep_limit) +{ + GtkTreeIter iter, *last_dir_iter = NULL; + gchar *path, *path_new, *display_name; + gboolean is_dir, expanded; + GDir *dir;
+ const gchar *name, *basename; + gchar *utf8_dir, *utf8_name; + GSList *list, *node;
-static gboolean// get from filebrowser.c (with little modifications) -check_filtered(const gchar *base_name) + GtkTreePath *gpath; + + if (deep_limit < 1) + return; + + deep_limit--; + + directory = g_strconcat(directory, G_DIR_SEPARATOR_S, NULL); + + if (parent && gtk_tree_view_row_expanded(GTK_TREE_VIEW(treeview), gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), parent))) + expanded = TRUE; + else + expanded = FALSE; + + gtk_tree_store_iter_clear_nodes(parent, FALSE); + + list = utils_get_file_list(directory, NULL, NULL); + if (list != NULL) + { + foreach_slist_free(node, list) + { + gchar *fname = node->data; + gchar *uri = g_strconcat(directory, fname, NULL); + is_dir = g_file_test (uri, G_FILE_TEST_IS_DIR); + utf8_name = utils_get_utf8_from_locale(fname); + + if (!(fname[0] == '.' && CONFIG_SHOW_HIDDEN_FILES == FALSE)) + { + if (is_dir) + { + if (last_dir_iter == NULL) + gtk_tree_store_prepend(treestore, &iter, parent); + else + { + gtk_tree_store_insert_after(treestore, &iter, parent, last_dir_iter); + gtk_tree_iter_free(last_dir_iter); + } + last_dir_iter = gtk_tree_iter_copy(&iter); + gtk_tree_store_set(treestore, &iter, + TREEBROWSER_COLUMN_ICON, GTK_STOCK_DIRECTORY, + TREEBROWSER_COLUMN_NAME, fname, + TREEBROWSER_COLUMN_URI, uri, + -1); + treebrowser_browse(uri, &iter, deep_limit); + } + else + { + if (check_filtered(utf8_name)) + { + gtk_tree_store_append(treestore, &iter, parent); + gtk_tree_store_set(treestore, &iter, + TREEBROWSER_COLUMN_ICON, GTK_STOCK_FILE, + TREEBROWSER_COLUMN_NAME, fname, + TREEBROWSER_COLUMN_URI, uri, + -1); + } + } + } + g_free(fname); + g_free(uri); + } + } + + if (expanded) + gtk_tree_view_expand_row(GTK_TREE_VIEW(treeview), gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), parent), FALSE); + +} + +static gboolean +treebrowser_search(gchar *uri, gpointer parent) { - if (gtk_entry_get_text_length(GTK_ENTRY(filter)) < 1) - return TRUE; + GtkTreeIter iter, iter_parent; + GtkTreePath *path; + gchar *uri_current;
- if (utils_str_equal(base_name, "*") || g_pattern_match_simple(gtk_entry_get_text(GTK_ENTRY(filter)), base_name)) - return TRUE; + gtk_tree_model_iter_children(GTK_TREE_MODEL(treestore), &iter, parent); + do + { + gtk_tree_model_get(GTK_TREE_MODEL(treestore), &iter, TREEBROWSER_COLUMN_URI, &uri_current, -1);
- return FALSE; + if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(treestore), &iter)) + { + if (treebrowser_search(uri, &iter)) + return TRUE; + } + + if (g_strcmp0(uri,uri_current) == 0) + { + path = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter); + gtk_tree_view_expand_to_path(GTK_TREE_VIEW(treeview), path); + gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path, TREEBROWSER_COLUMN_ICON, FALSE, 0, 0); + gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), path, treeview_column_text, FALSE); + return TRUE; + } + + } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(treestore), &iter)); + }
-static gchar* -get_default_dir(void) +static void +fs_remove(gchar *root, gboolean delete_root) { - gchar *dir; - GeanyProject *project = geany->app->project; - GeanyDocument *doc = document_get_current();
- if (doc != NULL && doc->file_name != NULL && ! g_path_is_absolute(doc->file_name)) - return g_path_get_dirname(doc->file_name); + if (! g_file_test(root, G_FILE_TEST_EXISTS)) + return; + + if (g_file_test(root, G_FILE_TEST_IS_DIR)) + { + + GDir *dir; + const gchar *name; + + dir = g_dir_open (root, 0, NULL); + + if (!dir) + return; + + name = g_dir_read_name (dir); + while (name != NULL) + { + gchar *path; + path = g_build_filename (root, name, NULL); + if (g_file_test (path, G_FILE_TEST_IS_DIR)) + fs_remove(path, delete_root); + g_remove(path); + name = g_dir_read_name(dir); + g_free (path); + } + } else - if (project) - return project->base_path; - else - if (geany->prefs) - return geany->prefs->default_open_path; - else - return g_get_current_dir(); + delete_root = TRUE; + + if (delete_root) + g_remove(root); + + return; }
static void -on_renamed(GtkCellRenderer *renderer, const gchar *path_string, const gchar *newname, gpointer data) +showbars(gboolean state) { + if (state) gtk_widget_show(vbox_bars); + else gtk_widget_hide(vbox_bars); + CONFIG_SHOW_BARS = state; +}
- GtkTreeViewColumn *column; - GList *renderers; - GtkTreeIter iter; - gchar *uri, *newuri; +static void +gtk_tree_store_iter_clear_nodes(gpointer iter, gboolean delete_root) +{ + GtkTreeIter i; + while (gtk_tree_model_iter_children(GTK_TREE_MODEL(treestore), &i, iter)) + { + if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(treestore), &i)) + gtk_tree_store_iter_clear_nodes(&i, TRUE); + gtk_tree_store_remove(GTK_TREE_STORE(treestore), &i); + }
- column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0); - renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column)); - renderer = g_list_nth_data(renderers, TREEBROWSER_RENDER_TEXT); + if (delete_root) + gtk_tree_store_remove(GTK_TREE_STORE(treestore), iter); +}
- g_object_set(G_OBJECT(renderer), "editable", FALSE, NULL); +static gboolean +treebrowser_track_current(void) +{
- if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(treestore), &iter, path_string)) + GeanyDocument *doc = document_get_current(); + gchar *path_current, *path_search = "/"; + gchar **path_segments; + gint i; + + if (doc != NULL && doc->file_name != NULL && g_path_is_absolute(doc->file_name)) { - gtk_tree_model_get(GTK_TREE_MODEL(treestore), &iter, TREEBROWSER_COLUMN_URI, &uri, -1); - if (uri) + path_current = utils_get_locale_from_utf8(doc->file_name); + + path_segments = g_strsplit(path_current, G_DIR_SEPARATOR_S, 0); + + treebrowser_search(path_current, NULL); + + return FALSE; + for (i = 0; path_segments[i]; i++) { - newuri = g_strconcat(g_path_get_dirname(uri), G_DIR_SEPARATOR_S, newname, NULL); - if (g_rename(uri, newuri) == 0) - gtk_tree_store_set(treestore, &iter, - TREEBROWSER_COLUMN_NAME, newname, - TREEBROWSER_COLUMN_URI, newuri, - -1); + path_search = g_build_filename(path_search, path_segments[i], NULL); + //dialogs_show_msgbox(GTK_MESSAGE_INFO, "%s", path_search); + treebrowser_search(path_search, NULL); + return FALSE; } + + return TRUE; } + return FALSE; }
-/* - * RIGHT CLICK MENU - */ +// +// RIGHTCLICK MENU EVENTS +//
static void -on_menu_external_open(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_open_externally(GtkMenuItem *menuitem, gpointer *user_data) {
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); @@ -246,13 +404,6 @@ }
static void -on_menu_go_parent(GtkMenuItem *menuitem, gpointer *user_data) -{ - treebrowser_chroot(g_path_get_dirname(addressbar_last_address)); -} - - -static void on_menu_set_as_root(GtkMenuItem *menuitem, gpointer *user_data) {
@@ -269,70 +420,79 @@ } }
- static void -on_menu_refresh(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_create_new_object(GtkMenuItem *menuitem, gchar *type) { - treebrowser_chroot(addressbar_last_address); -} - -static void -on_menu_create_new_directory(GtkMenuItem *menuitem, gpointer *user_data) -{ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - GtkTreeIter iter_new; - gpointer iter = NULL; + GtkTreeIter iter; GtkTreeModel *model; - gchar *uri, *newuri; + gchar *uri, *uri_new; + GtkTreePath *path_parent;
- if (gtk_tree_selection_get_selected(selection, &model, iter)) - gtk_tree_model_get(model, iter, TREEBROWSER_COLUMN_URI, &uri, -1); + 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)) + { + uri = g_path_get_dirname(uri); + path_parent = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter); + if (gtk_tree_path_up(path_parent)) + { + gtk_tree_model_get_iter(GTK_TREE_MODEL(treestore), &iter, path_parent); + } + } + } + else return; + + if (type == "directory") + uri_new = g_strconcat(uri, G_DIR_SEPARATOR_S, _("NewDirectory"), NULL); else - uri = addressbar_last_address; + if (type == "file") + uri_new = g_strconcat(uri, G_DIR_SEPARATOR_S, _("NewFile"), NULL); + else + return;
- newuri = g_strconcat(uri, G_DIR_SEPARATOR_S, _("NewDirectory"), NULL); + while(g_file_test(uri_new, G_FILE_TEST_EXISTS)) + uri_new = g_strconcat(uri_new, "_", NULL);
- while(g_file_test(newuri, G_FILE_TEST_EXISTS)) - newuri = g_strconcat(newuri, "_", NULL); - - if (g_mkdir(newuri, 0755) == 0) + if (type == "directory") { - gtk_tree_store_prepend(treestore, &iter_new, iter ? iter : NULL); - gtk_tree_store_set(treestore, &iter_new, - TREEBROWSER_COLUMN_ICON, GTK_STOCK_DIRECTORY, - TREEBROWSER_COLUMN_NAME, g_path_get_basename(newuri), - TREEBROWSER_COLUMN_URI, newuri, - -1); + if (g_mkdir(uri_new, 0755) == 0) + treebrowser_browse(uri, &iter, CONFIG_INITIAL_DIR_DEEP); } + else + { + if (g_creat(uri_new, 0755) != -1) + treebrowser_browse(uri, &iter, CONFIG_INITIAL_DIR_DEEP); + } }
static void -on_menu_create_new_file(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_rename(GtkMenuItem *menuitem, gpointer *user_data) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - GtkTreeIter iter_new; - gpointer iter = NULL; - GtkTreeModel *model; - gchar *uri, *newuri; + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeViewColumn *column; + GtkCellRenderer *renderer; + GtkTreePath *path; + GList *renderers;
- if (gtk_tree_selection_get_selected(selection, &model, iter)) - gtk_tree_model_get(model, iter, TREEBROWSER_COLUMN_URI, &uri, -1); - else - uri = addressbar_last_address; + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + path = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter); + if (G_LIKELY(path != NULL)) + { + column = gtk_tree_view_get_column(GTK_TREE_VIEW (treeview), 0); + renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT (column)); + renderer = g_list_nth_data(renderers, TREEBROWSER_RENDER_TEXT);
- newuri = g_strconcat(uri, G_DIR_SEPARATOR_S, _("NewFile"), NULL); + g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL); + gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(treeview), path, column, renderer, TRUE);
- while(g_file_test(newuri, G_FILE_TEST_EXISTS)) - newuri = g_strconcat(newuri, "_", NULL); - - if (g_creat(newuri, 0755) != -1) - { - gtk_tree_store_prepend(GTK_TREE_STORE(treestore), &iter_new, iter ? iter : NULL); - gtk_tree_store_set(GTK_TREE_STORE(treestore), &iter_new, - TREEBROWSER_COLUMN_ICON, GTK_STOCK_FILE, - TREEBROWSER_COLUMN_NAME, g_path_get_basename(newuri), - TREEBROWSER_COLUMN_URI, newuri, - -1); + gtk_tree_path_free(path); + g_list_free(renderers); + } } }
@@ -343,51 +503,42 @@ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); GtkTreeIter iter; GtkTreeModel *model; - gchar *uri, *msg; + GtkTreePath *path_parent; + gchar *uri;
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gtk_tree_model_get(model, &iter, TREEBROWSER_COLUMN_URI, &uri, -1);
- if (dialogs_yesno(g_strdup_printf(_("Do you want to remove '%s'?"), uri))) + if (dialogs_show_question(_("Do you want to remove '%s'?"), uri)) { fs_remove(uri, TRUE); + path_parent = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter); + if (gtk_tree_path_up(path_parent)) + gtk_tree_model_get_iter(GTK_TREE_MODEL(treestore), &iter, path_parent); + treebrowser_browse(g_path_get_dirname(uri), &iter, CONFIG_INITIAL_DIR_DEEP); } } }
static void -on_menu_rename_activated(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_refresh(GtkMenuItem *menuitem, gpointer *user_data) { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); GtkTreeIter iter; GtkTreeModel *model; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - GtkTreePath *path; - GList *renderers; + gchar *uri;
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - path = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter); - if (G_LIKELY(path != NULL)) - { - column = gtk_tree_view_get_column(GTK_TREE_VIEW (treeview), 0); - renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT (column)); - renderer = g_list_nth_data(renderers, TREEBROWSER_RENDER_TEXT); - - g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL); - gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(treeview), path, column, renderer, TRUE); - - gtk_tree_path_free(path); - g_list_free(renderers); - } + gtk_tree_model_get(model, &iter, TREEBROWSER_COLUMN_URI, &uri, -1); + if (g_file_test(uri, G_FILE_TEST_IS_DIR)) + treebrowser_browse(uri, &iter, CONFIG_INITIAL_DIR_DEEP); } }
- static void -on_menu_showhide_bars(GtkMenuItem *menuitem, gpointer *user_data) +on_menu_show_bars(GtkMenuItem *menuitem, gpointer *user_data) { showbars(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))); } @@ -399,13 +550,9 @@
menu = gtk_menu_new();
- item = ui_image_menu_item_new(GTK_STOCK_GO_UP, _("Go parent")); - gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_go_parent), 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_external_open), NULL); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_open_externally), NULL);
item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Set as root")); gtk_container_add(GTK_CONTAINER(menu), item); @@ -417,15 +564,15 @@
item = ui_image_menu_item_new(GTK_STOCK_ADD, _("Create new directory")); gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_directory), NULL); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_object), "directory");
item = ui_image_menu_item_new(GTK_STOCK_NEW, _("Create new file")); gtk_container_add(GTK_CONTAINER(menu), item); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_file), NULL); + 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_activated), NULL); + 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); @@ -435,7 +582,7 @@ gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(menu), item);
- item = ui_image_menu_item_new(GTK_STOCK_REFRESH, _("Refresh root")); + item = ui_image_menu_item_new(GTK_STOCK_REFRESH, _("Refresh")); gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_refresh), NULL);
@@ -446,7 +593,7 @@ item = gtk_check_menu_item_new_with_mnemonic(_("Show bars")); gtk_container_add(GTK_CONTAINER(menu), item); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), CONFIG_SHOW_BARS); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_showhide_bars), NULL); + g_signal_connect(item, "activate", G_CALLBACK(on_menu_show_bars), NULL);
gtk_widget_show_all(menu);
@@ -454,39 +601,67 @@ }
+// +// TOOLBAR`S EVENTS +//
+static void +on_button_go_up(void) +{ + treebrowser_chroot(g_path_get_dirname(addressbar_last_address)); +}
+static void +on_button_refresh(void) +{ + treebrowser_chroot(addressbar_last_address); +}
-// SIGNALS CALLBACK FUNCTIONS +static void +on_button_go_home(void) +{ + treebrowser_chroot(g_strdup(g_get_home_dir())); +}
+static void +on_button_current_path(void) +{ + treebrowser_chroot(get_default_dir()); +}
+static void +on_addressbar_activate(GtkEntry *entry, gpointer user_data) +{ + gchar *directory = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); + treebrowser_chroot(directory); +}
+static void +on_filter_activate(GtkEntry *entry, gpointer user_data) +{ + treebrowser_chroot(addressbar_last_address); +} + + +// +// TREEVIEW EVENTS +// + static gboolean -on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data) +on_treeview_mouseclick(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { - - /*if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) + if (event->button == 3) { - //on_open_clicked(NULL, NULL); - return TRUE; - } - else */ 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); - /* don't return TRUE here, unless the selection won't be changed */ } return FALSE; - }
- static void -on_changed(GtkWidget *widget, gpointer user_data) +on_treeview_changed(GtkWidget *widget, gpointer user_data) { GtkTreeIter iter; GtkTreeModel *model; @@ -497,12 +672,21 @@ gtk_tree_model_get(GTK_TREE_MODEL(treestore), &iter, TREEBROWSER_COLUMN_URI, &uri, -1); - treebrowser_browse(uri, iter, FALSE, CONFIG_DIRECTORY_DEEP); + if (g_file_test(uri, G_FILE_TEST_EXISTS)) + { + if (g_file_test(uri, G_FILE_TEST_IS_DIR)) + treebrowser_browse(uri, &iter, CONFIG_INITIAL_DIR_DEEP); + else + if (CONFIG_ONE_CLICK_CHDOC) + document_open_file(uri, FALSE, NULL, NULL); + } + else + gtk_tree_store_iter_clear_nodes(&iter, TRUE); } }
static void -on_row_activated (GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) +on_treeview_row_activated(GtkWidget *widget, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { GtkTreeIter iter; gchar *uri; @@ -525,238 +709,149 @@ }
static void -on_row_expanded(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) +on_treeview_row_expanded(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { gtk_tree_store_set(treestore, iter, TREEBROWSER_COLUMN_ICON, GTK_STOCK_OPEN, -1); }
static void -on_row_collapsed(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) +on_treeview_row_collapsed(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { gtk_tree_store_set(treestore, iter, TREEBROWSER_COLUMN_ICON, GTK_STOCK_DIRECTORY, -1); }
static void -on_addressbar_activate(GtkEntry *entry, gpointer user_data) +on_treeview_renamed(GtkCellRenderer *renderer, const gchar *path_string, const gchar *name_new, gpointer data) { - gchar *directory = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); - treebrowser_chroot(directory); -}
-static void -on_addressbar_icon -(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data) -{ + GtkTreeViewColumn *column; + GList *renderers; + GtkTreeIter iter, iter_parent; + gchar *uri, *uri_new; + GtkTreePath *path_parent;
- if (icon_pos == GTK_ENTRY_ICON_PRIMARY) - { - return; - } + column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0); + renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column)); + renderer = g_list_nth_data(renderers, TREEBROWSER_RENDER_TEXT);
- if (icon_pos == GTK_ENTRY_ICON_SECONDARY) - { - //treebrowser_track_path(get_default_dir()); - treebrowser_chroot(get_default_dir()); - return; - } -} + g_object_set(G_OBJECT(renderer), "editable", FALSE, NULL);
-static void -on_filter_activate(GtkEntry *entry, gpointer user_data) -{ - treebrowser_chroot(addressbar_last_address); -} -// END OF SIGNALS - - -// SYSTEM FUNCTIONS - - -static void // recursive removing files -fs_remove(gchar *root, gboolean delete_root) -{ - - if (! g_file_test(root, G_FILE_TEST_EXISTS)) - return; - - if (g_file_test(root, G_FILE_TEST_IS_DIR)) + if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(treestore), &iter, path_string)) { + gtk_tree_model_get(GTK_TREE_MODEL(treestore), &iter, TREEBROWSER_COLUMN_URI, &uri, -1); + if (uri) + { + uri_new = g_strconcat(g_path_get_dirname(uri), G_DIR_SEPARATOR_S, name_new, NULL); + if (g_rename(uri, uri_new) == 0) + { + gtk_tree_store_set(treestore, &iter, + TREEBROWSER_COLUMN_NAME, name_new, + TREEBROWSER_COLUMN_URI, uri_new, + -1);
- GDir *dir; - const gchar *name; + path_parent = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), &iter);
- dir = g_dir_open (root, 0, NULL); - - if (!dir) - return; - - name = g_dir_read_name (dir); - while (name != NULL) - { - gchar *path; - path = g_build_filename (root, name, NULL); - if (g_file_test (path, G_FILE_TEST_IS_DIR)) - fs_remove(path, delete_root); - g_remove(path); - name = g_dir_read_name(dir); - g_free (path); + if (gtk_tree_path_up(path_parent)) + { + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(treestore), &iter_parent, path_parent)) + treebrowser_browse(g_path_get_dirname(uri_new), &iter_parent, CONFIG_INITIAL_DIR_DEEP); + else + treebrowser_browse(g_path_get_dirname(uri_new), NULL, CONFIG_INITIAL_DIR_DEEP); + } + else + treebrowser_browse(g_path_get_dirname(uri_new), NULL, CONFIG_INITIAL_DIR_DEEP); + } } } - else - delete_root = TRUE; +}
- if (delete_root) - g_remove(root);
- return; -} - static void -showbars(gboolean state) +treebrowser_track_current_cb(void) { - if (state) gtk_widget_show(vbox_bars); - else gtk_widget_hide(vbox_bars); - CONFIG_SHOW_BARS = state; + if (CONFIG_FOLLOW_CURRENT_DOC) + treebrowser_track_current_cb(); } +// +// TREEBROWSER INITIAL FUNCTIONS +//
-static int // recursive removing all nodes and subnodes in some node :) -gtk_tree_store_iter_clear_nodes(GtkTreeIter iter, gboolean delete_root) +static void +create_sidebar(void) { - //return 0; - GtkTreeIter i; + GtkWidget *scrollwin; + GtkWidget *toolbar; + GtkWidget *wid; + GtkTreeSelection *selection;
- while (gtk_tree_model_iter_children(GTK_TREE_MODEL(treestore), &i, &iter)) - { - if (gtk_tree_store_iter_depth(treestore, &i) > 0) - gtk_tree_store_iter_clear_nodes(i, TRUE); + vbox = gtk_vbox_new(FALSE, 0); + vbox_bars = gtk_vbox_new(FALSE, 0);
- gtk_tree_store_remove(GTK_TREE_STORE(treestore), &i); - } + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + addressbar = gtk_entry_new(); + filter = gtk_entry_new();
- //if (delete_root) - // gtk_tree_store_remove(GTK_TREE_STORE(treestore), &iter); + scrollwin = gtk_scrolled_window_new(NULL, NULL);
- return 1; -} + page_number = gtk_notebook_append_page(GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook), + vbox, gtk_label_new(_("Tree Browser")));
-static gboolean* -treebrowser_track_path_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) -{ - gchar *path_str, *uri; + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_tree_model_get(GTK_TREE_MODEL(treestore), iter, TREEBROWSER_COLUMN_URI, &uri, -1); + toolbar = gtk_toolbar_new(); + gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), GTK_ICON_SIZE_MENU); + gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
- path_str = gtk_tree_path_to_string(path); + wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_GO_UP)); + ui_widget_set_tooltip_text(wid, _("Go up")); + g_signal_connect(wid, "clicked", G_CALLBACK(on_button_go_up), NULL); + gtk_container_add(GTK_CONTAINER(toolbar), wid);
- if (user_data == uri) - { - msgbox(uri); - return FALSE; - } + wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH)); + ui_widget_set_tooltip_text(wid, _("Refresh")); + g_signal_connect(wid, "clicked", G_CALLBACK(on_button_refresh), NULL); + gtk_container_add(GTK_CONTAINER(toolbar), wid);
- //g_free(path_str); - //g_free(uri); + wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_HOME)); + ui_widget_set_tooltip_text(wid, _("Home")); + g_signal_connect(wid, "clicked", G_CALLBACK(on_button_go_home), NULL); + gtk_container_add(GTK_CONTAINER(toolbar), wid);
- return FALSE; -} + wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_JUMP_TO)); + ui_widget_set_tooltip_text(wid, _("Set path from document")); + g_signal_connect(wid, "clicked", G_CALLBACK(on_button_current_path), NULL); + gtk_container_add(GTK_CONTAINER(toolbar), wid);
-static void -treebrowser_track_path(gchar *directory) -{ - //void gtk_tree_view_column_set_expand (GtkTreeViewColumn *tree_column, - // gboolean expand); - //gtk_tree_model_foreach(GTK_ENTRY(treestore), treebrowser_track_path_cb, directory); -} + wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_DIRECTORY)); + ui_widget_set_tooltip_text(wid, _("Track path")); + g_signal_connect(wid, "clicked", G_CALLBACK(treebrowser_track_current), NULL); + gtk_container_add(GTK_CONTAINER(toolbar), wid);
-static void -treebrowser_chroot(gchar *directory) -{ - GtkTreeIter toplevel_unused; + gtk_container_add(GTK_CONTAINER(scrollwin), treeview); + gtk_box_pack_start(GTK_BOX(vbox_bars), filter, FALSE, TRUE, 1); + gtk_box_pack_start(GTK_BOX(vbox_bars), addressbar, FALSE, TRUE, 1); + gtk_box_pack_start(GTK_BOX(vbox_bars), toolbar, FALSE, TRUE, 1);
- gtk_entry_set_text(GTK_ENTRY(addressbar), directory); + gtk_box_pack_start(GTK_BOX(vbox), scrollwin, TRUE, TRUE, 1); + gtk_box_pack_start(GTK_BOX(vbox), vbox_bars, FALSE, TRUE, 1);
- gtk_tree_store_clear(treestore); + g_signal_connect(selection, "changed", G_CALLBACK(on_treeview_changed), NULL); + g_signal_connect(treeview, "button-press-event", G_CALLBACK(on_treeview_mouseclick), selection); + g_signal_connect(treeview, "row-activated", G_CALLBACK(on_treeview_row_activated), NULL); + g_signal_connect(treeview, "row-collapsed", G_CALLBACK(on_treeview_row_collapsed), NULL); + g_signal_connect(treeview, "row-expanded", G_CALLBACK(on_treeview_row_expanded), NULL); + g_signal_connect(addressbar, "activate", G_CALLBACK(on_addressbar_activate), NULL); + g_signal_connect(filter, "activate", G_CALLBACK(on_filter_activate), NULL);
- if (! g_file_test(directory, G_FILE_TEST_IS_DIR)) - { - gtk_entry_set_icon_from_stock(GTK_ENTRY(addressbar), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_NO); - return; - } + gtk_widget_show_all(vbox);
- gtk_entry_set_icon_from_stock(GTK_ENTRY(addressbar), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIRECTORY); - - addressbar_last_address = directory; - treebrowser_browse(directory, toplevel_unused, TRUE, CONFIG_DIRECTORY_DEEP); + showbars(CONFIG_SHOW_BARS); }
-static void -treebrowser_browse(gchar *directory, GtkTreeIter parent, gboolean isRoot, gint deep_limit) +static GtkWidget* +create_view_and_model(void) { - if (deep_limit < 1) return; - deep_limit--; - GtkTreeIter iter_new; - GtkTreeIter *last_dir_iter = NULL; - gchar *path, *display_name, *newpath; - gboolean is_dir; - GDir *dir; - const gchar *name; - const gchar *basename; - directory = g_strconcat(directory, G_DIR_SEPARATOR_S, NULL);
- if (!isRoot) - gtk_tree_store_iter_clear_nodes(parent, FALSE); - - gchar *utf8_dir, *utf8_name; - GSList *list, *node; - list = utils_get_file_list(directory, NULL, NULL); - if (list != NULL) - { - - foreach_slist_free(node, list) - { - gchar *fname = node->data; - gchar *uri = g_strconcat(directory, fname, NULL); - is_dir = g_file_test (uri, G_FILE_TEST_IS_DIR); - utf8_name = utils_get_utf8_from_locale(fname); - - if (!(fname[0] == '.' && CONFIG_SHOW_HIDDEN_FILES == FALSE)) - { - - if (is_dir) - { - if (last_dir_iter == NULL) - gtk_tree_store_prepend(treestore, &iter_new, isRoot ? NULL : &parent); - else - { - gtk_tree_store_insert_after(treestore, &iter_new, isRoot ? NULL : &parent, last_dir_iter); - gtk_tree_iter_free(last_dir_iter); - } - last_dir_iter = gtk_tree_iter_copy(&iter_new); - gtk_tree_store_set(treestore, &iter_new, 0, is_dir ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE, 1, fname, 2, uri,-1); - - treebrowser_browse(uri, iter_new, FALSE, deep_limit); - } - else - { - if (check_filtered(utf8_name)) - { - gtk_tree_store_append(treestore, &iter_new, isRoot ? NULL : &parent); - gtk_tree_store_set(treestore, &iter_new, 0, is_dir ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE, 1, fname, 2, uri,-1); - } - } - } - g_free(fname); - g_free(uri); - } - } - -} - - -static GtkWidget * -create_view_and_model (void) -{ - GtkWidget *view;
view = gtk_tree_view_new(); @@ -767,83 +862,115 @@
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
- //gtk_tree_view_append_column(GTK_TREE_VIEW(view), treeview_column_icon); gtk_tree_view_append_column(GTK_TREE_VIEW(view), treeview_column_text);
gtk_tree_view_column_pack_start(treeview_column_text, render_icon, FALSE); gtk_tree_view_column_set_attributes(treeview_column_text, render_icon, "stock-id", TREEBROWSER_RENDER_ICON, NULL);
- //gtk_tree_view_column_set_sort_order(treeview_column_text, GTK_SORT_ASCENDING); - //gtk_tree_view_column_get_sort_column_id(treeview_column_text); - //gtk_tree_view_column_get_clickable(treeview_column_text); - gtk_tree_view_column_pack_start(treeview_column_text, render_text, TRUE); gtk_tree_view_column_add_attribute(treeview_column_text, render_text, "text", TREEBROWSER_RENDER_TEXT);
- treestore = gtk_tree_store_new(TREEBROWSER_COLUMNC, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); + treestore = gtk_tree_store_new(TREEBROWSER_COLUMNC, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(treestore));
- g_signal_connect(G_OBJECT(render_text), "edited", G_CALLBACK (on_renamed), view); + g_signal_connect(G_OBJECT(render_text), "edited", G_CALLBACK(on_treeview_renamed), view);
return view; }
-void -plugin_init(GeanyData *data) +// +// CONFIG DIALOG +// + +static void +on_configure_response(GtkDialog *dialog, gint response, gpointer user_data) { - GtkWidget *scrollwin; - GtkTreeSelection *selection; + if (! (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY)) + return;
- treeview = create_view_and_model(); - vbox = gtk_vbox_new(FALSE, 0); - vbox_bars = gtk_vbox_new(FALSE, 0); - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - addressbar = gtk_entry_new(); - filter = gtk_entry_new(); + //dialogs_show_msgbox(GTK_MESSAGE_INFO, "OKAY");
- scrollwin = gtk_scrolled_window_new(NULL, NULL); +}
- page_number = gtk_notebook_append_page(GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook), - vbox, gtk_label_new(_("Tree Browser"))); +GtkWidget* +plugin_configure(GtkDialog *dialog) +{ + GtkWidget *label, *entry, *checkbox; + GtkWidget *vbox, *hbox;
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + vbox = gtk_vbox_new(FALSE, 0);
- gtk_entry_set_icon_from_stock(GTK_ENTRY(filter), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND); - gtk_entry_set_icon_from_stock(GTK_ENTRY(addressbar), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIRECTORY); - gtk_entry_set_icon_from_stock(GTK_ENTRY(addressbar), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_JUMP_TO); + label = gtk_label_new(_("This is experimental and not working for now.")); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_container_add(GTK_CONTAINER(scrollwin), treeview); + hbox = gtk_hbox_new(FALSE, 0); + label = gtk_label_new(_("External open command: ")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + entry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox_bars), filter, FALSE, TRUE, 1); - gtk_box_pack_start(GTK_BOX(vbox_bars), addressbar, FALSE, TRUE, 1); + hbox = gtk_hbox_new(FALSE, 0); + label = gtk_label_new(_("Initial directory deep: ")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + entry = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 6);
- gtk_box_pack_start(GTK_BOX(vbox), scrollwin, TRUE, TRUE, 1); - gtk_box_pack_start(GTK_BOX(vbox), vbox_bars, FALSE, TRUE, 1); + checkbox = gtk_check_button_new_with_label(_("Show hidden files")); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), CONFIG_SHOW_HIDDEN_FILES); + gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
- g_signal_connect(selection, "changed", G_CALLBACK(on_changed), NULL); - g_signal_connect(treeview, "button-press-event", G_CALLBACK(on_button_press), selection); - g_signal_connect(treeview, "row-activated", G_CALLBACK(on_row_activated), NULL); - g_signal_connect(treeview, "row-collapsed", G_CALLBACK(on_row_collapsed), NULL); - g_signal_connect(treeview, "row-expanded", G_CALLBACK(on_row_expanded), NULL); - g_signal_connect(addressbar, "activate", G_CALLBACK(on_addressbar_activate), NULL); - g_signal_connect(addressbar, "icon-release", G_CALLBACK(on_addressbar_icon), NULL); - g_signal_connect(filter, "activate", G_CALLBACK(on_filter_activate), NULL); + checkbox = gtk_check_button_new_with_label(_("Reverse filter")); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), CONFIG_REVERSE_FILTER); + gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
+ checkbox = gtk_check_button_new_with_label(_("Follow path")); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), CONFIG_FOLLOW_CURRENT_DOC); + gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0); + + checkbox = gtk_check_button_new_with_label(_("On click document change")); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), CONFIG_ONE_CLICK_CHDOC); + gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0); + + checkbox = gtk_check_button_new_with_label(_("Chroot on dclick")); + gtk_button_set_focus_on_click(GTK_BUTTON(checkbox), FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), CONFIG_CHROOT_ON_DCLICK); + gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0); + gtk_widget_show_all(vbox);
- //treebrowser_chroot("/tmp"); - treebrowser_chroot(get_default_dir()); + g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL);
- showbars(CONFIG_SHOW_BARS); + return vbox; }
+// +// GEANY HOOKS +// + void +plugin_init(GeanyData *data) +{ + treeview = create_view_and_model(); + create_sidebar(); + treebrowser_chroot(get_default_dir()); + //treebrowser_chroot("/tmp"); + + plugin_signal_connect(geany_plugin, NULL, "document-activate", TRUE, + (GCallback) &treebrowser_track_current_cb, NULL); +} + +void plugin_cleanup(void) { gtk_widget_destroy(GTK_WIDGET(vbox));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.