]> git.sur5r.net Git - glabels/blob - glabels2/src/commands.c
Initial revision
[glabels] / glabels2 / src / commands.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  commands.c:  GLabels commands 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 #include <config.h>
24
25 #include <gtk/gtk.h>
26 #include <libgnome/libgnome.h>
27 #include <libgnomeui/libgnomeui.h>
28
29 #include "commands.h"
30 #include "glabels.h"
31 #include "mdi-child.h"
32 #include "view.h"
33 #include "file.h"
34 #include "print.h"
35 #include "prefs.h"
36 #include "prefs-dialog.h"
37 #include "debug.h"
38
39 #ifdef PACKAGE_DATA_DIR
40 #define LOGO_PIXMAP (PACKAGE_DATA_DIR "/pixmaps/glabels/glabels-about-logo.png")
41 #else
42 #define LOGO_PIXMAP gnome_pixmap_file("glabels/glabels-about-logo.png")
43 #endif
44
45 \f
46 /****************************************************************************/
47 /* File->New command.                                                       */
48 /****************************************************************************/
49 void 
50 gl_cmd_file_new (BonoboUIComponent *uic,
51                  gpointer user_data,
52                  const gchar* verbname)
53 {
54         gl_debug (DEBUG_COMMANDS, "verbname: %s", verbname);
55         
56         gl_file_new ();
57 }
58
59 /****************************************************************************/
60 /* File->Open command.                                                      */
61 /****************************************************************************/
62 void 
63 gl_cmd_file_open (BonoboUIComponent *uic,
64                   gpointer user_data,
65                   const gchar* verbname)
66 {
67         BonoboMDIChild *active_child;
68         
69         gl_debug (DEBUG_COMMANDS, "");
70
71         active_child = bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi));
72         
73         gl_file_open ((glMDIChild*) active_child);
74 }
75
76 /****************************************************************************/
77 /* File->Save command.                                                      */
78 /****************************************************************************/
79 void 
80 gl_cmd_file_save (BonoboUIComponent *uic,
81                   gpointer user_data,
82                   const gchar* verbname)
83 {
84         glMDIChild *active_child;
85         
86         gl_debug (DEBUG_COMMANDS, "");
87
88         active_child = GL_MDI_CHILD (bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi)));
89         if (active_child == NULL)
90                 return;
91         
92         gl_file_save (active_child);
93 }
94
95 /****************************************************************************/
96 /* File->Save_as command.                                                   */
97 /****************************************************************************/
98 void 
99 gl_cmd_file_save_as (BonoboUIComponent *uic,
100                      gpointer user_data,
101                      const gchar* verbname)
102 {
103         glMDIChild *active_child;
104         
105         gl_debug (DEBUG_COMMANDS, "");
106
107         active_child = GL_MDI_CHILD (bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi)));
108         if (active_child == NULL)
109                 return;
110         
111         gl_file_save_as (active_child);
112 }
113
114 /****************************************************************************/
115 /* File->Print command.                                                     */
116 /****************************************************************************/
117 void
118 gl_cmd_file_print (BonoboUIComponent *uic,
119                    gpointer user_data,
120                    const gchar* verbname)
121 {
122         glLabel *label = glabels_get_active_label ();
123         BonoboWindow *win = glabels_get_active_window ();
124         
125         gl_debug (DEBUG_COMMANDS, "");
126
127         g_return_if_fail (label != NULL);
128         g_return_if_fail (win != NULL);
129
130         gl_print_dialog (label, win);
131
132 }
133
134 /****************************************************************************/
135 /* File->Close command.                                                     */
136 /****************************************************************************/
137 void 
138 gl_cmd_file_close (BonoboUIComponent *uic,
139                    gpointer user_data,
140                    const gchar* verbname)
141 {
142         GtkWidget *active_view;
143         
144         gl_debug (DEBUG_COMMANDS, "");
145
146         active_view = bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi));
147         
148         if (active_view == NULL)
149                 return;
150         
151         glabels_close_x_button_pressed = TRUE;
152         
153         gl_file_close (active_view);
154
155         glabels_close_x_button_pressed = FALSE;
156 }
157
158 /****************************************************************************/
159 /* File->Close_all command.                                                 */
160 /****************************************************************************/
161 void 
162 gl_cmd_file_close_all (BonoboUIComponent *uic,
163                        gpointer user_data,
164                        const gchar* verbname)
165 {
166         gl_debug (DEBUG_COMMANDS, "");
167
168         glabels_close_x_button_pressed = TRUE;
169         
170         gl_file_close_all ();
171
172         glabels_close_x_button_pressed = FALSE;
173 }
174
175 /****************************************************************************/
176 /* File->Exit command.                                                      */
177 /****************************************************************************/
178 void 
179 gl_cmd_file_exit (BonoboUIComponent *uic,
180                   gpointer user_data,
181                   const gchar* verbname)
182 {
183         gl_debug (DEBUG_COMMANDS, "");
184
185         glabels_exit_button_pressed = TRUE;
186         
187         gl_file_exit ();        
188
189         glabels_exit_button_pressed = FALSE;
190 }
191
192
193 /****************************************************************************/
194 /* Edit->Cut command.                                                       */
195 /****************************************************************************/
196 void 
197 gl_cmd_edit_cut (BonoboUIComponent *uic,
198                  gpointer user_data,
199                  const gchar* verbname)
200 {
201         glView* active_view;
202
203         active_view = GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi)));
204         g_return_if_fail (active_view);
205         
206         gl_view_cut (active_view); 
207 }
208
209 /****************************************************************************/
210 /* Edit->Copy command.                                                      */
211 /****************************************************************************/
212 void 
213 gl_cmd_edit_copy (BonoboUIComponent *uic,
214                   gpointer user_data,
215                   const gchar* verbname)
216 {
217         glView* active_view;
218
219         active_view = GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi)));
220         g_return_if_fail (active_view);
221         
222         gl_view_copy (active_view); 
223 }
224
225 /****************************************************************************/
226 /* Edit->Paste command.                                                     */
227 /****************************************************************************/
228 void 
229 gl_cmd_edit_paste (BonoboUIComponent *uic,
230                    gpointer user_data,
231                    const gchar* verbname)
232 {
233         glView* active_view;
234
235         active_view = GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi)));
236         g_return_if_fail (active_view);
237         
238         gl_view_paste (active_view); 
239 }
240
241
242 /****************************************************************************/
243 /* Edit->Delete command.                                                    */
244 /****************************************************************************/
245 void 
246 gl_cmd_edit_delete (BonoboUIComponent *uic,
247                     gpointer user_data,
248                     const gchar* verbname)
249 {
250         glView* active_view;
251
252         active_view = GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi)));
253         g_return_if_fail (active_view);
254         
255         gl_view_delete_selection (active_view); 
256 }
257
258
259 /****************************************************************************/
260 /* Edit->Select_all command.                                                */
261 /****************************************************************************/
262 void
263 gl_cmd_edit_select_all (BonoboUIComponent *uic,
264                         gpointer user_data,
265                         const gchar* verbname)
266 {
267         glView* active_view;
268
269         active_view =
270                 GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI(glabels_mdi)));
271
272         g_return_if_fail (active_view);
273         
274         gl_view_select_all (active_view); 
275 }
276
277 /****************************************************************************/
278 /* Edit->Select_all command.                                                */
279 /****************************************************************************/
280 void
281 gl_cmd_edit_unselect_all (BonoboUIComponent *uic,
282                           gpointer user_data,
283                           const gchar* verbname)
284 {
285         glView* active_view;
286
287         active_view =
288                 GL_VIEW (bonobo_mdi_get_active_view (BONOBO_MDI(glabels_mdi)));
289
290         g_return_if_fail (active_view);
291         
292         gl_view_unselect_all (active_view); 
293 }
294
295 /****************************************************************************/
296 /* Settings->Preferences command.                                           */
297 /****************************************************************************/
298 void
299 gl_cmd_settings_preferences (BonoboUIComponent *uic,
300                              gpointer user_data,
301                              const gchar* verbname)
302 {
303         static GtkWidget *dlg = NULL;
304
305         gl_debug (DEBUG_COMMANDS, "");
306
307         if (dlg != NULL)
308         {
309                 gtk_window_present (GTK_WINDOW (dlg));
310                 gtk_window_set_transient_for (GTK_WINDOW (dlg), 
311                                               GTK_WINDOW (glabels_get_active_window ()));
312
313                 return;
314         }
315                 
316         dlg = gl_prefs_dialog_new (GTK_WINDOW (glabels_get_active_window ()));
317
318         g_signal_connect (G_OBJECT (dlg), "destroy",
319                           G_CALLBACK (gtk_widget_destroyed), &dlg);
320         
321         gtk_widget_show (dlg);
322 }
323
324 /****************************************************************************/
325 /* Help->Contents command.                                                  */
326 /****************************************************************************/
327 void 
328 gl_cmd_help_contents (BonoboUIComponent *uic,
329                       gpointer user_data,
330                       const gchar* verbname)
331 {
332         GError *error = NULL;
333
334         gl_debug (DEBUG_COMMANDS, "");
335
336         gnome_help_display_with_doc_id (NULL, NULL, "glabels.xml", NULL, &error);
337         
338         if (error != NULL)
339         {
340                 g_warning (error->message);
341
342                 g_error_free (error);
343         }
344 }
345
346 /****************************************************************************/
347 /* Help->About command.                                                     */
348 /****************************************************************************/
349 void 
350 gl_cmd_help_about (BonoboUIComponent *uic,
351                    gpointer user_data,
352                    const gchar* verbname)
353 {
354         static GtkWidget *about = NULL;
355         GdkPixbuf* pixbuf = NULL;
356         
357         gchar *copy_text = "Copyright 2001-2002 Jim Evins";
358         gchar *about_text =
359             _("A label and business card creation program for GNOME.\n"
360               " \n"
361               "Glabels is free software; you can redistribute it and/or modify it "
362               "under the terms of the GNU General Public License as published by "
363               "the Free Software Foundation; either version 2 of the License, or "
364               "(at your option) any later version.\n" " \n"
365               "This program is distributed in the hope that it will be useful, but "
366               "WITHOUT ANY WARRANTY; without even the implied warranty of "
367               "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU "
368               "General Public License for more details.\n");
369
370         gchar *authors[] = {
371                 _("Author:"),
372                 "\tJim Evins <evins@snaught.com>",
373                 "",
374                 _("See the file AUTHORS for additional acknowledgments,"),
375                 _("or visit http://snaught.com/glabels"),
376                 NULL
377         };
378         
379         gchar *documenters[] = {
380                 "",
381                 NULL
382         };
383
384         gchar *translator_credits = _("");
385
386         gl_debug (DEBUG_COMMANDS, "");
387
388         if (about != NULL)
389         {
390                 gdk_window_show (about->window);
391                 gdk_window_raise (about->window);
392                 return;
393         }
394         
395         pixbuf = gdk_pixbuf_new_from_file ( LOGO_PIXMAP, NULL);
396
397         about = gnome_about_new (_("glabels"), VERSION,
398                                  copy_text,
399                                  about_text,
400                                 (const char **)authors,
401                                 (const char **)documenters,
402                                 (const char *)translator_credits,
403                                 pixbuf);
404
405         gtk_window_set_transient_for (GTK_WINDOW (about),
406                         GTK_WINDOW (glabels_get_active_window ()));
407
408         gtk_window_set_destroy_with_parent (GTK_WINDOW (about), TRUE);
409
410         if (pixbuf != NULL)
411                 g_object_unref (pixbuf);
412         
413         g_signal_connect (G_OBJECT (about), "destroy",
414                           G_CALLBACK (gtk_widget_destroyed), &about);
415         
416         gtk_widget_show (about);
417 }
418
419