[amtk] gmenu: add some convenience functions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [amtk] gmenu: add some convenience functions
- Date: Fri, 13 Apr 2018 07:24:09 +0000 (UTC)
commit 719e0062ffdc22e6897b89a4314d3a5252001053
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Apr 12 20:12:30 2018 +0200
gmenu: add some convenience functions
amtk/Makefile.am | 2 +
amtk/amtk-gmenu.c | 72 ++++++++++++++++++++++++++++++++++
amtk/amtk-gmenu.h | 40 +++++++++++++++++++
amtk/amtk.h | 3 +-
docs/reference/amtk-5.0-sections.txt | 6 +++
docs/reference/amtk-docs.xml.in | 1 +
po/POTFILES.in | 1 +
tests/test-headerbar.c | 19 ++-------
8 files changed, 129 insertions(+), 15 deletions(-)
---
diff --git a/amtk/Makefile.am b/amtk/Makefile.am
index aed1998..fa3b3c6 100644
--- a/amtk/Makefile.am
+++ b/amtk/Makefile.am
@@ -18,6 +18,7 @@ amtk_public_headers = \
amtk-action-map.h \
amtk-application-window.h \
amtk-factory.h \
+ amtk-gmenu.h \
amtk-init.h \
amtk-menu-item.h \
amtk-menu-shell.h \
@@ -31,6 +32,7 @@ amtk_public_c_files = \
amtk-action-map.c \
amtk-application-window.c \
amtk-factory.c \
+ amtk-gmenu.c \
amtk-init.c \
amtk-menu-item.c \
amtk-menu-shell.c \
diff --git a/amtk/amtk-gmenu.c b/amtk/amtk-gmenu.c
new file mode 100644
index 0000000..9b5d02f
--- /dev/null
+++ b/amtk/amtk-gmenu.c
@@ -0,0 +1,72 @@
+/*
+ * 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-gmenu.h"
+
+/**
+ * SECTION:amtk-gmenu
+ * @Short_description: #GMenu convenience functions
+ * @Title: AmtkGmenu
+ *
+ * #GMenu convenience functions.
+ */
+
+/**
+ * amtk_gmenu_append_item:
+ * @menu: a #GMenu.
+ * @item: (transfer full): a #GMenuItem to append.
+ *
+ * Like g_menu_append_item() but with (transfer full) for the @item parameter.
+ *
+ * Since: 5.0
+ */
+void
+amtk_gmenu_append_item (GMenu *menu,
+ GMenuItem *item)
+{
+ g_return_if_fail (G_IS_MENU (menu));
+ g_return_if_fail (G_IS_MENU_ITEM (item));
+
+ g_menu_append_item (menu, item);
+ g_object_unref (item);
+}
+
+/**
+ * amtk_gmenu_append_section:
+ * @menu: a #GMenu.
+ * @label: (nullable): the section label, or %NULL.
+ * @section: (transfer full): a #GMenu with the items of the section.
+ *
+ * Like g_menu_append_section() but with (transfer full) and a different type
+ * for the @section parameter, and calls g_menu_freeze() on @section.
+ *
+ * Since: 5.0
+ */
+void
+amtk_gmenu_append_section (GMenu *menu,
+ const gchar *label,
+ GMenu *section)
+{
+ g_return_if_fail (G_IS_MENU (menu));
+ g_return_if_fail (G_IS_MENU (section));
+
+ g_menu_freeze (section);
+ g_menu_append_section (menu, label, G_MENU_MODEL (section));
+ g_object_unref (section);
+}
diff --git a/amtk/amtk-gmenu.h b/amtk/amtk-gmenu.h
new file mode 100644
index 0000000..84dc487
--- /dev/null
+++ b/amtk/amtk-gmenu.h
@@ -0,0 +1,40 @@
+/*
+ * 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_GMENU_H
+#define AMTK_GMENU_H
+
+#if !defined (AMTK_H_INSIDE) && !defined (AMTK_COMPILATION)
+#error "Only <amtk/amtk.h> can be included directly."
+#endif
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void amtk_gmenu_append_item (GMenu *menu,
+ GMenuItem *item);
+
+void amtk_gmenu_append_section (GMenu *menu,
+ const gchar *label,
+ GMenu *section);
+
+G_END_DECLS
+
+#endif /* AMTK_GMENU_H */
diff --git a/amtk/amtk.h b/amtk/amtk.h
index 03754cc..efbd656 100644
--- a/amtk/amtk.h
+++ b/amtk/amtk.h
@@ -1,7 +1,7 @@
/*
* This file is part of Amtk - Actions, Menus and Toolbars Kit
*
- * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2017, 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
@@ -31,6 +31,7 @@
#include <amtk/amtk-action-map.h>
#include <amtk/amtk-application-window.h>
#include <amtk/amtk-factory.h>
+#include <amtk/amtk-gmenu.h>
#include <amtk/amtk-init.h>
#include <amtk/amtk-menu-item.h>
#include <amtk/amtk-menu-shell.h>
diff --git a/docs/reference/amtk-5.0-sections.txt b/docs/reference/amtk-5.0-sections.txt
index 745f8f2..229ea89 100644
--- a/docs/reference/amtk-5.0-sections.txt
+++ b/docs/reference/amtk-5.0-sections.txt
@@ -134,6 +134,12 @@ amtk_factory_flags_get_type
</SECTION>
<SECTION>
+<FILE>amtk-gmenu</FILE>
+amtk_gmenu_append_item
+amtk_gmenu_append_section
+</SECTION>
+
+<SECTION>
<FILE>amtk-menu-item</FILE>
amtk_menu_item_get_long_description
amtk_menu_item_set_long_description
diff --git a/docs/reference/amtk-docs.xml.in b/docs/reference/amtk-docs.xml.in
index b03ffe2..13f10ef 100644
--- a/docs/reference/amtk-docs.xml.in
+++ b/docs/reference/amtk-docs.xml.in
@@ -23,6 +23,7 @@
<xi:include href="xml/amtk-action-info-central-store.xml"/>
<xi:include href="xml/amtk-action-map.xml"/>
<xi:include href="xml/amtk-factory.xml"/>
+ <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-utils.xml"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c8f9ce9..62e5230 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ amtk/amtk-action-info-store.c
amtk/amtk-action-map.c
amtk/amtk-application-window.c
amtk/amtk-factory.c
+amtk/amtk-gmenu.c
amtk/amtk-init.c
amtk/amtk-menu-item.c
amtk/amtk-menu-shell.c
diff --git a/tests/test-headerbar.c b/tests/test-headerbar.c
index 09af4c2..bf83a75 100644
--- a/tests/test-headerbar.c
+++ b/tests/test-headerbar.c
@@ -83,25 +83,16 @@ add_win_actions (GtkApplicationWindow *window,
static GMenuModel *
create_window_menu (void)
{
- AmtkFactory *factory;
GMenu *menu;
- GMenuItem *item;
+ AmtkFactory *factory;
menu = g_menu_new ();
- factory = amtk_factory_new_with_default_application ();
-
- /* TODO create a utility function to append+unref a GMenuItem to a
- * GMenu.
- */
- item = amtk_factory_create_gmenu_item (factory, "win.show-side-panel");
- g_menu_append_item (menu, item);
- g_object_unref (item);
-
- item = amtk_factory_create_gmenu_item (factory, "win.print");
- g_menu_append_item (menu, item);
- g_object_unref (item);
+ factory = amtk_factory_new_with_default_application ();
+ amtk_gmenu_append_item (menu, amtk_factory_create_gmenu_item (factory, "win.show-side-panel"));
+ amtk_gmenu_append_item (menu, amtk_factory_create_gmenu_item (factory, "win.print"));
g_object_unref (factory);
+
g_menu_freeze (menu);
return G_MENU_MODEL (menu);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]