From 3cb53ec9ead751459126ef08304e63ceda20a4e1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 9 Apr 2021 00:32:19 +0300 Subject: [PATCH 24/24] Ruledit: Prevent multiple "Edit Values" dialogs for same ruleset item See osdn #41951 Signed-off-by: Marko Lindqvist --- common/improvement.c | 1 + common/improvement.h | 1 + common/unittype.c | 1 + common/unittype.h | 1 + tools/ruledit/edit_impr.cpp | 8 ++++++++ tools/ruledit/edit_impr.h | 3 +++ tools/ruledit/edit_utype.cpp | 8 ++++++++ tools/ruledit/edit_utype.h | 3 +++ tools/ruledit/tab_building.cpp | 9 +++++++-- tools/ruledit/tab_unit.cpp | 9 +++++++-- 10 files changed, 40 insertions(+), 4 deletions(-) diff --git a/common/improvement.c b/common/improvement.c index b5b67214b0..4b9fa54b9c 100644 --- a/common/improvement.c +++ b/common/improvement.c @@ -56,6 +56,7 @@ void improvements_init(void) requirement_vector_init(&p->reqs); requirement_vector_init(&p->obsolete_by); p->disabled = FALSE; + p->ruledit_dlg = NULL; } } diff --git a/common/improvement.h b/common/improvement.h index 83c161976d..7b425dc848 100644 --- a/common/improvement.h +++ b/common/improvement.h @@ -69,6 +69,7 @@ struct impr_type { Impr_type_id item_number; struct name_translation name; bool disabled; /* Does not really exist - hole in improvements array */ + void *ruledit_dlg; char graphic_str[MAX_LEN_NAME]; /* city icon of improv. */ char graphic_alt[MAX_LEN_NAME]; /* city icon of improv. */ struct requirement_vector reqs; diff --git a/common/unittype.c b/common/unittype.c index 5c0c502860..c27ad72e6b 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -1710,6 +1710,7 @@ void unit_types_init(void) unit_types[i].veteran = NULL; unit_types[i].bonuses = combat_bonus_list_new(); unit_types[i].disabled = FALSE; + unit_types[i].ruledit_dlg = NULL; } } diff --git a/common/unittype.h b/common/unittype.h index 4a5fdd0fe5..e989586bfd 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -470,6 +470,7 @@ struct unit_type { Unit_type_id item_number; struct name_translation name; bool disabled; /* Does not really exist - hole in units array */ + void *ruledit_dlg; char graphic_str[MAX_LEN_NAME]; char graphic_alt[MAX_LEN_NAME]; char sound_move[MAX_LEN_NAME]; diff --git a/tools/ruledit/edit_impr.cpp b/tools/ruledit/edit_impr.cpp index a3e5074e54..e1f13fae18 100644 --- a/tools/ruledit/edit_impr.cpp +++ b/tools/ruledit/edit_impr.cpp @@ -60,6 +60,14 @@ edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : QDialog() setLayout(main_layout); } +/************************************************************************** + User is closing dialog. +**************************************************************************/ +void edit_impr::closeEvent(QCloseEvent *cevent) +{ + impr->ruledit_dlg = nullptr; +} + /************************************************************************** Refresh the information. **************************************************************************/ diff --git a/tools/ruledit/edit_impr.h b/tools/ruledit/edit_impr.h index 184d19c7cd..ba8f3dd640 100644 --- a/tools/ruledit/edit_impr.h +++ b/tools/ruledit/edit_impr.h @@ -37,6 +37,9 @@ class edit_impr : public QDialog struct impr_type *impr; QSpinBox *bcost; + protected: + void closeEvent(QCloseEvent *cevent); + private slots: void set_bcost_value(int value); }; diff --git a/tools/ruledit/edit_utype.cpp b/tools/ruledit/edit_utype.cpp index bded454ed1..b1b57751ae 100644 --- a/tools/ruledit/edit_utype.cpp +++ b/tools/ruledit/edit_utype.cpp @@ -77,6 +77,14 @@ edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in) : QDialog setLayout(main_layout); } +/************************************************************************** + User is closing dialog. +**************************************************************************/ +void edit_utype::closeEvent(QCloseEvent *cevent) +{ + utype->ruledit_dlg = nullptr; +} + /************************************************************************** Refresh the information. **************************************************************************/ diff --git a/tools/ruledit/edit_utype.h b/tools/ruledit/edit_utype.h index 3b7361041c..5756cb510b 100644 --- a/tools/ruledit/edit_utype.h +++ b/tools/ruledit/edit_utype.h @@ -40,6 +40,9 @@ class edit_utype : public QDialog QToolButton *req_button; QSpinBox *bcost; + protected: + void closeEvent(QCloseEvent *cevent); + private slots: void req_menu(QAction *action); void set_bcost_value(int value); diff --git a/tools/ruledit/tab_building.cpp b/tools/ruledit/tab_building.cpp index e2fda74a4f..4534d69593 100644 --- a/tools/ruledit/tab_building.cpp +++ b/tools/ruledit/tab_building.cpp @@ -297,8 +297,13 @@ void tab_building::edit_reqs() void tab_building::edit_now() { if (selected != nullptr) { - edit_impr *edit = new edit_impr(ui, selected); + if (selected->ruledit_dlg == nullptr) { + edit_impr *edit = new edit_impr(ui, selected); - edit->show(); + edit->show(); + selected->ruledit_dlg = edit; + } else { + ((edit_impr *)selected->ruledit_dlg)->raise(); + } } } diff --git a/tools/ruledit/tab_unit.cpp b/tools/ruledit/tab_unit.cpp index 263d0e16f4..92999a316c 100644 --- a/tools/ruledit/tab_unit.cpp +++ b/tools/ruledit/tab_unit.cpp @@ -220,9 +220,14 @@ void tab_unit::delete_now() void tab_unit::edit_now() { if (selected != nullptr) { - edit_utype *edit = new edit_utype(ui, selected); + if (selected->ruledit_dlg == nullptr) { + edit_utype *edit = new edit_utype(ui, selected); - edit->show(); + edit->show(); + selected->ruledit_dlg = edit; + } else { + ((edit_utype *)selected->ruledit_dlg)->raise(); + } } } -- 2.30.2