239 |
addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE), |
addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE), |
240 |
allRegionsCheckBox(_("All Regions")) |
allRegionsCheckBox(_("All Regions")) |
241 |
{ |
{ |
242 |
|
ignoreColumnClicked = true; |
243 |
|
|
244 |
set_title(_("Dimensions of selected Region")); |
set_title(_("Dimensions of selected Region")); |
245 |
add(vbox); |
add(vbox); |
246 |
scrolledWindow.add(treeView); |
scrolledWindow.add(treeView); |
273 |
treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones); |
treeView.get_column(2)->add_attribute(m_cellRendererIntSet.propertyValue(), tableModel.m_zones); |
274 |
treeView.show(); |
treeView.show(); |
275 |
|
|
276 |
|
treeView.signal_cursor_changed().connect( |
277 |
|
sigc::mem_fun(*this, &DimensionManager::onColumnClicked) |
278 |
|
); |
279 |
|
|
280 |
addButton.signal_clicked().connect( |
addButton.signal_clicked().connect( |
281 |
sigc::mem_fun(*this, &DimensionManager::addDimension) |
sigc::mem_fun(*this, &DimensionManager::addDimension) |
282 |
); |
); |
368 |
} |
} |
369 |
|
|
370 |
void DimensionManager::show(gig::Region* region) { |
void DimensionManager::show(gig::Region* region) { |
371 |
|
ignoreColumnClicked = true; |
372 |
this->region = region; |
this->region = region; |
373 |
refreshManager(); |
refreshManager(); |
374 |
Gtk::Window::show(); |
Gtk::Window::show(); |
375 |
deiconify(); |
deiconify(); |
376 |
|
ignoreColumnClicked = false; |
377 |
} |
} |
378 |
|
|
379 |
void DimensionManager::set_region(gig::Region* region) { |
void DimensionManager::set_region(gig::Region* region) { |
380 |
|
ignoreColumnClicked = true; |
381 |
this->region = region; |
this->region = region; |
382 |
refreshManager(); |
refreshManager(); |
383 |
|
ignoreColumnClicked = false; |
384 |
|
} |
385 |
|
|
386 |
|
void DimensionManager::onColumnClicked() { |
387 |
|
//HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired |
388 |
|
if (ignoreColumnClicked) { |
389 |
|
ignoreColumnClicked = false; |
390 |
|
return; |
391 |
|
} |
392 |
|
|
393 |
|
Gtk::TreeModel::Path path; |
394 |
|
Gtk::TreeViewColumn* focus_column; |
395 |
|
treeView.get_cursor(path, focus_column); |
396 |
|
//const int row = path[0]; |
397 |
|
if (focus_column == treeView.get_column(0)) { |
398 |
|
Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path); |
399 |
|
Gtk::TreeModel::Row row = *it; |
400 |
|
gig::dimension_t oldType = row[tableModel.m_type]; |
401 |
|
|
402 |
|
Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/); |
403 |
|
int oldTypeIndex = -1; |
404 |
|
Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel); |
405 |
|
for (int i = 0x01, count = 0; i < 0xff; i++) { |
406 |
|
Glib::ustring sType = |
407 |
|
dimTypeAsString(static_cast<gig::dimension_t>(i)); |
408 |
|
if (i == oldType) oldTypeIndex = count; |
409 |
|
if (sType.find("Unknown") != 0) { |
410 |
|
Gtk::TreeModel::Row row = *(refComboModel->append()); |
411 |
|
row[comboModel.m_type_id] = i; |
412 |
|
row[comboModel.m_type_name] = sType; |
413 |
|
count++; |
414 |
|
} |
415 |
|
} |
416 |
|
Gtk::Table table(1, 2); |
417 |
|
Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START); |
418 |
|
Gtk::ComboBox comboDimType; |
419 |
|
comboDimType.set_model(refComboModel); |
420 |
|
comboDimType.pack_start(comboModel.m_type_id); |
421 |
|
comboDimType.pack_start(comboModel.m_type_name); |
422 |
|
table.attach(labelDimType, 0, 1, 0, 1); |
423 |
|
table.attach(comboDimType, 1, 2, 0, 1); |
424 |
|
dialog.get_vbox()->pack_start(table); |
425 |
|
|
426 |
|
dialog.add_button(Gtk::Stock::OK, 0); |
427 |
|
dialog.add_button(Gtk::Stock::CANCEL, 1); |
428 |
|
dialog.show_all_children(); |
429 |
|
|
430 |
|
comboDimType.set_active(oldTypeIndex); |
431 |
|
|
432 |
|
if (!dialog.run()) { // OK selected ... |
433 |
|
Gtk::TreeModel::iterator iterType = comboDimType.get_active(); |
434 |
|
if (!iterType) return; |
435 |
|
Gtk::TreeModel::Row rowType = *iterType; |
436 |
|
if (!rowType) return; |
437 |
|
int iTypeID = rowType[comboModel.m_type_id]; |
438 |
|
gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID); |
439 |
|
if (newType == oldType) return; |
440 |
|
//printf("change 0x%x -> 0x%x\n", oldType, newType); |
441 |
|
ignoreColumnClicked = true; |
442 |
|
|
443 |
|
// assemble the list of regions where the selected dimension type |
444 |
|
// shall be changed |
445 |
|
std::vector<gig::Region*> vRegions; |
446 |
|
if (allRegions()) { |
447 |
|
gig::Instrument* instr = (gig::Instrument*)region->GetParent(); |
448 |
|
for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) { |
449 |
|
if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn); |
450 |
|
} |
451 |
|
} else vRegions.push_back(region); |
452 |
|
|
453 |
|
std::set<Glib::ustring> errors; |
454 |
|
|
455 |
|
for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) { |
456 |
|
gig::Region* region = vRegions[iRgn]; |
457 |
|
try { |
458 |
|
// notify everybody that we're going to update the region |
459 |
|
region_to_be_changed_signal.emit(region); |
460 |
|
// change the dimension type on that region |
461 |
|
region->SetDimensionType(oldType, newType); |
462 |
|
// let everybody know there was a change |
463 |
|
region_changed_signal.emit(region); |
464 |
|
} catch (RIFF::Exception e) { |
465 |
|
// notify that the changes are over (i.e. to avoid dead locks) |
466 |
|
region_changed_signal.emit(region); |
467 |
|
Glib::ustring txt = _("Could not alter dimension: ") + e.Message; |
468 |
|
if (vRegions.size() == 1) { |
469 |
|
// show error message directly |
470 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
471 |
|
msg.run(); |
472 |
|
} else { |
473 |
|
// remember error, they are shown after all regions have been processed |
474 |
|
errors.insert(txt); |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
|
// update all GUI elements |
479 |
|
refreshManager(); |
480 |
|
|
481 |
|
if (!errors.empty()) { |
482 |
|
Glib::ustring txt = _( |
483 |
|
"The following errors occurred while trying to change the dimension type on all regions:" |
484 |
|
); |
485 |
|
txt += "\n\n"; |
486 |
|
for (std::set<Glib::ustring>::const_iterator it = errors.begin(); |
487 |
|
it != errors.end(); ++it) |
488 |
|
{ |
489 |
|
txt += "-> " + *it + "\n"; |
490 |
|
} |
491 |
|
txt += "\n"; |
492 |
|
txt += _( |
493 |
|
"You might also want to check the console for further warnings and " |
494 |
|
"error messages." |
495 |
|
); |
496 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
497 |
|
msg.run(); |
498 |
|
} |
499 |
|
} |
500 |
|
} |
501 |
} |
} |
502 |
|
|
503 |
void DimensionManager::addDimension() { |
void DimensionManager::addDimension() { |