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