/[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 2921 by schoenebeck, Wed May 18 11:57:58 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    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2
405        // prevents app to crash if this dialog is closed
406        if (!get_visible())
407            return;
408    #else
409    # warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type !
410    #endif
411    
412        Gtk::TreeModel::Path path;
413        Gtk::TreeViewColumn* focus_column;
414        treeView.get_cursor(path, focus_column);
415        //const int row = path[0];
416        if (focus_column == treeView.get_column(0)) {
417            Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);
418            Gtk::TreeModel::Row row = *it;
419            gig::dimension_t oldType = row[tableModel.m_type];
420    
421            Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/);
422            int oldTypeIndex = -1;
423            Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
424            for (int i = 0x01, count = 0; i < 0xff; i++) {
425                Glib::ustring sType =
426                    dimTypeAsString(static_cast<gig::dimension_t>(i));
427                if (i == oldType) oldTypeIndex = count;
428                if (sType.find("Unknown") != 0) {
429                    Gtk::TreeModel::Row row = *(refComboModel->append());
430                    row[comboModel.m_type_id]   = i;
431                    row[comboModel.m_type_name] = sType;
432                    count++;
433                }
434            }
435            Gtk::Table table(1, 2);
436            Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
437            Gtk::ComboBox comboDimType;
438            comboDimType.set_model(refComboModel);
439            comboDimType.pack_start(comboModel.m_type_id);
440            comboDimType.pack_start(comboModel.m_type_name);
441            table.attach(labelDimType, 0, 1, 0, 1);
442            table.attach(comboDimType, 1, 2, 0, 1);
443            dialog.get_vbox()->pack_start(table);
444    
445            dialog.add_button(_("_OK"), 0);
446            dialog.add_button(_("_Cancel"), 1);
447            dialog.show_all_children();
448            
449            comboDimType.set_active(oldTypeIndex);
450    
451            if (!dialog.run()) { // OK selected ...
452                ignoreColumnClicked = true;
453                Gtk::TreeModel::iterator iterType = comboDimType.get_active();
454                if (!iterType) return;
455                Gtk::TreeModel::Row rowType = *iterType;
456                if (!rowType) return;
457                int iTypeID = rowType[comboModel.m_type_id];
458                gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);
459                if (newType == oldType) return;
460                //printf("change 0x%x -> 0x%x\n", oldType, newType);
461    
462                // assemble the list of regions where the selected dimension type
463                // shall be changed
464                std::vector<gig::Region*> vRegions;
465                if (allRegions()) {
466                    gig::Instrument* instr = (gig::Instrument*)region->GetParent();
467                    for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
468                        if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn);
469                    }
470                } else vRegions.push_back(region);
471    
472                std::set<Glib::ustring> errors;
473    
474                for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
475                    gig::Region* region = vRegions[iRgn];
476                    try {
477                        // notify everybody that we're going to update the region
478                        region_to_be_changed_signal.emit(region);
479                        // change the dimension type on that region
480                        region->SetDimensionType(oldType, newType);
481                        // let everybody know there was a change
482                        region_changed_signal.emit(region);
483                    } catch (RIFF::Exception e) {
484                        // notify that the changes are over (i.e. to avoid dead locks)
485                        region_changed_signal.emit(region);
486                        Glib::ustring txt = _("Could not alter dimension: ") + e.Message;
487                        if (vRegions.size() == 1) {
488                            // show error message directly
489                            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
490                            msg.run();
491                        } else {
492                            // remember error, they are shown after all regions have been processed
493                            errors.insert(txt);
494                        }
495                    }
496                }
497                // update all GUI elements
498                refreshManager();
499    
500                if (!errors.empty()) {
501                    Glib::ustring txt = _(
502                        "The following errors occurred while trying to change the dimension type on all regions:"
503                    );
504                    txt += "\n\n";
505                    for (std::set<Glib::ustring>::const_iterator it = errors.begin();
506                        it != errors.end(); ++it)
507                    {
508                        txt += "-> " + *it + "\n";
509                    }
510                    txt += "\n";
511                    txt += _(
512                        "You might also want to check the console for further warnings and "
513                        "error messages."
514                    );
515                    Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
516                    msg.run();
517                }
518            }
519        }
520  }  }
521    
522  void DimensionManager::addDimension() {  void DimensionManager::addDimension() {
# Line 426  void DimensionManager::addDimension() { Line 572  void DimensionManager::addDimension() {
572          table.attach(spinZones, 1, 2, 1, 2);          table.attach(spinZones, 1, 2, 1, 2);
573      }      }
574    
575      dialog.add_button(Gtk::Stock::OK, 0);      dialog.add_button(_("_OK"), 0);
576      dialog.add_button(Gtk::Stock::CANCEL, 1);      dialog.add_button(_("_Cancel"), 1);
577      dialog.show_all_children();      dialog.show_all_children();
578    
579      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...

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

  ViewVC Help
Powered by ViewVC