/[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 3021 by persson, Sun Oct 23 07:24:40 2016 UTC revision 3174 by schoenebeck, Wed May 10 23:10:37 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2016 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# 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 57  Line 59 
59  #include "ReferencesView.h"  #include "ReferencesView.h"
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"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    
66  MainWindow::MainWindow() :  MainWindow::MainWindow() :
67      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
68      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
69      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
70      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
71      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
72        labelLegend(_("Legend:")),
73        labelNoSample(_(" No Sample")),
74        labelMissingSample(_(" Missing some Sample(s)")),
75        labelLooped(_(" Looped")),
76        labelSomeLoops(_(" Some Loop(s)"))
77  {  {
78        loadBuiltInPix();
79    
80  //    set_border_width(5);  //    set_border_width(5);
81  //    set_default_size(400, 200);  //    set_default_size(400, 200);
82    
   
83      add(m_VBox);      add(m_VBox);
84    
85      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 113  MainWindow::MainWindow() :
113      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
114      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
115      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
116        {
117            legend_hbox.add(labelLegend);
118    
119            imageNoSample.set(redDot);
120            imageNoSample.set_alignment(Gtk::ALIGN_END);
121            labelNoSample.set_alignment(Gtk::ALIGN_START);
122            legend_hbox.add(imageNoSample);
123            legend_hbox.add(labelNoSample);
124    
125            imageMissingSample.set(yellowDot);
126            imageMissingSample.set_alignment(Gtk::ALIGN_END);
127            labelMissingSample.set_alignment(Gtk::ALIGN_START);
128            legend_hbox.add(imageMissingSample);
129            legend_hbox.add(labelMissingSample);
130    
131            imageLooped.set(blackLoop);
132            imageLooped.set_alignment(Gtk::ALIGN_END);
133            labelLooped.set_alignment(Gtk::ALIGN_START);
134            legend_hbox.add(imageLooped);
135            legend_hbox.add(labelLooped);
136    
137            imageSomeLoops.set(grayLoop);
138            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
139            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
140            legend_hbox.add(imageSomeLoops);
141            legend_hbox.add(labelSomeLoops);
142    
143            legend_hbox.show_all_children();
144        }
145        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
146      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
147    
148      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 117  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 149  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 162  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 185  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 212  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 225  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 272  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 284  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 320  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 343  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 705  MainWindow::MainWindow() : Line 829  MainWindow::MainWindow() :
829    
830      // select 'Instruments' tab by default      // select 'Instruments' tab by default
831      // (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)
832      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
833    
834        Gtk::Clipboard::get()->signal_owner_change().connect(
835            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
836        );
837        updateClipboardPasteAvailable();
838        updateClipboardCopyAvailable();
839    
840        // setup macros and their keyboard accelerators
841        {
842            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
843                uiManager->get_widget("/MenuBar/MenuMacro")
844            )->get_submenu();
845    
846            const Gdk::ModifierType primaryModifierKey =
847    #if defined(__APPLE__)
848                Gdk::META_MASK; // Cmd key on Mac
849    #else
850                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
851    #endif
852    
853            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
854            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
855            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
856            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
857            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
858            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
859            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
867    
868            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
869            menuMacro->set_accel_group(accelGroup);
870    
871            updateMacroMenu();
872        }
873  }  }
874    
875  MainWindow::~MainWindow()  MainWindow::~MainWindow()
876  {  {
877  }  }
878    
879    void MainWindow::updateMacroMenu() {
880        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
881            uiManager->get_widget("/MenuBar/MenuMacro")
882        )->get_submenu();
883    
884        // remove all entries from "Macro" menu
885        {
886            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
887            for (int i = 0; i < children.size(); ++i) {
888                Gtk::Widget* child = children[i];
889                menuMacro->remove(*child);
890                delete child;
891            }
892        }
893    
894        // (re)load all macros from config file
895        try {
896            Settings::singleton()->loadMacros(m_macros);
897        } catch (Serialization::Exception e) {
898            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
899        } catch (...) {
900            std::cerr << "Unknown exception while loading macros!" << std::endl;
901        }
902    
903        // add all configured macros as menu items to the "Macro" menu
904        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
905            const Serialization::Archive& macro = m_macros[iMacro];
906            std::string name =
907                macro.name().empty() ?
908                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
909            Gtk::MenuItem* item = new Gtk::MenuItem(name);
910            item->signal_activate().connect(
911                sigc::bind(
912                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
913                )
914            );
915            menuMacro->append(*item);
916            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
917            Glib::ustring comment = macro.comment();
918            if (!comment.empty())
919                item->set_tooltip_text(comment);
920        }
921        // if there are no macros configured at all, then show a dummy entry instead
922        if (m_macros.empty()) {
923            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
924            item->set_sensitive(false);
925            menuMacro->append(*item);
926        }
927    
928        // add separator line to menu
929        menuMacro->append(*new Gtk::SeparatorMenuItem);
930    
931        {
932            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
933            item->signal_activate().connect(
934                sigc::mem_fun(*this, &MainWindow::setupMacros)
935            );
936            menuMacro->append(*item);
937            item->set_accel_path("<Macros>/SetupMacros");
938        }
939    
940        menuMacro->show_all_children();
941    }
942    
943    void MainWindow::onMacroSelected(int iMacro) {
944        printf("onMacroSelected(%d)\n", iMacro);
945        if (iMacro < 0 || iMacro >= m_macros.size()) return;
946        Glib::ustring errorText;
947        try {
948            applyMacro(m_macros[iMacro]);
949        } catch (Serialization::Exception e) {
950            errorText = e.Message;
951        } catch (...) {
952            errorText = _("Unknown exception while applying macro");
953        }
954        if (!errorText.empty()) {
955            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
956            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
957            msg.run();
958        }
959    }
960    
961    void MainWindow::setupMacros() {
962        MacrosSetup* setup = new MacrosSetup();
963        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
964        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
965        setup->signal_macros_changed().connect(
966            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
967        );
968        setup->show();
969    }
970    
971    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
972        m_macros = macros;
973        Settings::singleton()->saveMacros(m_macros);
974        updateMacroMenu();
975    }
976    
977  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
978  {  {
979      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 776  void MainWindow::update_dimregs() Line 1038  void MainWindow::update_dimregs()
1038              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1039          }          }
1040      }      }
1041    
1042        m_RegionChooser.setModifyAllRegions(all_regions);
1043        m_DimRegionChooser.setModifyAllRegions(all_regions);
1044        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1045        m_DimRegionChooser.setModifyBothChannels(stereo);
1046    
1047        updateClipboardCopyAvailable();
1048  }  }
1049    
1050  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 1078  bool MainWindow::close_confirmation_dial Line 1347  bool MainWindow::close_confirmation_dial
1347      g_free(msg);      g_free(msg);
1348      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."));
1349      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1350      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1351      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);
1352      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1353      int response = dialog.run();      int response = dialog.run();
1354      dialog.hide();      dialog.hide();
# Line 1110  bool MainWindow::leaving_shared_mode_dia Line 1379  bool MainWindow::leaving_shared_mode_dia
1379            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1380            "load it."));            "load it."));
1381      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1382      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1383      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1384      int response = dialog.run();      int response = dialog.run();
1385      dialog.hide();      dialog.hide();
# Line 1124  void MainWindow::on_action_file_open() Line 1393  void MainWindow::on_action_file_open()
1393      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1394    
1395      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1396      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1397      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1398      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1399  #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
1400      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1320  void MainWindow::on_action_file_save_as( Line 1589  void MainWindow::on_action_file_save_as(
1589    
1590  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1591  {  {
1592      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1593      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1594      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1595      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1596      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1597    
# Line 1408  void MainWindow::__import_queued_samples Line 1677  void MainWindow::__import_queued_samples
1677      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1678      Glib::ustring error_files;      Glib::ustring error_files;
1679      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1680      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1681           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1682          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1683          SF_INFO info;          SF_INFO info;
1684          info.format = 0;          info.format = 0;
1685          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);
1686          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1687          try {          try {
1688              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1436  void MainWindow::__import_queued_samples Line 1705  void MainWindow::__import_queued_samples
1705                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1706              }              }
1707    
1708                // reset write position for sample
1709                iter->first->SetPos(0);
1710    
1711              const int bufsize = 10000;              const int bufsize = 10000;
1712              switch (bitdepth) {              switch (bitdepth) {
1713                  case 16: {                  case 16: {
# Line 1445  void MainWindow::__import_queued_samples Line 1717  void MainWindow::__import_queued_samples
1717                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1718                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1719                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1720                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1721                          cnt -= n;                          cnt -= n;
1722                      }                      }
1723                      delete[] buffer;                      delete[] buffer;
# Line 1465  void MainWindow::__import_queued_samples Line 1737  void MainWindow::__import_queued_samples
1737                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1738                          }                          }
1739                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1740                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1741                          cnt -= n;                          cnt -= n;
1742                      }                      }
1743                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1476  void MainWindow::__import_queued_samples Line 1748  void MainWindow::__import_queued_samples
1748              // cleanup              // cleanup
1749              sf_close(hFile);              sf_close(hFile);
1750              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1751              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1752              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1753              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1754              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1755              ++iter;              ++iter;
1756              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1757          } catch (std::string what) {          } catch (std::string what) {
1758              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1759              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1760              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1761              ++iter;              ++iter;
1762          }          }
1763      }      }
# Line 1527  void MainWindow::on_action_help_about() Line 1799  void MainWindow::on_action_help_about()
1799      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1800  #endif  #endif
1801      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1802      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1803      const std::string sComment =      const std::string sComment =
1804          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1805          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1564  PropDialog::PropDialog() Line 1836  PropDialog::PropDialog()
1836        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1837        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1838        eSubject(_("Subject")),        eSubject(_("Subject")),
1839        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1840        table(2, 1),        table(2, 1),
1841        m_file(NULL)        m_file(NULL)
1842  {  {
# Line 1687  void InstrumentProps::set_MIDIProgram(ui Line 1959  void InstrumentProps::set_MIDIProgram(ui
1959  }  }
1960    
1961  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1962      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1963      table(2,1),      table(2,1),
1964      eName(_("Name")),      eName(_("Name")),
1965      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 2576  void MainWindow::add_or_replace_sample(b Line 2848  void MainWindow::add_or_replace_sample(b
2848    
2849      // show 'browse for file' dialog      // show 'browse for file' dialog
2850      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2851      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2852      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2853      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
2854    
2855      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2707  void MainWindow::add_or_replace_sample(b Line 2979  void MainWindow::add_or_replace_sample(b
2979                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2980                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2981                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2982                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2983                  // add sample to the tree view                  // add sample to the tree view
2984                  if (replace) {                  if (replace) {
2985                      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 2777  void MainWindow::on_action_replace_all_s Line 3049  void MainWindow::on_action_replace_all_s
3049      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3050      description.show();      description.show();
3051      entryArea.show_all();      entryArea.show_all();
3052      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3053      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3054      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3055      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2817  void MainWindow::on_action_replace_all_s Line 3089  void MainWindow::on_action_replace_all_s
3089                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3090                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3091                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3092                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3093                  sf_close(hFile);                  sf_close(hFile);
3094                  file_changed();                  file_changed();
3095              }              }
# Line 2869  void MainWindow::on_action_remove_sample Line 3141  void MainWindow::on_action_remove_sample
3141                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3142                  // them from the import queue                  // them from the import queue
3143                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3144                       member != members.end(); ++member) {                       member != members.end(); ++member)
3145                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3146                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3147                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3148                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3149                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3150                      }                      }
3151                  }                  }
3152                  file_changed();                  file_changed();
# Line 2892  void MainWindow::on_action_remove_sample Line 3161  void MainWindow::on_action_remove_sample
3161                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3162                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3163                  // the import queue                  // the import queue
3164                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3165                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3166                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3167                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3168                  }                  }
3169                  dimreg_changed();                  dimreg_changed();
3170                  file_changed();                  file_changed();
# Line 2955  void MainWindow::on_action_remove_unused Line 3220  void MainWindow::on_action_remove_unused
3220              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3221              // remove sample from the .gig file              // remove sample from the .gig file
3222              file->DeleteSample(sample);              file->DeleteSample(sample);
3223              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3224              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3225                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3226              {                         m_SampleImportQueue[sample].sample_path.c_str());
3227                  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;  
                 }  
