/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3109 by schoenebeck, Sun Feb 12 16:35:03 2017 UTC revision 3197 by schoenebeck, Sat May 20 17:15:36 2017 UTC
# Line 35  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
38    #include <gtkmm/stock.h>
39  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
40  #include <gtkmm/main.h>  #include <gtkmm/main.h>
41  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
42    #include <gtkmm/accelmap.h>
43  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
44  #include "wrapLabel.hh"  #include "wrapLabel.hh"
45  #endif  #endif
# Line 58  Line 60 
60  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
61  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
62  #include "gfx/builtinpix.h"  #include "gfx/builtinpix.h"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    
66  MainWindow::MainWindow() :  MainWindow::MainWindow() :
67      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 153  MainWindow::MainWindow() : Line 157  MainWindow::MainWindow() :
157      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
158    
159      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
160      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
161                       sigc::mem_fun(                       sigc::mem_fun(
162                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
163      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
164                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
165        action->property_label() = action->property_label() + "...";
166        actionGroup->add(action,
167                       sigc::mem_fun(                       sigc::mem_fun(
168                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
169      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
172      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
173        action->property_label() = action->property_label() + "...";
174        actionGroup->add(action,
175                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
176                       sigc::mem_fun(                       sigc::mem_fun(
177                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
178      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
179                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
180                       sigc::mem_fun(                       sigc::mem_fun(
181                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
182      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
183                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
184                       sigc::mem_fun(                       sigc::mem_fun(
185                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
186      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 185  MainWindow::MainWindow() : Line 191  MainWindow::MainWindow() :
191                                           _("_Script Slots...")),                                           _("_Script Slots...")),
192                       sigc::mem_fun(                       sigc::mem_fun(
193                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
194      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
195                       sigc::mem_fun(                       sigc::mem_fun(
196                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
197      actionGroup->add(      actionGroup->add(
# Line 198  MainWindow::MainWindow() : Line 203  MainWindow::MainWindow() :
203          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
204      );      );
205      actionGroup->add(      actionGroup->add(
206          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
207          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
208      );      );
209      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
210    
211      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
212    
213        const Gdk::ModifierType primaryModifierKey =
214    #if defined(__APPLE__)
215        Gdk::META_MASK; // Cmd key on Mac
216    #else
217        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
218    #endif
219    
220        actionGroup->add(Gtk::Action::create("CopyDimRgn",
221                                             _("Copy selected dimension region")),
222                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("PasteDimRgn",
226                                             _("Paste dimension region")),
227                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
228                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
229    
230        actionGroup->add(Gtk::Action::create("AdjustClipboard",
231                                             _("Adjust Clipboard Content")),
232                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
233                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
236                                             _("Select Previous Region")),
237                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextRegion",
241                                             _("Select Next Region")),
242                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
243                         sigc::mem_fun(*this, &MainWindow::select_next_region));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
246                                             _("Select Previous Dimension Region Zone")),
247                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
251                                             _("Select Next Dimension Region Zone")),
252                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
254    
255        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
256                                             _("Select Previous Dimension")),
257                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
259    
260        actionGroup->add(Gtk::Action::create("SelectNextDimension",
261                                             _("Select Next Dimension")),
262                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
264    
265        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
266                                             _("Add Previous Dimension Region Zone to Selection")),
267                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
268                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
269    
270        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
271                                             _("Add Next Dimension Region Zone to Selection")),
272                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
273                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
274    
275      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
276          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
277      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 221  MainWindow::MainWindow() : Line 288  MainWindow::MainWindow() :
288      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
289    
290    
291      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
292    
293    
294        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
295      toggle_action =      toggle_action =
296          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
297      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 248  MainWindow::MainWindow() : Line 318  MainWindow::MainWindow() :
318          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
319      );                      );                
320    
321      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
322      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
323                                             action->property_label()));
324        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
325                       sigc::mem_fun(                       sigc::mem_fun(
326                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
327      actionGroup->add(      actionGroup->add(
# Line 261  MainWindow::MainWindow() : Line 333  MainWindow::MainWindow() :
333          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
334      );      );
335      actionGroup->add(      actionGroup->add(
336          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
337          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
338      );      );
339    
# Line 308  MainWindow::MainWindow() : Line 380  MainWindow::MainWindow() :
380    
381      // sample right-click popup actions      // sample right-click popup actions
382      actionGroup->add(      actionGroup->add(
383          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
384          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
385      );      );
386      actionGroup->add(      actionGroup->add(
# Line 320  MainWindow::MainWindow() : Line 392  MainWindow::MainWindow() :
392          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
393      );      );
394      actionGroup->add(      actionGroup->add(
395          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
396          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
397      );      );
398      actionGroup->add(      actionGroup->add(
# Line 356  MainWindow::MainWindow() : Line 428  MainWindow::MainWindow() :
428          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
429      );      );
430      actionGroup->add(      actionGroup->add(
431          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
432          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
433      );      );
434    
# Line 379  MainWindow::MainWindow() : Line 451  MainWindow::MainWindow() :
451          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
452          "    </menu>"          "    </menu>"
453          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
454            "      <menuitem action='CopyDimRgn'/>"
455            "      <menuitem action='AdjustClipboard'/>"
456            "      <menuitem action='PasteDimRgn'/>"
457            "      <separator/>"
458            "      <menuitem action='SelectPrevRegion'/>"
459            "      <menuitem action='SelectNextRegion'/>"
460            "      <separator/>"
461            "      <menuitem action='SelectPrevDimension'/>"
462            "      <menuitem action='SelectNextDimension'/>"
463            "      <menuitem action='SelectPrevDimRgnZone'/>"
464            "      <menuitem action='SelectNextDimRgnZone'/>"
465            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
466            "      <menuitem action='SelectAddNextDimRgnZone'/>"
467            "      <separator/>"
468          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
469          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
470          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
471          "    </menu>"          "    </menu>"
472            "    <menu action='MenuMacro'>"
473            "    </menu>"
474          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
475          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
476          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 566  MainWindow::MainWindow() : Line 654  MainWindow::MainWindow() :
654      // Add the TreeView's view columns:      // Add the TreeView's view columns:
655      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
656      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
657        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
658      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
659            
660      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 741  MainWindow::MainWindow() : Line 830  MainWindow::MainWindow() :
830    
831      // select 'Instruments' tab by default      // select 'Instruments' tab by default
832      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
833      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
834    
835        Gtk::Clipboard::get()->signal_owner_change().connect(
836            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
837        );
838        updateClipboardPasteAvailable();
839        updateClipboardCopyAvailable();
840    
841        // setup macros and their keyboard accelerators
842        {
843            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
844                uiManager->get_widget("/MenuBar/MenuMacro")
845            )->get_submenu();
846    
847            const Gdk::ModifierType primaryModifierKey =
848    #if defined(__APPLE__)
849                Gdk::META_MASK; // Cmd key on Mac
850    #else
851                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
852    #endif
853    
854            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
855            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
856            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
857            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
858            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
859            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
867            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
868    
869            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
870            menuMacro->set_accel_group(accelGroup);
871    
872            updateMacroMenu();
873        }
874  }  }
875    
876  MainWindow::~MainWindow()  MainWindow::~MainWindow()
877  {  {
878  }  }
879    
880    void MainWindow::updateMacroMenu() {
881        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
882            uiManager->get_widget("/MenuBar/MenuMacro")
883        )->get_submenu();
884    
885        // remove all entries from "Macro" menu
886        {
887            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
888            for (int i = 0; i < children.size(); ++i) {
889                Gtk::Widget* child = children[i];
890                menuMacro->remove(*child);
891                delete child;
892            }
893        }
894    
895        // (re)load all macros from config file
896        try {
897            Settings::singleton()->loadMacros(m_macros);
898        } catch (Serialization::Exception e) {
899            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
900        } catch (...) {
901            std::cerr << "Unknown exception while loading macros!" << std::endl;
902        }
903    
904        // add all configured macros as menu items to the "Macro" menu
905        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
906            const Serialization::Archive& macro = m_macros[iMacro];
907            std::string name =
908                macro.name().empty() ?
909                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
910            Gtk::MenuItem* item = new Gtk::MenuItem(name);
911            item->signal_activate().connect(
912                sigc::bind(
913                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
914                )
915            );
916            menuMacro->append(*item);
917            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
918            Glib::ustring comment = macro.comment();
919            if (!comment.empty())
920                item->set_tooltip_text(comment);
921        }
922        // if there are no macros configured at all, then show a dummy entry instead
923        if (m_macros.empty()) {
924            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
925            item->set_sensitive(false);
926            menuMacro->append(*item);
927        }
928    
929        // add separator line to menu
930        menuMacro->append(*new Gtk::SeparatorMenuItem);
931    
932        {
933            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
934            item->signal_activate().connect(
935                sigc::mem_fun(*this, &MainWindow::setupMacros)
936            );
937            menuMacro->append(*item);
938            item->set_accel_path("<Macros>/SetupMacros");
939        }
940    
941        menuMacro->show_all_children();
942    }
943    
944    void MainWindow::onMacroSelected(int iMacro) {
945        printf("onMacroSelected(%d)\n", iMacro);
946        if (iMacro < 0 || iMacro >= m_macros.size()) return;
947        Glib::ustring errorText;
948        try {
949            applyMacro(m_macros[iMacro]);
950        } catch (Serialization::Exception e) {
951            errorText = e.Message;
952        } catch (...) {
953            errorText = _("Unknown exception while applying macro");
954        }
955        if (!errorText.empty()) {
956            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
957            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
958            msg.run();
959        }
960    }
961    
962    void MainWindow::setupMacros() {
963        MacrosSetup* setup = new MacrosSetup();
964        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
965        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
966        setup->signal_macros_changed().connect(
967            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
968        );
969        setup->show();
970    }
971    
972    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
973        m_macros = macros;
974        Settings::singleton()->saveMacros(m_macros);
975        updateMacroMenu();
976    }
977    
978  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
979  {  {
980      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 813  void MainWindow::update_dimregs() Line 1040  void MainWindow::update_dimregs()
1040          }          }
1041      }      }
1042    
1043        m_RegionChooser.setModifyAllRegions(all_regions);
1044      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1045      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1046      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
1047    
1048        updateClipboardCopyAvailable();
1049  }  }
1050    
1051  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 975  void Saver::thread_function() Line 1205  void Saver::thread_function()
1205                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1206                  // then move the saved file over the old file                  // then move the saved file over the old file
1207                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1208                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1209                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1210                  #if defined(WIN32)                  #if defined(WIN32)
1211                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 983  void Saver::thread_function() Line 1213  void Saver::thread_function()
1213                  }                  }
1214                  #else // POSIX ...                  #else // POSIX ...
1215                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1216                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1217                  }                  }
1218                  #endif                  #endif
1219                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1220                      #if defined(WIN32)                      #if defined(WIN32)
1221                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1222                      #else                      #else
1223                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1224                      #endif                      #endif
1225                  }                  }
1226              }              }
# Line 1118  bool MainWindow::close_confirmation_dial Line 1348  bool MainWindow::close_confirmation_dial
1348      g_free(msg);      g_free(msg);
1349      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
1350      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1351      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1352      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
1353      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1354      int response = dialog.run();      int response = dialog.run();
1355      dialog.hide();      dialog.hide();
# Line 1150  bool MainWindow::leaving_shared_mode_dia Line 1380  bool MainWindow::leaving_shared_mode_dia
1380            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1381            "load it."));            "load it."));
1382      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1383      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1384      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1385      int response = dialog.run();      int response = dialog.run();
1386      dialog.hide();      dialog.hide();
# Line 1164  void MainWindow::on_action_file_open() Line 1394  void MainWindow::on_action_file_open()
1394      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1395    
1396      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1397      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1398      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1399      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1400  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1401      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1360  void MainWindow::on_action_file_save_as( Line 1590  void MainWindow::on_action_file_save_as(
1590    
1591  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1592  {  {
1593      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1594      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1595      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1596      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1597      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1598    
# Line 1448  void MainWindow::__import_queued_samples Line 1678  void MainWindow::__import_queued_samples
1678      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1679      Glib::ustring error_files;      Glib::ustring error_files;
1680      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1681      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1682           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1683          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1684          SF_INFO info;          SF_INFO info;
1685          info.format = 0;          info.format = 0;
1686          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
1687          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1688          try {          try {
1689              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1476  void MainWindow::__import_queued_samples Line 1706  void MainWindow::__import_queued_samples
1706                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1707              }              }
1708    
1709                // reset write position for sample
1710                iter->first->SetPos(0);
1711    
1712              const int bufsize = 10000;              const int bufsize = 10000;
1713              switch (bitdepth) {              switch (bitdepth) {
1714                  case 16: {                  case 16: {
# Line 1485  void MainWindow::__import_queued_samples Line 1718  void MainWindow::__import_queued_samples
1718                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1719                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1720                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1721                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1722                          cnt -= n;                          cnt -= n;
1723                      }                      }
1724                      delete[] buffer;                      delete[] buffer;
# Line 1505  void MainWindow::__import_queued_samples Line 1738  void MainWindow::__import_queued_samples
1738                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1739                          }                          }
1740                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1741                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1742                          cnt -= n;                          cnt -= n;
1743                      }                      }
1744                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1516  void MainWindow::__import_queued_samples Line 1749  void MainWindow::__import_queued_samples
1749              // cleanup              // cleanup
1750              sf_close(hFile);              sf_close(hFile);
1751              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1752              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1753              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1754              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1755              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1756              ++iter;              ++iter;
1757              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1758          } catch (std::string what) {          } catch (std::string what) {
1759              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1760              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1761              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1762              ++iter;              ++iter;
1763          }          }
1764      }      }
# Line 1604  PropDialog::PropDialog() Line 1837  PropDialog::PropDialog()
1837        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1838        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1839        eSubject(_("Subject")),        eSubject(_("Subject")),
1840        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1841        table(2, 1),        table(2, 1),
1842        m_file(NULL)        m_file(NULL)
1843  {  {
# Line 1727  void InstrumentProps::set_MIDIProgram(ui Line 1960  void InstrumentProps::set_MIDIProgram(ui
1960  }  }
1961    
1962  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1963      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1964      table(2,1),      table(2,1),
1965      eName(_("Name")),      eName(_("Name")),
1966      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1866  void MainWindow::load_gig(gig::File* gig Line 2099  void MainWindow::load_gig(gig::File* gig
2099      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2100           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2101          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2102            const int iScriptSlots = instrument->ScriptSlotCount();
2103    
2104          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2105          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2106          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2107          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2108          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2109            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2110    
2111          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2112      }      }
# Line 2010  void MainWindow::show_script_slots() { Line 2245  void MainWindow::show_script_slots() {
2245    
2246      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2247      window->setInstrument(instrument);      window->setInstrument(instrument);
2248        window->signal_script_slots_changed().connect(
2249            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2250        );
2251      //window->reparent(*this);      //window->reparent(*this);
2252      window->show();      window->show();
2253  }  }
2254    
2255    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2256        if (!pInstrument) return;
2257        const int iScriptSlots = pInstrument->ScriptSlotCount();
2258    
2259        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2260        for (int i = 0; i < model->children().size(); ++i) {
2261            Gtk::TreeModel::Row row = model->children()[i];
2262            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2263            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2264            break;
2265        }
2266    }
2267    
2268  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2269      __refreshEntireGUI();      __refreshEntireGUI();
2270  }  }
# Line 2328  void MainWindow::add_instrument(gig::Ins Line 2579  void MainWindow::add_instrument(gig::Ins
2579      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2580      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2581      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2582        rowInstr[m_Columns.m_col_scripts] = "";
2583      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2584    
2585      add_instrument_to_menu(name);      add_instrument_to_menu(name);
# Line 2616  void MainWindow::add_or_replace_sample(b Line 2868  void MainWindow::add_or_replace_sample(b
2868    
2869      // show 'browse for file' dialog      // show 'browse for file' dialog
2870      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2871      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2872      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2873      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2874    
2875      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2747  void MainWindow::add_or_replace_sample(b Line 2999  void MainWindow::add_or_replace_sample(b
2999                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3000                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3001                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3002                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3003                  // add sample to the tree view                  // add sample to the tree view
3004                  if (replace) {                  if (replace) {
3005                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2817  void MainWindow::on_action_replace_all_s Line 3069  void MainWindow::on_action_replace_all_s
3069      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3070      description.show();      description.show();
3071      entryArea.show_all();      entryArea.show_all();
3072      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3073      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3074      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3075      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2857  void MainWindow::on_action_replace_all_s Line 3109  void MainWindow::on_action_replace_all_s
3109                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3110                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3111                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3112                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3113                  sf_close(hFile);                  sf_close(hFile);
3114                  file_changed();                  file_changed();
3115              }              }
# Line 2909  void MainWindow::on_action_remove_sample Line 3161  void MainWindow::on_action_remove_sample
3161                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3162                  // them from the import queue                  // them from the import queue
3163                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3164                       member != members.end(); ++member) {                       member != members.end(); ++member)
3165                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3166                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3167                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3168                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3169                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3170                      }                      }
3171                  }                  }
3172                  file_changed();                  file_changed();
# Line 2932  void MainWindow::on_action_remove_sample Line 3181  void MainWindow::on_action_remove_sample
3181                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3182                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3183                  // the import queue                  // the import queue
3184                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3185                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3186                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3187                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3188                  }                  }
3189                  dimreg_changed();                  dimreg_changed();
3190                  file_changed();                  file_changed();
# Line 2995  void MainWindow::on_action_remove_unused Line 3240  void MainWindow::on_action_remove_unused
3240              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3241              // remove sample from the .gig file              // remove sample from the .gig file
3242              file->DeleteSample(sample);              file->DeleteSample(sample);
3243              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3244              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3245                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3246              {                         m_SampleImportQueue[sample].sample_path.c_str());
3247                  if ((*iter).gig_sample == sample) {                  m_SampleImportQueue.erase(sample);
                     printf("Removing previously added sample '%s'\n",  
                            (*iter).sample_path.c_str());  
                     m_SampleImportQueue.erase(iter);  
                     break;  
                 }  
