[amtk] shortcuts: add some convenience functions



commit 08bb0a84cfeb631417c37e09e7b8bfe2a66cf3eb
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Apr 14 13:03:26 2018 +0200

    shortcuts: add some convenience functions
    
    And use them in test-headerbar.c.

 amtk/Makefile.am                     |    2 +
 amtk/amtk-shortcuts.c                |   91 ++++++++++++++++++++++++++++++++++
 amtk/amtk-shortcuts.h                |   39 ++++++++++++++
 amtk/amtk.h                          |    1 +
 docs/reference/amtk-5.0-sections.txt |    7 +++
 docs/reference/amtk-docs.xml.in      |    1 +
 po/POTFILES.in                       |    1 +
 tests/test-headerbar.c               |   15 +-----
 8 files changed, 145 insertions(+), 12 deletions(-)
---
diff --git a/amtk/Makefile.am b/amtk/Makefile.am
index fa3b3c6..6f22bd1 100644
--- a/amtk/Makefile.am
+++ b/amtk/Makefile.am
@@ -22,6 +22,7 @@ amtk_public_headers =                         \
        amtk-init.h                             \
        amtk-menu-item.h                        \
        amtk-menu-shell.h                       \
+       amtk-shortcuts.h                        \
        amtk-types.h                            \
        amtk-utils.h
 
@@ -36,6 +37,7 @@ amtk_public_c_files =                         \
        amtk-init.c                             \
        amtk-menu-item.c                        \
        amtk-menu-shell.c                       \
+       amtk-shortcuts.c                        \
        amtk-utils.c
 
 amtk_built_public_headers =    \
diff --git a/amtk/amtk-shortcuts.c b/amtk/amtk-shortcuts.c
new file mode 100644
index 0000000..c6f6b67
--- /dev/null
+++ b/amtk/amtk-shortcuts.c
@@ -0,0 +1,91 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2018 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Amtk 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.
+ *
+ * Amtk 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 "amtk-shortcuts.h"
+
+/**
+ * SECTION:amtk-shortcuts
+ * @Short_description: GtkShortcuts convenience functions
+ * @Title: AmtkShortcuts
+ *
+ * Convenience functions to create a #GtkShortcutsWindow. At the time of writing
+ * the GtkShortcuts* classes don't provide any function.
+ *
+ * You need to also use gtk_container_add(), and g_object_set() to set other
+ * properties.
+ */
+
+/**
+ * amtk_shortcuts_window_new:
+ *
+ * Creates a new #GtkShortcutsWindow. It is on purpose that the return type is
+ * #GtkShortcutsWindow, not #GtkWidget or something else, so in C when you
+ * declare the variable as #GtkShortcutsWindow it's easier to find it later
+ * (searching "GtkShortcuts" will return something in your codebase).
+ *
+ * Returns: (transfer floating): a new #GtkShortcutsWindow.
+ * Since: 5.0
+ */
+GtkShortcutsWindow *
+amtk_shortcuts_window_new (void)
+{
+       return g_object_new (GTK_TYPE_SHORTCUTS_WINDOW, NULL);
+}
+
+/**
+ * amtk_shortcuts_section_new:
+ * @title: the #GtkShortcutsSection:title.
+ *
+ * Returns: (transfer floating): a new #GtkShortcutsSection.
+ * Since: 5.0
+ */
+GtkContainer *
+amtk_shortcuts_section_new (const gchar *title)
+{
+       GtkContainer *section;
+
+       section = g_object_new (GTK_TYPE_SHORTCUTS_SECTION,
+                               "title", title,
+                               NULL);
+
+       gtk_widget_show (GTK_WIDGET (section));
+
+       return section;
+}
+
+/**
+ * amtk_shortcuts_group_new:
+ * @title: the #GtkShortcutsGroup:title.
+ *
+ * Returns: (transfer floating): a new #GtkShortcutsGroup.
+ * Since: 5.0
+ */
+GtkContainer *
+amtk_shortcuts_group_new (const gchar *title)
+{
+       GtkContainer *group;
+
+       group = g_object_new (GTK_TYPE_SHORTCUTS_GROUP,
+                             "title", title,
+                             NULL);
+
+       gtk_widget_show (GTK_WIDGET (group));
+
+       return group;
+}
diff --git a/amtk/amtk-shortcuts.h b/amtk/amtk-shortcuts.h
new file mode 100644
index 0000000..2956928
--- /dev/null
+++ b/amtk/amtk-shortcuts.h
@@ -0,0 +1,39 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2018 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Amtk 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.
+ *
+ * Amtk 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 AMTK_SHORTCUTS_H
+#define AMTK_SHORTCUTS_H
+
+#if !defined (AMTK_H_INSIDE) && !defined (AMTK_COMPILATION)
+#error "Only <amtk/amtk.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkShortcutsWindow *   amtk_shortcuts_window_new       (void);
+
+GtkContainer *         amtk_shortcuts_section_new      (const gchar *title);
+
+GtkContainer *         amtk_shortcuts_group_new        (const gchar *title);
+
+G_END_DECLS
+
+#endif /* AMTK_SHORTCUTS_H */
diff --git a/amtk/amtk.h b/amtk/amtk.h
index efbd656..bf7d5ea 100644
--- a/amtk/amtk.h
+++ b/amtk/amtk.h
@@ -35,6 +35,7 @@
 #include <amtk/amtk-init.h>
 #include <amtk/amtk-menu-item.h>
 #include <amtk/amtk-menu-shell.h>
