2013-04-20 01:38:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-07 21:32:37 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-04-20 01:38:47 +00:00
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "shell-menu-tracker.h"
|
|
|
|
#include "gtkmenutracker.h"
|
|
|
|
|
2013-05-09 16:28:44 +00:00
|
|
|
/**
|
|
|
|
* SECTION:shell-menu-tracker
|
|
|
|
* @short_description: a simple wrapper around #GtkMenuTracker
|
|
|
|
* to make it bindable.
|
|
|
|
*/
|
|
|
|
|
2013-04-20 01:38:47 +00:00
|
|
|
struct _ShellMenuTracker
|
|
|
|
{
|
|
|
|
guint ref_count;
|
|
|
|
|
|
|
|
GtkMenuTracker *tracker;
|
|
|
|
|
|
|
|
ShellMenuTrackerInsertFunc insert_func;
|
|
|
|
gpointer insert_user_data;
|
|
|
|
GDestroyNotify insert_notify;
|
|
|
|
ShellMenuTrackerRemoveFunc remove_func;
|
|
|
|
gpointer remove_user_data;
|
|
|
|
GDestroyNotify remove_notify;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-05-09 16:28:44 +00:00
|
|
|
shell_menu_tracker_insert_func (GtkMenuTrackerItem *item,
|
|
|
|
gint position,
|
2013-04-20 01:38:47 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellMenuTracker *tracker = (ShellMenuTracker *) user_data;
|
2013-05-09 16:28:44 +00:00
|
|
|
tracker->insert_func (item, position, tracker->insert_user_data);
|
2013-04-20 01:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_menu_tracker_remove_func (gint position,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellMenuTracker *tracker = (ShellMenuTracker *) user_data;
|
|
|
|
tracker->remove_func (position, tracker->remove_user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_menu_tracker_new:
|
2013-05-09 16:28:44 +00:00
|
|
|
* @observable:
|
2013-04-20 01:38:47 +00:00
|
|
|
* @model:
|
2014-05-28 19:54:02 +00:00
|
|
|
* @action_namespace: (nullable):
|
2013-04-20 01:38:47 +00:00
|
|
|
* @insert_func:
|
|
|
|
* @insert_user_data:
|
|
|
|
* @insert_notify:
|
|
|
|
* @remove_func:
|
|
|
|
* @remove_user_data:
|
|
|
|
* @remove_notify:
|
|
|
|
*/
|
|
|
|
ShellMenuTracker *
|
2013-05-09 16:28:44 +00:00
|
|
|
shell_menu_tracker_new (GtkActionObservable *observable,
|
|
|
|
GMenuModel *model,
|
2013-04-20 01:38:47 +00:00
|
|
|
const gchar *action_namespace,
|
|
|
|
ShellMenuTrackerInsertFunc insert_func,
|
|
|
|
gpointer insert_user_data,
|
|
|
|
GDestroyNotify insert_notify,
|
|
|
|
ShellMenuTrackerRemoveFunc remove_func,
|
|
|
|
gpointer remove_user_data,
|
|
|
|
GDestroyNotify remove_notify)
|
|
|
|
{
|
|
|
|
ShellMenuTracker *tracker = g_slice_new0 (ShellMenuTracker);
|
|
|
|
|
|
|
|
tracker->ref_count = 1;
|
|
|
|
tracker->insert_func = insert_func;
|
|
|
|
tracker->insert_user_data = insert_user_data;
|
|
|
|
tracker->insert_notify = insert_notify;
|
|
|
|
tracker->remove_func = remove_func;
|
|
|
|
tracker->remove_user_data = remove_user_data;
|
|
|
|
tracker->remove_notify = remove_notify;
|
|
|
|
|
2013-05-09 16:28:44 +00:00
|
|
|
tracker->tracker = gtk_menu_tracker_new (observable,
|
|
|
|
model,
|
2013-04-20 01:38:47 +00:00
|
|
|
TRUE, /* with separators */
|
|
|
|
action_namespace,
|
|
|
|
shell_menu_tracker_insert_func,
|
|
|
|
shell_menu_tracker_remove_func,
|
|
|
|
tracker);
|
|
|
|
|
|
|
|
return tracker;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:39:21 +00:00
|
|
|
ShellMenuTracker *
|
|
|
|
shell_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
|
|
|
|
ShellMenuTrackerInsertFunc insert_func,
|
|
|
|
gpointer insert_user_data,
|
|
|
|
GDestroyNotify insert_notify,
|
|
|
|
ShellMenuTrackerRemoveFunc remove_func,
|
|
|
|
gpointer remove_user_data,
|
|
|
|
GDestroyNotify remove_notify)
|
|
|
|
{
|
|
|
|
ShellMenuTracker *tracker = g_slice_new0 (ShellMenuTracker);
|
|
|
|
|
|
|
|
tracker->ref_count = 1;
|
|
|
|
tracker->insert_func = insert_func;
|
|
|
|
tracker->insert_user_data = insert_user_data;
|
|
|
|
tracker->insert_notify = insert_notify;
|
|
|
|
tracker->remove_func = remove_func;
|
|
|
|
tracker->remove_user_data = remove_user_data;
|
|
|
|
tracker->remove_notify = remove_notify;
|
|
|
|
|
|
|
|
tracker->tracker = gtk_menu_tracker_new_for_item_submenu (item,
|
|
|
|
shell_menu_tracker_insert_func,
|
|
|
|
shell_menu_tracker_remove_func,
|
|
|
|
tracker);
|
|
|
|
|
|
|
|
return tracker;
|
|
|
|
}
|
|
|
|
|
2013-04-20 01:38:47 +00:00
|
|
|
ShellMenuTracker *
|
|
|
|
shell_menu_tracker_ref (ShellMenuTracker *tracker)
|
|
|
|
{
|
|
|
|
tracker->ref_count++;
|
|
|
|
return tracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shell_menu_tracker_unref (ShellMenuTracker *tracker)
|
|
|
|
{
|
|
|
|
if (tracker->ref_count-- <= 0)
|
|
|
|
{
|
|
|
|
shell_menu_tracker_destroy (tracker);
|
|
|
|
g_slice_free (ShellMenuTracker, tracker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shell_menu_tracker_destroy (ShellMenuTracker *tracker)
|
|
|
|
{
|
|
|
|
if (tracker->tracker != NULL)
|
|
|
|
{
|
|
|
|
gtk_menu_tracker_free (tracker->tracker);
|
|
|
|
tracker->tracker = NULL;
|
|
|
|
tracker->insert_notify (tracker->insert_user_data);
|
|
|
|
tracker->remove_notify (tracker->remove_user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE(ShellMenuTracker,
|
|
|
|
shell_menu_tracker,
|
|
|
|
shell_menu_tracker_ref,
|
|
|
|
shell_menu_tracker_unref)
|