--- gigedit/trunk/src/gigedit/mainwindow.cpp 2020/08/14 10:54:44 3807 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2020/10/15 18:08:49 3831 @@ -1734,6 +1734,24 @@ #endif raise(); present(); + + // restore user specified splitter position + if (Settings::singleton()->mainWindowSplitterPosX >= 0 && + Settings::singleton()->autoRestoreWindowDimension) + { + const int pos = Settings::singleton()->mainWindowSplitterPosX; + printf("Restoring user's preferred splitter position=%d\n", pos); + m_HPaned.set_position(pos); + } + // this signal handler is late-connected after the UI build-up has settled + // to prevent the UI build-up from overwriting user's setting for splitter + // position unintentionally + m_HPaned.property_position().signal_changed().connect([this]{ + if (!Settings::singleton()->autoRestoreWindowDimension) return; + const int pos = m_HPaned.get_position(); + printf("Saving user's preferred splitter position=%d\n", pos); + Settings::singleton()->mainWindowSplitterPosX = pos; + }); } void MainWindow::updateMacroMenu() { @@ -1945,7 +1963,9 @@ // select item in instrument menu std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows(); if (!rows.empty()) { - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[0]); + // convert index of visual selection (i.e. if filtered) to index of model + Gtk::TreeModel::Path row = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]); + Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(row); if (it) { Gtk::TreePath path(it); int index = path[0]; @@ -3612,13 +3632,18 @@ { instrumentProps.signal_name_changed().clear(); + // get visual selection std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows(); if (rows.empty()) { instrumentProps.hide(); return false; } + + // convert index of visual selection (i.e. if filtered) to index of model + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]); + //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though. - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[0]); + Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path); if (it) { Gtk::TreeModel::Row row = *it; gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr]; @@ -3728,13 +3753,9 @@ void MainWindow::show_script_slots() { if (!file) return; + // get selected instrument - std::vector rows = m_TreeViewInstruments.get_selection()->get_selected_rows(); - if (rows.empty()) return; - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[0]); - if (!it) return; - Gtk::TreeModel::Row row = *it; - gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr]; + gig::Instrument* instrument = get_instrument(); if (!instrument) return; ScriptSlots* window = new ScriptSlots; @@ -3973,7 +3994,14 @@ find(children.begin(), children.end(), item); if (it != children.end()) { int index = it - children.begin(); - m_TreeViewInstruments.get_selection()->select(Gtk::TreePath(ToString(index))); + + // convert index of model to index of visual presentation (i.e. if filtered) + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_child_path_to_path(Gtk::TreePath(ToString(index))); + + if (path) + m_TreeViewInstruments.get_selection()->select(path); + else + m_TreeViewInstruments.get_selection()->unselect_all(); m_RegionChooser.set_instrument(file->GetInstrument(index)); } @@ -4416,7 +4444,9 @@ Glib::RefPtr sel = m_TreeViewInstruments.get_selection(); std::vector rows = sel->get_selected_rows(); for (int r = 0; r < rows.size(); ++r) { - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]); + // convert index of visual selection (i.e. if filtered) to index of model + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]); + Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path); if (it) { Gtk::TreeModel::Row row = *it; gig::Instrument* instrOrig = row[m_InstrumentsModel.m_col_instr]; @@ -4447,7 +4477,16 @@ } Glib::RefPtr sel = m_TreeViewInstruments.get_selection(); - std::vector rows = sel->get_selected_rows(); + std::vector rowsVisual = sel->get_selected_rows(); + + // convert indeces of visual selection (i.e. if filtered) to indeces of model + std::vector rows; + for (int rv = 0; rv < rowsVisual.size(); ++rv) { + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rowsVisual[rv]); + if (path) + rows.push_back(path); + } + for (int r = rows.size() - 1; r >= 0; --r) { Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]); if (!it) continue; @@ -5042,28 +5081,7 @@ if (!file) return; // collect all samples that are not referenced by any instrument - std::list lsamples; - for (int iSample = 0; file->GetSample(iSample); ++iSample) { - gig::Sample* sample = file->GetSample(iSample); - bool isUsed = false; - for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; - instrument = file->GetNextInstrument()) - { - for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; - rgn = instrument->GetNextRegion()) - { - for (int i = 0; i < 256; ++i) { - if (!rgn->pDimensionRegions[i]) continue; - if (rgn->pDimensionRegions[i]->pSample != sample) continue; - isUsed = true; - goto endOfRefSearch; - } - } - } - endOfRefSearch: - if (!isUsed) lsamples.push_back(sample); - } - + std::list lsamples = unusedSamples(file); if (lsamples.empty()) return; // notify everybody that we're going to remove these samples @@ -5142,7 +5160,9 @@ Glib::RefPtr sel = m_TreeViewInstruments.get_selection(); std::vector rows = sel->get_selected_rows(); if (!rows.empty()) { - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[0]); + // convert index of visual selection (i.e. if filtered) to index of model + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]); + Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path); if (it) { Gtk::TreeModel::Row row = *it; src = row[m_InstrumentsModel.m_col_instr]; @@ -5170,6 +5190,10 @@ const bool found = m_TreeViewInstruments.get_path_at_pos(x, y, path); if (!found) return; + // convert index of visual selection (i.e. if filtered) to index of model + path = m_refInstrumentsModelFilter->convert_path_to_child_path(path); + if (!path) return; + Gtk::TreeModel::iterator iter = m_refInstrumentsTreeModel->get_iter(path); if (!iter) return; Gtk::TreeModel::Row row = *iter; @@ -5422,7 +5446,9 @@ Glib::RefPtr sel = m_TreeViewInstruments.get_selection(); std::vector rows = sel->get_selected_rows(); for (int r = 0; r < rows.size(); ++r) { - Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]); + // convert index of visual selection (i.e. if filtered) to index of model + Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]); + Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path); if (it) { Gtk::TreeModel::Row row = *it; int index = row[m_InstrumentsModel.m_col_nr];