/[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 1322 by schoenebeck, Tue Sep 4 11:04:56 2007 UTC revision 1411 by schoenebeck, Fri Oct 12 17:46:29 2007 UTC
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
 #include <libintl.h>  
20  #include <iostream>  #include <iostream>
21    
22  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
# Line 26  Line 25 
25  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
26  #include <gtkmm/main.h>  #include <gtkmm/main.h>
27    
28    #include "global.h"
29    
30  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
31  #define ABOUT_DIALOG  #define ABOUT_DIALOG
32  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
# Line 48  Glib::ustring filename_display_basename( Line 49  Glib::ustring filename_display_basename(
49    
50  #include "mainwindow.h"  #include "mainwindow.h"
51    
52  #define _(String) gettext(String)  #include "../../gfx/status_attached.xpm"
53    #include "../../gfx/status_detached.xpm"
54    
55  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
56      std::stringstream ss;      std::stringstream ss;
# Line 211  MainWindow::MainWindow() Line 213  MainWindow::MainWindow()
213      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
214      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
215      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
216        m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
217    
218        // Status Bar:
219        m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
220        m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
221        m_StatusBar.show();
222    
223      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
224          sigc::mem_fun(*this, &MainWindow::region_changed) );          sigc::mem_fun(*this, &MainWindow::region_changed) );
# Line 295  MainWindow::MainWindow() Line 303  MainWindow::MainWindow()
303    
304      file = 0;      file = 0;
305      file_is_changed = false;      file_is_changed = false;
306        set_file_is_shared(false);
307    
308      show_all_children();      show_all_children();
309    
# Line 308  MainWindow::~MainWindow() Line 317  MainWindow::~MainWindow()
317    
318  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
319  {  {
320      return file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
321  }  }
322    
323  void MainWindow::on_action_quit()  void MainWindow::on_action_quit()
324  {  {
325      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
326      hide();      hide();
327  }  }
328    
# Line 427  void MainWindow::__clear() { Line 436  void MainWindow::__clear() {
436      m_refTreeModel->clear();      m_refTreeModel->clear();
437      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
438      // free libgig's gig::File instance      // free libgig's gig::File instance
439      if (file) {      if (file && !file_is_shared) delete file;
440          delete file;      file = NULL;
441          file = NULL;      set_file_is_shared(false);
     }  
