/[svn]/gigedit/trunk/src/gigedit/dimensionmanager.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/dimensionmanager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2562 by schoenebeck, Mon May 19 18:06:57 2014 UTC revision 2919 by schoenebeck, Wed May 18 11:37:31 2016 UTC
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20    #include <glibmmconfig.h>
21    // threads.h must be included first to be able to build with
22    // G_DISABLE_DEPRECATED
23    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
24        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
25    #include <glibmm/threads.h>
26    #endif
27    
28  #include "dimensionmanager.h"  #include "dimensionmanager.h"
29    
 #include <gtkmm/stock.h>  
30  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
31  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
32  #include <gtkmm/comboboxtext.h>  #include <gtkmm/comboboxtext.h>
# Line 236  void IntSetCellRenderer::valueChanged() Line 243  void IntSetCellRenderer::valueChanged()
243  }  }
244    
245  DimensionManager::DimensionManager() :  DimensionManager::DimensionManager() :
246  addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE),      addButton(_("_Add"), true),
247  allRegionsCheckBox(_("All Regions"))      removeButton(_("_Remove"), true),
248        allRegionsCheckBox(_("All Regions"))
249  {  {
250        ignoreColumnClicked = true;
251    
252      set_title(_("Dimensions of selected Region"));      set_title(_("Dimensions of selected Region"));
253      add(vbox);      add(vbox);
254      scrolledWindow.add(treeView);      scrolledWindow.add(treeView);
# Line 271  allRegionsCheckBox(_("All Regions")) Line 281  allRegionsCheckBox(_("All Regions"))
281      treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones);      treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones);
282      treeView.show();      treeView.show();
283    
284        treeView.signal_cursor_changed().connect(
285            sigc::mem_fun(*this, &DimensionManager::onColumnClicked)
286        );
287    
288      addButton.signal_clicked().connect(      addButton.signal_clicked().connect(
289          sigc::mem_fun(*this, &DimensionManager::addDimension)          sigc::mem_fun(*this, &DimensionManager::addDimension)
290      );      );
# Line 362  void DimensionManager::refreshManager() Line 376  void DimensionManager::refreshManager()
376  }  }
377    
378  void DimensionManager::show(gig::Region* region) {  void DimensionManager::show(gig::Region* region) {
379        ignoreColumnClicked = true;
380      this->region = region;      this->region = region;
381      refreshManager();      refreshManager();
382      Gtk::Window::show();      Gtk::Window::show();
383      deiconify();      deiconify();
384        ignoreColumnClicked = false;
385  }  }
386    
387  void DimensionManager::set_region(gig::Region* region) {  void DimensionManager::set_region(gig::Region* region) {
388        ignoreColumnClicked = true;
389      this->region = region;      this->region = region;
390      refreshManager();      refreshManager();
391        ignoreColumnClicked = false;
392    }
393    
394    void DimensionManager::onColumnClicked() {
395        printf("DimensionManager::onColumnClicked()\n");
396    
397        //FIXME: BUG: this method is currently very unreliably called, it should actually be called when the user selects another column, it is ATM however also called when the table content changed programmatically causing the dialog below to popup at undesired times !
398    
399        //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired
400        if (ignoreColumnClicked) {
401            ignoreColumnClicked = false;
402            return;
403        }
404        // prevents app to crash if this dialog is closed
405        if (!get_visible())
406            return;
407    
408        Gtk::TreeModel::Path path;
409        Gtk::TreeViewColumn* focus_column;
410        treeView.get_cursor(path, focus_column);
411        //const int row = path[0];
412        if (focus_column == treeView.get_column(0)) {
413            Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);
414            Gtk::TreeModel::Row row = *it;
415            gig::dimension_t oldType = row[tableModel.m_type];
416    
417            Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/);
418            int oldTypeIndex = -1;
419            Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
420            for (int i = 0x01, count = 0; i < 0xff; i++) {
421                Glib::ustring sType =
422                    dimTypeAsString(static_cast<gig::dimension_t>(i));
423                if (i == oldType) oldTypeIndex = count;
424                if (sType.find("Unknown") != 0) {
425                    Gtk::TreeModel::Row row = *(refComboModel->append());
426                    row[comboModel.m_type_id]   = i;
427                    row[comboModel.m_type_name] = sType;
428                    count++;
429                }
430            }
431            Gtk::Table table(1, 2);
432            Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
433            Gtk::ComboBox comboDimType;
434            comboDimType.set_model(refComboModel);
435            comboDimType.pack_start(comboModel.m_type_id);
436            comboDimType.pack_start(comboModel.m_type_name);
437            table.attach(labelDimType, 0, 1, 0, 1);
438            table.attach(comboDimType, 1, 2, 0, 1);
439            dialog.get_vbox()->pack_start(table);
440    
441            dialog.add_button(_("_OK"), 0);
442            dialog.add_button(_("_Cancel"), 1);
443            dialog.show_all_children();
444            
445            comboDimType.set_active(oldTypeIndex);
446    
447            if (!dialog.run()) { // OK selected ...
448                ignoreColumnClicked = true;
449                Gtk::TreeModel::iterator iterType = comboDimType.get_active();
450                if (!iterType) return;
451                Gtk::TreeModel::Row rowType = *iterType;
452                if (!rowType) return;
453                int iTypeID = rowType[comboModel.m_type_id];
454                gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);
455                if (newType == oldType) return;
456                //printf("change 0x%x -> 0x%x\n", oldType, newType);
457    
458                // assemble the list of regions where the selected dimension type
459                // shall be changed
460                std::vector<gig::Region*> vRegions;
461                if (allRegions()) {
462                    gig::Instrument* instr = (gig::Instrument*)region->GetParent();
463                    for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
464                        if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn);
465                    }
466                } else vRegions.push_back(region);
467    
468                std::set<Glib::ustring> errors;
469    
470                for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
471                    gig::Region* region = vRegions[iRgn];
472                    try {
473                        // notify everybody that we're going to update the region
474                        region_to_be_changed_signal.emit(region);
475                        // change the dimension type on that region
476                        region->SetDimensionType(oldType, newType);
477                        // let everybody know there was a change
478                        region_changed_signal.emit(region);
479                    } catch (RIFF::Exception e) {
480                        // notify that the changes are over (i.e. to avoid dead locks)
481                        region_changed_signal.emit(region);
482                        Glib::ustring txt = _("Could not alter dimension: ") + e.Message;
483                        if (vRegions.size() == 1) {
484                            // show error message directly
485                            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
486                            msg.run();
487                        } else {
488                            // remember error, they are shown after all regions have been processed
489                            errors.insert(txt);
490                        }
491                    }
492                }
493                // update all GUI elements
494                refreshManager();
495    
496                if (!errors.empty()) {
497                    Glib::ustring txt = _(
498                        "The following errors occurred while trying to change the dimension type on all regions:"
499                    );
500                    txt += "\n\n";
501                    for (std::set<Glib::ustring>::const_iterator it = errors.begin();
502                        it != errors.end(); ++it)
503                    {
504                        txt += "-> " + *it + "\n";
505                    }
506                    txt += "\n";
507                    txt += _(
508                        "You might also want to check the console for further warnings and "
509                        "error messages."
510                    );
511                    Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
512                    msg.run();
513                }
514            }
515        }
516  }  }
517    
518  void DimensionManager::addDimension() {  void DimensionManager::addDimension() {
# Line 426  void DimensionManager::addDimension() { Line 568  void DimensionManager::addDimension() {
568          table.attach(spinZones, 1, 2, 1, 2);          table.attach(spinZones, 1, 2, 1, 2);
569      }      }
570    
571      dialog.add_button(Gtk::Stock::OK, 0);      dialog.add_button(_("_OK"), 0);
572      dialog.add_button(Gtk::Stock::CANCEL, 1);      dialog.add_button(_("_Cancel"), 1);
573      dialog.show_all_children();      dialog.show_all_children();
574    
575      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...

Legend:
Removed from v.2562  
changed lines
  Added in v.2919

  ViewVC Help
Powered by ViewVC