+/*******************************************************************************
+ * All accelerator-related stuff below
+ ******************************************************************************/
+
+typedef gboolean (*TildaWindowAccelCallback) (TildaWindow *self, gpointer data);
+
+/**
+ * This function updates the accelerator used to call the given function for this
+ * TildaWindow. If accel is NULL, then func will be removed (no accelerator will
+ * cause func to be called).
+ *
+ * Returns: TRUE on success, FALSE on failure
+ */
+static gboolean
+tilda_window_update_accelerator (TildaWindow *self, /* object */
+ gchar **accel_to_update, /* self->??? */
+ const gchar *accel, /* new accel */
+ const TildaWindowAccelCallback func)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+ debug_assert (accel_to_update != NULL);
+ debug_assert (func != NULL);
+
+ gboolean ret;
+ guint key;
+ GdkModifierType mod;
+ GClosure *closure;
+
+ /* Remove the old accelerator if there was a previous one set */
+ if (*accel_to_update != NULL)
+ {
+ /* This should always parse, we've done it before! */
+ gtk_accelerator_parse (*accel_to_update, &key, &mod);
+ ret = gtk_accel_group_disconnect_key (self->accel_group, key, mod);
+ }
+
+ /* If we are just removing the old accelerator, we're already done */
+ if (accel == NULL)
+ {
+ g_free (*accel_to_update);
+ *accel_to_update = NULL;
+ return TRUE;
+ }
+
+ /* Create the closure for this function */
+ closure = g_cclosure_new_swap (G_CALLBACK(func), self, NULL);
+
+ /* Try to parse the new accelerator */
+ gtk_accelerator_parse (accel, &key, &mod);
+
+ if (!gtk_accelerator_valid (key, mod))
+ {
+ g_warning (_("Failed to parse accelerator: %s\n"), accel);
+
+ /* Re-install the old accelerator */
+ if (*accel_to_update != NULL)
+ {
+ gtk_accelerator_parse (*accel_to_update, &key, &mod);
+ gtk_accel_group_connect (self->accel_group, key, mod, GTK_ACCEL_VISIBLE, closure);
+ }
+ return FALSE;
+ }
+
+ /* All good, g_free() the old accelerator, g_strdup() the new one */
+ g_free (*accel_to_update);
+ *accel_to_update = g_strdup(accel);
+
+ /* Add the new accelerator */
+ gtk_accel_group_connect (self->accel_group, key, mod, GTK_ACCEL_VISIBLE, closure);
+
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_quit_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ tilda_window_close (self);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_next_tab_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ gint num_pages;
+ gint current_page;
+
+ num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook));
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
+
+ /* Go to next page (with wrapping) */
+ if (num_pages != (current_page + num_pages))
+ gtk_notebook_next_page (GTK_NOTEBOOK(self->notebook));
+ else
+ gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), num_pages-1);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_prev_tab_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ gint num_pages;
+ gint current_page;
+
+ num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->notebook));
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
+
+ if ((num_pages-1) != current_page)
+ gtk_notebook_prev_page (GTK_NOTEBOOK(self->notebook));
+ else
+ gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), 0);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_add_term_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ tilda_window_add_terminal (self);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_remove_term_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ TildaTerminal *tt = tilda_window_find_current_terminal (self);
+
+ tilda_window_remove_terminal (self, tt->number);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_copy_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ TildaTerminal *tt = tilda_window_find_current_terminal (self);
+
+ vte_terminal_copy_clipboard (VTE_TERMINAL(tt->vte_term));
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_paste_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ TildaTerminal *tt = tilda_window_find_current_terminal (self);
+
+ vte_terminal_paste_clipboard (VTE_TERMINAL(tt->vte_term));
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_goto_generic (TildaWindow *self, guint number)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK(self->notebook), number-1);
+
+ /* Do not keep propagating */
+ return TRUE;
+}
+
+static gboolean
+tilda_window_accel_goto_1_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 1);
+}
+
+static gboolean
+tilda_window_accel_goto_2_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 2);
+}
+
+static gboolean
+tilda_window_accel_goto_3_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 3);
+}
+
+static gboolean
+tilda_window_accel_goto_4_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 4);
+}
+
+static gboolean
+tilda_window_accel_goto_5_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 5);
+}
+
+static gboolean
+tilda_window_accel_goto_6_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 6);
+}
+
+static gboolean
+tilda_window_accel_goto_7_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 7);
+}
+
+static gboolean
+tilda_window_accel_goto_8_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 8);
+}
+
+static gboolean
+tilda_window_accel_goto_9_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 9);
+}
+
+static gboolean
+tilda_window_accel_goto_10_cb (TildaWindow *self, gpointer data)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_WINDOW(self));
+
+ return tilda_window_accel_goto_generic (self, 10);
+}
+