3248              }              }
3249          }          }
3250      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3453  void MainWindow::on_action_merge_files() Line 3693  void MainWindow::on_action_merge_files()
3693      }      }
3694    
3695      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3696      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3697      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3698      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3699  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 3580  void MainWindow::show_scripts_tab() { Line 3820  void MainWindow::show_scripts_tab() {
3820      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3821  }  }
3822    
3823    void MainWindow::select_prev_region() {
3824        m_RegionChooser.select_prev_region();
3825    }
3826    
3827    void MainWindow::select_next_region() {
3828        m_RegionChooser.select_next_region();
3829    }
3830    
3831    void MainWindow::select_next_dim_rgn_zone() {
3832        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3833        m_DimRegionChooser.select_next_dimzone();
3834    }
3835    
3836    void MainWindow::select_prev_dim_rgn_zone() {
3837        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3838        m_DimRegionChooser.select_prev_dimzone();
3839    }
3840    
3841    void MainWindow::select_add_next_dim_rgn_zone() {
3842        m_DimRegionChooser.select_next_dimzone(true);
3843    }
3844    
3845    void MainWindow::select_add_prev_dim_rgn_zone() {
3846        m_DimRegionChooser.select_prev_dimzone(true);
3847    }
3848    
3849    void MainWindow::select_prev_dimension() {
3850        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3851        m_DimRegionChooser.select_prev_dimension();
3852    }
3853    
3854    void MainWindow::select_next_dimension() {
3855        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3856        m_DimRegionChooser.select_next_dimension();
3857    }
3858    
3859    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3860        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3861    
3862    void MainWindow::copy_selected_dimrgn() {
3863        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3864        if (!pDimRgn) {
3865            updateClipboardPasteAvailable();
3866            updateClipboardCopyAvailable();
3867            return;
3868        }
3869    
3870        std::vector<Gtk::TargetEntry> targets;
3871        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3872    
3873        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3874        clipboard->set(
3875            targets,
3876            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3877            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3878        );
3879    
3880        m_serializationArchive.serialize(pDimRgn);
3881    
3882        updateClipboardPasteAvailable();
3883    }
3884    
3885    void MainWindow::paste_copied_dimrgn() {
3886        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3887        clipboard->request_contents(
3888            CLIPBOARD_DIMENSIONREGION_TARGET,
3889            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3890        );
3891        updateClipboardPasteAvailable();
3892    }
3893    
3894    void MainWindow::adjust_clipboard_content() {
3895        MacroEditor* editor = new MacroEditor();
3896        editor->setMacro(&m_serializationArchive, true);
3897        editor->show();
3898    }
3899    
3900    void MainWindow::updateClipboardPasteAvailable() {
3901        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3902        clipboard->request_targets(
3903            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3904        );
3905    }
3906    
3907    void MainWindow::updateClipboardCopyAvailable() {
3908        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3909        static_cast<Gtk::MenuItem*>(
3910            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3911        )->set_sensitive(bDimensionRegionCopyIsPossible);
3912    }
3913    
3914    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3915        updateClipboardPasteAvailable();
3916    }
3917    
3918    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3919        const std::string target = selection_data.get_target();
3920        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3921            selection_data.set(
3922                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3923                &m_serializationArchive.rawData()[0],
3924                m_serializationArchive.rawData().size()
3925            );
3926        } else {
3927            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3928        }
3929    }
3930    
3931    void MainWindow::on_clipboard_clear() {
3932        m_serializationArchive.clear();
3933        updateClipboardPasteAvailable();
3934        updateClipboardCopyAvailable();
3935    }
3936    
3937    //NOTE: Might throw exception !!!
3938    void MainWindow::applyMacro(Serialization::Archive& macro) {
3939        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3940        if (!pDimRgn) return;
3941    
3942        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3943             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3944        {
3945            gig::DimensionRegion* pDimRgn = *itDimReg;
3946            DimRegionChangeGuard(this, pDimRgn);
3947            macro.deserialize(pDimRgn);
3948        }
3949        //region_changed()
3950        file_changed();
3951        dimreg_changed();
3952    }
3953    
3954    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3955        const std::string target = selection_data.get_target();
3956        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3957            Glib::ustring errorText;
3958            try {
3959                m_serializationArchive.decode(
3960                    selection_data.get_data(), selection_data.get_length()
3961                );
3962                applyMacro(m_serializationArchive);
3963            } catch (Serialization::Exception e) {
3964                errorText = e.Message;
3965            } catch (...) {
3966                errorText = _("Unknown exception while pasting DimensionRegion");
3967            }
3968            if (!errorText.empty()) {
3969                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3970                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3971                msg.run();
3972            }
3973        }
3974    }
3975    
3976    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3977        const bool bDimensionRegionPasteIsPossible =
3978            std::find(targets.begin(), targets.end(),
3979                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3980    
3981        static_cast<Gtk::MenuItem*>(
3982            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3983        )->set_sensitive(bDimensionRegionPasteIsPossible);
3984    
3985        static_cast<Gtk::MenuItem*>(
3986            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3987        )->set_sensitive(bDimensionRegionPasteIsPossible);
3988    }
3989    
3990  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3991      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3992  }  }

Legend:
Removed from v.3109  
changed lines
  Added in v.3197

  ViewVC Help
Powered by ViewVC