Gedit bio-patch; Next & Prior Documents keystrokes



GNOMEs:

I have been using gedit (with a couple tweaks) full-time at work.

The only feature I missed was one that can keep my hand off the mouse -
the ability to switch between open documents from the keyboard (without
a romp thru the Documents menu!)

I have added this feature to 0.9.6. The source code to do it is below my
sig.

It uses <Ctrl+PageUp> to go to the next document, and
<Ctrl+PageDown> to go to the previous one. This factoid needs to be
added to the Document menu & the docs.

I chose <Ctrl+PageUp> & <Ctrl+PageDown> because according to the /Common
User Access/ they are the standard keystrokes to change between tabs in
a "notebook" interface. We are therefor compliant with a feature of
M$-Windows that none of their users know about when they reach for that
mouse.

Live long and prosper!

-- 
  Phlip                          phlip_cpp my-deja com
========== http://greencheese.org/SonseOne ===========
  --  "In my experience, the customer doesn't know what he wants
       until you don't give it to him." --David Brady  --



#define db(x) g_message(#x ": %x", (long) (x))


        static void
next_document(GtkWidget *w, int delta)
{

        long num = g_list_length (mdi->children);
        
//      db(g_list_length (mdi->children));
        
        if (num > 1)
                {
                int i;
                GeditDocument * doc  = doc = gedit_document_current ();

                for (i = 0; i < g_list_length (mdi->children); i++)
                        {
                        GeditDocument * findDoc = (GeditDocument
*)g_list_nth_data
(mdi->children, i);
                        
                        if (doc == findDoc)
                                {
                                
                                // Is there an easier way to get the
current slot
number?
                                
                                long next = i + delta;
                                
                                if (next < 0)  next = num - 1;
                                else if (next >= num)  next = 0;
                                
                                {
                                GeditDocument * nextDoc = (GeditDocument
*)g_list_nth_data
(mdi->children, next);
                                GeditView     * view    =
g_list_nth_data
(nextDoc->views, 0);
                                g_assert (view != gedit_view_active());
                                gnome_mdi_set_active_view (mdi,
GTK_WIDGET (view));
                                }
                                
                                break;
                                }
                        }
                }

}


static gint
gedit_event_key_press (GtkWidget *w, GdkEventKey *event)
{
        gedit_debug (DEBUG_VIEW, "");

        gedit_view_update_line_indicator ();

        if (event->state & GDK_MOD1_MASK)
        {
                gtk_signal_emit_stop_by_name (GTK_OBJECT (w),
"key_press_event");
                return FALSE;
        }

        /* Control key related */
        if (event->state & GDK_CONTROL_MASK)
        {
                switch (event->keyval)
                {
                
                case GDK_Page_Up  :  next_document(w, -1);  break;
                case GDK_Page_Down:  next_document(w, +1);  break;
                
                        /* This is nasty, NASTY NASTY !!!!!!!
                           since it depends on the current language */
                case 's':
                        file_save_cb (w, NULL);
                        break;
                case 'p':
                        gedit_print_cb (w, NULL);
                        break;
                case 'n':
                        return FALSE;
                        break;
                case 'w':
                        file_close_cb (w, NULL);
                        /* If the user cancels the file_close action,
the cut still
happens*/
                        gtk_signal_emit_stop_by_name (GTK_OBJECT (w),
"key_press_event");
                        return TRUE;
                case 'z':
                        /* Undo is getting called twice, 1 thru this
function
                           and 1 time thru the aceleratior. Chema 
                        gedit_undo_do (w, NULL);
                        */
                        break;
                case 'r':
                        /* Same as undo_do 
                        gedit_undo_redo (w, NULL);
                        */
                        break;
                case 'q':
                        file_quit_cb (w, NULL);
                        break;
                default:
                        return TRUE;
                        break;
                }
        }

        return TRUE;
}

-- 
  Phlip                          phlip_cpp my-deja com
======== http://greencheese.org/SpringPicnic =========
  --  This machine last rebooted during the Second Millenium  --




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]