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

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

  ViewVC Help
Powered by ViewVC