/[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 3144 by schoenebeck, Wed May 3 19:00:11 2017 UTC revision 3258 by schoenebeck, Tue May 30 20:17:12 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    #if defined(__APPLE__)
66    # include "MacHelper.h"
67    #endif
68    
69  MainWindow::MainWindow() :  MainWindow::MainWindow() :
70      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 74  MainWindow::MainWindow() : Line 81  MainWindow::MainWindow() :
81      loadBuiltInPix();      loadBuiltInPix();
82    
83  //    set_border_width(5);  //    set_border_width(5);
84  //    set_default_size(400, 200);  
85        if (!Settings::singleton()->autoRestoreWindowDimension) {
86            set_default_size(800, 600);
87            set_position(Gtk::WIN_POS_CENTER);
88        }
89    
90      add(m_VBox);      add(m_VBox);
91    
# Line 153  MainWindow::MainWindow() : Line 164  MainWindow::MainWindow() :
164      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
165    
166      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
167      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
168                       sigc::mem_fun(                       sigc::mem_fun(
169                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
170      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
171                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
172        action->property_label() = action->property_label() + "...";
173        actionGroup->add(action,
174                       sigc::mem_fun(                       sigc::mem_fun(
175                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
176      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
177                       sigc::mem_fun(                       sigc::mem_fun(
178                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
179      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
180        action->property_label() = action->property_label() + "...";
181        actionGroup->add(action,
182                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
183                       sigc::mem_fun(                       sigc::mem_fun(
184                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
185      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
186                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
189      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
190                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
191                       sigc::mem_fun(                       sigc::mem_fun(
192                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
193      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 185  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198                                           _("_Script Slots...")),                                           _("_Script Slots...")),
199                       sigc::mem_fun(                       sigc::mem_fun(
200                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
201      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
202                       sigc::mem_fun(                       sigc::mem_fun(
203                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
204      actionGroup->add(      actionGroup->add(
# Line 222  MainWindow::MainWindow() : Line 234  MainWindow::MainWindow() :
234                       Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),                       Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
235                       sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));                       sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
236    
237        actionGroup->add(Gtk::Action::create("AdjustClipboard",
238                                             _("Adjust Clipboard Content")),
239                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
240                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
241    
242      actionGroup->add(Gtk::Action::create("SelectPrevRegion",      actionGroup->add(Gtk::Action::create("SelectPrevRegion",
243                                           _("Select Previous Region")),                                           _("Select Previous Region")),
244                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
# Line 278  MainWindow::MainWindow() : Line 295  MainWindow::MainWindow() :
295      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
296    
297    
298        actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
299    
300    
301      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
302      toggle_action =      toggle_action =
303          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
# Line 305  MainWindow::MainWindow() : Line 325  MainWindow::MainWindow() :
325          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
326      );                      );                
327    
328      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
329      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
330                                             action->property_label()));
331        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
332                       sigc::mem_fun(                       sigc::mem_fun(
333                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
334      actionGroup->add(      actionGroup->add(
# Line 318  MainWindow::MainWindow() : Line 340  MainWindow::MainWindow() :
340          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
341      );      );
342      actionGroup->add(      actionGroup->add(
343          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
344          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
345      );      );
346    
# Line 365  MainWindow::MainWindow() : Line 387  MainWindow::MainWindow() :
387    
388      // sample right-click popup actions      // sample right-click popup actions
389      actionGroup->add(      actionGroup->add(
390          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
391          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
392      );      );
393      actionGroup->add(      actionGroup->add(
# Line 377  MainWindow::MainWindow() : Line 399  MainWindow::MainWindow() :
399          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
400      );      );
401      actionGroup->add(      actionGroup->add(
402          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
403          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
404      );      );
405      actionGroup->add(      actionGroup->add(
# Line 413  MainWindow::MainWindow() : Line 435  MainWindow::MainWindow() :
435          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
436      );      );
437      actionGroup->add(      actionGroup->add(
438          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
439          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
440      );      );
441    
# Line 437  MainWindow::MainWindow() : Line 459  MainWindow::MainWindow() :
459          "    </menu>"          "    </menu>"
460          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
461          "      <menuitem action='CopyDimRgn'/>"          "      <menuitem action='CopyDimRgn'/>"
462            "      <menuitem action='AdjustClipboard'/>"
463          "      <menuitem action='PasteDimRgn'/>"          "      <menuitem action='PasteDimRgn'/>"
464          "      <separator/>"          "      <separator/>"
465          "      <menuitem action='SelectPrevRegion'/>"          "      <menuitem action='SelectPrevRegion'/>"
# Line 453  MainWindow::MainWindow() : Line 476  MainWindow::MainWindow() :
476          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
477          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
478          "    </menu>"          "    </menu>"
479            "    <menu action='MenuMacro'>"
480            "    </menu>"
481          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
482          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
483          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 636  MainWindow::MainWindow() : Line 661  MainWindow::MainWindow() :
661      // Add the TreeView's view columns:      // Add the TreeView's view columns:
662      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
663      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
664        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
665      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
666            
667      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 818  MainWindow::MainWindow() : Line 844  MainWindow::MainWindow() :
844      );      );
845      updateClipboardPasteAvailable();      updateClipboardPasteAvailable();
846      updateClipboardCopyAvailable();      updateClipboardCopyAvailable();
847    
848        // setup macros and their keyboard accelerators
849        {
850            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
851                uiManager->get_widget("/MenuBar/MenuMacro")
852            )->get_submenu();
853    
854            const Gdk::ModifierType primaryModifierKey =
855    #if defined(__APPLE__)
856                Gdk::META_MASK; // Cmd key on Mac
857    #else
858                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
859    #endif
860    
861            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
862            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
867            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
868            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
869            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
870            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
871            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
872            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
873            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
874            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
875    
876            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
877            menuMacro->set_accel_group(accelGroup);
878    
879            updateMacroMenu();
880        }
881    
882        Glib::signal_idle().connect_once(
883            sigc::mem_fun(*this, &MainWindow::bringToFront),
884            200
885        );
886  }  }
887    
888  MainWindow::~MainWindow()  MainWindow::~MainWindow()
889  {  {
890  }  }
891    
892    void MainWindow::bringToFront() {
893        #if defined(__APPLE__)
894        macRaiseAppWindow();
895        #endif
896        raise();
897        present();
898    }
899    
900    void MainWindow::updateMacroMenu() {
901        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
902            uiManager->get_widget("/MenuBar/MenuMacro")
903        )->get_submenu();
904    
905        // remove all entries from "Macro" menu
906        {
907            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
908            for (int i = 0; i < children.size(); ++i) {
909                Gtk::Widget* child = children[i];
910                menuMacro->remove(*child);
911                delete child;
912            }
913        }
914    
915        // (re)load all macros from config file
916        try {
917            Settings::singleton()->loadMacros(m_macros);
918        } catch (Serialization::Exception e) {
919            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
920        } catch (...) {
921            std::cerr << "Unknown exception while loading macros!" << std::endl;
922        }
923    
924        // add all configured macros as menu items to the "Macro" menu
925        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
926            const Serialization::Archive& macro = m_macros[iMacro];
927            std::string name =
928                macro.name().empty() ?
929                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
930            Gtk::MenuItem* item = new Gtk::MenuItem(name);
931            item->signal_activate().connect(
932                sigc::bind(
933                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
934                )
935            );
936            menuMacro->append(*item);
937            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
938            Glib::ustring comment = macro.comment();
939            if (!comment.empty())
940                item->set_tooltip_text(comment);
941        }
942        // if there are no macros configured at all, then show a dummy entry instead
943        if (m_macros.empty()) {
944            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
945            item->set_sensitive(false);
946            menuMacro->append(*item);
947        }
948    
949        // add separator line to menu
950        menuMacro->append(*new Gtk::SeparatorMenuItem);
951    
952        {
953            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
954            item->signal_activate().connect(
955                sigc::mem_fun(*this, &MainWindow::setupMacros)
956            );
957            menuMacro->append(*item);
958            item->set_accel_path("<Macros>/SetupMacros");
959        }
960    
961        menuMacro->show_all_children();
962    }
963    
964    void MainWindow::onMacroSelected(int iMacro) {
965        printf("onMacroSelected(%d)\n", iMacro);
966        if (iMacro < 0 || iMacro >= m_macros.size()) return;
967        Glib::ustring errorText;
968        try {
969            applyMacro(m_macros[iMacro]);
970        } catch (Serialization::Exception e) {
971            errorText = e.Message;
972        } catch (...) {
973            errorText = _("Unknown exception while applying macro");
974        }
975        if (!errorText.empty()) {
976            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
977            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
978            msg.run();
979        }
980    }
981    
982    void MainWindow::setupMacros() {
983        MacrosSetup* setup = new MacrosSetup();
984        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
985        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
986        setup->signal_macros_changed().connect(
987            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
988        );
989        setup->show();
990    }
991    
992    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
993        m_macros = macros;
994        Settings::singleton()->saveMacros(m_macros);
995        updateMacroMenu();
996    }
997    
998  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
999  {  {
1000      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 889  void MainWindow::update_dimregs() Line 1060  void MainWindow::update_dimregs()
1060          }          }
1061      }      }
1062    
1063        m_RegionChooser.setModifyAllRegions(all_regions);
1064      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1065      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1066      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
# Line 1053  void Saver::thread_function() Line 1225  void Saver::thread_function()
1225                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1226                  // then move the saved file over the old file                  // then move the saved file over the old file
1227                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1228                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1229                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1230                  #if defined(WIN32)                  #if defined(WIN32)
1231                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 1061  void Saver::thread_function() Line 1233  void Saver::thread_function()
1233                  }                  }
1234                  #else // POSIX ...                  #else // POSIX ...
1235                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1236                      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)));
1237                  }                  }
1238                  #endif                  #endif
1239                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1240                      #if defined(WIN32)                      #if defined(WIN32)
1241                      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).");
1242                      #else                      #else
1243                      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)));
1244                      #endif                      #endif
1245                  }                  }
1246              }              }
# Line 1196  bool MainWindow::close_confirmation_dial Line 1368  bool MainWindow::close_confirmation_dial
1368      g_free(msg);      g_free(msg);
1369      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."));
1370      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1371      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1372      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);
1373      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1374      int response = dialog.run();      int response = dialog.run();
1375      dialog.hide();      dialog.hide();
# Line 1228  bool MainWindow::leaving_shared_mode_dia Line 1400  bool MainWindow::leaving_shared_mode_dia
1400            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1401            "load it."));            "load it."));
1402      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1403      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1404      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1405      int response = dialog.run();      int response = dialog.run();
1406      dialog.hide();      dialog.hide();
# Line 1242  void MainWindow::on_action_file_open() Line 1414  void MainWindow::on_action_file_open()
1414      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1415    
1416      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1417      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1418      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1419      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1420  #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
1421      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1438  void MainWindow::on_action_file_save_as( Line 1610  void MainWindow::on_action_file_save_as(
1610    
1611  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1612  {  {
1613      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1614      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1615      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1616      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1617      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1618    
# Line 1664  void MainWindow::on_action_help_about() Line 1836  void MainWindow::on_action_help_about()
1836      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1837      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1838      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1839        dialog.set_position(Gtk::WIN_POS_CENTER);
1840      dialog.run();      dialog.run();
1841  }  }
1842    
# Line 1685  PropDialog::PropDialog() Line 1858  PropDialog::PropDialog()
1858        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1859        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1860        eSubject(_("Subject")),        eSubject(_("Subject")),
1861        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1862        table(2, 1),        table(2, 1),
1863        m_file(NULL)        m_file(NULL)
1864  {  {
1865        if (!Settings::singleton()->autoRestoreWindowDimension) {
1866            set_default_size(470, 390);
1867            set_position(Gtk::WIN_POS_MOUSE);
1868        }
1869    
1870      set_title(_("File Properties"));      set_title(_("File Properties"));
1871      eName.set_width_chars(50);      eName.set_width_chars(50);
1872    
# Line 1808  void InstrumentProps::set_MIDIProgram(ui Line 1986  void InstrumentProps::set_MIDIProgram(ui
1986  }  }
1987    
1988  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1989      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1990      table(2,1),      table(2,1),
1991      eName(_("Name")),      eName(_("Name")),
1992      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1823  InstrumentProps::InstrumentProps() : Line 2001  InstrumentProps::InstrumentProps() :
2001      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2002      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2003  {  {
2004        if (!Settings::singleton()->autoRestoreWindowDimension) {
2005            //set_default_size(470, 390);
2006            set_position(Gtk::WIN_POS_MOUSE);
2007        }
2008    
2009      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2010    
2011      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1947  void MainWindow::load_gig(gig::File* gig Line 2130  void MainWindow::load_gig(gig::File* gig
2130      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2131           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2132          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2133            const int iScriptSlots = instrument->ScriptSlotCount();
2134    
2135          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2136          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2137          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2138          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2139          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2140            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2141    
2142          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2143      }      }
# Line 2091  void MainWindow::show_script_slots() { Line 2276  void MainWindow::show_script_slots() {
2276    
2277      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2278      window->setInstrument(instrument);      window->setInstrument(instrument);
2279        window->signal_script_slots_changed().connect(
2280            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2281        );
2282      //window->reparent(*this);      //window->reparent(*this);
2283      window->show();      window->show();
2284  }  }
2285    
2286    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2287        if (!pInstrument) return;
2288        const int iScriptSlots = pInstrument->ScriptSlotCount();
2289    
2290        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2291        for (int i = 0; i < model->children().size(); ++i) {
2292            Gtk::TreeModel::Row row = model->children()[i];
2293            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2294            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2295            break;
2296        }
2297    }
2298    
2299  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2300      __refreshEntireGUI();      __refreshEntireGUI();
2301  }  }
# Line 2409  void MainWindow::add_instrument(gig::Ins Line 2610  void MainWindow::add_instrument(gig::Ins
2610      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2611      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2612      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2613        rowInstr[m_Columns.m_col_scripts] = "";
2614      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2615    
2616      add_instrument_to_menu(name);      add_instrument_to_menu(name);
# Line 2697  void MainWindow::add_or_replace_sample(b Line 2899  void MainWindow::add_or_replace_sample(b
2899    
2900      // show 'browse for file' dialog      // show 'browse for file' dialog
2901      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2902      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2903      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2904      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
2905    
2906      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2898  void MainWindow::on_action_replace_all_s Line 3100  void MainWindow::on_action_replace_all_s
3100      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3101      description.show();      description.show();
3102      entryArea.show_all();      entryArea.show_all();
3103      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3104      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3105      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3106      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 3387  void MainWindow::instrument_name_changed Line 3589  void MainWindow::instrument_name_changed
3589  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3590      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3591      d->show_all();      d->show_all();
     d->resize(500, 400);  
