[libmetaterm] libmetaterm: Add basic menubar
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libmetaterm] libmetaterm: Add basic menubar
- Date: Fri, 3 Jun 2011 02:35:11 +0000 (UTC)
commit 13ebf4e7e96690348db60c58b9c5d06282d97fb6
Author: Colin Walters <walters verbum org>
Date: Thu Jun 2 22:35:51 2011 -0400
libmetaterm: Add basic menubar
libmetaterm/libmetaterm.c | 158 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 155 insertions(+), 3 deletions(-)
---
diff --git a/libmetaterm/libmetaterm.c b/libmetaterm/libmetaterm.c
index 53f860b..438acc4 100644
--- a/libmetaterm/libmetaterm.c
+++ b/libmetaterm/libmetaterm.c
@@ -32,27 +32,179 @@ enum
struct _MetatermAppPrivate
{
+ GtkActionGroup *actions;
GtkWindow *window;
+ GtkUIManager *ui;
GtkNotebook *notebook;
- VteTerminal *term;
+ VteTerminal *active_term;
gchar *title;
};
+static void metaterm_app_create_new_tab (MetatermApp *self);
+
G_DEFINE_TYPE (MetatermApp, metaterm_app, GTK_TYPE_APPLICATION);
static void
+file_new_tab_callback (GtkAction *action,
+ gpointer datap)
+{
+ MetatermApp *app = METATERM_APP (datap);
+
+ metaterm_app_create_new_tab (app);
+}
+
+static void
+file_close_tab_callback (GtkAction *action,
+ gpointer datap)
+{
+ MetatermApp *app = METATERM_APP (datap);
+
+ gtk_notebook_remove_page (app->priv->notebook,
+ gtk_notebook_get_current_page (app->priv->notebook));
+}
+
+static void
+edit_copy_callback (GtkAction *action,
+ gpointer datap)
+{
+ MetatermApp *app = datap;
+
+ vte_terminal_copy_clipboard (app->priv->active_term);
+}
+
+static void
+clipboard_targets_received_cb (GtkClipboard *clipboard,
+ GdkAtom *targets,
+ int n_targets,
+ gpointer data)
+{
+ VteTerminal *term = data;
+
+ if (targets)
+ vte_terminal_paste_clipboard (term);
+
+ g_object_unref (term);
+}
+
+static void
+edit_paste_callback (GtkAction *action,
+ gpointer datap)
+{
+ MetatermApp *app = datap;
+ GtkClipboard *clipboard;
+
+ if (!app->priv->active_term)
+ return;
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (app->priv->window), GDK_SELECTION_CLIPBOARD);
+
+ gtk_clipboard_request_targets (clipboard,
+ (GtkClipboardTargetsReceivedFunc) clipboard_targets_received_cb,
+ g_object_ref (app->priv->active_term));
+}
+
+static void
+on_switch_page (GtkNotebook *notebook,
+ GtkWidget *widget,
+ guint cur_page,
+ gpointer datap)
+{
+ MetatermApp *app = datap;
+
+ app->priv->active_term = (VteTerminal*)widget;
+}
+
+static void
+file_quit_callback (GtkAction *action,
+ gpointer datap)
+{
+ MetatermApp *app = datap;
+
+ gtk_widget_destroy (GTK_WIDGET (app->priv->window));
+}
+
+static void
metaterm_app_base_init (MetatermApp *self)
{
+ GtkAccelGroup *accel_group;
+ GError *error = NULL;
+ GtkWidget *menubar;
+ GtkWidget *main_vbox;
+ const GtkActionEntry menu_entries[] =
+ {
+ /* Toplevel */
+ { "File", NULL, N_("File") },
+ { "Edit", NULL, N_("Edit") },
+
+ /* File menu */
+ { "FileNewTab", GTK_STOCK_NEW, N_("Open Tab"), "<shift><control>T",
+ NULL,
+ G_CALLBACK (file_new_tab_callback) },
+ { "FileCloseTab", GTK_STOCK_CLOSE, N_("Close Tab"), "<shift><control>W",
+ NULL,
+ G_CALLBACK (file_close_tab_callback) },
+ { "FileQuit", GTK_STOCK_QUIT, N_("Quit"), "<shift><control>Q",
+ NULL,
+ G_CALLBACK (file_quit_callback) },
+
+ /* Edit menu */
+ { "EditCopy", GTK_STOCK_COPY, NULL, "<shift><control>C",
+ NULL,
+ G_CALLBACK (edit_copy_callback) },
+ { "EditPaste", GTK_STOCK_PASTE, NULL, "<shift><control>V",
+ NULL,
+ G_CALLBACK (edit_paste_callback) },
+ };
+
if (self->priv->window)
return;
self->priv->window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
if (self->priv->title)
gtk_window_set_title (self->priv->window, self->priv->title);
+
+ main_vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (self->priv->window), main_vbox);
+ gtk_widget_show (main_vbox);
+
+ self->priv->ui = gtk_ui_manager_new ();
+ accel_group = gtk_ui_manager_get_accel_group (self->priv->ui);
+ gtk_window_add_accel_group (GTK_WINDOW (self->priv->window), accel_group);
+
+ self->priv->actions = gtk_action_group_new ("Main");
+ gtk_action_group_add_actions (self->priv->actions, menu_entries,
+ G_N_ELEMENTS (menu_entries), self);
+
+ gtk_ui_manager_insert_action_group (self->priv->ui, self->priv->actions, 0);
+ g_object_unref (self->priv->actions);
+
+ gtk_ui_manager_add_ui_from_string (self->priv->ui, "<ui>"
+" <menubar>"
+" <menu action=\"File\">"
+" <menuitem action=\"FileNewTab\" />"
+" <separator />"
+" <menuitem action=\"FileCloseTab\" />"
+" <menuitem action=\"FileQuit\" />"
+" </menu>"
+" <menu action=\"Edit\">"
+" <menuitem action=\"EditCopy\" />"
+" <menuitem action=\"EditPaste\" />"
+" </menu>"
+" </menubar>"
+"</ui>"
+ , -1, &error);
+ g_assert_no_error (error);
+
+ menubar = gtk_ui_manager_get_widget (self->priv->ui, "/menubar");
+ gtk_box_pack_start (GTK_BOX (main_vbox),
+ menubar,
+ FALSE, FALSE, 0);
+
gtk_window_set_default_size (GTK_WINDOW (self->priv->window), 640, 480);
self->priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
- gtk_container_add (GTK_CONTAINER (self->priv->window),
- GTK_WIDGET (self->priv->notebook));
+ g_signal_connect (self->priv->notebook, "switch-page",
+ G_CALLBACK (on_switch_page), self);
+ gtk_box_pack_end (GTK_BOX (main_vbox), GTK_WIDGET (self->priv->notebook), TRUE, TRUE, 0);
gtk_application_add_window (GTK_APPLICATION (self), self->priv->window);
gtk_widget_show_all (GTK_WIDGET (self->priv->window));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]