Too Busy For Words - the PaulWay Blog

Mon 8th Jan, 2007

First Patch Manual Assist

I'm taking my first steps into a wider world of open source coding today, because I've decided to try to put in a patch for Gedit. It suddenly occurred to me today that the document menu, which shows you the various files you have open and allows you to choose from them, amongst other things, doesn't give you a 'short cut' key to select the document quickly. Given that the files (as tabs) are already accessed by <alt>-1 through <alt>-9 and <alt>-0, I thought that this number would be the logical choice for the short cut key (or accelerator, or whatever it's called in GNOME jargon).

So, off I go, downloading the CVS source for Gedit and charging into it. It took a little time to find where I needed to edit, but I guessed it was in gedit-window.c and it would be related to the words 'Document' and 'New Window' (since the text 'Move to New Window' occurs in the menu). A little searching turned up the update_documents_list_menu function, and a little further down there was a bit that got the various file names and turned them into radio actions complete with a tip for choosing them (e.g. <Alt>-1).

A bit of looking in the GNOME Developer's GTK+ reference manual taught me that I'd have to change the item label, and in Gedit this is helpfully fed through a function called gedit_utils_escape_underscore so that underscores in the file name wouldn't trigger GTK to make that the accelerator key. I just needed to prepend the suitably formatted accelerator number. Since the underscore escaping function obviously manipulated the string in some way, I looked at it, and found out that it used the g_string_append utility function to append characters to the new underscore-escaped string (which also grows the target string if necessary). I needed to prepend, so I looked for a g_string_prepend function. And, lo and behold, there was one.

So my patch so far is:

diff -r1.47 gedit-window.c
>         /* Put a 0..9 as a shortcut key before the first ten items */
>         if (i < 10) {
>             g_string_prepend(
>                 name,
>                 g_strdup_printf("_%d: ", ((i + 1) % 10))
>             );
>         }

I'm still installing bits and pieces (my intltool is out of date, it seems) so I haven't test it yet. Who knows, it could be complete garbage. But ones task of contributing additions to open source code is made manifestly easier when the code base is already feature-rich - you can look at previous examples to find out how to do what you want, and there's probably already utility functions to do the lower-level manipulation.

Fotonote: Now submitted as bug #394153!

Last updated: | path: tech | permanent link to this entry

All posts licensed under the CC-BY-NC license. Author Paul Wayper.

Main index / tbfw/ - © 2004-2016 Paul Wayper
Valid HTML5 Valid CSS!