diff --git a/rtgui/controlspotpanel.cc b/rtgui/controlspotpanel.cc index 2e3fe4f3c..f7e87287d 100644 --- a/rtgui/controlspotpanel.cc +++ b/rtgui/controlspotpanel.cc @@ -1718,28 +1718,32 @@ int ControlSpotPanel::getSelectedSpot() return id; } -void ControlSpotPanel::setSelectedSpot(const int id) +bool ControlSpotPanel::setSelectedSpot(const int id) { // printf("setSelectedSpot: %d\n", id); MyMutex::MyLock lock(mTreeview); - disableParamlistener(true); - const Gtk::TreeModel::Children children = treemodel_->children(); for (auto iter = children.begin(); iter != children.end(); iter++) { const Gtk::TreeModel::Row row = *iter; if (row[spots_.id] == id) { + disableParamlistener(true); + treeview_->set_cursor(treemodel_->get_path(row)); load_ControlSpot_param(); updateParamVisibility(); updateCurveOpacity(row); + + disableParamlistener(false); + + return true; } } - disableParamlistener(false); + return false; } int ControlSpotPanel::getNewId() diff --git a/rtgui/controlspotpanel.h b/rtgui/controlspotpanel.h index 2dfd0e0cf..e1f665833 100644 --- a/rtgui/controlspotpanel.h +++ b/rtgui/controlspotpanel.h @@ -152,8 +152,9 @@ public: * Setter of selected spot * * @param id The id of spot to be selected + * @return True if a spot corresponding to the id has been selected */ - void setSelectedSpot(const int id); + bool setSelectedSpot(const int id); // Control spot creation functions /** diff --git a/rtgui/locallab.cc b/rtgui/locallab.cc index 7a36fb194..f75864202 100644 --- a/rtgui/locallab.cc +++ b/rtgui/locallab.cc @@ -1569,13 +1569,21 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited) if (pp->locallab.spots.at(i).id == spotId) { // ProcParams update pp->locallab.nbspot--; - pp->locallab.selspot = 0; pp->locallab.spots.erase(pp->locallab.spots.begin() + i); expsettings->deleteControlSpot(spotId); - // Select one remaining spot + // Select the first remaining spot before deleted one if (pp->locallab.nbspot > 0) { - expsettings->setSelectedSpot(pp->locallab.spots.at(pp->locallab.selspot).id); + for (int j = i - 1; j >= 0; j--) { // procparams spots uses zero-based index whereas spot ids use one-based index + if (expsettings->setSelectedSpot(j + 1)) { // True if an existing spot has been selected on controlspotpanel + pp->locallab.selspot = j; + + break; + } + } + } else { + // Reset selspot + pp->locallab.selspot = 0; } // Update Locallab tools GUI with selected spot