+#include <amtk/amtk-shortcuts.h>
 #include <amtk/amtk-utils.h>
 
 #undef AMTK_H_INSIDE
diff --git a/docs/reference/amtk-5.0-sections.txt b/docs/reference/amtk-5.0-sections.txt
index df1ae10..de3fee2 100644
--- a/docs/reference/amtk-5.0-sections.txt
+++ b/docs/reference/amtk-5.0-sections.txt
@@ -167,6 +167,13 @@ amtk_menu_shell_get_type
 </SECTION>
 
 <SECTION>
+<FILE>amtk-shortcuts</FILE>
+amtk_shortcuts_window_new
+amtk_shortcuts_section_new
+amtk_shortcuts_group_new
+</SECTION>
+
+<SECTION>
 <FILE>amtk-utils</FILE>
 amtk_utils_remove_mnemonic
 amtk_utils_recent_chooser_menu_get_item_uri
diff --git a/docs/reference/amtk-docs.xml.in b/docs/reference/amtk-docs.xml.in
index 13f10ef..74362de 100644
--- a/docs/reference/amtk-docs.xml.in
+++ b/docs/reference/amtk-docs.xml.in
@@ -26,6 +26,7 @@
     <xi:include href="xml/amtk-gmenu.xml"/>
     <xi:include href="xml/amtk-menu-item.xml"/>
     <xi:include href="xml/amtk-menu-shell.xml"/>
+    <xi:include href="xml/amtk-shortcuts.xml"/>
     <xi:include href="xml/amtk-utils.xml"/>
   </part>
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 62e5230..6ebaee2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,4 +9,5 @@ amtk/amtk-gmenu.c
 amtk/amtk-init.c
 amtk/amtk-menu-item.c
 amtk/amtk-menu-shell.c
+amtk/amtk-shortcuts.c
 amtk/amtk-utils.c
diff --git a/tests/test-headerbar.c b/tests/test-headerbar.c
index 04f0714..407304c 100644
--- a/tests/test-headerbar.c
+++ b/tests/test-headerbar.c
@@ -70,15 +70,8 @@ shortcuts_window_activate_cb (GSimpleAction *action,
        GtkContainer *group;
        AmtkFactory *factory;
 
-       /* TODO Add AmtkFactory function, and maybe some convenience functions
-        * too.
-        */
-
        /* Create group */
-       group = g_object_new (GTK_TYPE_SHORTCUTS_GROUP,
-                             "visible", TRUE,
-                             "title", "General",
-                             NULL);
+       group = amtk_shortcuts_group_new ("General");
 
        factory = amtk_factory_new (NULL);
        amtk_factory_set_default_flags (factory, AMTK_FACTORY_IGNORE_GACTION);
@@ -87,12 +80,10 @@ shortcuts_window_activate_cb (GSimpleAction *action,
        g_object_unref (factory);
 
        /* Create section and window */
-       section = g_object_new (GTK_TYPE_SHORTCUTS_SECTION,
-                               "visible", TRUE,
-                               NULL);
+       section = amtk_shortcuts_section_new (NULL);
        gtk_container_add (section, GTK_WIDGET (group));
 
-       window = g_object_new (GTK_TYPE_SHORTCUTS_WINDOW, NULL);
+       window = amtk_shortcuts_window_new ();
        gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (section));
 
        gtk_widget_show_all (GTK_WIDGET (window));


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