After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 308237 - Sort the languages list alphabetically
Sort the languages list alphabetically
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.10.x
Other Linux
: Normal enhancement
: 2.12.0
Assigned To: Gedit maintainers
gedit QA volunteers
Depends on:
Blocks:
 
 
Reported: 2005-06-19 00:08 UTC by Josh Lee
Modified: 2005-08-01 17:23 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
screenshot of Ubuntu Hoary (43.86 KB, image/jpeg)
2005-07-27 10:51 UTC, Guillaume Desmottes
  Details
add a gedit_get_available_languages_sorted () function (5.49 KB, patch)
2005-07-28 14:36 UTC, Guillaume Desmottes
none Details | Review
new patch using g_utf8_collate (5.49 KB, patch)
2005-07-28 21:19 UTC, Guillaume Desmottes
needs-work Details | Review
cache the result (4.80 KB, patch)
2005-07-31 14:37 UTC, Guillaume Desmottes
needs-work Details | Review
Better cache system and ChangeLog entry (5.91 KB, patch)
2005-08-01 11:31 UTC, Guillaume Desmottes
none Details | Review
Committed patch (6.27 KB, patch)
2005-08-01 17:21 UTC, Paolo Maggi
committed Details | Review

Description Josh Lee 2005-06-19 00:08:53 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
Comment 1 Paolo Maggi 2005-07-21 17:37:43 UTC
I agree with you.
Comment 2 Caleb Groom 2005-07-25 21:57:36 UTC
Should this be done in gedit or in gtksourceview as
gtk_source_languages_manager_get_available_languages_sorted?
Comment 3 Paolo Borelli 2005-07-26 07:41:27 UTC
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...
Comment 4 Guillaume Desmottes 2005-07-26 10:29:02 UTC
On my Breezy (gedit 2.10.3 and gtksourceview 1.2.1), lists are sorted.
I think that bug can be closed.
Comment 5 Paolo Borelli 2005-07-27 07:41:14 UTC
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.
Comment 6 Guillaume Desmottes 2005-07-27 10:51:11 UTC
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.
Comment 7 Paolo Maggi 2005-07-27 11:53:50 UTC
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.
Comment 8 Guillaume Desmottes 2005-07-28 14:36:39 UTC
Created attachment 49880 [details] [review]
add a gedit_get_available_languages_sorted () function

Patch for CVS HEAD.
Comment 9 Paolo Borelli 2005-07-28 15:05:41 UTC
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.
Comment 10 Guillaume Desmottes 2005-07-28 21:19:49 UTC
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 11 Paolo Maggi 2005-07-29 08:53:34 UTC
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.
Comment 12 Guillaume Desmottes 2005-07-29 11:09:21 UTC
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.
Comment 13 Paolo Borelli 2005-07-29 11:25:06 UTC
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
Comment 14 Paolo Maggi 2005-07-29 12:06:14 UTC
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.
Comment 15 Guillaume Desmottes 2005-07-31 14:37:00 UTC
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
Comment 16 Paolo Borelli 2005-07-31 15:28:58 UTC
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.
Comment 17 Guillaume Desmottes 2005-07-31 15:31:10 UTC
> - 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.
Comment 18 Paolo Maggi 2005-08-01 10:29:17 UTC
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.
Comment 19 Paolo Maggi 2005-08-01 10:33:53 UTC
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.
Comment 20 Guillaume Desmottes 2005-08-01 11:31:51 UTC
Created attachment 50062 [details] [review]
Better cache system and ChangeLog entry

Hope it will be good :-)
Comment 21 Paolo Maggi 2005-08-01 13:11:30 UTC
The patch looks very good to me. I will test and commit it ASAP.
Comment 22 Guillaume Desmottes 2005-08-01 14:45:10 UTC
I have open a bugreport about duplicated languages in gtksourceview.
See bug 312241. 
Comment 23 Paolo Maggi 2005-08-01 17:21:41 UTC
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.
Comment 24 Paolo Maggi 2005-08-01 17:23:34 UTC
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