442  }  }
443    
444  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
445  {  {
446      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
447    
448        if (file_is_shared && !leaving_shared_mode_dialog()) return;
449    
450      // clear all GUI elements      // clear all GUI elements
451      __clear();      __clear();
# Line 467  bool MainWindow::close_confirmation_dial Line 477  bool MainWindow::close_confirmation_dial
477      return response != Gtk::RESPONSE_CANCEL;      return response != Gtk::RESPONSE_CANCEL;
478  }  }
479    
480    bool MainWindow::leaving_shared_mode_dialog() {
481        Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
482        Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
483    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
484        dialog.set_secondary_text(
485            _("If you proceed to work on another instrument file, it won't be "
486              "used by the sampler until you tell the sampler explicitly to "
487              "load it.")
488       );
489    #endif
490        dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
491        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
492        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
493        int response = dialog.run();
494        dialog.hide();
495        return response == Gtk::RESPONSE_YES;
496    }
497    
498  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
499  {  {
500      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
501    
502        if (file_is_shared && !leaving_shared_mode_dialog()) return;
503    
504      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
505      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
# Line 510  void MainWindow::load_instrument(gig::In Line 540  void MainWindow::load_instrument(gig::In
540          msg.run();          msg.run();
541          Gtk::Main::quit();          Gtk::Main::quit();
542      }      }
543        // clear all GUI elements
544        __clear();
545        // load the instrument
546      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
547      load_gig(pFile, 0 /*file name*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
548      //TODO: automatically select the given instrument      //TODO: automatically select the given instrument
549  }  }
550    
# Line 560  bool MainWindow::check_if_savable() Line 593  bool MainWindow::check_if_savable()
593  bool MainWindow::file_save()  bool MainWindow::file_save()
594  {  {
595      if (!check_if_savable()) return false;      if (!check_if_savable()) return false;
596      if (!file_has_name) return file_save_as();      if (!file_is_shared && !file_has_name) return file_save_as();
597    
598      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
599      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
# Line 572  bool MainWindow::file_save() Line 605  bool MainWindow::file_save()
605          }          }
606      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
607          file_structure_changed_signal.emit(this->file);          file_structure_changed_signal.emit(this->file);
608          Glib::ustring txt = "Could not save file: " + e.Message;          Glib::ustring txt = _("Could not save file: ") + e.Message;
609          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
610          msg.run();          msg.run();
611          return false;          return false;
# Line 627  bool MainWindow::file_save_as() Line 660  bool MainWindow::file_save_as()
660              file_is_changed = false;              file_is_changed = false;
661          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
662              file_structure_changed_signal.emit(this->file);              file_structure_changed_signal.emit(this->file);
663              Glib::ustring txt = "Could not save file: " + e.Message;              Glib::ustring txt = _("Could not save file: ") + e.Message;
664              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
665              msg.run();              msg.run();
666              return false;              return false;
# Line 724  void MainWindow::__import_queued_samples Line 757  void MainWindow::__import_queued_samples
757      }      }
758      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
759      if (error_files.size()) {      if (error_files.size()) {
760          Glib::ustring txt = "Could not import the following sample(s):\n" + error_files;          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
761          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
762          msg.run();          msg.run();
763      }      }
# Line 918  void InstrumentProps::key_range_high_cha Line 951  void InstrumentProps::key_range_high_cha
951      if (h < l) eDimensionKeyRangeLow.set_value(h);      if (h < l) eDimensionKeyRangeLow.set_value(h);
952  }  }
953    
954  sigc::signal<void> InstrumentProps::signal_instrument_changed()  sigc::signal<void>& InstrumentProps::signal_instrument_changed()
955  {  {
956      return instrument_changed;      return instrument_changed;
957  }  }
# Line 931  void MainWindow::file_changed() Line 964  void MainWindow::file_changed()
964      }      }
965  }  }
966    
967  void MainWindow::load_gig(gig::File* gig, const char* filename)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
968  {  {
969      file = 0;      file = 0;
970        set_file_is_shared(isSharedInstrument);
971    
972      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
973      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
# Line 1067  void MainWindow::on_action_add_instrumen Line 1101  void MainWindow::on_action_add_instrumen
1101    
1102  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1103      if (!file) return;      if (!file) return;
1104        if (file_is_shared) {
1105            Gtk::MessageDialog msg(
1106                *this,
1107                 _("You cannot delete an instrument from this file, since it's "
1108                   "currently used by the sampler."),
1109                 false, Gtk::MESSAGE_INFO
1110            );
1111            msg.run();
1112            return;
1113        }
1114    
1115      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1116      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
1117      if (it) {      if (it) {
# Line 1253  void MainWindow::on_action_add_sample() Line 1298  void MainWindow::on_action_add_sample()
1298          }          }
1299          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
1300          if (error_files.size()) {          if (error_files.size()) {
1301              Glib::ustring txt = "Could not add the following sample(s):\n" + error_files;              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
1302              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1303              msg.run();              msg.run();
1304          }          }
# Line 1466  void MainWindow::instrument_name_changed Line 1511  void MainWindow::instrument_name_changed
1511      }      }
1512  }  }
1513    
1514  sigc::signal<void, gig::File*> MainWindow::signal_file_structure_to_be_changed() {  void MainWindow::set_file_is_shared(bool b) {
1515        this->file_is_shared = b;
1516    
1517        if (file_is_shared) {
1518            m_AttachedStateLabel.set_label(_("live-mode"));
1519            m_AttachedStateImage.set(
1520                Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
1521            );
1522        } else {
1523            m_AttachedStateLabel.set_label(_("stand-alone"));
1524            m_AttachedStateImage.set(
1525                Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
1526            );
1527        }
1528    }
1529    
1530    sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
1531      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
1532  }  }
1533    
1534  sigc::signal<void, gig::File*> MainWindow::signal_file_structure_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
1535      return file_structure_changed_signal;      return file_structure_changed_signal;
1536  }  }
1537    
1538  sigc::signal<void, std::list<gig::Sample*> > MainWindow::signal_samples_to_be_removed() {  sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
1539      return samples_to_be_removed_signal;      return samples_to_be_removed_signal;
1540  }  }
1541    
1542  sigc::signal<void> MainWindow::signal_samples_removed() {  sigc::signal<void>& MainWindow::signal_samples_removed() {
1543      return samples_removed_signal;      return samples_removed_signal;
1544  }  }
1545    
1546  sigc::signal<void, gig::Region*> MainWindow::signal_region_to_be_changed() {  sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
1547      return region_to_be_changed_signal;      return region_to_be_changed_signal;
1548  }  }
1549    
1550  sigc::signal<void, gig::Region*> MainWindow::signal_region_changed() {  sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
1551      return region_changed_signal;      return region_changed_signal;
1552  }  }
1553    
1554  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/> MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
1555      return sample_ref_changed_signal;      return sample_ref_changed_signal;
1556  }  }
1557    
1558  sigc::signal<void, gig::DimensionRegion*> MainWindow::signal_dimreg_to_be_changed() {  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
1559      return dimreg_to_be_changed_signal;      return dimreg_to_be_changed_signal;
1560  }  }
1561    
1562  sigc::signal<void, gig::DimensionRegion*> MainWindow::signal_dimreg_changed() {  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
1563      return dimreg_changed_signal;      return dimreg_changed_signal;
1564  }  }

Legend:
Removed from v.1322  
changed lines
  Added in v.1411

  ViewVC Help
Powered by ViewVC