diff --git a/ChangeLog b/ChangeLog index 2569703e..27d41cb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2021-05-13 Markus Gans + * Prevent duplicate widget in the close widget list + 2021-05-07 Markus Gans * Some pointers were replaced by references diff --git a/src/fwidget.cpp b/src/fwidget.cpp index ee0dc57a..0db33288 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -851,7 +851,7 @@ bool FWidget::close() { hide(); - if ( ! flags.modal ) + if ( ! flags.modal && ! isInFWidgetList(close_widget, this) ) close_widget->push_back(this); } diff --git a/src/fwidget_functions.cpp b/src/fwidget_functions.cpp index a2d91a6d..4d915fd8 100644 --- a/src/fwidget_functions.cpp +++ b/src/fwidget_functions.cpp @@ -20,6 +20,8 @@ * . * ***********************************************************************/ +#include + #include "final/fapplication.h" #include "final/fcolorpair.h" #include "final/fstatusbar.h" @@ -53,6 +55,16 @@ bool isFocusPrevKey (const FKey key) return false; } +//---------------------------------------------------------------------- +bool isInFWidgetList (const FWidget::FWidgetList* list, const FWidget* obj) +{ + if ( ! list || ! obj ) + return false; + + return std::any_of ( list->begin(), list->end() + , [&obj] (FWidget* w) { return w == obj; } ); +} + //---------------------------------------------------------------------- FApplication* getFApplication() { diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index aa409340..7748093e 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -507,6 +507,7 @@ class FWidget : public FVTerm, public FObject void detectTermSize(); bool isFocusNextKey (const FKey); bool isFocusPrevKey (const FKey); +bool isInFWidgetList (const FWidget::FWidgetList*, const FWidget*); FKey getHotkey (const FString&); std::size_t getHotkeyPos (const FString& src, FString& dest); void setHotkeyViaString (FWidget*, const FString&);