[glibmm] Gio::MenuModel: Make MenuAttribute and MenuLink enum class
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::MenuModel: Make MenuAttribute and MenuLink enum class
- Date: Sun, 19 Jul 2020 14:49:00 +0000 (UTC)
commit 04a84d7ddcd8e25fe720d467f2dfbaeda183be6f
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Sun Jul 19 16:43:38 2020 +0200
Gio::MenuModel: Make MenuAttribute and MenuLink enum class
Change enum Gio::MenuAttribute to Gio::MenuModel::Attribute and
change enum Gio::MenuLink to Gio::MenuModel::Link.
Add new enum values to Attribute.
gio/src/menumodel.ccg | 17 +++++---
gio/src/menumodel.hg | 119 ++++++++++++++++++++++++++++++++++++--------------
2 files changed, 96 insertions(+), 40 deletions(-)
---
diff --git a/gio/src/menumodel.ccg b/gio/src/menumodel.ccg
index 9adbe29e..c76b896d 100644
--- a/gio/src/menumodel.ccg
+++ b/gio/src/menumodel.ccg
@@ -18,26 +18,29 @@
#include <giomm/menuattributeiter.h>
#include <giomm/menulinkiter.h>
+using Attribute = Gio::MenuModel::Attribute;
+using Link = Gio::MenuModel::Link;
+
namespace Gio
{
-// Make sure the order here is the same order as in Gio::MenuAttribute.
+// Make sure the order here is the same order as in Gio::MenuModel::Attribute.
static const char* const _attribute_strings[] = { G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_LABEL,
- G_MENU_ATTRIBUTE_TARGET };
+ G_MENU_ATTRIBUTE_TARGET, G_MENU_ATTRIBUTE_ACTION_NAMESPACE, G_MENU_ATTRIBUTE_ICON };
const char*
-giomm_get_menu_attribute(MenuAttribute attribute)
+giomm_get_menu_attribute(MenuModel::Attribute attribute)
{
- return _attribute_strings[attribute];
+ return _attribute_strings[static_cast<int>(attribute)];
}
-// Make sure the order here is the same order as in Gio::MenuLink.
+// Make sure the order here is the same order as in Gio::MenuModel::Link.
static const char* const _link_strings[] = { G_MENU_LINK_SECTION, G_MENU_LINK_SUBMENU };
const char*
-giomm_get_menu_link(MenuLink link)
+giomm_get_menu_link(MenuModel::Link link)
{
- return _link_strings[link];
+ return _link_strings[static_cast<int>(link)];
}
} // namespace Gio
diff --git a/gio/src/menumodel.hg b/gio/src/menumodel.hg
index 0cc37ce8..07b8e9b3 100644
--- a/gio/src/menumodel.hg
+++ b/gio/src/menumodel.hg
@@ -24,27 +24,6 @@ _PINCLUDE(glibmm/private/object_p.h)
namespace Gio
{
-enum MenuAttribute
-{
- /// The "action" menu attribute.
- MENU_ATTRIBUTE_ACTION,
-
- /// The "label" menu attribute.
- MENU_ATTRIBUTE_LABEL,
-
- /// The "target" menu attribute.
- MENU_ATTRIBUTE_TARGET
-};
-
-enum MenuLink
-{
- /// The "section" menu link.
- MENU_LINK_SECTION,
-
- /// The "submenu" menu link.
- MENU_LINK_SUBMENU
-};
-
class GIOMM_API MenuAttributeIter;
class GIOMM_API MenuLinkIter;
@@ -75,15 +54,13 @@ class GIOMM_API MenuLinkIter;
*
* The API of MenuModel is very generic, with iterators for the attributes and
* links of an item, see iterate_item_attributes() and iterate_item_links().
- * The 'standard' attributes and link types have predefined names:
- * Gio::MENU_ATTRIBUTE_LABEL, Gio::MENU_ATTRIBUTE_ACTION,
- * Gio::MENU_ATTRIBUTE_TARGET, Gio::MENU_LINK_SECTION and
- * Gio::MENU_LINK_SUBMENU.
+ * The 'standard' attributes and link types have predefined names,
+ * listed in the enums Gio::MenuModel::Attribute and Gio::MenuModel::Link.
*
* Items in a MenuModel represent active controls if they refer to an action
* that can get activated when the user interacts with the menu item. The
* reference to the action is encoded by the string id in the
- * Gio::MENU_ATTRIBUTE_ACTION attribute. An action id uniquely identifies an
+ * Gio::MenuModel::Attribute::ACTION attribute. An action id uniquely identifies an
* action in an action group. Which action group(s) provide actions depends on
* the context in which the menu model is used. E.g. when the model is exported
* as the application menu of a Gtk::Application, actions can be
@@ -130,26 +107,102 @@ protected:
_CTOR_DEFAULT
public:
+
+// Keep the enum values in sync with giomm_get_menu_attribute() in menumodel.ccg.
+/** Attributes in Gio::MenuModel::get_item_attribute().
+ *
+ * @ingroup giommEnums
+ */
+enum class Attribute
+{
+ /** The "action" menu attribute.
+ *
+ * The menu item attribute which holds the action name of the item. %Action
+ * names are namespaced with an identifier for the action group in which the
+ * action resides. For example, "win." for window-specific actions and "app."
+ * for application-wide actions.
+ */
+ ACTION,
+
+ /** The "label" menu attribute.
+ *
+ * The menu item attribute which holds the label of the item.
+ */
+ LABEL,
+
+ /** The "target" menu attribute.
+ *
+ * The menu item attribute which holds the target with which the item's action
+ * will be activated.
+ */
+ TARGET,
+
+ /** The "action-namespace" menu attribute.
+ *
+ * The menu item attribute that holds the namespace for all action names in
+ * menus that are linked from this item.
+ *
+ * @newin{2,66}
+ */
+ ACTION_NAMESPACE,
+
+ /** The "icon" menu attribute.
+ *
+ * The menu item attribute which holds the icon of the item.
+ *
+ * The icon is stored in the format returned by Gio::Icon::serialize().
+ *
+ * This attribute is intended only to represent 'noun' icons such as
+ * favicons for a webpage, or application icons. It should not be used
+ * for 'verbs' (ie: stock icons).
+ *
+ * @newin{2,66}
+ */
+ ICON,
+};
+
+// Keep the enum values in sync with giomm_get_menu_link() in menumodel.ccg.
+/** %Link types in Gio::MenuModel::get_item_link().
+ *
+ * @ingroup giommEnums
+ */
+enum class Link
+{
+ /** The "section" menu link.
+ *
+ * The name of the link that associates a menu item with a section. The linked
+ * menu will usually be shown in place of the menu item, using the item's label
+ * as a header.
+ */
+ SECTION,
+
+ /** The "submenu" menu link.
+ *
+ * The name of the link that associates a menu item with a submenu.
+ */
+ SUBMENU
+};
+
#m4begin
dnl See the .ccg implementation for how this conversion works.
-
- _CONVERSION(`MenuAttribute',`const gchar*',`giomm_get_menu_attribute($3)')
+ _CONVERSION(`Attribute',`const gchar*',`giomm_get_menu_attribute($3)')
#m4end
-
//TODO: Add a get_item_attribute() templated method to get values directly
//instead of returning a Glib::VariantBase?
- _WRAP_METHOD(Glib::VariantBase get_item_attribute(int item_index, MenuAttribute attribute, const
Glib::VariantType& expected_type) const, g_menu_model_get_item_attribute_value)
+ _WRAP_METHOD(Glib::VariantBase get_item_attribute(int item_index, Attribute attribute,
+ const Glib::VariantType& expected_type) const, g_menu_model_get_item_attribute_value)
// Ignore varargs function
_IGNORE(g_menu_model_get_item_attribute)
#m4begin
dnl See the .ccg implementation for how this conversion works.
- _CONVERSION(`MenuLink',`const gchar*',`giomm_get_menu_link($3)')
+ _CONVERSION(`Link',`const gchar*',`giomm_get_menu_link($3)')
#m4end
- _WRAP_METHOD(Glib::RefPtr<MenuModel> get_item_link(int item_index, MenuLink link),
g_menu_model_get_item_link)
- _WRAP_METHOD(Glib::RefPtr<const MenuModel> get_item_link(int item_index, MenuLink link) const,
g_menu_model_get_item_link, constversion)
+ _WRAP_METHOD(Glib::RefPtr<MenuModel> get_item_link(int item_index, Link link), g_menu_model_get_item_link)
+ _WRAP_METHOD(Glib::RefPtr<const MenuModel> get_item_link(int item_index, Link link) const,
+ g_menu_model_get_item_link, constversion)
_WRAP_METHOD(bool is_mutable() const, g_menu_model_is_mutable)
_WRAP_METHOD(int get_n_items() const, g_menu_model_get_n_items)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]