Shared folders support with a GUI.
[claws.git] / src / menu.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtkmenu.h>
27 #include <gtk/gtkmenubar.h>
28 #include <gtk/gtkitemfactory.h>
29 #include <gtk/gtkcheckmenuitem.h>
30
31 #include "intl.h"
32 #include "menu.h"
33
34 static gchar *menu_translate(const gchar *path, gpointer data);
35
36 GtkWidget *menubar_create(GtkWidget *window, GtkItemFactoryEntry *entries,
37                           guint n_entries, const gchar *path, gpointer data)
38 {
39         GtkItemFactory *factory;
40         GtkAccelGroup *accel_group;
41
42         accel_group = gtk_accel_group_new();
43         factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, path, accel_group);
44         gtk_item_factory_set_translate_func(factory, menu_translate,
45                                             NULL, NULL);
46         gtk_item_factory_create_items(factory, n_entries, entries, data);
47         gtk_accel_group_attach(accel_group, GTK_OBJECT(window));
48
49         return gtk_item_factory_get_widget(factory, path);
50 }
51
52 GtkWidget *menu_create_items(GtkItemFactoryEntry *entries,
53                              guint n_entries, const gchar *path,
54                              GtkItemFactory **factory, gpointer data)
55 {
56         *factory = gtk_item_factory_new(GTK_TYPE_MENU, path, NULL);
57         gtk_item_factory_set_translate_func(*factory, menu_translate,
58                                             NULL, NULL);
59         gtk_item_factory_create_items(*factory, n_entries, entries, data);
60
61         return gtk_item_factory_get_widget(*factory, path);
62 }
63
64 static gchar *menu_translate(const gchar *path, gpointer data)
65 {
66         gchar *retval;
67
68         retval = gettext(path);
69
70         return retval;
71 }
72
73 void menu_set_sensitive(GtkItemFactory *ifactory, const gchar *path,
74                         gboolean sensitive)
75 {
76         GtkWidget *widget;
77
78         g_return_if_fail(ifactory != NULL);
79
80         widget = gtk_item_factory_get_item(ifactory, path);
81         gtk_widget_set_sensitive(widget, sensitive);
82 }
83
84 void menu_set_insensitive_all(GtkMenuShell *menu_shell)
85 {
86         GList *cur;
87
88         for (cur = menu_shell->children; cur != NULL; cur = cur->next)
89                 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), FALSE);
90 }
91
92 void menu_set_toggle(GtkItemFactory *ifactory, const gchar *path,
93                         gboolean active)
94 {
95         GtkWidget *widget;
96
97         g_return_if_fail(ifactory != NULL);
98
99         widget = gtk_item_factory_get_item(ifactory, path);
100         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), active);
101 }