3228              }              }
3229          }          }
3230      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3413  void MainWindow::on_action_merge_files() Line 3673  void MainWindow::on_action_merge_files()
3673      }      }
3674    
3675      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3676      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3677      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3678      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3679  #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 3540  void MainWindow::show_scripts_tab() { Line 3800  void MainWindow::show_scripts_tab() {
3800      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3801  }  }
3802    
3803    void MainWindow::select_prev_region() {
3804        m_RegionChooser.select_prev_region();
3805    }
3806    
3807    void MainWindow::select_next_region() {
3808        m_RegionChooser.select_next_region();
3809    }
3810    
3811    void MainWindow::select_next_dim_rgn_zone() {
3812        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3813        m_DimRegionChooser.select_next_dimzone();
3814    }
3815    
3816    void MainWindow::select_prev_dim_rgn_zone() {
3817        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3818        m_DimRegionChooser.select_prev_dimzone();
3819    }
3820    
3821    void MainWindow::select_add_next_dim_rgn_zone() {
3822        m_DimRegionChooser.select_next_dimzone(true);
3823    }
3824    
3825    void MainWindow::select_add_prev_dim_rgn_zone() {
3826        m_DimRegionChooser.select_prev_dimzone(true);
3827    }
3828    
3829    void MainWindow::select_prev_dimension() {
3830        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3831        m_DimRegionChooser.select_prev_dimension();
3832    }
3833    
3834    void MainWindow::select_next_dimension() {
3835        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3836        m_DimRegionChooser.select_next_dimension();
3837    }
3838    
3839    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3840        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3841    
3842    void MainWindow::copy_selected_dimrgn() {
3843        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3844        if (!pDimRgn) {
3845            updateClipboardPasteAvailable();
3846            updateClipboardCopyAvailable();
3847            return;
3848        }
3849    
3850        std::vector<Gtk::TargetEntry> targets;
3851        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3852    
3853        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3854        clipboard->set(
3855            targets,
3856            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3857            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3858        );
3859    
3860        m_serializationArchive.serialize(pDimRgn);
3861    
3862        updateClipboardPasteAvailable();
3863    }
3864    
3865    void MainWindow::paste_copied_dimrgn() {
3866        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3867        clipboard->request_contents(
3868            CLIPBOARD_DIMENSIONREGION_TARGET,
3869            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3870        );
3871        updateClipboardPasteAvailable();
3872    }
3873    
3874    void MainWindow::adjust_clipboard_content() {
3875        MacroEditor* editor = new MacroEditor();
3876        editor->setMacro(&m_serializationArchive, true);
3877        editor->show();
3878    }
3879    
3880    void MainWindow::updateClipboardPasteAvailable() {
3881        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3882        clipboard->request_targets(
3883            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3884        );
3885    }
3886    
3887    void MainWindow::updateClipboardCopyAvailable() {
3888        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3889        static_cast<Gtk::MenuItem*>(
3890            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3891        )->set_sensitive(bDimensionRegionCopyIsPossible);
3892    }
3893    
3894    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3895        updateClipboardPasteAvailable();
3896    }
3897    
3898    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3899        const std::string target = selection_data.get_target();
3900        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3901            selection_data.set(
3902                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3903                &m_serializationArchive.rawData()[0],
3904                m_serializationArchive.rawData().size()
3905            );
3906        } else {
3907            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3908        }
3909    }
3910    
3911    void MainWindow::on_clipboard_clear() {
3912        m_serializationArchive.clear();
3913        updateClipboardPasteAvailable();
3914        updateClipboardCopyAvailable();
3915    }
3916    
3917    //NOTE: Might throw exception !!!
3918    void MainWindow::applyMacro(Serialization::Archive& macro) {
3919        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3920        if (!pDimRgn) return;
3921    
3922        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3923             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3924        {
3925            gig::DimensionRegion* pDimRgn = *itDimReg;
3926            dimreg_to_be_changed_signal.emit(pDimRgn);
3927            macro.deserialize(pDimRgn);
3928            dimreg_changed_signal.emit(pDimRgn);
3929        }
3930        //region_changed()
3931        file_changed();
3932        dimreg_changed();
3933    }
3934    
3935    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3936        const std::string target = selection_data.get_target();
3937        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3938            Glib::ustring errorText;
3939            try {
3940                m_serializationArchive.decode(
3941                    selection_data.get_data(), selection_data.get_length()
3942                );
3943                applyMacro(m_serializationArchive);
3944            } catch (Serialization::Exception e) {
3945                errorText = e.Message;
3946            } catch (...) {
3947                errorText = _("Unknown exception while pasting DimensionRegion");
3948            }
3949            if (!errorText.empty()) {
3950                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3951                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3952                msg.run();
3953            }
3954        }
3955    }
3956    
3957    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3958        const bool bDimensionRegionPasteIsPossible =
3959            std::find(targets.begin(), targets.end(),
3960                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3961    
3962        static_cast<Gtk::MenuItem*>(
3963            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3964        )->set_sensitive(bDimensionRegionPasteIsPossible);
3965    
3966        static_cast<Gtk::MenuItem*>(
3967            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3968        )->set_sensitive(bDimensionRegionPasteIsPossible);
3969    }
3970    
3971  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3972      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3973  }  }

Legend:
Removed from v.3021  
changed lines
  Added in v.3174

  ViewVC Help
Powered by ViewVC