From e2260edf15b9d483fa8b68b8e77824aa160f651e Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Mon, 8 Jan 2007 20:55:09 -0600 Subject: [PATCH] Added Alt-Number shortcuts to switch tabs; made moo_edit_window_num_docs() return signed int --- moo/mooedit/mooeditwindow.c | 75 ++++++++++++++++++++------ moo/mooedit/mooeditwindow.h | 2 +- moo/moopython/pygtk/mooedit-pygtk.defs | 2 +- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index 66a36ab0..caef7597 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -220,6 +220,8 @@ static void action_close_tab (MooEditWindow *window); static void action_close_all (MooEditWindow *window); static void action_previous_tab (MooEditWindow *window); static void action_next_tab (MooEditWindow *window); +static void action_switch_to_tab (MooEditWindow *window, + guint n); #ifdef ENABLE_BOOKMARKS static void action_toggle_bookmark (MooEditWindow *window); static void action_next_bookmark (MooEditWindow *window); @@ -649,6 +651,23 @@ moo_edit_window_class_init (MooEditWindowClass *klass) "condition::visible", "has-stop-clients", NULL); + for (i = 1; i < 10; ++i) + { + char *action_id = g_strdup_printf ("SwitchToTab%u", i); + char *accel = g_strdup_printf ("%u", i); + _moo_window_class_new_action_callback (window_class, action_id, NULL, + G_CALLBACK (action_switch_to_tab), + _moo_marshal_VOID__UINT, + G_TYPE_NONE, 1, + G_TYPE_UINT, i - 1, + "accel", accel, + "connect-accel", TRUE, + "visible", FALSE, + NULL); + g_free (accel); + g_free (action_id); + } + #ifdef ENABLE_BOOKMARKS for (i = 1; i < 10; ++i) { @@ -1213,32 +1232,56 @@ action_close_all (MooEditWindow *window) static void -action_previous_tab (MooEditWindow *window) +switch_to_tab (MooEditWindow *window, + int n) { MooEdit *doc; - int n = moo_notebook_get_current_page (window->priv->notebook); - if (n > 0) - moo_notebook_set_current_page (window->priv->notebook, n - 1); - else - moo_notebook_set_current_page (window->priv->notebook, -1); - doc = moo_edit_window_get_active_doc (window); - if (doc) + + if (n < 0) + n = moo_edit_window_num_docs (window) - 1; + + if (n < 0 || n >= moo_edit_window_num_docs (window)) + return; + + moo_notebook_set_current_page (window->priv->notebook, n); + + if ((doc = moo_edit_window_get_active_doc (window))) gtk_widget_grab_focus (GTK_WIDGET (doc)); } +static void +action_previous_tab (MooEditWindow *window) +{ + int n; + + n = moo_notebook_get_current_page (window->priv->notebook); + + if (n > 0) + switch_to_tab (window, n - 1); + else + switch_to_tab (window, -1); +} + static void action_next_tab (MooEditWindow *window) { - MooEdit *doc; - int n = moo_notebook_get_current_page (window->priv->notebook); + int n; + + n = moo_notebook_get_current_page (window->priv->notebook); + if (n < moo_notebook_get_n_pages (window->priv->notebook) - 1) - moo_notebook_set_current_page (window->priv->notebook, n + 1); + switch_to_tab (window, n + 1); else - moo_notebook_set_current_page (window->priv->notebook, 0); - doc = moo_edit_window_get_active_doc (window); - if (doc) - gtk_widget_grab_focus (GTK_WIDGET (doc)); + switch_to_tab (window, 0); +} + + +static void +action_switch_to_tab (MooEditWindow *window, + guint n) +{ + switch_to_tab (window, n); } @@ -1993,7 +2036,7 @@ moo_edit_window_list_docs (MooEditWindow *window) } -guint +int moo_edit_window_num_docs (MooEditWindow *window) { g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), 0); diff --git a/moo/mooedit/mooeditwindow.h b/moo/mooedit/mooeditwindow.h index ce8b6c31..4457639d 100644 --- a/moo/mooedit/mooeditwindow.h +++ b/moo/mooedit/mooeditwindow.h @@ -86,7 +86,7 @@ MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window, guint n); /* list must be freed, elements must not be unref'ed */ GSList *moo_edit_window_list_docs (MooEditWindow *window); -guint moo_edit_window_num_docs (MooEditWindow *window); +int moo_edit_window_num_docs (MooEditWindow *window); void moo_edit_window_set_title_prefix (MooEditWindow *window, const char *prefix); diff --git a/moo/moopython/pygtk/mooedit-pygtk.defs b/moo/moopython/pygtk/mooedit-pygtk.defs index 0b2c49e5..aac4312e 100644 --- a/moo/moopython/pygtk/mooedit-pygtk.defs +++ b/moo/moopython/pygtk/mooedit-pygtk.defs @@ -468,7 +468,7 @@ (define-method num_docs (of-object "MooEditWindow") (c-name "moo_edit_window_num_docs") - (return-type "guint") + (return-type "int") ) (define-method close_all