From 9d468bc6ee42029d6151c276cebe03936b92a346 Mon Sep 17 00:00:00 2001 From: Pandagrapher Date: Fri, 17 Apr 2020 17:00:04 +0200 Subject: [PATCH] Avoid a case where no spot is selected using Ctrl+click on treeview --- rtgui/controlspotpanel.cc | 24 +++++++++++++++++++++++- rtgui/controlspotpanel.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rtgui/controlspotpanel.cc b/rtgui/controlspotpanel.cc index 62d784756..715d30b2b 100644 --- a/rtgui/controlspotpanel.cc +++ b/rtgui/controlspotpanel.cc @@ -135,6 +135,11 @@ ControlSpotPanel::ControlSpotPanel(): sigc::mem_fun( *this, &ControlSpotPanel::blockTreeviewSearch), false); + // Avoid situation where no spot is selected (Ctrl+click on treeview) + treeview_->signal_button_press_event().connect( + sigc::mem_fun( + *this, &ControlSpotPanel::onSpotSelectionEvent), false); + auto cell = Gtk::manage(new Gtk::CellRendererText()); int cols_count = treeview_->append_column(M("TP_LOCALLAB_COL_NAME"), *cell); auto col = treeview_->get_column(cols_count - 1); @@ -709,6 +714,17 @@ bool ControlSpotPanel::blockTreeviewSearch(GdkEventKey* event) return false; } +bool ControlSpotPanel::onSpotSelectionEvent(GdkEventButton* event) +{ + if (event->state & Gdk::CONTROL_MASK) { // Ctrl + // No action is performed to avoid a situation where no spot is selected + return true; + } + + // Otherwise selection action is transfered to treeview widget + return false; +} + void ControlSpotPanel::load_ControlSpot_param() { // printf("load_ControlSpot_param\n"); @@ -768,9 +784,15 @@ void ControlSpotPanel::controlspotChanged() } // Raise event + const int selIndex = getSelectedSpot(); + + if (selIndex == -1) { // No selected spot + return; + } + selSpotChanged_ = true; eventType = SpotSelection; - SpotRow* const spotRow = getSpot(getSelectedSpot()); + SpotRow* const spotRow = getSpot(selIndex); // Image area shall be regenerated if mask preview was active when switching spot if (maskPrevActive) { diff --git a/rtgui/controlspotpanel.h b/rtgui/controlspotpanel.h index fadf0fc73..0ae41e91b 100644 --- a/rtgui/controlspotpanel.h +++ b/rtgui/controlspotpanel.h @@ -190,6 +190,7 @@ private: bool on_button_visibility(GdkEventButton* event); bool blockTreeviewSearch(GdkEventKey* event); + bool onSpotSelectionEvent(GdkEventButton* event); void load_ControlSpot_param();