~ps-jenkins/ido/latestsnapshot-13.10.0+13.10.20130930-0ubuntu1

« back to all changes in this revision

Viewing changes to src/idomenuitemfactory.c

  • Committer: Tarmac
  • Author(s): Charles Kerr, Lars Uebernickel
  • Date: 2013-05-31 19:51:15 UTC
  • mfrom: (126.1.12 support-slider)
  • Revision ID: tarmac-20130531195115-c2c11w551db984km
Put a framework in place to move custom menu items from the indicator packages into ido. It depends on a vendor-patch to gtk (see bug #1183505), because gtk+ does not yet have an API for inserting arbitrary menu items into menus created with gtk_menu_new_from_model().

IdoMenuItemFactory implements the GtkMenuItemFactory interface, which is used by (the patched) gtk+ to create menu items that have an "x-canonical-type" attribute.

IdoActionHelper contains some common functionality that all menu items need (watching the action group for action additions and removals, as well es enabled and state changes). It can be used to glue a menu item widget to an action in IdoMenuItemFactory.

This changeset also adds the first widget: IdoUserMenuItem (merged from lp:~charlesk/ido/add-idousermenuitem). Please follow this example when adding additional widgets.

Approved by PS Jenkins bot, Ted Gould.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *     Lars Uebernickel <lars.uebernickel@canonical.com>
 
18
 */
 
19
 
 
20
#include <gtk/gtk.h>
 
21
#include <gtk/ubuntu-private.h>
 
22
 
 
23
#include "idousermenuitem.h"
 
24
 
 
25
#define IDO_TYPE_MENU_ITEM_FACTORY         (ido_menu_item_factory_get_type ())
 
26
#define IDO_MENU_ITEM_FACTORY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory))
 
27
#define IDO_IS_MENU_ITEM_FACTORY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), IDO_TYPE_MENU_ITEM_FACTORY))
 
28
 
 
29
typedef GObject      IdoMenuItemFactory;
 
30
typedef GObjectClass IdoMenuItemFactoryClass;
 
31
 
 
32
GType       ido_menu_item_factory_get_type (void);
 
33
static void ido_menu_item_factory_interface_init (UbuntuMenuItemFactoryInterface *iface);
 
34
 
 
35
G_DEFINE_TYPE_WITH_CODE (IdoMenuItemFactory, ido_menu_item_factory, G_TYPE_OBJECT,
 
36
  G_IMPLEMENT_INTERFACE (UBUNTU_TYPE_MENU_ITEM_FACTORY, ido_menu_item_factory_interface_init)
 
37
  g_io_extension_point_implement (UBUNTU_MENU_ITEM_FACTORY_EXTENSION_POINT_NAME,
 
38
                                  g_define_type_id, "ido", 0);)
 
39
 
 
40
static GtkMenuItem *
 
41
ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory,
 
42
                                        const gchar           *type,
 
43
                                        GMenuItem             *menuitem,
 
44
                                        GActionGroup          *actions)
 
45
{
 
46
  GtkMenuItem *item = NULL;
 
47
 
 
48
  if (g_str_equal (type, "indicator.user-menu-item"))
 
49
    item = ido_user_menu_item_new_from_model (menuitem, actions);
 
50
 
 
51
  return item;
 
52
}
 
53
 
 
54
static void
 
55
ido_menu_item_factory_class_init (IdoMenuItemFactoryClass *class)
 
56
{
 
57
}
 
58
 
 
59
static void
 
60
ido_menu_item_factory_interface_init (UbuntuMenuItemFactoryInterface *iface)
 
61
{
 
62
  iface->create_menu_item = ido_menu_item_factory_create_menu_item;
 
63
}
 
64
 
 
65
static void
 
66
ido_menu_item_factory_init (IdoMenuItemFactory *factory)
 
67
{
 
68
}