/[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 2701 by schoenebeck, Mon Jan 12 23:28:04 2015 UTC revision 2715 by schoenebeck, Tue Jan 20 18:48:15 2015 UTC
# Line 261  MainWindow::MainWindow() : Line 261  MainWindow::MainWindow() :
261          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
262      );      );
263      actionGroup->add(      actionGroup->add(
264            Gtk::Action::create("ReplaceSample",
265                                _("Replace Sample...")),
266            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
267        );
268        actionGroup->add(
269          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
270                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
271          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 312  MainWindow::MainWindow() : Line 317  MainWindow::MainWindow() :
317          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
318          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
319          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
320            "      <menuitem action='ReplaceSample' />"
321          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
322          "      <separator/>"          "      <separator/>"
323          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
# Line 364  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
371          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
372          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
373            "    <menuitem action='ReplaceSample' />"
374          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
375          "    <separator/>"          "    <separator/>"
376          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
# Line 2334  void MainWindow::on_action_add_group() { Line 2341  void MainWindow::on_action_add_group() {
2341      file_changed();      file_changed();
2342  }  }
2343    
2344    void MainWindow::on_action_replace_sample() {
2345        add_or_replace_sample(true);
2346    }
2347    
2348  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2349        add_or_replace_sample(false);
2350    }
2351    
2352    void MainWindow::add_or_replace_sample(bool replace) {
2353      if (!file) return;      if (!file) return;
2354      // get selected group  
2355        // get selected group (and probably selected sample)
2356      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2357      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2358      if (!it) return;      if (!it) return;
2359      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2360        gig::Sample* sample = NULL;
2361      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2362      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2363          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2364          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2365          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2366          if (!it) return;          if (!it) return;
2367          row = *it;          if (!replace) row = *it;
2368          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2369          if (!group) return;          if (!group) return;
2370      }      }
2371        if (replace && !sample) return;
2372    
2373      // show 'browse for file' dialog      // show 'browse for file' dialog
2374      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2375      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2376      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2377      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2378    
2379      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2380  #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 2426  void MainWindow::on_action_add_sample() Line 2445  void MainWindow::on_action_add_sample()
2445                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2446                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2447                  }                  }
2448                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2449                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2450                  // file name without path                  // file name without path
2451                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2452                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2478  void MainWindow::on_action_add_sample() Line 2497  void MainWindow::on_action_add_sample()
2497                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2498                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2499                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2500                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2501                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2502                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2503                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2486  void MainWindow::on_action_add_sample() Line 2505  void MainWindow::on_action_add_sample()
2505                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2506                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2507                  // add sample to the tree view                  // add sample to the tree view
2508                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2509                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2510                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2511                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2512                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2513                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2514                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2515                            gig_to_utf8(sample->pInfo->Name);
2516                        rowSample[m_SamplesModel.m_col_sample] = sample;
2517                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2518                    }
2519                  // close sound file                  // close sound file
2520                  sf_close(hFile);                  sf_close(hFile);
2521                  file_changed();                  file_changed();
# Line 2503  void MainWindow::on_action_add_sample() Line 2526  void MainWindow::on_action_add_sample()
2526          }          }
2527          // 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
2528          if (!error_files.empty()) {          if (!error_files.empty()) {
2529              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2530                    (replace
2531                        ? _("Failed to replace sample with:\n")
2532                        : _("Could not add the following sample(s):\n"))
2533                    + error_files;
2534              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2535              msg.run();              msg.run();
2536          }          }

Legend:
Removed from v.2701  
changed lines
  Added in v.2715

  ViewVC Help
Powered by ViewVC