/[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 3225 by schoenebeck, Fri May 26 22:10:16 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# 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    
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
# Line 236  void IntSetCellRenderer::valueChanged() Line 244  void IntSetCellRenderer::valueChanged()
244  }  }
245    
246  DimensionManager::DimensionManager() :  DimensionManager::DimensionManager() :
247  addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE),      addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE),
248  allRegionsCheckBox(_("All Regions"))      allRegionsCheckBox(_("All Regions"))
249  {  {
250        ignoreColumnClicked = true;
251    
252        if (!Settings::singleton()->autoRestoreWindowDimension) {
253            set_default_size(630, 250);
254            set_position(Gtk::WIN_POS_MOUSE);
255        }
256    
257      set_title(_("Dimensions of selected Region"));      set_title(_("Dimensions of selected Region"));
258      add(vbox);      add(vbox);
259      scrolledWindow.add(treeView);      scrolledWindow.add(treeView);
# Line 271  allRegionsCheckBox(_("All Regions")) Line 286  allRegionsCheckBox(_("All Regions"))
286      treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones);      treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones);
287      treeView.show();      treeView.show();
288    
289        treeView.signal_cursor_changed().connect(
290            sigc::mem_fun(*this, &DimensionManager::onColumnClicked)
291        );
292    
293      addButton.signal_clicked().connect(      addButton.signal_clicked().connect(
294          sigc::mem_fun(*this, &DimensionManager::addDimension)          sigc::mem_fun(*this, &DimensionManager::addDimension)
295      );      );
# Line 283  allRegionsCheckBox(_("All Regions")) Line 302  allRegionsCheckBox(_("All Regions"))
302      );      );
303    
304      show_all_children();      show_all_children();
       
     resize(460,300);  
305  }  }
306    
307  bool DimensionManager::allRegions() const {  bool DimensionManager::allRegions() const {
# Line 362  void DimensionManager::refreshManager() Line 379  void DimensionManager::refreshManager()
379  }  }
380    
381  void DimensionManager::show(gig::Region* region) {  void DimensionManager::show(gig::Region* region) {
382        ignoreColumnClicked = true;
383      this->region = region;      this->region = region;
384      refreshManager();      refreshManager();
385      Gtk::Window::show();      Gtk::Window::show();
386      deiconify();      deiconify();
387        ignoreColumnClicked = false;
388  }  }
389    
390  void DimensionManager::set_region(gig::Region* region) {  void DimensionManager::set_region(gig::Region* region) {
391        ignoreColumnClicked = true;
392      this->region = region;      this->region = region;
393      refreshManager();      refreshManager();
394        ignoreColumnClicked = false;
395    }
396    
397    void DimensionManager::onColumnClicked() {
398        printf("DimensionManager::onColumnClicked()\n");
399    
400        //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 !
401    
402        //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired
403        if (ignoreColumnClicked) {
404            ignoreColumnClicked = false;
405            return;
406        }
407    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2
408        // prevents app to crash if this dialog is closed
409        if (!get_visible())
410            return;
411    #else
412    # warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type !
413    #endif
414    
415    #if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 3
416        if (!is_visible()) return;
417    #endif
418    
419        Gtk::TreeModel::Path path;
420        Gtk::TreeViewColumn* focus_column;
421        treeView.get_cursor(path, focus_column);
422        //const int row = path[0];
423        if (focus_column == treeView.get_column(0)) {
424            Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);
425            if (!it) return;
426            Gtk::TreeModel::Row row = *it;
427            gig::dimension_t oldType = row[tableModel.m_type];
428    
429            Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/);
430            int oldTypeIndex = -1;
431            Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
432            for (int i = 0x01, count = 0; i < 0xff; i++) {
433                Glib::ustring sType =
434                    dimTypeAsString(static_cast<gig::dimension_t>(i));
435                if (i == oldType) oldTypeIndex = count;
436                if (sType.find("Unknown") != 0) {
437                    Gtk::TreeModel::Row row = *(refComboModel->append());
438                    row[comboModel.m_type_id]   = i;
439                    row[comboModel.m_type_name] = sType;
440                    count++;
441                }
442            }
443            Gtk::Table table(1, 2);
444            Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
445            Gtk::ComboBox comboDimType;
446            comboDimType.set_model(refComboModel);
447            comboDimType.pack_start(comboModel.m_type_id);
448            comboDimType.pack_start(comboModel.m_type_name);
449            table.attach(labelDimType, 0, 1, 0, 1);
450            table.attach(comboDimType, 1, 2, 0, 1);
451            dialog.get_vbox()->pack_start(table);
452    
453            dialog.add_button(Gtk::Stock::OK, 0);
454            dialog.add_button(Gtk::Stock::CANCEL, 1);
455            dialog.show_all_children();
456            
457            comboDimType.set_active(oldTypeIndex);
458    
459            if (!dialog.run()) { // OK selected ...
460                ignoreColumnClicked = true;
461                Gtk::TreeModel::iterator iterType = comboDimType.get_active();
462                if (!iterType) return;
463                Gtk::TreeModel::Row rowType = *iterType;
464                if (!rowType) return;
465                int iTypeID = rowType[comboModel.m_type_id];
466                gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);
467                if (newType == oldType) return;
468                //printf("change 0x%x -> 0x%x\n", oldType, newType);
469    
470                // assemble the list of regions where the selected dimension type
471                // shall be changed
472                std::vector<gig::Region*> vRegions;
473                if (allRegions()) {
474                    gig::Instrument* instr = (gig::Instrument*)region->GetParent();
475                    for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
476                        if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn);
477                    }
478                } else vRegions.push_back(region);
479    
480                std::set<Glib::ustring> errors;
481    
482                for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
483                    gig::Region* region = vRegions[iRgn];
484                    try {
485                        // notify everybody that we're going to update the region
486                        region_to_be_changed_signal.emit(region);
487                        // change the dimension type on that region
488                        region->SetDimensionType(oldType, newType);
489                        // let everybody know there was a change
490                        region_changed_signal.emit(region);
491                    } catch (RIFF::Exception e) {
492                        // notify that the changes are over (i.e. to avoid dead locks)
493                        region_changed_signal.emit(region);
494                        Glib::ustring txt = _("Could not alter dimension: ") + e.Message;
495                        if (vRegions.size() == 1) {
496                            // show error message directly
497                            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
498                            msg.run();
499                        } else {
500                            // remember error, they are shown after all regions have been processed
501                            errors.insert(txt);
502                        }
503                    }
504                }
505                // update all GUI elements
506                refreshManager();
507    
508                if (!errors.empty()) {
509                    Glib::ustring txt = _(
510                        "The following errors occurred while trying to change the dimension type on all regions:"
511                    );
512                    txt += "\n\n";
513                    for (std::set<Glib::ustring>::const_iterator it = errors.begin();
514                        it != errors.end(); ++it)
515                    {
516                        txt += "-> " + *it + "\n";
517                    }
518                    txt += "\n";
519                    txt += _(
520                        "You might also want to check the console for further warnings and "
521                        "error messages."
522                    );
523                    Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
524                    msg.run();
525                }
526            }
527        } else if (focus_column == treeView.get_column(1) || focus_column == treeView.get_column(2)) {
528            Glib::ustring txt = _("Right-click on a specific dimension zone of the dimension region selector to delete or split that particular dimension zone!");
529            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_INFO);
530            msg.run();
531        }
532  }  }
533    
534  void DimensionManager::addDimension() {  void DimensionManager::addDimension() {

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

  ViewVC Help
Powered by ViewVC