[tepl/wip/edit-menu] Edit actions: implement win.tepl-select-all GAction



commit 1345af1cdbbc08f84abe7d45a04bb839cc2f2ded
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 11 16:27:23 2017 +0200

    Edit actions: implement win.tepl-select-all GAction

 docs/reference/Makefile.am             |   15 ++++---
 po/POTFILES.in                         |    1 +
 tepl/Makefile.am                       |   28 +++++++------
 tepl/tepl-application-window-actions.c |   67 ++++++++++++++++++++++++++++++++
 tepl/tepl-application-window-actions.h |   35 ++++++++++++++++
 tepl/tepl-application-window.c         |   20 +++++++++
 6 files changed, 146 insertions(+), 20 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index ab0c71a..a2d878d 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -23,13 +23,14 @@ CFILE_GLOB = $(top_srcdir)/tepl/*.c
 
 # Header files or dirs to ignore when scanning. Use base file/dir names
 # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
-IGNORE_HFILES =                                \
-       tepl.h                          \
-       tepl-buffer-input-stream.h      \
-       tepl-encoding-converter.h       \
-       tepl-encoding-private.h         \
-       tepl-file-content-loader.h      \
-       tepl-io-error-info-bar.h        \
+IGNORE_HFILES =                                        \
+       tepl.h                                  \
+       tepl-application-window-actions.h       \
+       tepl-buffer-input-stream.h              \
+       tepl-encoding-converter.h               \
+       tepl-encoding-private.h                 \
+       tepl-file-content-loader.h              \
+       tepl-io-error-info-bar.h                \
        tepl-progress-info-bar.h
 
 # Extra options to supply to gtkdoc-mkdb
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7ca7415..b8f60b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ tepl/tepl-action-info-store.c
 tepl/tepl-action-map.c
 tepl/tepl-application.c
 tepl/tepl-application-window.c
+tepl/tepl-application-window-actions.c
 tepl/tepl-buffer.c
 tepl/tepl-buffer-input-stream.c
 tepl/tepl-encoding.c
diff --git a/tepl/Makefile.am b/tepl/Makefile.am
index ebfa007..b35ca51 100644
--- a/tepl/Makefile.am
+++ b/tepl/Makefile.am
@@ -64,21 +64,23 @@ tepl_public_c_files =                               \
        tepl-utils.c                            \
        tepl-view.c
 
-tepl_private_headers =                 \
-       gconstructor.h                  \
-       tepl-buffer-input-stream.h      \
-       tepl-encoding-converter.h       \
-       tepl-encoding-private.h         \
-       tepl-file-content-loader.h      \
-       tepl-io-error-info-bar.h        \
+tepl_private_headers =                         \
+       gconstructor.h                          \
+       tepl-application-window-actions.h       \
+       tepl-buffer-input-stream.h              \
+       tepl-encoding-converter.h               \
+       tepl-encoding-private.h                 \
+       tepl-file-content-loader.h              \
+       tepl-io-error-info-bar.h                \
        tepl-progress-info-bar.h
 
-tepl_private_c_files =                 \
-       tepl-buffer-input-stream.c      \
-       tepl-encoding-converter.c       \
-       tepl-file-content-loader.c      \
-       tepl-init.c                     \
-       tepl-io-error-info-bar.c        \
+tepl_private_c_files =                         \
+       tepl-application-window-actions.c       \
+       tepl-buffer-input-stream.c              \
+       tepl-encoding-converter.c               \
+       tepl-file-content-loader.c              \
+       tepl-init.c                             \
+       tepl-io-error-info-bar.c                \
        tepl-progress-info-bar.c
 
 tepl_built_public_headers =            \
diff --git a/tepl/tepl-application-window-actions.c b/tepl/tepl-application-window-actions.c
new file mode 100644
index 0000000..b4fa79d
--- /dev/null
+++ b/tepl/tepl-application-window-actions.c
@@ -0,0 +1,67 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tepl-application-window-actions.h"
+#include "tepl-application-window.h"
+#include "tepl-action-map.h"
+#include "tepl-tab-group.h"
+#include "tepl-view.h"
+
+/* GAction implementations for TeplApplicationWindow. This is implemented in a
+ * separate file to not clutter TeplApplicationWindow.
+ */
+
+static void
+select_all_cb (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+       TeplView *active_view;
+
+       active_view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+
+       if (active_view != NULL)
+       {
+               tepl_view_select_all (active_view);
+       }
+}
+
+void
+_tepl_application_window_add_actions (TeplApplicationWindow *tepl_window)
+{
+       GtkApplicationWindow *gtk_window;
+
+       /* The actions need to be namespaced, to not conflict with the
+        * application or other libraries.
+        *
+        * Do not forget to document each action in the TeplApplicationWindow
+        * class description.
+        */
+       const GActionEntry entries[] = {
+               { "tepl-select-all", select_all_cb },
+       };
+
+       gtk_window = tepl_application_window_get_application_window (tepl_window);
+
+       tepl_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
+                                                      entries,
+                                                      G_N_ELEMENTS (entries),
+                                                      tepl_window);
+}
diff --git a/tepl/tepl-application-window-actions.h b/tepl/tepl-application-window-actions.h
new file mode 100644
index 0000000..b699b7f
--- /dev/null
+++ b/tepl/tepl-application-window-actions.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEPL_APPLICATION_WINDOW_ACTIONS_H
+#define TEPL_APPLICATION_WINDOW_ACTIONS_H
+
+#include <glib.h>
+#include "tepl-types.h"
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+void   _tepl_application_window_add_actions    (TeplApplicationWindow *tepl_window);
+
+G_END_DECLS
+
+#endif /* TEPL_APPLICATION_WINDOW_ACTIONS_H */
+
+/* ex:set ts=8 noet: */
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 763dced..1ae9d91 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "tepl-application-window.h"
 #include <glib/gi18n-lib.h>
+#include "tepl-application-window-actions.h"
 #include "tepl-application.h"
 #include "tepl-action-info.h"
 #include "tepl-action-info-central-store.h"
@@ -42,6 +43,11 @@
  * without subclassing it, because several libraries might want to extend
  * #GtkApplicationWindow and an application needs to be able to use all those
  * extensions at the same time.
+ *
+ * # GActions
+ *
+ * This class adds the following #GAction's to the #GtkApplicationWindow:
+ * - `"win.tepl-select-all"`: calls tepl_view_select_all() on the active view.
  */
 
 struct _TeplApplicationWindowPrivate
@@ -125,6 +131,19 @@ tepl_application_window_set_property (GObject      *object,
 }
 
 static void
+tepl_application_window_constructed (GObject *object)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (object);
+
+       if (G_OBJECT_CLASS (tepl_application_window_parent_class)->constructed != NULL)
+       {
+               G_OBJECT_CLASS (tepl_application_window_parent_class)->constructed (object);
+       }
+
+       _tepl_application_window_add_actions (tepl_window);
+}
+
+static void
 tepl_application_window_dispose (GObject *object)
 {
        TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (object);
@@ -143,6 +162,7 @@ tepl_application_window_class_init (TeplApplicationWindowClass *klass)
 
        object_class->get_property = tepl_application_window_get_property;
        object_class->set_property = tepl_application_window_set_property;
+       object_class->constructed = tepl_application_window_constructed;
        object_class->dispose = tepl_application_window_dispose;
 
        /**


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