GNOME Bugzilla – Bug 308237
Sort the languages list alphabetically
Last modified: 2005-08-01 17:23:34 UTC
Version details: 2.10.3 Distribution/Version: Debian The list of available languages to highlight is not sorted alphabetically. This makes it hard to find the right language. This bug shows up in two places: * "Syntax Highlighting" preferences tab * "View > Highlight Mode" menu
I agree with you.
Should this be done in gedit or in gtksourceview as gtk_source_languages_manager_get_available_languages_sorted?
I don't think it's worth introducing a gtk_source_languages_manager_get_available_languages_sorted, but maybe gtk_source_languages_manager_get_available_languages can be modified to return a sorted list since I don't think that sorting it is going to be a performance problem. Let's see what Paolo (Maggi) thinks...
On my Breezy (gedit 2.10.3 and gtksourceview 1.2.1), lists are sorted. I think that bug can be closed.
Guillaume: I don't think that's possible, no one fixed the code. Caleb: thinking again about it, the sorting should be done by the caller (in gedit) not in gtksourceview, since different locales may have different collation rules.
Created attachment 49830 [details] screenshot of Ubuntu Hoary yes it's possible, believe in me ;) Here a screenshot with Ubuntu Hoary. It's strange because seems to have no patch into gedit and gtksourceview ubuntu package.
Yes, it is possible since you don't have per-user .lang files. and also since in your case the file are sorted in the dir in such a way "readdir" read them in the right order. I agree with pbor, the sorting should be done by the caller.
Created attachment 49880 [details] [review] add a gedit_get_available_languages_sorted () function Patch for CVS HEAD.
Guillaume, thanks for the patch, IMHO you should use g_utf8_collate or even better g_utf8_collate_key to order the list, so that the list is sorted according to the locale specific rules.
Created attachment 49903 [details] [review] new patch using g_utf8_collate I don't see how to use g_utf8_collate_key without a significant increase of the code complexity.
Comment on attachment 49903 [details] [review] new patch using g_utf8_collate Thanks for your help. It is very appreciated. Here some comments. >+GSList* >+gedit_get_available_languages_sorted (void) >+{ I'd prefer to call this function: const GSList * gedit_languages_manager_get_available_languages_sorted (GtkSourceLanguagesManager *lm); The function should cache the results. In this way we will have some performace gain at the cost of a minimal additional memory consumption and we will reduce the code changes in other parts of the code. While you are looking at this bug, it would be cool if you could fix other two little problems: - removing duplicated languages from the list reported by gtk_source_languages_manager_get_available_languages (see the TODO in the code - fixing bug #309187 Thanks again for your help.
Ok ok. If it cache the list, we'll must restart gedit if .lang files are added during gedit is running. It's ok? (Or we must monitor lang repertories and think it's a very complication for a small thing). I will look for the 2 others bugs.
As far as I recall, gtksourceview already caches and reads the .lang just at startup so not detecting new files in that function is not an issue
As pbor said, gtksourceview already caches and reads the .lang just at startup. So this is not a problem. Since it may be this behavior will change in the future, you can simply check if the pointer returned by gtk_source_languages_manager_get_available_languages is changed and in that case re-generate the cache.
Created attachment 50016 [details] [review] cache the result Done. I have a little warning and don't know how to remove it. gedit-languages-manager.c: In function ‘gedit_languages_manager_get_available_languages_sorted’: gedit-languages-manager.c:343: attention : passing argument 1 of ‘g_slist_copy’ discards qualifiers from pointer target type
the patch looks ok to me, but I'll wait for Paolo (Maggi) to double check. Removing 'const' from the variable declaration should get rid of the warnings.
> - removing duplicated languages from the list reported by > gtk_source_languages_manager_get_available_languages (see the TODO in the code Could you tell me a little more about this bug? I don't find the TODO into the code.
With the current implementation of GtkSourceLanguageManager your patch works great. Since it may be in the future GtkSourceLanguageManager could change, I'd prefer to have a more intelligent cache. I think you should add a "languages_list" global variable and write something like: static const GSList *languages_list; ... ... const GSList * gedit_languages_manager_get_available_languages_sorted (GtkSourceLanguagesManager *lm) { const GSList *languages; languages = gtk_source_languages_manager_get_available_languages if ((languages_list_sorted == NULL) || (languages != languages_list)) { languages_list = languages; languages_list_sorted = g_slist_copy ((GSList *)languages); languages_list_sorted = g_slist_sort (languages_list_sorted, (GCompareFunc)language_compare); } return languages_list_sorted; } Please, remember to add a space before left brackets. Add a ChangeLog entry. Thanks again for your help.
About the TODO. Search for TODO in gtksourceview/gtksourceview/gtksourcelanguagesmanager.c. You have to remove duplicate languages, i.e. if you have two languages with the same id, remove the second one.
Created attachment 50062 [details] [review] Better cache system and ChangeLog entry Hope it will be good :-)
The patch looks very good to me. I will test and commit it ASAP.
I have open a bugreport about duplicated languages in gtksourceview. See bug 312241.
Created attachment 50083 [details] [review] Committed patch Looking again at the patch I have found a mem leak in the compare function. I have fixed it. This is the patch I'm going to commit.
Fixed in CVS HEAD. 2005-08-01 Guillaume Desmottes <cass@skynet.be> Fixed bug #308237 (sort the languages list alphabetically) * gedit-languages-manager.h: new function gedit_languages_manager_get_available_languages_sorted * gedit-languages-manager.c: new functions gedit_languages_manager_get_available_languages_sorted and language_compare. Add two global variables: languages_list and languages_list_sorted * gedit-mdi.c: use gedit_languages_manager_get_available_languages_sorted instead of gtk_source_languages_manager_get_available_languages * dialogs/gedit-preferences-dialog.c: ditto