]> git.sur5r.net Git - glabels/blob - glabels2/src/menus.c
Initial revision
[glabels] / glabels2 / src / menus.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  menus.c:  GLabels menus module
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 /*
24  * This file is based on gedit-menus.c from gedit2:
25  *
26  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
27  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi 
28  *
29  */
30 #include <config.h>
31
32 #include "menus.h"
33 #include "commands.h"
34 #include "tools.h"
35 #include "glabels.h"
36
37 BonoboUIVerb gl_verbs [] = {
38         BONOBO_UI_VERB ("FileNew", gl_cmd_file_new),
39         BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open),
40         BONOBO_UI_VERB ("FileSave", gl_cmd_file_save),
41         BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as),
42         BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print),
43         BONOBO_UI_VERB ("FileClose", gl_cmd_file_close),
44         BONOBO_UI_VERB ("FileCloseAll", gl_cmd_file_close_all),
45         BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit),
46         BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut),
47         BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy),
48         BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste),
49         BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete),
50         BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all),
51         BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all),
52         BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow),
53         BONOBO_UI_VERB ("ToolsText", gl_tools_text),
54         BONOBO_UI_VERB ("ToolsBox", gl_tools_box),
55         BONOBO_UI_VERB ("ToolsLine", gl_tools_line),
56         BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse),
57         BONOBO_UI_VERB ("ToolsImage", gl_tools_image),
58         BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode),
59         BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin),
60         BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout),
61         BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1),
62         BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties),
63         BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences),
64         BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents),
65         BONOBO_UI_VERB ("About", gl_cmd_help_about),
66
67         BONOBO_UI_VERB_END
68 };
69
70 gchar* gl_menus_no_docs_sensible_verbs [] = {
71         "/commands/FileSave",
72         "/commands/FileSaveAs",
73         "/commands/FilePrint",
74         "/commands/FilePrintPreview",
75         "/commands/FileClose",
76         "/commands/FileCloseAll",
77         "/commands/EditUndo",
78         "/commands/EditRedo",
79         "/commands/EditCut",
80         "/commands/EditCopy",
81         "/commands/EditPaste",
82         "/commands/EditDelete",
83         "/commands/EditSelectAll",
84         "/commands/EditUnSelectAll",
85         "/commands/ToolsArrow",
86         "/commands/ToolsText",
87         "/commands/ToolsLine",
88         "/commands/ToolsBox",
89         "/commands/ToolsEllipse",
90         "/commands/ToolsImage",
91         "/commands/ToolsBarcode",
92         "/commands/ToolsZoomIn",
93         "/commands/ToolsZoomOut",
94         "/commands/ToolsZoom1to1",
95         "/commands/ToolsMergeProperties",
96
97         NULL
98 };
99
100 gchar* gl_menus_not_modified_doc_sensible_verbs [] = {
101         "/commands/FileSave",
102
103         NULL
104 };
105
106
107 void
108 gl_menus_set_verb_sensitive (BonoboUIComponent *ui_component, gchar* cname, gboolean sensitive)
109 {
110         g_return_if_fail (cname != NULL);
111         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
112
113         bonobo_ui_component_set_prop (
114                 ui_component, cname, "sensitive", sensitive ? "1" : "0", NULL);
115 }
116
117 void
118 gl_menus_set_verb_list_sensitive (BonoboUIComponent *ui_component, gchar** vlist, gboolean sensitive)
119 {
120         g_return_if_fail (vlist != NULL);
121         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
122
123         for ( ; *vlist; ++vlist)
124         {
125                 bonobo_ui_component_set_prop (
126                         ui_component, *vlist, "sensitive", sensitive ? "1" : "0", NULL);
127         }
128 }
129
130 void
131 gl_menus_set_verb_state (BonoboUIComponent *ui_component, gchar* cname, gboolean state)
132 {
133         g_return_if_fail (cname != NULL);
134         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
135
136         bonobo_ui_component_set_prop (
137                 ui_component, cname, "state", state ? "1" : "0", NULL);
138 }
139
140 void
141 gl_menus_add_menu_item (BonoboWindow *window, const gchar *path,
142                      const gchar *name, const gchar *label,
143                      const gchar *tooltip, const gchar *stock_pixmap,
144                      BonoboUIVerbFn cb)
145 {
146         BonoboUIComponent *ui_component;
147         gchar *item_path;
148         gchar *cmd;
149
150         g_return_if_fail (window != NULL);
151         g_return_if_fail (path != NULL);
152         g_return_if_fail (label != NULL);
153         g_return_if_fail (cb != NULL);
154         
155         item_path = g_strconcat (path, name, NULL);
156         ui_component = bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window));
157         if (!bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
158                 gchar *xml;
159
160                 xml = g_strdup_printf ("<menuitem name=\"%s\" verb=\"\""
161                                        " _label=\"%s\""
162                                        " _tip=\"%s\" hident=\"0\" />", name,
163                                        label, tooltip);
164
165
166                 if (stock_pixmap != NULL) {
167                         cmd = g_strdup_printf ("<cmd name=\"%s\""
168                                 " pixtype=\"stock\" pixname=\"%s\" />",
169                                 name, stock_pixmap);
170                 }
171                 else {
172                         cmd = g_strdup_printf ("<cmd name=\"%s\" />", name);
173                 }
174
175
176                 bonobo_ui_component_set_translate (ui_component, path,
177                                                    xml, NULL);
178
179                 bonobo_ui_component_set_translate (ui_component, "/commands/",
180                                                    cmd, NULL);
181                                                    
182                 bonobo_ui_component_add_verb (ui_component, name, cb, NULL);
183
184                 g_free (xml);
185                 g_free (cmd);
186         }
187
188         g_free (item_path);
189 }
190
191 void
192 gl_menus_remove_menu_item (BonoboWindow *window, const gchar *path,
193                         const gchar *name)
194 {
195         BonoboUIComponent *ui_component;
196         gchar *item_path;
197
198         g_return_if_fail (window != NULL);
199         g_return_if_fail (path != NULL);
200         g_return_if_fail (name != NULL);
201
202         item_path = g_strconcat (path, name, NULL);
203         ui_component = bonobo_mdi_get_ui_component_from_window (BONOBO_WINDOW (window));
204
205         if (bonobo_ui_component_path_exists (ui_component, item_path, NULL)) {
206                 gchar *cmd;
207
208                 cmd = g_strdup_printf ("/commands/%s", name);
209                 
210                 bonobo_ui_component_rm (ui_component, item_path, NULL);
211                 bonobo_ui_component_rm (ui_component, cmd, NULL);
212                 
213                 g_free (cmd);
214         }
215
216         g_free (item_path);
217 }
218
219 void
220 gl_menus_add_menu_item_all (const gchar *path, const gchar *name,
221                          const gchar *label, const gchar *tooltip,
222                          const gchar *stock_pixmap,
223                          BonoboUIVerbFn cb)
224 {
225         GList* top_windows;
226         
227         top_windows = glabels_get_top_windows ();
228         g_return_if_fail (top_windows != NULL);
229        
230         while (top_windows)
231         {
232                 BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
233
234
235                 gl_menus_add_menu_item (window, path, name, label, tooltip,
236                                      stock_pixmap, cb);
237                 
238                 top_windows = g_list_next (top_windows);
239         }
240 }
241
242 void
243 gl_menus_remove_menu_item_all (const gchar *path, const gchar *name)
244 {
245         GList* top_windows;
246         
247         top_windows = glabels_get_top_windows ();
248         g_return_if_fail (top_windows != NULL);
249        
250         while (top_windows)
251         {
252                 BonoboWindow* window = BONOBO_WINDOW (top_windows->data);
253
254
255                 gl_menus_remove_menu_item (window, path, name);
256
257                 
258                 top_windows = g_list_next (top_windows);
259         }
260 }