3592      d->run();      d->run();
3593      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3594          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3522  void MainWindow::on_action_merge_files() Line 3723  void MainWindow::on_action_merge_files()
3723      }      }
3724    
3725      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3726      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3727      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3728      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3729  #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 3720  void MainWindow::paste_copied_dimrgn() { Line 3921  void MainWindow::paste_copied_dimrgn() {
3921      updateClipboardPasteAvailable();      updateClipboardPasteAvailable();
3922  }  }
3923    
3924    void MainWindow::adjust_clipboard_content() {
3925        MacroEditor* editor = new MacroEditor();
3926        editor->setMacro(&m_serializationArchive, true);
3927        editor->show();
3928    }
3929    
3930  void MainWindow::updateClipboardPasteAvailable() {  void MainWindow::updateClipboardPasteAvailable() {
3931      Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();      Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3932      clipboard->request_targets(      clipboard->request_targets(
# Line 3757  void MainWindow::on_clipboard_clear() { Line 3964  void MainWindow::on_clipboard_clear() {
3964      updateClipboardCopyAvailable();      updateClipboardCopyAvailable();
3965  }  }
3966    
3967    //NOTE: Might throw exception !!!
3968    void MainWindow::applyMacro(Serialization::Archive& macro) {
3969        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3970        if (!pDimRgn) return;
3971    
3972        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3973             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3974        {
3975            gig::DimensionRegion* pDimRgn = *itDimReg;
3976            DimRegionChangeGuard(this, pDimRgn);
3977            macro.deserialize(pDimRgn);
3978        }
3979        //region_changed()
3980        file_changed();
3981        dimreg_changed();
3982    }
3983    
3984  void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {  void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3985      const std::string target = selection_data.get_target();      const std::string target = selection_data.get_target();
3986      if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {      if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
         gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();  
         if (!pDimRgn) return;  
   
3987          Glib::ustring errorText;          Glib::ustring errorText;
3988          try {          try {
3989              m_serializationArchive.decode(              m_serializationArchive.decode(
3990                  selection_data.get_data(), selection_data.get_length()                  selection_data.get_data(), selection_data.get_length()
3991              );              );
3992                applyMacro(m_serializationArchive);
             for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();  
                  itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)  
             {  
                 gig::DimensionRegion* pDimRgn = *itDimReg;  
   
                 dimreg_to_be_changed_signal.emit(pDimRgn);  
   
                 m_serializationArchive.deserialize(pDimRgn);  
   
                 dimreg_changed_signal.emit(pDimRgn);  
             }  
   
             //region_changed()  
             file_changed();  
             dimreg_changed();  
   
3993          } catch (Serialization::Exception e) {          } catch (Serialization::Exception e) {
3994              errorText = e.Message;              errorText = e.Message;
3995          } catch (...) {          } catch (...) {
3996              errorText = _("Unknown exception during deserialization decoding");              errorText = _("Unknown exception while pasting DimensionRegion");
3997          }          }
3998          if (!errorText.empty()) {          if (!errorText.empty()) {
3999              Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;              Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
# Line 3806  void MainWindow::on_clipboard_received_t Line 4011  void MainWindow::on_clipboard_received_t
4011      static_cast<Gtk::MenuItem*>(      static_cast<Gtk::MenuItem*>(
4012          uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")          uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4013      )->set_sensitive(bDimensionRegionPasteIsPossible);      )->set_sensitive(bDimensionRegionPasteIsPossible);
4014    
4015        static_cast<Gtk::MenuItem*>(
4016            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4017        )->set_sensitive(bDimensionRegionPasteIsPossible);
4018  }  }
4019    
4020  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {

Legend:
Removed from v.3144  
changed lines
  Added in v.3258

  ViewVC Help
Powered by ViewVC