448 |
// Create the Tree model: |
// Create the Tree model: |
449 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
450 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
451 |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
452 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
453 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
454 |
); |
); |
456 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
457 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
458 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
459 |
|
|
460 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
461 |
|
// the sequence of instruments within the gig file |
462 |
|
{ |
463 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
464 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
465 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
466 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
467 |
|
m_TreeView.signal_drag_begin().connect( |
468 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
469 |
|
); |
470 |
|
m_TreeView.signal_drag_data_get().connect( |
471 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
472 |
|
); |
473 |
|
m_TreeView.signal_drag_data_received().connect( |
474 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
475 |
|
); |
476 |
|
} |
477 |
|
|
478 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
479 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
521 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
522 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
523 |
); |
); |
524 |
//FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? |
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
525 |
m_TreeViewScripts.signal_row_activated().connect( |
m_TreeViewScripts.signal_row_activated().connect( |
526 |
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
527 |
); |
); |
965 |
int response = dialog.run(); |
int response = dialog.run(); |
966 |
dialog.hide(); |
dialog.hide(); |
967 |
|
|
968 |
|
// user decided to exit app without saving |
969 |
|
if (response == Gtk::RESPONSE_NO) return true; |
970 |
|
|
971 |
|
// user cancelled dialog, thus don't close app |
972 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
973 |
|
|
974 |
// TODO: the following return valid is disabled and hard coded instead for |
// TODO: the following return valid is disabled and hard coded instead for |
975 |
// now, due to the fact that saving with progress bar is now implemented |
// now, due to the fact that saving with progress bar is now implemented |
976 |
// asynchronously, as a result the app does not close automatically anymore |
// asynchronously, as a result the app does not close automatically anymore |
1187 |
|
|
1188 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1189 |
|
|
1190 |
load_gig(this->file, this->filename.c_str()); |
__refreshEntireGUI(); |
1191 |
progress_dialog->hide(); |
progress_dialog->hide(); |
1192 |
} |
} |
1193 |
|
|
1911 |
} |
} |
1912 |
} |
} |
1913 |
|
|
1914 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1915 |
|
if (!instrument) return; |
1916 |
|
|
1917 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1918 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1919 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1920 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1921 |
|
// select and show the respective instrument in the list view |
1922 |
|
show_intruments_tab(); |
1923 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1924 |
|
Gtk::TreePath path( |
1925 |
|
m_TreeView.get_selection()->get_selected() |
1926 |
|
); |
1927 |
|
m_TreeView.scroll_to_row(path); |
1928 |
|
on_sel_change(); // the regular instrument selection change callback |
1929 |
|
} |
1930 |
|
} |
1931 |
|
} |
1932 |
|
|
1933 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
1934 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
1935 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
1936 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
1937 |
|
|
1938 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1939 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1940 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1941 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
1942 |
|
// select and show the respective instrument in the list view |
1943 |
|
show_intruments_tab(); |
1944 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1945 |
|
Gtk::TreePath path( |
1946 |
|
m_TreeView.get_selection()->get_selected() |
1947 |
|
); |
1948 |
|
m_TreeView.scroll_to_row(path); |
1949 |
|
on_sel_change(); // the regular instrument selection change callback |
1950 |
|
|
1951 |
|
// select respective region in the region selector |
1952 |
|
m_RegionChooser.set_region(pRegion); |
1953 |
|
|
1954 |
|
// select and show the respective dimension region in the editor |
1955 |
|
//update_dimregs(); |
1956 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
1957 |
|
//dimreg_edit.set_dim_region(dimRgn); |
1958 |
|
|
1959 |
|
return true; |
1960 |
|
} |
1961 |
|
} |
1962 |
|
|
1963 |
|
return false; |
1964 |
|
} |
1965 |
|
|
1966 |
void MainWindow::select_sample(gig::Sample* sample) { |
void MainWindow::select_sample(gig::Sample* sample) { |
1967 |
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
1968 |
for (int g = 0; g < model->children().size(); ++g) { |
for (int g = 0; g < model->children().size(); ++g) { |
2713 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2714 |
} |
} |
2715 |
|
|
2716 |
|
// see comment on on_sample_treeview_drag_begin() |
2717 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2718 |
|
{ |
2719 |
|
first_call_to_drag_data_get = true; |
2720 |
|
} |
2721 |
|
|
2722 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2723 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2724 |
|
{ |
2725 |
|
if (!first_call_to_drag_data_get) return; |
2726 |
|
first_call_to_drag_data_get = false; |
2727 |
|
|
2728 |
|
// get selected source instrument |
2729 |
|
gig::Instrument* src = NULL; |
2730 |
|
{ |
2731 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2732 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2733 |
|
if (it) { |
2734 |
|
Gtk::TreeModel::Row row = *it; |
2735 |
|
src = row[m_Columns.m_col_instr]; |
2736 |
|
} |
2737 |
|
} |
2738 |
|
if (!src) return; |
2739 |
|
|
2740 |
|
// pass the source gig::Instrument as pointer |
2741 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2742 |
|
sizeof(src)/*length of data in bytes*/); |
2743 |
|
} |
2744 |
|
|
2745 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2746 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2747 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2748 |
|
{ |
2749 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2750 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2751 |
|
return; |
2752 |
|
|
2753 |
|
gig::Instrument* dst = NULL; |
2754 |
|
{ |
2755 |
|
Gtk::TreeModel::Path path; |
2756 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2757 |
|
if (!found) return; |
2758 |
|
|
2759 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2760 |
|
if (!iter) return; |
2761 |
|
Gtk::TreeModel::Row row = *iter; |
2762 |
|
dst = row[m_Columns.m_col_instr]; |
2763 |
|
} |
2764 |
|
if (!dst) return; |
2765 |
|
|
2766 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2767 |
|
src->MoveTo(dst); |
2768 |
|
__refreshEntireGUI(); |
2769 |
|
select_instrument(src); |
2770 |
|
} |
2771 |
|
|
2772 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2773 |
// drag'n'drop (at least when target is an Entry). This work-around |
// drag'n'drop (at least when target is an Entry). This work-around |
2774 |
// makes sure the code in drag_data_get and drop_drag_data_received is |
// makes sure the code in drag_data_get and drop_drag_data_received is |
2991 |
|
|
2992 |
ReferencesView* d = new ReferencesView(*this); |
ReferencesView* d = new ReferencesView(*this); |
2993 |
d->setSample(sample); |
d->setSample(sample); |
2994 |
|
d->dimension_region_selected.connect( |
2995 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
2996 |
|
); |
2997 |
d->show_all(); |
d->show_all(); |
2998 |
d->resize(500, 400); |
d->resize(500, 400); |
2999 |
d->run(); |
d->run(); |