[tepl] ApplicationWindow: implement win.tepl-new-file GAction



commit 1d6ca38677b6c56a559a187f70769d760bc62c52
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jul 23 12:42:24 2017 +0200

    ApplicationWindow: implement win.tepl-new-file GAction
    
    With the corresponding AmtkActionInfo. Isn't life beautiful?

 tepl/tepl-application-window.c |   24 ++++++++++++++++++++++++
 tepl/tepl-application.c        |   12 ++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 255ecbd..175223c 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -20,6 +20,7 @@
 #include "tepl-application-window.h"
 #include <amtk/amtk.h>
 #include "tepl-tab-group.h"
+#include "tepl-tab.h"
 #include "tepl-view.h"
 
 /**
@@ -43,6 +44,11 @@
  * Corresponding #AmtkActionInfo's are available with
  * tepl_application_get_tepl_action_info_store().
  *
+ * ## For the File menu
+ *
+ * - `"win.tepl-new-file"`: creates a new #TeplTab, appends it with
+ *   tepl_tab_group_append_tab() and set it as the active tab.
+ *
  * ## For the Edit menu
  *
  * The following actions require the %AMTK_FACTORY_IGNORE_ACCELS_FOR_APP flag,
@@ -85,6 +91,20 @@ G_DEFINE_TYPE_WITH_CODE (TeplApplicationWindow,
                                                tepl_tab_group_interface_init))
 
 static void
+new_file_cb (GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplTab *new_tab;
+
+       /* TODO: implement an Abstract Factory to create the TeplTab. */
+       new_tab = tepl_tab_new ();
+       gtk_widget_show (GTK_WIDGET (new_tab));
+       tepl_tab_group_append_tab (TEPL_TAB_GROUP (tepl_window), new_tab, TRUE);
+}
+
+static void
 cut_cb (GSimpleAction *action,
        GVariant      *parameter,
        gpointer       user_data)
@@ -175,6 +195,10 @@ add_actions (TeplApplicationWindow *tepl_window)
         * in tepl-application.c.
         */
        const GActionEntry entries[] = {
+               /* File menu */
+               { "tepl-new-file", new_file_cb },
+
+               /* Edit menu */
                { "tepl-cut", cut_cb },
                { "tepl-copy", copy_cb },
                { "tepl-paste", paste_cb },
diff --git a/tepl/tepl-application.c b/tepl/tepl-application.c
index 51fd1ec..5d0a2e7 100644
--- a/tepl/tepl-application.c
+++ b/tepl/tepl-application.c
@@ -61,6 +61,18 @@ init_tepl_action_info_store (TeplApplication *tepl_app)
        {
                /* action, icon, label, accel, tooltip */
 
+               /* File menu */
+
+               // Why "file" and not "document"? "Document" is not the best
+               // word because the action is not always to create a new
+               // document. For example a LaTeX document can be composed of
+               // several _files_. Or for source code we do not really create a
+               // new "document".
+               { "win.tepl-new-file", "document-new", N_("_New"), "<Control>n",
+                 N_("New file") },
+
+               /* Edit menu */
+
                { "win.tepl-cut", "edit-cut", N_("Cu_t"), "<Control>x",
                  N_("Cut the selection") },
 


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