~desrt/menu-factory/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright © 2012 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, 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 along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Ryan Lortie <desrt@desrt.ca>
 */

#include "menu-factory-gtk.h"

static void
menu_factory_gtk_drop_all_children (GtkContainer *container)
{
  GList *children;

  children = gtk_container_get_children (container);
  while (children)
    {
      gtk_container_remove (container, children->data);
      children = g_list_delete_link (children, children);
    }
}

void
menu_factory_gtk_populate_menu_shell (GtkMenuShell *shell,
                                      GMenuModel   *model,
                                      GActionGroup *actions)
{
  menu_factory_gtk_drop_all_children (GTK_CONTAINER (shell));

  gtk_menu_shell_append (shell, gtk_menu_item_new_with_label ("Example item"));
}

GtkMenu *
menu_factory_gtk_new_menu (GMenuModel   *model,
                           GActionGroup *actions)
{
  GtkWidget *menu;

  menu = gtk_menu_new ();

  menu_factory_gtk_populate_menu_shell (GTK_MENU_SHELL (menu), model, actions);

  return GTK_MENU (menu);
}

GtkMenuBar *
menu_factory_gtk_new_menubar (GMenuModel   *model,
                              GActionGroup *actions)
{
  GtkWidget *menubar;

  menubar = gtk_menu_bar_new ();

  menu_factory_gtk_populate_menu_shell (GTK_MENU_SHELL (menubar), model, actions);

  return GTK_MENU_BAR (menubar);
}