/[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 1339 by schoenebeck, Mon Sep 10 19:56:26 2007 UTC revision 1396 by schoenebeck, Wed Oct 10 15:48:54 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    
 #define _(String) gettext(String)  
   
52  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
53      std::stringstream ss;      std::stringstream ss;
54      ss << o;      ss << o;
# Line 295  MainWindow::MainWindow() Line 294  MainWindow::MainWindow()
294    
295      file = 0;      file = 0;
296      file_is_changed = false;      file_is_changed = false;
297        file_is_shared  = false;
298    
299      show_all_children();      show_all_children();
300    
# Line 308  MainWindow::~MainWindow() Line 308  MainWindow::~MainWindow()
308    
309  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
310  {  {
311      return file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
312  }  }
313    
314  void MainWindow::on_action_quit()  void MainWindow::on_action_quit()
315  {  {
316      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
317      hide();      hide();
318  }  }
319    
# Line 427  void MainWindow::__clear() { Line 427  void MainWindow::__clear() {
427      m_refTreeModel->clear();      m_refTreeModel->clear();
428      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
429      // free libgig's gig::File instance      // free libgig's gig::File instance
430      if (file) {      if (file && !file_is_shared) delete file;
431          delete file;      file = NULL;
432          file = NULL;      file_is_shared = false;
     }  
433  }  }
434    
435  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
436  {  {
437      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
438    
439        if (file_is_shared && !leaving_shared_mode_dialog()) return;
440    
441      // clear all GUI elements      // clear all GUI elements
442      __clear();      __clear();
# Line 467  bool MainWindow::close_confirmation_dial Line 468  bool MainWindow::close_confirmation_dial
468      return response != Gtk::RESPONSE_CANCEL;      return response != Gtk::RESPONSE_CANCEL;
469  }  }
470    
471    bool MainWindow::leaving_shared_mode_dialog() {
472        Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
473        Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
474    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
475        dialog.set_secondary_text(
476            _("If you proceed to work on another instrument file, it won't be "
477              "used by the sampler until you tell the sampler explicitly to "
478              "load it.")
479       );
480    #endif
481        dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
482        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
483        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
484        int response = dialog.run();
485        dialog.hide();
486        return response == Gtk::RESPONSE_YES;
487    }
488    
489  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
490  {  {
491      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
492    
493        if (file_is_shared && !leaving_shared_mode_dialog()) return;
494    
495      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
496      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
# Line 514  void MainWindow::load_instrument(gig::In Line 535  void MainWindow::load_instrument(gig::In
535      __clear();      __clear();
536      // load the instrument      // load the instrument
537      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
538      load_gig(pFile, 0 /*file name*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
539      //TODO: automatically select the given instrument      //TODO: automatically select the given instrument
540  }  }
541    
# Line 563  bool MainWindow::check_if_savable() Line 584  bool MainWindow::check_if_savable()
584  bool MainWindow::file_save()  bool MainWindow::file_save()
585  {  {
586      if (!check_if_savable()) return false;      if (!check_if_savable()) return false;
587      if (!file_has_name) return file_save_as();      if (!file_is_shared && !file_has_name) return file_save_as();
588    
589      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
590      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
# Line 575  bool MainWindow::file_save() Line 596  bool MainWindow::file_save()
596          }          }
597      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
598          file_structure_changed_signal.emit(this->file);          file_structure_changed_signal.emit(this->file);
599          Glib::ustring txt = "Could not save file: " + e.Message;          Glib::ustring txt = _("Could not save file: ") + e.Message;
600          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
601          msg.run();          msg.run();
602          return false;          return false;
# Line 630  bool MainWindow::file_save_as() Line 651  bool MainWindow::file_save_as()
651              file_is_changed = false;              file_is_changed = false;
652          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
653              file_structure_changed_signal.emit(this->file);              file_structure_changed_signal.emit(this->file);
654              Glib::ustring txt = "Could not save file: " + e.Message;              Glib::ustring txt = _("Could not save file: ") + e.Message;
655              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
656              msg.run();              msg.run();
657              return false;              return false;
# Line 727  void MainWindow::__import_queued_samples Line 748  void MainWindow::__import_queued_samples
748      }      }
749      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
750      if (error_files.size()) {      if (error_files.size()) {
751          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;
752          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
753          msg.run();          msg.run();
754      }      }
# Line 934  void MainWindow::file_changed() Line 955  void MainWindow::file_changed()
955      }      }
956  }  }
957    
958  void MainWindow::load_gig(gig::File* gig, const char* filename)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
959  {  {
960      file = 0;      file = 0;
961        file_is_shared = isSharedInstrument;
962    
963      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
964      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
# Line 1070  void MainWindow::on_action_add_instrumen Line 1092  void MainWindow::on_action_add_instrumen
1092    
1093  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1094      if (!file) return;      if (!file) return;
1095        if (file_is_shared) {
1096            Gtk::MessageDialog msg(
1097                *this,
1098                 _("You cannot delete an instrument from this file, since it's "
1099                   "currently used by the sampler."),
1100                 false, Gtk::MESSAGE_INFO
1101            );
1102            msg.run();
1103            return;
1104        }
1105    
1106      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1107      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
1108      if (it) {      if (it) {
# Line 1256  void MainWindow::on_action_add_sample() Line 1289  void MainWindow::on_action_add_sample()
1289          }          }
1290          // 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
1291          if (error_files.size()) {          if (error_files.size()) {
1292              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;
1293              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1294              msg.run();              msg.run();
1295          }          }

Legend:
Removed from v.1339  
changed lines
  Added in v.1396

  ViewVC Help
Powered by ViewVC