1 | /* |
---|
2 | * input/output routines |
---|
3 | * |
---|
4 | * based on sample-container from Nat Friedman (nat@nat.org) |
---|
5 | * |
---|
6 | * Author: |
---|
7 | * Dietmar Maurer (dietmar@maurer-it.com) |
---|
8 | * |
---|
9 | * Copyright 1999 Maurer IT Systemlösungen (http://www.maurer-it.com) |
---|
10 | */ |
---|
11 | |
---|
12 | #include <config.h> |
---|
13 | #include <fcntl.h> |
---|
14 | #include "inout.h" |
---|
15 | #include "ui.h" |
---|
16 | |
---|
17 | static gint last_verb_id = 0; |
---|
18 | |
---|
19 | static void |
---|
20 | buffer_save_pf (Buffer *buffer, gchar *filename) |
---|
21 | { |
---|
22 | Bonobo_PersistFile persist; |
---|
23 | CORBA_Environment ev; |
---|
24 | |
---|
25 | g_return_if_fail (buffer != NULL); |
---|
26 | g_return_if_fail (filename != NULL); |
---|
27 | |
---|
28 | CORBA_exception_init (&ev); |
---|
29 | |
---|
30 | persist = Bonobo_Unknown_queryInterface ( |
---|
31 | BONOBO_OBJREF (buffer->server), |
---|
32 | "IDL:Bonobo/PersistFile:1.0", |
---|
33 | &ev); |
---|
34 | |
---|
35 | if (ev._major != CORBA_NO_EXCEPTION || persist == CORBA_OBJECT_NIL) { |
---|
36 | g_warning ("component doesn't support PersistFile!"); |
---|
37 | CORBA_exception_free (&ev); |
---|
38 | return; |
---|
39 | } |
---|
40 | |
---|
41 | /* fixme: only save when dirty - this is currently not |
---|
42 | supported by most components */ |
---|
43 | /* |
---|
44 | if (!Bonobo_PersistFile_isDirty (persist, &ev)) { |
---|
45 | g_warning ("No changes need to be saved"); |
---|
46 | Bonobo_Unknown_unref (persist, &ev); |
---|
47 | CORBA_exception_free (&ev); |
---|
48 | return; |
---|
49 | } |
---|
50 | */ |
---|
51 | |
---|
52 | Bonobo_PersistFile_save (persist, (CORBA_char *) filename, &ev); |
---|
53 | |
---|
54 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
55 | gnome_warning_dialog (_("An exception occured while trying " |
---|
56 | "to save data from the component with " |
---|
57 | "PersistFile")); |
---|
58 | } |
---|
59 | if (ev._major != CORBA_SYSTEM_EXCEPTION) |
---|
60 | CORBA_Object_release (persist, &ev); |
---|
61 | |
---|
62 | Bonobo_Unknown_unref (persist, &ev); |
---|
63 | CORBA_exception_free (&ev); |
---|
64 | } |
---|
65 | |
---|
66 | static void |
---|
67 | buffer_load_pf (Buffer *buffer, gchar *filename) |
---|
68 | { |
---|
69 | Bonobo_PersistFile persist; |
---|
70 | CORBA_Environment ev; |
---|
71 | |
---|
72 | g_return_if_fail (buffer != NULL); |
---|
73 | g_return_if_fail (filename != NULL); |
---|
74 | |
---|
75 | CORBA_exception_init (&ev); |
---|
76 | |
---|
77 | persist = Bonobo_Unknown_queryInterface ( |
---|
78 | BONOBO_OBJREF (buffer->server), |
---|
79 | "IDL:Bonobo/PersistFile:1.0", |
---|
80 | &ev); |
---|
81 | |
---|
82 | if (ev._major != CORBA_NO_EXCEPTION || persist == CORBA_OBJECT_NIL) { |
---|
83 | g_warning ("component doesn't support PersistFile!"); |
---|
84 | CORBA_exception_free (&ev); |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | Bonobo_PersistFile_load (persist, (CORBA_char *) filename, &ev); |
---|
89 | |
---|
90 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
91 | gnome_warning_dialog (_("An exception occured while trying " |
---|
92 | "to load data into the component with " |
---|
93 | "PersistFile")); |
---|
94 | } |
---|
95 | if (ev._major != CORBA_SYSTEM_EXCEPTION) |
---|
96 | CORBA_Object_release (persist, &ev); |
---|
97 | |
---|
98 | Bonobo_Unknown_unref (persist, &ev); |
---|
99 | CORBA_exception_free (&ev); |
---|
100 | } |
---|
101 | |
---|
102 | static void |
---|
103 | buffer_save_ps (Buffer *buffer, gchar *filename) |
---|
104 | { |
---|
105 | Bonobo_PersistStream persist; |
---|
106 | CORBA_Environment ev; |
---|
107 | BonoboStream *stream; |
---|
108 | |
---|
109 | g_return_if_fail (buffer != NULL); |
---|
110 | g_return_if_fail (filename != NULL); |
---|
111 | |
---|
112 | if (!(stream = bonobo_stream_open ( |
---|
113 | "fs", filename, Bonobo_Storage_WRITE, O_WRONLY))) { |
---|
114 | char *error_msg; |
---|
115 | error_msg = g_strdup_printf (_("Could not save file %s"), |
---|
116 | filename); |
---|
117 | gnome_warning_dialog (error_msg); |
---|
118 | g_free (error_msg); |
---|
119 | return; |
---|
120 | } |
---|
121 | |
---|
122 | CORBA_exception_init (&ev); |
---|
123 | |
---|
124 | persist = Bonobo_Unknown_queryInterface ( |
---|
125 | BONOBO_OBJREF (buffer->server), |
---|
126 | "IDL:Bonobo/PersistStream:1.0", |
---|
127 | &ev); |
---|
128 | |
---|
129 | if (ev._major != CORBA_NO_EXCEPTION || persist == CORBA_OBJECT_NIL) { |
---|
130 | g_warning ("component doesn't support PersistStream!"); |
---|
131 | CORBA_exception_free (&ev); |
---|
132 | return; |
---|
133 | } |
---|
134 | |
---|
135 | /* fixme: only save when dirty - this is currently not |
---|
136 | supported by most components */ |
---|
137 | /* |
---|
138 | if (!Bonobo_PersistStream_isDirty (persist, &ev)) { |
---|
139 | g_warning ("No changes need to be saved"); |
---|
140 | Bonobo_Unknown_unref (persist, &ev); |
---|
141 | CORBA_exception_free (&ev); |
---|
142 | return; |
---|
143 | } |
---|
144 | */ |
---|
145 | |
---|
146 | Bonobo_PersistStream_save (persist, |
---|
147 | (Bonobo_Stream) BONOBO_OBJREF (stream), |
---|
148 | "", &ev); |
---|
149 | |
---|
150 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
151 | gnome_warning_dialog (_("An exception occured while trying " |
---|
152 | "to save data from the component with " |
---|
153 | "PersistStream")); |
---|
154 | } |
---|
155 | if (ev._major != CORBA_SYSTEM_EXCEPTION) |
---|
156 | CORBA_Object_release (persist, &ev); |
---|
157 | |
---|
158 | Bonobo_Unknown_unref (persist, &ev); |
---|
159 | CORBA_exception_free (&ev); |
---|
160 | bonobo_object_unref (BONOBO_OBJECT(stream)); |
---|
161 | } |
---|
162 | |
---|
163 | static void |
---|
164 | buffer_load_ps (Buffer *buffer, gchar *filename) |
---|
165 | { |
---|
166 | Bonobo_PersistStream persist; |
---|
167 | CORBA_Environment ev; |
---|
168 | BonoboStream *stream; |
---|
169 | |
---|
170 | g_return_if_fail (buffer != NULL); |
---|
171 | g_return_if_fail (filename != NULL); |
---|
172 | |
---|
173 | if (!(stream = bonobo_stream_open ( |
---|
174 | "fs", filename, Bonobo_Storage_READ, O_RDONLY))) { |
---|
175 | char *error_msg; |
---|
176 | error_msg = g_strdup_printf (_("Could not open file %s"), |
---|
177 | filename); |
---|
178 | gnome_warning_dialog (error_msg); |
---|
179 | g_free (error_msg); |
---|
180 | return; |
---|
181 | } |
---|
182 | |
---|
183 | CORBA_exception_init (&ev); |
---|
184 | |
---|
185 | persist = Bonobo_Unknown_queryInterface ( |
---|
186 | BONOBO_OBJREF (buffer->server), |
---|
187 | "IDL:Bonobo/PersistStream:1.0", |
---|
188 | &ev); |
---|
189 | |
---|
190 | if (ev._major != CORBA_NO_EXCEPTION || persist == CORBA_OBJECT_NIL) { |
---|
191 | g_warning ("component doesn't support PersistStream!"); |
---|
192 | CORBA_exception_free (&ev); |
---|
193 | return; |
---|
194 | } |
---|
195 | |
---|
196 | Bonobo_PersistStream_load (persist, |
---|
197 | (Bonobo_Stream) BONOBO_OBJREF (stream), |
---|
198 | "", &ev); |
---|
199 | |
---|
200 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
201 | gnome_warning_dialog (_("An exception occured while trying " |
---|
202 | "to load data into the component with " |
---|
203 | "PersistStream")); |
---|
204 | } |
---|
205 | if (ev._major != CORBA_SYSTEM_EXCEPTION) |
---|
206 | CORBA_Object_release (persist, &ev); |
---|
207 | |
---|
208 | Bonobo_Unknown_unref (persist, &ev); |
---|
209 | CORBA_exception_free (&ev); |
---|
210 | bonobo_object_unref (BONOBO_OBJECT(stream)); |
---|
211 | } |
---|
212 | |
---|
213 | static void |
---|
214 | file_save_as_cb (GtkWidget *widget, Frame *frame) |
---|
215 | { |
---|
216 | Buffer *buffer; |
---|
217 | BonoboViewFrame *view_frame; |
---|
218 | gchar *name; |
---|
219 | |
---|
220 | name = g_strdup(gtk_file_selection_get_filename(app.fs)); |
---|
221 | gtk_widget_destroy (GTK_WIDGET(app.fs)); |
---|
222 | |
---|
223 | if (!(view_frame = get_active_view_frame (frame))) { |
---|
224 | g_warning ("unable to get active view frame"); |
---|
225 | g_free (name); |
---|
226 | return; |
---|
227 | } |
---|
228 | |
---|
229 | if (!(buffer = gtk_object_get_data(GTK_OBJECT(view_frame),"gshell:buffer"))) { |
---|
230 | g_warning ("unable to get active buffer"); |
---|
231 | g_free (name); |
---|
232 | return; |
---|
233 | } |
---|
234 | |
---|
235 | if (bonobo_object_client_has_interface(buffer->server, |
---|
236 | "IDL:Bonobo/PersistFile:1.0", |
---|
237 | NULL)) { |
---|
238 | buffer_save_pf (buffer, name); |
---|
239 | } else if (bonobo_object_client_has_interface(buffer->server, |
---|
240 | "IDL:Bonobo/PersistStream:1.0", |
---|
241 | NULL)) { |
---|
242 | buffer_save_ps (buffer, name); |
---|
243 | } else { |
---|
244 | g_warning ("no storage interface found"); |
---|
245 | } |
---|
246 | |
---|
247 | g_free (name); |
---|
248 | } |
---|
249 | |
---|
250 | typedef struct |
---|
251 | { |
---|
252 | Frame *frame; |
---|
253 | Buffer *buffer; |
---|
254 | } BufferSelect_CbData; |
---|
255 | |
---|
256 | static void |
---|
257 | verb_BufferSelect_cb (BonoboUIComponent *component, BufferSelect_CbData *cb_data, const char *cname) |
---|
258 | { |
---|
259 | Buffer *tmp; |
---|
260 | BonoboViewFrame *view_frame; |
---|
261 | gint pos = -1; |
---|
262 | |
---|
263 | g_message ("set_buffer: `%s'", cname); |
---|
264 | |
---|
265 | if ((view_frame = get_active_view_frame (cb_data->frame))) { |
---|
266 | tmp = gtk_object_get_data(GTK_OBJECT(view_frame), |
---|
267 | "gshell:buffer"); |
---|
268 | if (tmp == cb_data->buffer) return; |
---|
269 | pos = view_remove (cb_data->frame, view_frame); |
---|
270 | } |
---|
271 | buffer_add_view (cb_data->buffer, cb_data->frame, pos); |
---|
272 | } |
---|
273 | |
---|
274 | void |
---|
275 | file_open (Frame *frame, gchar *name) |
---|
276 | { |
---|
277 | const gchar *mime, *bid; |
---|
278 | Buffer *buffer; |
---|
279 | BonoboViewFrame *view_frame; |
---|
280 | BufferSelect_CbData *cb_data; |
---|
281 | gint pos = -1; |
---|
282 | |
---|
283 | if (!g_file_test(name, G_FILE_TEST_ISFILE)) return; |
---|
284 | |
---|
285 | if (!(mime = gnome_mime_type_of_file (name))) { |
---|
286 | g_warning ("unable to detect mime type"); |
---|
287 | return; |
---|
288 | } |
---|
289 | |
---|
290 | #if USING_OAF |
---|
291 | if (!(bid = gnome_mime_get_value (mime, "default_component_iid"))) { |
---|
292 | g_warning ("unable to detect the default_component_iid"); |
---|
293 | printf ("for mime type %s\n",mime); |
---|
294 | return; |
---|
295 | } |
---|
296 | #else |
---|
297 | if (!(bid = gnome_mime_get_value (mime, "bonobo-goad-id"))) { |
---|
298 | g_warning ("unable to detect the bonobo-goad-id"); |
---|
299 | printf ("for mime type %s\n",mime); |
---|
300 | return; |
---|
301 | } |
---|
302 | #endif |
---|
303 | |
---|
304 | if (!(buffer = buffer_create (bid))) { |
---|
305 | g_warning ("unable to create the bonobo component"); |
---|
306 | return; |
---|
307 | } |
---|
308 | |
---|
309 | buffer->name = g_strdup (name); |
---|
310 | buffer->verb_id = ++last_verb_id; |
---|
311 | buffer->verb = g_strdup_printf ("SelectBuffer%d", buffer->verb_id); |
---|
312 | |
---|
313 | cb_data = g_new0 (BufferSelect_CbData, 1); |
---|
314 | cb_data->frame = frame; |
---|
315 | cb_data->buffer = buffer; |
---|
316 | |
---|
317 | bonobo_ui_component_add_verb_full (frame->component, buffer->verb, |
---|
318 | (BonoboUIVerbFn) verb_BufferSelect_cb, |
---|
319 | cb_data, (GDestroyNotify) g_free); |
---|
320 | |
---|
321 | if ((view_frame = get_active_view_frame (frame))) { |
---|
322 | pos = view_remove (frame, view_frame); |
---|
323 | } |
---|
324 | |
---|
325 | if (bonobo_object_client_has_interface(buffer->server, |
---|
326 | "IDL:Bonobo/PersistFile:1.0", |
---|
327 | NULL)) { |
---|
328 | buffer_load_pf (buffer, name); |
---|
329 | } else if (bonobo_object_client_has_interface(buffer->server, |
---|
330 | "IDL:Bonobo/PersistStream:1.0", |
---|
331 | NULL)) { |
---|
332 | buffer_load_ps (buffer, name); |
---|
333 | } else { |
---|
334 | g_warning ("no storage interface found"); |
---|
335 | } |
---|
336 | |
---|
337 | buffer_add_view (buffer, frame, pos); |
---|
338 | update_buffer_menu (); |
---|
339 | } |
---|
340 | |
---|
341 | static void |
---|
342 | file_open_cb (GtkWidget *widget, Frame *frame) |
---|
343 | { |
---|
344 | gchar *name; |
---|
345 | |
---|
346 | name = g_strdup (gtk_file_selection_get_filename (app.fs)); |
---|
347 | gtk_widget_destroy (GTK_WIDGET(app.fs)); |
---|
348 | app.fs = NULL; |
---|
349 | |
---|
350 | if (!name) |
---|
351 | return; |
---|
352 | |
---|
353 | file_open (frame, name); |
---|
354 | |
---|
355 | g_free(name); |
---|
356 | } |
---|
357 | |
---|
358 | static void |
---|
359 | verb_FileOpen_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
360 | { |
---|
361 | g_return_if_fail(component != NULL); |
---|
362 | g_return_if_fail(BONOBO_IS_UI_COMPONENT(component)); |
---|
363 | |
---|
364 | app.fs=GTK_FILE_SELECTION(gtk_file_selection_new(_("Open"))); |
---|
365 | gtk_file_selection_hide_fileop_buttons(app.fs); |
---|
366 | gtk_signal_connect_object(GTK_OBJECT (app.fs->cancel_button), |
---|
367 | "clicked", |
---|
368 | (GtkSignalFunc) gtk_widget_destroy, |
---|
369 | (gpointer)app.fs); |
---|
370 | gtk_signal_connect(GTK_OBJECT(app.fs->ok_button), |
---|
371 | "clicked", |
---|
372 | (GtkSignalFunc)file_open_cb, |
---|
373 | (gpointer) frame); |
---|
374 | |
---|
375 | gtk_widget_show(GTK_WIDGET(app.fs)); |
---|
376 | gtk_window_set_modal (GTK_WINDOW(app.fs), TRUE); |
---|
377 | } |
---|
378 | |
---|
379 | static void |
---|
380 | verb_LaunchControl_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
381 | { |
---|
382 | const gchar *interfaces[] = { "IDL:Bonobo/Control:1.0", NULL }; |
---|
383 | BonoboViewFrame *view_frame; |
---|
384 | BufferSelect_CbData *cb_data; |
---|
385 | GtkWidget *selector; |
---|
386 | Buffer *buffer; |
---|
387 | gchar *oaf_iid, *name; |
---|
388 | gint pos = -1, n; |
---|
389 | |
---|
390 | g_return_if_fail(component != NULL); |
---|
391 | g_return_if_fail(BONOBO_IS_UI_COMPONENT(component)); |
---|
392 | |
---|
393 | selector = bonobo_selector_new (_("Launch component"), interfaces); |
---|
394 | n = gnome_dialog_run (GNOME_DIALOG (selector)); |
---|
395 | |
---|
396 | if (n == -1) |
---|
397 | return; |
---|
398 | |
---|
399 | if (n != 0) { |
---|
400 | gtk_widget_destroy (selector); |
---|
401 | return; |
---|
402 | } |
---|
403 | |
---|
404 | oaf_iid = bonobo_selector_get_selected_id (BONOBO_SELECTOR (selector)); |
---|
405 | name = bonobo_selector_get_selected_name (BONOBO_SELECTOR (selector)); |
---|
406 | |
---|
407 | gtk_widget_destroy (selector); |
---|
408 | |
---|
409 | if (!(buffer = buffer_create_for_control (oaf_iid))) { |
---|
410 | g_warning ("unable to create the bonobo component"); |
---|
411 | return; |
---|
412 | } |
---|
413 | |
---|
414 | buffer->name = g_strdup (name); |
---|
415 | buffer->verb_id = ++last_verb_id; |
---|
416 | buffer->verb = g_strdup_printf ("SelectBuffer%d", buffer->verb_id); |
---|
417 | |
---|
418 | cb_data = g_new0 (BufferSelect_CbData, 1); |
---|
419 | cb_data->frame = frame; |
---|
420 | cb_data->buffer = buffer; |
---|
421 | |
---|
422 | g_free (oaf_iid); |
---|
423 | g_free (name); |
---|
424 | |
---|
425 | bonobo_ui_component_add_verb_full (frame->component, buffer->verb, |
---|
426 | (BonoboUIVerbFn) verb_BufferSelect_cb, |
---|
427 | cb_data, (GDestroyNotify) g_free); |
---|
428 | |
---|
429 | if ((view_frame = get_active_view_frame (frame))) |
---|
430 | pos = view_remove (frame, view_frame); |
---|
431 | |
---|
432 | buffer_add_view (buffer, frame, pos); |
---|
433 | update_buffer_menu (); |
---|
434 | } |
---|
435 | |
---|
436 | static void |
---|
437 | verb_LaunchEmbeddable_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
438 | { |
---|
439 | const gchar *interfaces[] = { "IDL:Bonobo/Embeddable:1.0", NULL }; |
---|
440 | BonoboViewFrame *view_frame; |
---|
441 | BufferSelect_CbData *cb_data; |
---|
442 | GtkWidget *selector; |
---|
443 | Buffer *buffer; |
---|
444 | gchar *oaf_iid, *name; |
---|
445 | gint pos = -1, n; |
---|
446 | |
---|
447 | g_return_if_fail(component != NULL); |
---|
448 | g_return_if_fail(BONOBO_IS_UI_COMPONENT(component)); |
---|
449 | |
---|
450 | selector = bonobo_selector_new (_("Launch component"), interfaces); |
---|
451 | n = gnome_dialog_run (GNOME_DIALOG (selector)); |
---|
452 | |
---|
453 | if (n == -1) |
---|
454 | return; |
---|
455 | |
---|
456 | if (n != 0) { |
---|
457 | gtk_widget_destroy (selector); |
---|
458 | return; |
---|
459 | } |
---|
460 | |
---|
461 | oaf_iid = bonobo_selector_get_selected_id (BONOBO_SELECTOR (selector)); |
---|
462 | name = bonobo_selector_get_selected_name (BONOBO_SELECTOR (selector)); |
---|
463 | |
---|
464 | gtk_widget_destroy (selector); |
---|
465 | |
---|
466 | if (!(buffer = buffer_create (oaf_iid))) { |
---|
467 | g_warning ("unable to create the bonobo component"); |
---|
468 | return; |
---|
469 | } |
---|
470 | |
---|
471 | buffer->name = g_strdup (name); |
---|
472 | buffer->verb_id = ++last_verb_id; |
---|
473 | buffer->verb = g_strdup_printf ("SelectBuffer%d", buffer->verb_id); |
---|
474 | |
---|
475 | cb_data = g_new0 (BufferSelect_CbData, 1); |
---|
476 | cb_data->frame = frame; |
---|
477 | cb_data->buffer = buffer; |
---|
478 | |
---|
479 | g_free (oaf_iid); |
---|
480 | g_free (name); |
---|
481 | |
---|
482 | bonobo_ui_component_add_verb_full (frame->component, buffer->verb, |
---|
483 | (BonoboUIVerbFn) verb_BufferSelect_cb, |
---|
484 | cb_data, (GDestroyNotify) g_free); |
---|
485 | |
---|
486 | if ((view_frame = get_active_view_frame (frame))) |
---|
487 | pos = view_remove (frame, view_frame); |
---|
488 | |
---|
489 | buffer_add_view (buffer, frame, pos); |
---|
490 | update_buffer_menu (); |
---|
491 | } |
---|
492 | |
---|
493 | static void |
---|
494 | file_load (Frame *frame, gchar *name) |
---|
495 | { |
---|
496 | BonoboViewFrame *view_frame; |
---|
497 | Buffer *buffer; |
---|
498 | gint pos = -1; |
---|
499 | |
---|
500 | if (!g_file_test(name, G_FILE_TEST_ISFILE)) return; |
---|
501 | |
---|
502 | if (!(view_frame = get_active_view_frame (frame))) { |
---|
503 | g_warning ("unable to get active view frame"); |
---|
504 | return; |
---|
505 | } |
---|
506 | |
---|
507 | if (!(buffer = gtk_object_get_data(GTK_OBJECT(view_frame),"gshell:buffer"))) { |
---|
508 | g_warning ("unable to get active buffer"); |
---|
509 | return; |
---|
510 | } |
---|
511 | |
---|
512 | if (bonobo_object_client_has_interface(buffer->server, |
---|
513 | "IDL:Bonobo/PersistFile:1.0", |
---|
514 | NULL)) { |
---|
515 | buffer_load_pf (buffer, name); |
---|
516 | } else if (bonobo_object_client_has_interface(buffer->server, |
---|
517 | "IDL:Bonobo/PersistStream:1.0", |
---|
518 | NULL)) { |
---|
519 | buffer_load_ps (buffer, name); |
---|
520 | } else { |
---|
521 | g_warning ("no storage interface found"); |
---|
522 | } |
---|
523 | |
---|
524 | pos = view_remove (frame, view_frame); |
---|
525 | |
---|
526 | g_free (buffer->name); |
---|
527 | buffer->name = g_strdup (name); |
---|
528 | |
---|
529 | buffer_add_view (buffer, frame, pos); |
---|
530 | update_buffer_menu (); |
---|
531 | } |
---|
532 | |
---|
533 | static void |
---|
534 | file_load_cb (GtkWidget *widget, Frame *frame) |
---|
535 | { |
---|
536 | gchar *name; |
---|
537 | |
---|
538 | name = g_strdup(gtk_file_selection_get_filename(app.fs)); |
---|
539 | gtk_widget_destroy (GTK_WIDGET(app.fs)); |
---|
540 | app.fs = NULL; |
---|
541 | if (!name) return; |
---|
542 | |
---|
543 | file_load(frame, name); |
---|
544 | g_free(name); |
---|
545 | } |
---|
546 | |
---|
547 | static void |
---|
548 | verb_FileLoad_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
549 | { |
---|
550 | g_return_if_fail(component != NULL); |
---|
551 | g_return_if_fail(BONOBO_IS_UI_COMPONENT(component)); |
---|
552 | |
---|
553 | app.fs=GTK_FILE_SELECTION(gtk_file_selection_new(_("Load"))); |
---|
554 | gtk_file_selection_hide_fileop_buttons(app.fs); |
---|
555 | gtk_signal_connect_object(GTK_OBJECT (app.fs->cancel_button), |
---|
556 | "clicked", |
---|
557 | (GtkSignalFunc) gtk_widget_destroy, |
---|
558 | (gpointer)app.fs); |
---|
559 | gtk_signal_connect(GTK_OBJECT(app.fs->ok_button), |
---|
560 | "clicked", |
---|
561 | (GtkSignalFunc)file_load_cb, |
---|
562 | (gpointer) frame); |
---|
563 | |
---|
564 | gtk_widget_show(GTK_WIDGET(app.fs)); |
---|
565 | gtk_window_set_modal (GTK_WINDOW(app.fs), TRUE); |
---|
566 | } |
---|
567 | |
---|
568 | static void |
---|
569 | verb_FileSave_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
570 | { |
---|
571 | Buffer *buffer; |
---|
572 | BonoboViewFrame *view_frame; |
---|
573 | |
---|
574 | if (!(view_frame = get_active_view_frame (frame))) { |
---|
575 | g_warning ("unable to get active view frame"); |
---|
576 | return; |
---|
577 | } |
---|
578 | |
---|
579 | if (!(buffer = gtk_object_get_data(GTK_OBJECT(view_frame),"gshell:buffer"))) { |
---|
580 | g_warning ("unable to get active buffer"); |
---|
581 | return; |
---|
582 | } |
---|
583 | |
---|
584 | if (bonobo_object_client_has_interface(buffer->server, |
---|
585 | "IDL:Bonobo/PersistFile:1.0", |
---|
586 | NULL)) { |
---|
587 | buffer_save_pf (buffer, buffer->name); |
---|
588 | } else if (bonobo_object_client_has_interface(buffer->server, |
---|
589 | "IDL:Bonobo/PersistStream:1.0", |
---|
590 | NULL)) { |
---|
591 | buffer_save_ps (buffer, buffer->name); |
---|
592 | } else { |
---|
593 | g_warning ("no storage interface found"); |
---|
594 | } |
---|
595 | } |
---|
596 | |
---|
597 | static void |
---|
598 | verb_FileSaveAs_cb (BonoboUIComponent *component, Frame *frame, const char *cname) |
---|
599 | { |
---|
600 | BonoboViewFrame *view_frame; |
---|
601 | |
---|
602 | if (!(view_frame = get_active_view_frame (frame))) return; |
---|
603 | |
---|
604 | app.fs=GTK_FILE_SELECTION(gtk_file_selection_new(_("Save As"))); |
---|
605 | gtk_file_selection_hide_fileop_buttons(app.fs); |
---|
606 | gtk_signal_connect_object(GTK_OBJECT (app.fs->cancel_button), |
---|
607 | "clicked", |
---|
608 | (GtkSignalFunc) gtk_widget_destroy, |
---|
609 | (gpointer)app.fs); |
---|
610 | gtk_signal_connect(GTK_OBJECT(app.fs->ok_button), |
---|
611 | "clicked", |
---|
612 | (GtkSignalFunc)file_save_as_cb, |
---|
613 | (gpointer) frame); |
---|
614 | |
---|
615 | gtk_widget_show(GTK_WIDGET(app.fs)); |
---|
616 | gtk_window_set_modal (GTK_WINDOW(app.fs), TRUE); |
---|
617 | } |
---|
618 | |
---|
619 | BonoboUIVerb inout_verbs[] = { |
---|
620 | BONOBO_UI_UNSAFE_VERB ("FileOpen", verb_FileOpen_cb), |
---|
621 | BONOBO_UI_UNSAFE_VERB ("LaunchControl", verb_LaunchControl_cb), |
---|
622 | BONOBO_UI_UNSAFE_VERB ("LaunchEmbeddable", verb_LaunchEmbeddable_cb), |
---|
623 | BONOBO_UI_UNSAFE_VERB ("FileLoad", verb_FileLoad_cb), |
---|
624 | BONOBO_UI_UNSAFE_VERB ("FileSave", verb_FileSave_cb), |
---|
625 | BONOBO_UI_UNSAFE_VERB ("FileSaveAs", verb_FileSaveAs_cb), |
---|
626 | BONOBO_UI_VERB_END |
---|
627 | }; |
---|