summaryrefslogtreecommitdiff
path: root/gtk/gtkmenutracker.h
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-03-22 17:24:46 -0400
committerRyan Lortie <desrt@desrt.ca>2013-04-01 16:45:19 -0400
commit5617b584202b1f967f287dfd03a4560975f1389b (patch)
tree293e53b55dad608d229ee0e59b81498a1c8f100b /gtk/gtkmenutracker.h
parente250e52175d5f62e99c7491d95923ad521e1421c (diff)
downloadgtk+-5617b584202b1f967f287dfd03a4560975f1389b.tar.gz
Introduce GtkMenuTracker
GtkMenuTracker folds a nested structure of sections in a GMenuModel into a single linear menu, which it expresses to its user by means of 'insert item at position' and 'remove item at position' callbacks. The logic for where to insert separators and how to handle action namespaces is contained within the tracker, removing the need to have this logic duplicated in the 3 or 4 places that consume GMenuModel. In comparison with the previous code, the tracker no longer completely destroys and rebuilds menus every time a single change occurs. As a result, the new gtkmenu testcase now runs in approximately 3 seconds instead of ~60 before. https://bugzilla.gnome.org/show_bug.cgi?id=696468
Diffstat (limited to 'gtk/gtkmenutracker.h')
-rw-r--r--gtk/gtkmenutracker.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/gtk/gtkmenutracker.h b/gtk/gtkmenutracker.h
new file mode 100644
index 0000000000..51810a104c
--- /dev/null
+++ b/gtk/gtkmenutracker.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2013 Canonical Limited
+ *
+ * This library 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 of the licence, or (at your option) any later version.
+ *
+ * This library 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt@desrt.ca>
+ */
+
+#ifndef __GTK_MENU_TRACKER_H__
+#define __GTK_MENU_TRACKER_H__
+
+#include <gio/gio.h>
+
+typedef struct _GtkMenuTracker GtkMenuTracker;
+
+typedef void (* GtkMenuTrackerInsertFunc) (gint position,
+ GMenuModel *model,
+ gint item_index,
+ const gchar *action_namespace,
+ gboolean is_separator,
+ gpointer user_data);
+
+typedef void (* GtkMenuTrackerRemoveFunc) (gint position,
+ gpointer user_data);
+
+
+G_GNUC_INTERNAL
+GtkMenuTracker * gtk_menu_tracker_new (GMenuModel *model,
+ gboolean with_separators,
+ const gchar *action_namespace,
+ GtkMenuTrackerInsertFunc insert_func,
+ GtkMenuTrackerRemoveFunc remove_func,
+ gpointer user_data);
+
+G_GNUC_INTERNAL
+void gtk_menu_tracker_free (GtkMenuTracker *tracker);
+
+#endif /* __GTK_MENU_TRACKER_H__ */