Last active
October 26, 2021 23:55
Revisions
-
codebrainz revised this gist
Jul 1, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,9 +58,9 @@ static void document_notebook_set_tabs_reorderable(GtkNotebook *nb, gboolean reo gtk_notebook_set_tab_reorderable(nb, gtk_notebook_get_nth_page(nb, index), reorderable); } void plugin_init(GeanyData *data) { document_notebook_set_tabs_reorderable(GTK_NOTEBOOK(data->main_widgets->notebook), FALSE); plugin_signal_connect(geany_plugin, NULL, "document-open", TRUE, G_CALLBACK(sort_tabs_callback), NULL); } -
codebrainz created this gist
Oct 3, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ #include <geanyplugin.h> GeanyData *geany_data; GeanyPlugin *geany_plugin; GeanyFunctions *geany_functions; PLUGIN_VERSION_CHECK(211); PLUGIN_SET_INFO("Tab Sort", "Automatically keeps document tabs sorted", "v0.01", "Matthew Brush <[email protected]>"); struct tab_info { gchar *label; GtkWidget *page; }; static gint compare_tab_info(const struct tab_info *t1, const struct tab_info *t2) { return g_utf8_collate(t2->label, t1->label); } static void sort_tabs_callback(GObject *geany_object, GeanyDocument *doc, gpointer user_data) { GtkNotebook *nb = GTK_NOTEBOOK(geany_data->main_widgets->notebook); gint index, n_pages = gtk_notebook_get_n_pages(nb); GSList *tab, *tabs = NULL; gtk_notebook_set_tab_reorderable(nb, GTK_WIDGET(doc->editor->sci), FALSE); for (index = 0; index < n_pages; index++) { struct tab_info *inf = g_slice_alloc(sizeof(struct tab_info)); inf->page = gtk_notebook_get_nth_page(nb, index); inf->label = document_get_basename_for_display(document_get_from_page(index), index); tabs = g_slist_prepend(tabs, inf); } tabs = g_slist_sort(tabs, (GCompareFunc) compare_tab_info); for (tab = tabs, index = 0; tab != NULL && index < n_pages; tab = tab->next, n_pages++) gtk_notebook_reorder_child(nb, ((struct tab_info *)tab->data)->page, index); for (tab = tabs; tab != NULL; tab = tab->next) { struct tab_info *inf = tab->data; g_free(inf->label); g_slice_free1(sizeof(struct tab_info), inf); } g_slist_free(tabs); } static void document_notebook_set_tabs_reorderable(GtkNotebook *nb, gboolean reorderable) { gint index, n_pages = gtk_notebook_get_n_pages(nb); for (index = 0; index < n_pages; index++) gtk_notebook_set_tab_reorderable(nb, gtk_notebook_get_nth_page(nb, index), reorderable); } void plugin_init(void) { document_notebook_set_tabs_reorderable(GTK_NOTEBOOK(geany_data->main_widgets->notebook), FALSE); plugin_signal_connect(geany_plugin, NULL, "document-open", TRUE, G_CALLBACK(sort_tabs_callback), NULL); } void plugin_cleanup(void) { document_notebook_set_tabs_reorderable(GTK_NOTEBOOK(geany_data->main_widgets->notebook), TRUE); }