Revision: 2020 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2020&view=re... Author: eht16 Date: 2011-04-10 17:05:45 +0000 (Sun, 10 Apr 2011)
Log Message: ----------- Add preference for the DocList addon to define the order of the documents in the list (closes #3204573)
Modified Paths: -------------- trunk/geany-plugins/addons/src/addons.c trunk/geany-plugins/addons/src/ao_doclist.c trunk/geany-plugins/addons/src/ao_doclist.h
Modified: trunk/geany-plugins/addons/src/addons.c =================================================================== --- trunk/geany-plugins/addons/src/addons.c 2011-04-10 16:18:37 UTC (rev 2019) +++ trunk/geany-plugins/addons/src/addons.c 2011-04-10 17:05:45 UTC (rev 2020) @@ -40,7 +40,7 @@ GeanyFunctions *geany_functions;
-PLUGIN_VERSION_CHECK(206) +PLUGIN_VERSION_CHECK(207) PLUGIN_SET_TRANSLATABLE_INFO( LOCALEDIR, GETTEXT_PACKAGE, @@ -61,12 +61,11 @@ };
- typedef struct { /* general settings */ gchar *config_file; - gboolean show_toolbar_doclist_item; + gboolean enable_doclist; gboolean enable_openuri; gboolean enable_tasks; gboolean enable_systray; @@ -78,6 +77,8 @@ gchar *tasks_token_list; gboolean tasks_scan_all_documents;
+ DocListSortMode doclist_sort_mode; + /* instances and variables of components */ AoDocList *doclist; AoOpenUri *openuri; @@ -243,8 +244,10 @@ "plugins", G_DIR_SEPARATOR_S, "addons", G_DIR_SEPARATOR_S, "addons.conf", NULL);
g_key_file_load_from_file(config, ao_info->config_file, G_KEY_FILE_NONE, NULL); - ao_info->show_toolbar_doclist_item = utils_get_setting_boolean(config, + ao_info->enable_doclist = utils_get_setting_boolean(config, "addons", "show_toolbar_doclist_item", TRUE); + ao_info->doclist_sort_mode = utils_get_setting_integer(config, + "addons", "doclist_sort_mode", DOCLIST_SORT_BY_OCCURRENCE); ao_info->enable_openuri = utils_get_setting_boolean(config, "addons", "enable_openuri", FALSE); ao_info->enable_tasks = utils_get_setting_boolean(config, @@ -266,7 +269,7 @@
plugin_module_make_resident(geany_plugin);
- ao_info->doclist = ao_doc_list_new(ao_info->show_toolbar_doclist_item); + ao_info->doclist = ao_doc_list_new(ao_info->enable_doclist, ao_info->doclist_sort_mode); ao_info->openuri = ao_open_uri_new(ao_info->enable_openuri); ao_info->systray = ao_systray_new(ao_info->enable_systray); ao_info->bookmarklist = ao_bookmark_list_new(ao_info->enable_bookmarklist); @@ -298,6 +301,15 @@ }
+static void ao_configure_doclist_toggled_cb(GtkToggleButton *togglebutton, gpointer data) +{ + gboolean sens = gtk_toggle_button_get_active(togglebutton); + + gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(data), "radio_doclist_name"), sens); + gtk_widget_set_sensitive(g_object_get_data(G_OBJECT(data), "radio_doclist_occurrence"), sens); +} + + static void ao_configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) @@ -306,8 +318,14 @@ gchar *data; gchar *config_dir = g_path_get_dirname(ao_info->config_file);
- ao_info->show_toolbar_doclist_item = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( + ao_info->enable_doclist = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_doclist")))); + if (gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(dialog), "radio_doclist_name")))) + ao_info->doclist_sort_mode = DOCLIST_SORT_BY_NAME; + else + ao_info->doclist_sort_mode = DOCLIST_SORT_BY_OCCURRENCE; + ao_info->enable_openuri = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_openuri")))); ao_info->enable_tasks = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( @@ -330,7 +348,8 @@
g_key_file_load_from_file(config, ao_info->config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "addons", - "show_toolbar_doclist_item", ao_info->show_toolbar_doclist_item); + "show_toolbar_doclist_item", ao_info->enable_doclist); + g_key_file_set_integer(config, "addons", "doclist_sort_mode", ao_info->doclist_sort_mode); g_key_file_set_boolean(config, "addons", "enable_openuri", ao_info->enable_openuri); g_key_file_set_boolean(config, "addons", "enable_tasks", ao_info->enable_tasks); g_key_file_set_string(config, "addons", "tasks_token_list", ao_info->tasks_token_list); @@ -345,7 +364,8 @@ g_key_file_set_boolean(config, "addons", "enable_xmltagging", ao_info->enable_xmltagging);
- g_object_set(ao_info->doclist, "enable-doclist", ao_info->show_toolbar_doclist_item, NULL); + g_object_set(ao_info->doclist, "enable-doclist", ao_info->enable_doclist, NULL); + g_object_set(ao_info->doclist, "sort-mode", ao_info->doclist_sort_mode, NULL); g_object_set(ao_info->openuri, "enable-openuri", ao_info->enable_openuri, NULL); g_object_set(ao_info->systray, "enable-systray", ao_info->enable_systray, NULL); g_object_set(ao_info->bookmarklist, "enable-bookmarklist", @@ -378,7 +398,9 @@
GtkWidget *plugin_configure(GtkDialog *dialog) { - GtkWidget *vbox, *check_doclist, *check_openuri, *check_tasks, *check_systray; + GtkWidget *vbox, *check_openuri, *check_tasks, *check_systray; + GtkWidget *check_doclist, *vbox_doclist, *frame_doclist; + GtkWidget *radio_doclist_name, *radio_doclist_occurrence; GtkWidget *check_bookmarklist, *check_markword, *frame_tasks, *vbox_tasks; GtkWidget *check_tasks_scan_mode, *entry_tasks_tokens, *label_tasks_tokens, *tokens_hbox; GtkWidget *check_blanklines, *check_xmltagging; @@ -387,10 +409,32 @@
check_doclist = gtk_check_button_new_with_label( _("Show toolbar item to show a list of currently open documents")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_doclist), - ao_info->show_toolbar_doclist_item); - gtk_box_pack_start(GTK_BOX(vbox), check_doclist, FALSE, FALSE, 3); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_doclist), ao_info->enable_doclist); + g_signal_connect(check_doclist, "toggled", G_CALLBACK(ao_configure_doclist_toggled_cb), dialog);
+ radio_doclist_name = gtk_radio_button_new_with_mnemonic(NULL, _("Sort documents by _name")); + ui_widget_set_tooltip_text(radio_doclist_name, + _("Sort the documents in the list by their filename")); + + radio_doclist_occurrence = gtk_radio_button_new_with_mnemonic_from_widget( + GTK_RADIO_BUTTON(radio_doclist_name), _("Sort documents by _occurrence")); + ui_widget_set_tooltip_text(radio_doclist_name, + _("Sort the documents in the order of the document tabs")); + + if (ao_info->doclist_sort_mode == DOCLIST_SORT_BY_NAME) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_doclist_name), TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_doclist_occurrence), TRUE); + + vbox_doclist = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox_doclist), radio_doclist_name, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(vbox_doclist), radio_doclist_occurrence, TRUE, TRUE, 3); + + frame_doclist = gtk_frame_new(NULL); + gtk_frame_set_label_widget(GTK_FRAME(frame_doclist), check_doclist); + gtk_container_add(GTK_CONTAINER(frame_doclist), vbox_doclist); + gtk_box_pack_start(GTK_BOX(vbox), frame_doclist, FALSE, FALSE, 3); + check_openuri = gtk_check_button_new_with_label( /* TODO fix the string */ _("Show a 'Open URI' menu item in the editor menu")); @@ -465,6 +509,8 @@ gtk_box_pack_start(GTK_BOX(vbox), check_xmltagging, FALSE, FALSE, 3);
g_object_set_data(G_OBJECT(dialog), "check_doclist", check_doclist); + g_object_set_data(G_OBJECT(dialog), "radio_doclist_name", radio_doclist_name); + g_object_set_data(G_OBJECT(dialog), "radio_doclist_occurrence", radio_doclist_occurrence); g_object_set_data(G_OBJECT(dialog), "check_openuri", check_openuri); g_object_set_data(G_OBJECT(dialog), "check_tasks", check_tasks); g_object_set_data(G_OBJECT(dialog), "entry_tasks_tokens", entry_tasks_tokens); @@ -477,6 +523,7 @@ g_signal_connect(dialog, "response", G_CALLBACK(ao_configure_response_cb), NULL);
ao_configure_tasks_toggled_cb(GTK_TOGGLE_BUTTON(check_tasks), dialog); + ao_configure_doclist_toggled_cb(GTK_TOGGLE_BUTTON(check_doclist), dialog);
gtk_widget_show_all(vbox);
Modified: trunk/geany-plugins/addons/src/ao_doclist.c =================================================================== --- trunk/geany-plugins/addons/src/ao_doclist.c 2011-04-10 16:18:37 UTC (rev 2019) +++ trunk/geany-plugins/addons/src/ao_doclist.c 2011-04-10 17:05:45 UTC (rev 2020) @@ -48,13 +48,15 @@ struct _AoDocListPrivate { gboolean enable_doclist; + DocListSortMode sort_mode; GtkToolItem *toolbar_doclist_button; };
enum { PROP_0, - PROP_ENABLE_DOCLIST + PROP_ENABLE_DOCLIST, + PROP_SORT_MODE }; enum { @@ -87,6 +89,17 @@ "Whether to show a toolbar item to open a document list", TRUE, G_PARAM_WRITABLE)); + + g_object_class_install_property(g_object_class, + PROP_SORT_MODE, + g_param_spec_int( + "sort-mode", + "sort-mode", + "How to sort the documents in the list", + 0, + G_MAXINT, + DOCLIST_SORT_BY_OCCURRENCE, + G_PARAM_WRITABLE)); }
@@ -163,15 +176,22 @@ static GtkWidget *menu = NULL; GtkWidget *menu_item; GeanyDocument *current_doc = document_get_current(); + GCompareFunc sort_func; + AoDocListPrivate *priv = AO_DOC_LIST_GET_PRIVATE(data);
if (menu != NULL) gtk_widget_destroy(menu);
menu = gtk_menu_new();
- ui_menu_add_document_items(GTK_MENU(menu), current_doc, - G_CALLBACK(ao_doclist_menu_item_activate_cb)); + if (priv->sort_mode == DOCLIST_SORT_BY_NAME) + sort_func = document_sort_by_display_name; + else + sort_func = NULL;
+ ui_menu_add_document_items_sorted(GTK_MENU(menu), current_doc, + G_CALLBACK(ao_doclist_menu_item_activate_cb), sort_func); + menu_item = gtk_separator_menu_item_new(); gtk_widget_show(menu_item); gtk_container_add(GTK_CONTAINER(menu), menu_item); @@ -217,7 +237,7 @@ ui_add_document_sensitive(GTK_WIDGET(priv->toolbar_doclist_button));
g_signal_connect(priv->toolbar_doclist_button, "clicked", - G_CALLBACK(ao_toolbar_item_doclist_clicked_cb), NULL); + G_CALLBACK(ao_toolbar_item_doclist_clicked_cb), self); } gtk_widget_show(GTK_WIDGET(priv->toolbar_doclist_button)); } @@ -235,6 +255,9 @@ priv->enable_doclist = g_value_get_boolean(value); ao_toolbar_update(AO_DOC_LIST(object)); break; + case PROP_SORT_MODE: + priv->sort_mode = g_value_get_int(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -250,9 +273,9 @@ }
-AoDocList *ao_doc_list_new(gboolean enable) +AoDocList *ao_doc_list_new(gboolean enable, DocListSortMode sort_mode) { - return g_object_new(AO_DOC_LIST_TYPE, "enable-doclist", enable, NULL); + return g_object_new(AO_DOC_LIST_TYPE, "enable-doclist", enable, "sort-mode", sort_mode, NULL); }
Modified: trunk/geany-plugins/addons/src/ao_doclist.h =================================================================== --- trunk/geany-plugins/addons/src/ao_doclist.h 2011-04-10 16:18:37 UTC (rev 2019) +++ trunk/geany-plugins/addons/src/ao_doclist.h 2011-04-10 17:05:45 UTC (rev 2020) @@ -40,9 +40,16 @@ typedef struct _AoDocList AoDocList; typedef struct _AoDocListClass AoDocListClass;
+typedef enum +{ + DOCLIST_SORT_BY_NAME = 1, + DOCLIST_SORT_BY_OCCURRENCE = 2 +} DocListSortMode;
+ + GType ao_doc_list_get_type (void); -AoDocList* ao_doc_list_new (gboolean enable); +AoDocList* ao_doc_list_new (gboolean enable, DocListSortMode sort_mode);
G_END_DECLS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org