Extract translatable strings from some more files
[synfig.git] / synfig-studio / trunk / src / gtkmm / toolbox.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file toolbox.cpp
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === H E A D E R S ======================================================= */
27
28 #ifdef USING_PCH
29 #       include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 #       include <config.h>
33 #endif
34
35 #include <gtk/gtk.h>
36 #include <gtkmm/uimanager.h>
37
38 #include <gtkmm/ruler.h>
39 #include <gtkmm/arrow.h>
40 #include <gtkmm/image.h>
41 #include <gdkmm/pixbufloader.h>
42 #include <gtkmm/viewport.h>
43 #include <gtkmm/adjustment.h>
44 #include <gtkmm/scrolledwindow.h>
45 #include <gtkmm/table.h>
46 #include <gtkmm/statusbar.h>
47 #include <gtkmm/menubar.h>
48 #include <gtkmm/menu.h>
49 #include <gtkmm/button.h>
50 #include <gtkmm/toolbar.h>
51 #include <gtkmm/box.h>
52 #include <gtkmm/image.h>
53 #include <gtkmm/stock.h>
54 #include <gtkmm/handlebox.h>
55
56 #include <gtkmm/inputdialog.h>
57
58 #include <sigc++/signal.h>
59 #include <sigc++/hide.h>
60 #include <sigc++/slot.h>
61 #include <sigc++/retype_return.h>
62 #include <sigc++/retype.h>
63
64 #include <sstream>
65
66 #include "toolbox.h"
67 #include "instance.h"
68 #include "app.h"
69 #include "canvasview.h"
70 #include "dialog_gradient.h"
71 #include "dialog_color.h"
72 #include "dialog_tooloptions.h"
73 #include "dialog_preview.h"
74 #include "dockable.h"
75 #include "dockmanager.h"
76 #include "dockdialog.h"
77
78 #include "widget_defaults.h"
79
80 #include <synfigapp/main.h>
81
82 #include "general.h"
83
84 #endif
85
86 using namespace std;
87 using namespace etl;
88 using namespace synfig;
89 using namespace studio;
90 using namespace sigc;
91
92 /* === M A C R O S ========================================================= */
93
94 #define GRAB_HINT_DATA(y,default)       { \
95                 String x; \
96                 if(synfigapp::Main::settings().get_value(String("pref.")+y+"_hints",x)) \
97                 { \
98                         set_type_hint((Gdk::WindowTypeHint)atoi(x.c_str()));    \
99                 } else {\
100                         set_type_hint(default); \
101                 } \
102         }
103
104 /* === G L O B A L S ======================================================= */
105
106 /* === P R O C E D U R E S ================================================= */
107
108 /* === M E T H O D S ======================================================= */
109
110 #define TOGGLE_TOOLBOX_BUTTON(button,stockid,tooltip)   \
111         button = manage(new class Gtk::ToggleButton()); \
112         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)));    \
113         button->add(*icon);     \
114         tooltips.set_tip(*button,tooltip);      \
115         icon->show();   \
116         button->show()
117
118 #define TOOLBOX_BUTTON(button,stockid,tooltip)  \
119         button = manage(new class Gtk::Button());       \
120         icon=manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)));    \
121         button->add(*icon);     \
122         tooltips.set_tip(*button,tooltip);      \
123         icon->show();   \
124         button->show()
125
126 #define ADD_TOOLBOX_BUTTON(button,stockid,tooltip)      Gtk::Button *TOOLBOX_BUTTON(button,stockid,tooltip)
127
128 void
129 save_selected_instance()
130 {
131         if(!studio::App::get_selected_instance())
132         {
133                 App::dialog_error_blocking(_("Cannot save"),_("Nothing to save"));
134                 return;
135         }
136
137         studio::App::get_selected_instance()->save();
138 }
139
140 void
141 save_as_selected_instance()
142 {
143         if(!studio::App::get_selected_instance())
144         {
145                 App::dialog_error_blocking(_("Cannot save as"),_("Nothing to save"));
146                 return;
147         }
148
149         studio::App::get_selected_instance()->dialog_save_as();
150 }
151
152 void
153 save_all()
154 {
155         std::list<etl::handle<Instance> >::iterator iter;
156         for(iter=App::instance_list.begin();iter!=App::instance_list.end();iter++)
157                 (*iter)->save();
158 }
159
160 void
161 close_selected_instance()
162 {
163         etl::handle<studio::Instance> instance=studio::App::get_selected_instance();
164
165         if(!instance)
166         {
167                 App::dialog_error_blocking(_("Cannot close"),_("Nothing to close"));
168                 return;
169         }
170
171         instance->safe_close();
172
173         //assert(instance.unique());
174 }
175
176
177 static void
178 show_dialog_input()
179 {
180         App::dialog_input->present();
181 }
182
183 void _create_stock_dialog1()
184 {
185         DockDialog* dock_dialog(new DockDialog);
186         dock_dialog->set_contents("canvases history");
187         dock_dialog->set_composition_selector(true);
188         dock_dialog->present();
189 }
190 void _create_stock_dialog2()
191 {
192         DockDialog* dock_dialog(new DockDialog);
193         dock_dialog->set_contents("layers children keyframes | params");
194         dock_dialog->present();
195 }
196
197 Toolbox::Toolbox():
198         Gtk::Window(Gtk::WINDOW_TOPLEVEL),
199         dialog_settings(this,"toolbox")
200 {
201         GRAB_HINT_DATA(
202                 "toolbox",
203 //#ifdef __APPLE__
204                 Gdk::WINDOW_TYPE_HINT_NORMAL
205 //#else
206 //              Gdk::WINDOW_TYPE_HINT_UTILITY
207 //#endif
208         );
209         set_keep_above(false);
210         set_role("toolbox");
211
212
213
214         recent_files_menu= manage(new class Gtk::Menu());
215
216         Gtk::Menu       *filemenu       =manage(new class Gtk::Menu());
217
218         dock_dialogs=manage(new class Gtk::Menu());
219
220         dock_dialogs->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Vertical Dock: Canvases, History"),sigc::ptr_fun(_create_stock_dialog1)));
221         dock_dialogs->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Horizontal Dock: Layers, Children, Params"),sigc::ptr_fun(_create_stock_dialog2)));
222         dock_dialogs->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
223         dock_dialogs->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Reset Windows to Original Layout"),sigc::ptr_fun(App::reset_initial_window_configuration)));
224         dock_dialogs->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
225
226
227         filemenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::NEW,
228                 sigc::ptr_fun(&studio::App::new_instance)));
229         filemenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::OPEN,
230                 sigc::bind(sigc::ptr_fun(&studio::App::dialog_open), "")));
231
232         filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Open Recent"),*recent_files_menu));
233
234         filemenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-saveall"),
235                 sigc::ptr_fun(save_all)));
236         filemenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::CLOSE,
237                 sigc::ptr_fun(close_selected_instance)));
238         filemenu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
239         filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Panels"),*dock_dialogs));
240
241         //filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Canvas Browser..."),
242         //      sigc::mem_fun(studio::App::show_comp_view)));
243         //filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Gradient Editor..."),
244         //      sigc::mem_fun(show_dialog_gradient)));
245         //filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Tool Options"),
246         //      sigc::mem_fun(show_dialog_tool_options)));
247         //filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Colors..."),
248         //      sigc::mem_fun(show_dialog_color)));
249         //filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Color Palette..."),
250         //      sigc::mem_fun(show_dialog_palette)));
251         filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Input Devices..."),
252                 sigc::ptr_fun(&show_dialog_input)));
253         filemenu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Setup..."),
254                 sigc::ptr_fun(&studio::App::show_setup)));
255
256         filemenu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
257         filemenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID(Gtk::Stock::QUIT),
258                 sigc::ptr_fun(studio::App::quit)));
259
260 #define WIKI(title,page)                                                                                        \
261         helpmenu->items().push_back(Gtk::Menu_Helpers::MenuElem(title,  \
262                 sigc::bind(sigc::ptr_fun(&studio::App::open_url),String("http://synfig.org")+page)))
263
264         Gtk::Menu       *helpmenu = manage(new class Gtk::Menu());
265         helpmenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::HELP, sigc::ptr_fun(studio::App::dialog_help)));
266         helpmenu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
267
268         /* TRANSLATORS: Help menu entry */ WIKI(_("Synfig Wiki"),                               /* TRANSLATORS: a wiki page */ _("/Main_Page")                          );
269         /* TRANSLATORS: Help menu entry */ WIKI(_("Tutorials"),                                 /* TRANSLATORS: a wiki page */ _("/Tutorials")                          );
270         /* TRANSLATORS: Help menu entry */ WIKI(_("Frequently Asked Questions"),/* TRANSLATORS: a wiki page */ _("/FAQ")                                        );
271         /* TRANSLATORS: Help menu entry */ WIKI(_("Get Support"),                               /* TRANSLATORS: a wiki page */ _("/Communication")                      );
272         /* TRANSLATORS: Help menu entry */ WIKI(_("Keyboard Shortcuts"),                /* TRANSLATORS: a wiki page */ _("/Keyboard_Shortcuts")         );
273         /* TRANSLATORS: Help menu entry */ WIKI(_("Mouse Shortcuts"),                   /* TRANSLATORS: a wiki page */ _("/Mouse_Shortcuts")            );
274         /* TRANSLATORS: Help menu entry */ WIKI(_("All Pages"), "/Special:Allpages" );
275
276         helpmenu->items().push_back(Gtk::Menu_Helpers::SeparatorElem());
277         helpmenu->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-about"),
278                 sigc::ptr_fun(studio::App::dialog_about)));
279
280         Gtk::MenuBar *menubar1 = manage(new class Gtk::MenuBar());
281         menubar1->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_File"),*filemenu));
282         menubar1->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Help"),*helpmenu));
283
284
285         menubar1->show();
286
287         Gtk::Image *icon;
288
289         ADD_TOOLBOX_BUTTON(button_new,"gtk-new",_("New..."));
290         ADD_TOOLBOX_BUTTON(button_open,"gtk-open",_("Open..."));
291         ADD_TOOLBOX_BUTTON(button_save,"gtk-save",_("Save"));
292         ADD_TOOLBOX_BUTTON(button_saveas,"gtk-save-as",_("Save As..."));
293         ADD_TOOLBOX_BUTTON(button_save_all,"synfig-saveall",_("Save All"));
294         TOOLBOX_BUTTON(button_undo,"gtk-undo",_("Undo"));
295         TOOLBOX_BUTTON(button_redo,"gtk-redo",_("Redo"));
296         ADD_TOOLBOX_BUTTON(button_setup,"gtk-properties",_("Setup"));
297         ADD_TOOLBOX_BUTTON(button_about,"synfig-about",_("About Synfig Studio"));
298         ADD_TOOLBOX_BUTTON(button_help,"gtk-help",_("Help"));
299
300         button_setup->signal_clicked().connect(sigc::ptr_fun(studio::App::show_setup));
301         button_about->signal_clicked().connect(sigc::ptr_fun(studio::App::dialog_about));
302         button_help->signal_clicked().connect(sigc::ptr_fun(studio::App::dialog_help));
303         button_new->signal_clicked().connect(sigc::ptr_fun(studio::App::new_instance));
304         button_open->signal_clicked().connect(sigc::bind(sigc::ptr_fun(studio::App::dialog_open), ""));
305         button_save->signal_clicked().connect(sigc::ptr_fun(save_selected_instance));
306         button_saveas->signal_clicked().connect(sigc::ptr_fun(save_as_selected_instance));
307         button_save_all->signal_clicked().connect(sigc::ptr_fun(save_all));
308         button_undo->signal_clicked().connect(sigc::ptr_fun(studio::App::undo));
309         button_redo->signal_clicked().connect(sigc::ptr_fun(studio::App::redo));
310
311         // Create the file button cluster
312         Gtk::Table *file_buttons=manage(new class Gtk::Table());
313
314         file_buttons->attach(*button_new,      0,1, 0,1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
315         file_buttons->attach(*button_open,     1,2, 0,1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
316         file_buttons->attach(*button_save,     2,3, 0,1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
317         file_buttons->attach(*button_saveas,   3,4, 0,1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
318         file_buttons->attach(*button_save_all, 4,5, 0,1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
319
320         file_buttons->attach(*button_undo,     0,1, 1,2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
321         file_buttons->attach(*button_redo,     1,2, 1,2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
322         file_buttons->attach(*button_setup,    2,3, 1,2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
323         file_buttons->attach(*button_about,    3,4, 1,2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
324         file_buttons->attach(*button_help,     4,5, 1,2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
325
326         file_buttons->show();
327
328         tool_table=manage(new class Gtk::Table());
329         tool_table->show();
330         Gtk::HandleBox* handle_tools(manage(new Gtk::HandleBox()));
331         handle_tools->add(*tool_table);
332         handle_tools->show();
333         handle_tools->set_handle_position(Gtk::POS_TOP);
334         handle_tools->set_snap_edge(Gtk::POS_TOP);
335
336         Widget_Defaults* widget_defaults(manage(new Widget_Defaults()));
337         widget_defaults->show();
338         Gtk::HandleBox* handle_defaults(manage(new Gtk::HandleBox()));
339         handle_defaults->add(*widget_defaults);
340         handle_defaults->show();
341         handle_defaults->set_handle_position(Gtk::POS_TOP);
342         handle_defaults->set_snap_edge(Gtk::POS_TOP);
343
344         // Create the toplevel table
345         Gtk::Table *table1 = manage(new class Gtk::Table(1, 2, false));
346         table1->set_row_spacings(0);
347         table1->set_col_spacings(0);
348         table1->attach(*menubar1,        0,1, 0,1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 0, 0);
349         table1->attach(*file_buttons,    0,1, 1,2, Gtk::FILL|Gtk::EXPAND,Gtk::EXPAND|Gtk::FILL, 0, 0);
350         //table1->attach(*manage(new Gtk::Label(_("Tools"))), 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND,Gtk::EXPAND|Gtk::FILL, 0, 0);
351         table1->attach(*handle_tools,    0,1, 3,4, Gtk::FILL|Gtk::EXPAND,Gtk::EXPAND|Gtk::FILL, 0, 0);
352         table1->attach(*handle_defaults, 0,1, 4,5, Gtk::FILL|Gtk::EXPAND,Gtk::EXPAND|Gtk::FILL, 0, 0);
353         table1->show_all();
354
355
356
357         // Set the parameters for this window
358         add(*table1);
359         set_title(_("Synfig Studio"));
360         set_modal(false);
361         property_window_position().set_value(Gtk::WIN_POS_NONE);
362         signal_delete_event().connect(sigc::ptr_fun(App::shutdown_request));
363         set_resizable(false);
364
365
366
367         App::signal_instance_selected().connect(
368                 sigc::hide(
369                         sigc::mem_fun(*this,&studio::Toolbox::update_undo_redo)
370                 )
371         );
372
373         App::signal_recent_files_changed().connect(
374                         sigc::mem_fun(*this,&studio::Toolbox::on_recent_files_changed)
375         );
376
377         button_undo->set_sensitive(false);
378         button_redo->set_sensitive(false);
379
380         std::list<Gtk::TargetEntry> listTargets;
381         listTargets.push_back( Gtk::TargetEntry("text/plain") );
382         listTargets.push_back( Gtk::TargetEntry("image") );
383 //      listTargets.push_back( Gtk::TargetEntry("image/x-sif") );
384
385         drag_dest_set(listTargets);
386         signal_drag_data_received().connect( sigc::mem_fun(*this, &studio::Toolbox::on_drop_drag_data_received) );
387
388         App::dock_manager->signal_dockable_registered().connect(sigc::mem_fun(*this,&Toolbox::dockable_registered));
389
390         changing_state_=false;
391
392
393         add_accel_group(App::ui_manager()->get_accel_group());
394
395         App::signal_present_all().connect(sigc::mem_fun0(*this,&Toolbox::present));
396 }
397
398 Toolbox::~Toolbox()
399 {
400         hide();
401         //studio::App::cb.task(_("Toolbox: I was nailed!"));
402         //studio::App::quit();
403
404         if(studio::App::toolbox==this)
405                 studio::App::toolbox=NULL;
406
407 }
408
409 void
410 Toolbox::set_active_state(const synfig::String& statename)
411 {
412         std::map<synfig::String,Gtk::ToggleButton *>::iterator iter;
413
414         changing_state_=true;
415
416         synfigapp::Main::set_state(statename);
417
418         try
419         {
420
421                 for(iter=state_button_map.begin();iter!=state_button_map.end();++iter)
422                 {
423                         if(iter->first==statename)
424                         {
425                                 if(!iter->second->get_active())
426                                         iter->second->set_active(true);
427                         }
428                         else
429                         {
430                                 if(iter->second->get_active())
431                                         iter->second->set_active(false);
432                         }
433                 }
434         }
435         catch(...)
436         {
437                 changing_state_=false;
438                 throw;
439         }
440         changing_state_=false;
441 }
442
443 void
444 Toolbox::change_state(const synfig::String& statename)
445 {
446         etl::handle<studio::CanvasView> canvas_view(studio::App::get_selected_canvas_view());
447         if(canvas_view)
448         {
449                 if(statename==canvas_view->get_smach().get_state_name())
450                 {
451                         return;
452                 }
453
454                 if(state_button_map.count(statename))
455                 {
456                         state_button_map[statename]->clicked();
457                 }
458                 else
459                 {
460                         synfig::error("Unknown state \"%s\"",statename.c_str());
461                 }
462         }
463 }
464
465 void
466 Toolbox::change_state_(const Smach::state_base *state)
467 {
468         if(changing_state_)
469                 return;
470         changing_state_=true;
471
472         try
473         {
474                 etl::handle<studio::CanvasView> canvas_view(studio::App::get_selected_canvas_view());
475                 if(canvas_view)
476                 {
477                         if(state->get_name()==String("normal"))
478                         {
479                                 canvas_view->get_smach().egress();
480                         }
481                         else
482                         {
483                                 canvas_view->get_smach().enter(state);
484                         }
485                 }
486                 else
487                         refresh();
488         }
489         catch(...)
490         {
491                 changing_state_=false;
492                 throw;
493         }
494
495         changing_state_=false;
496 }
497
498 void
499 Toolbox::add_state(const Smach::state_base *state)
500 {
501         Gtk::Image *icon;
502
503         assert(state);
504
505         String name=state->get_name();
506
507         Gtk::StockItem stock_item;
508         Gtk::Stock::lookup(Gtk::StockID("synfig-"+name),stock_item);
509
510         Gtk::ToggleButton* button;
511         button=manage(new class Gtk::ToggleButton());
512
513         icon=manage(new Gtk::Image(stock_item.get_stock_id(),Gtk::IconSize(4)));
514         button->add(*icon);
515         tooltips.set_tip(*button,stock_item.get_label());
516         icon->show();
517         button->show();
518
519         int row=state_button_map.size()/5;
520         int col=state_button_map.size()%5;
521
522         tool_table->attach(*button,col,col+1,row,row+1, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
523
524         state_button_map[name]=button;
525
526         button->signal_clicked().connect(
527                 sigc::bind(
528                         sigc::mem_fun(*this,&studio::Toolbox::change_state_),
529                         state
530                 )
531         );
532
533         refresh();
534 }
535
536
537 void
538 Toolbox::update_undo_redo()
539 {
540         etl::handle<Instance> instance=App::get_selected_instance();
541         if(instance)
542         {
543                 button_undo->set_sensitive(instance->get_undo_status());
544                 button_redo->set_sensitive(instance->get_redo_status());
545         }
546
547         // This should probably go elsewhere, but it should
548         // work fine here with no troubles.
549         // These next several lines just adjust the tool buttons
550         // so that they are only clickable when they should be.
551         if(instance && App::get_selected_canvas_view())
552         {
553                 std::map<synfig::String,Gtk::ToggleButton *>::iterator iter;
554
555                 for(iter=state_button_map.begin();iter!=state_button_map.end();++iter)
556                         iter->second->set_sensitive(true);
557         }
558         else
559         {
560                 std::map<synfig::String,Gtk::ToggleButton *>::iterator iter;
561
562                 for(iter=state_button_map.begin();iter!=state_button_map.end();++iter)
563                         iter->second->set_sensitive(false);
564         }
565
566         etl::handle<CanvasView> canvas_view=App::get_selected_canvas_view();
567         if(canvas_view && canvas_view->get_smach().get_state_name())
568         {
569                 set_active_state(canvas_view->get_smach().get_state_name());
570         }
571         else
572                 set_active_state("none");
573
574 }
575
576 void
577 Toolbox::on_recent_files_changed()
578 {
579         while(recent_files_menu->get_children().size())
580                 recent_files_menu->remove(**recent_files_menu->get_children().begin());
581
582         list<string>::const_iterator iter;
583         for(iter=App::get_recent_files().begin();iter!=App::get_recent_files().end();iter++)
584         {
585                 string raw = basename(*iter), quoted;
586                 size_t pos = 0, last_pos = 0;
587
588                 // replace _ in filenames by __ or it won't show up in the menu
589                 for (pos = last_pos = 0; (pos = raw.find('_', pos)) != string::npos; last_pos = pos)
590                         quoted += raw.substr(last_pos, ++pos - last_pos) + '_';
591                 quoted += raw.substr(last_pos);
592
593                 recent_files_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(quoted,
594                         sigc::hide_return(sigc::bind(sigc::ptr_fun(&App::open),*iter))
595                 ));
596         }
597
598         // HACK
599         show();
600 }
601
602 void
603 Toolbox::on_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int /*x*/, int /*y*/, const Gtk::SelectionData& selection_data_, guint /*info*/, guint time)
604 {
605         // We will make this true once we have a solid drop
606         bool success(false);
607
608         if ((selection_data_.get_length() >= 0) && (selection_data_.get_format() == 8))
609         {
610                 synfig::String selection_data((gchar *)(selection_data_.get_data()));
611
612                 // For some reason, GTK hands us a list of URLs separated
613                 // by not only Carriage-Returns, but also Line-Feeds.
614                 // Line-Feeds will mess us up. Remove all the line-feeds.
615                 while(selection_data.find_first_of('\r')!=synfig::String::npos)
616                         selection_data.erase(selection_data.begin()+selection_data.find_first_of('\r'));
617
618                 std::stringstream stream(selection_data);
619
620                 while(stream)
621                 {
622                         synfig::String filename,URI;
623                         getline(stream,filename);
624
625                         // If we don't have a filename, move on.
626                         if(filename.empty())
627                                 continue;
628
629                         // Make sure this URL is of the "file://" type.
630                         URI=String(filename.begin(),filename.begin()+sizeof("file://")-1);
631                         if(URI!="file://")
632                         {
633                                 synfig::warning("Unknown URI (%s) in \"%s\"",URI.c_str(),filename.c_str());
634                                 continue;
635                         }
636
637                         // Strip the "file://" part from the filename
638                         filename=synfig::String(filename.begin()+sizeof("file://")-1,filename.end());
639
640                         synfig::info("Attempting to open "+filename);
641                         if(App::open(filename))
642                                 success=true;
643                         else
644                                 synfig::error("Drop failed: Unable to open "+filename);
645                 }
646         }
647         else
648                 synfig::error("Drop failed: bad selection data");
649
650         // Finish the drag
651         context->drag_finish(success, false, time);
652 }
653
654 void
655 Toolbox::dockable_registered(Dockable* x)
656 {
657         dock_dialogs->items().push_back(
658                 Gtk::Menu_Helpers::MenuElem(
659                         x->get_local_name(),
660                         sigc::mem_fun(
661                                 *x,
662                                 &Dockable::present
663                         )
664                 )
665         );
666 }