[gedit-list] [PATCH] Ctrl-Tab/Ctrl-Shift-Tab to move between tabs



Hello,

Attached is a patch that enables switching between tabs with Ctrl-Tab/Ctrl-Shift-Tab for backwards and forwards, respectively. This is my first gedit patch, so I'm treading a bit cautiously. There don't seem to be any issues, except that something doesn't feel right about have to handle the accelerator in gedit-window::key_press-event, and I'm sure accessibility is broken since I've stolen tab-to-focus~ ability.

Comments are most welcome.

Thanks,

--
Dave Barry
dave psax org
Index: gedit/gedit-commands-documents.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands-documents.c,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 gedit-commands-documents.c
--- gedit/gedit-commands-documents.c	11 Oct 2005 11:20:41 -0000	1.1.2.1
+++ gedit/gedit-commands-documents.c	23 Dec 2005 19:04:29 -0000
@@ -42,6 +42,38 @@
 #include "gedit-debug.h"
 
 void
+gedit_cmd_documents_move_one_window(GeditWindow *window, gint direction)
+{
+	GeditTab *tab;
+	GeditNotebook *notebook;
+	gint npages;
+	guint curpage;
+
+	gedit_debug (DEBUG_COMMANDS);
+
+	notebook = GEDIT_NOTEBOOK (_gedit_window_get_notebook (window));
+	if ((npages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook))) <= 1)
+		return;
+	curpage = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), (curpage + direction) % npages);
+}
+
+void
+gedit_cmd_documents_move_to_next_window (GtkAction   *action,
+					GeditWindow *window)
+{
+	gedit_cmd_documents_move_one_window(window, 1);
+}
+
+void
+gedit_cmd_documents_move_to_prev_window (GtkAction   *action,
+					GeditWindow *window)
+{
+	gedit_cmd_documents_move_one_window(window, -1);
+}
+
+void
 gedit_cmd_documents_move_to_new_window (GtkAction   *action,
 					GeditWindow *window)
 {
Index: gedit/gedit-commands.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands.h,v
retrieving revision 1.10.10.9
diff -u -r1.10.10.9 gedit-commands.h
--- gedit/gedit-commands.h	8 Dec 2005 22:27:57 -0000	1.10.10.9
+++ gedit/gedit-commands.h	23 Dec 2005 19:04:29 -0000
@@ -116,11 +116,18 @@
 
 void		gedit_cmd_documents_move_to_new_window	(GtkAction   *action,
 							 GeditWindow *window);
+void		gedit_cmd_documents_move_to_next_window	(GtkAction   *action,
+							 GeditWindow *window);
+void		gedit_cmd_documents_move_to_prev_window	(GtkAction   *action,
+							 GeditWindow *window);
 
 void		gedit_cmd_help_contents			(GtkAction   *action,
 							 GeditWindow *window);
 void		gedit_cmd_help_about			(GtkAction   *action,
 							 GeditWindow *window);
+
+void 		gedit_cmd_documents_move_one_window(GeditWindow *window, 
+							gint direction);
 
 /*
  * Non-exported function
Index: gedit/gedit-ui.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-ui.h,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 gedit-ui.h
--- gedit/gedit-ui.h	10 Jun 2005 13:51:44 -0000	1.1.2.11
+++ gedit/gedit-ui.h	23 Dec 2005 19:04:30 -0000
@@ -129,6 +129,11 @@
 	  N_("Close all open files"), G_CALLBACK (gedit_cmd_file_close_all) },
 	{ "DocumentsMoveToNewWindow", NULL, N_("_Move to New Window"), NULL,
 	  N_("Move the current document to a new window"), G_CALLBACK (gedit_cmd_documents_move_to_new_window) },
+
+	{ "DocumentsMoveToNext", NULL, N_("_Next Window"), "<control>Tab",
+	  N_("Move to the next document"), G_CALLBACK (gedit_cmd_documents_move_to_next_window) },
+	{ "DocumentsMoveToPrev", NULL, N_("_Previous Window"), "<control><shift>Tab",
+	  N_("Move to the next document"), G_CALLBACK (gedit_cmd_documents_move_to_prev_window) },
 };
 
 static const GtkToggleActionEntry gedit_toggle_menu_entries[] =
Index: gedit/gedit-ui.xml
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-ui.xml,v
retrieving revision 1.53.2.18
diff -u -r1.53.2.18 gedit-ui.xml
--- gedit/gedit-ui.xml	13 Oct 2005 14:30:17 -0000	1.53.2.18
+++ gedit/gedit-ui.xml	23 Dec 2005 19:04:30 -0000
@@ -110,8 +110,12 @@
       <menuitem action="FileCloseAll" />
       <separator/>       
       <menuitem action="DocumentsMoveToNewWindow"/>
-      <placeholder name="DocumentsListPlaceholder">
+	  <menuitem action="DocumentsMoveToNext"/>
+	  <menuitem action="DocumentsMoveToPrev"/>
         <separator/>
+	  <menuitem action="DocumentsMoveToNext"/>
+	  <menuitem action="DocumentsMoveToPrev"/>
+      <placeholder name="DocumentsListPlaceholder">
       </placeholder>
     </menu>
 
Index: gedit/gedit-window.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-window.c,v
retrieving revision 1.4.2.118
diff -u -r1.4.2.118 gedit-window.c
--- gedit/gedit-window.c	9 Dec 2005 08:36:13 -0000	1.4.2.118
+++ gedit/gedit-window.c	23 Dec 2005 19:04:32 -0000
@@ -40,6 +40,7 @@
 #include <gtksourceview/gtksourcelanguage.h>
 #include <gtksourceview/gtksourcelanguagesmanager.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <gdk/gdkkeysyms.h>
 
 #include "gedit-ui.h"
 #include "gedit-window.h"
@@ -216,6 +217,32 @@
 {
 	GtkWidget *focused_widget;
 	gboolean handled = FALSE;
+	gint direction = 0;
+	gint state = event->state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK);
+
+
+	switch (event->keyval)
+	{
+		case GDK_Tab:
+			if (state == (GDK_CONTROL_MASK|GDK_SHIFT_MASK))
+				direction = -1;
+			else
+				direction = 1;
+			break;
+		case GDK_ISO_Left_Tab:
+			if (state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK))
+				direction = -1;
+			break;
+		default:
+			break;
+	}
+
+	if (direction != 0)  
+	{
+		gedit_cmd_documents_move_one_window(GEDIT_WINDOW (widget), direction);
+		return TRUE;
+	}
+	
 
 	focused_widget = gtk_window_get_focus (GTK_WINDOW (widget));
 
@@ -2003,12 +2030,14 @@
 	GeditDocument *doc;
 	GtkTargetList *tl;
 	GtkAction *action;
+	gboolean enabled = FALSE;
 
 	gedit_debug (DEBUG_WINDOW);
 
 	g_return_if_fail ((window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION) == 0);
 	
 	++window->priv->num_tabs;
+	enabled = window->priv->num_tabs > 1;
 
 	/* Set sensitivity */
 	if (!gtk_action_group_get_sensitive (window->priv->action_group))
@@ -2017,8 +2046,13 @@
 
 	action = gtk_action_group_get_action (window->priv->action_group,
 					     "DocumentsMoveToNewWindow");
-	gtk_action_set_sensitive (action,
-				  window->priv->num_tabs > 1);
+	gtk_action_set_sensitive (action, enabled);
+	action = gtk_action_group_get_action (window->priv->action_group,
+					     "DocumentsMoveToNext");
+	gtk_action_set_sensitive (action, enabled);
+	action = gtk_action_group_get_action (window->priv->action_group,
+					     "DocumentsMoveToPrev");
+	gtk_action_set_sensitive (action, enabled);
 
 
 	view = gedit_tab_get_view (tab);


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