From fe89cb6b3ced817dee13002c4d1474a3121cd2bc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 9 Apr 2021 00:18:27 +0300 Subject: [PATCH 48/48] 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 6248504ea6..3712e6369e 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->ruledit_disabled = FALSE; + p->ruledit_dlg = NULL; } } diff --git a/common/improvement.h b/common/improvement.h index 57a2598cc3..342af9a6d8 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 ruledit_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 ae1bb1eef0..2680c10f06 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -2256,6 +2256,7 @@ void unit_types_init(void) unit_types[i].veteran = NULL; unit_types[i].bonuses = combat_bonus_list_new(); unit_types[i].ruledit_disabled = FALSE; + unit_types[i].ruledit_dlg = NULL; } } diff --git a/common/unittype.h b/common/unittype.h index e07554be97..17d0af85b8 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -473,6 +473,7 @@ struct unit_type { Unit_type_id item_number; struct name_translation name; bool ruledit_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 9ad04e27dd..4e5e3ce7d9 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 61c3a12e2f..c7d2de4c93 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 18c27163fa..31c9f6f328 100644 --- a/tools/ruledit/tab_building.cpp +++ b/tools/ruledit/tab_building.cpp @@ -318,8 +318,13 @@ void tab_building::edit_effects() 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 bab52747f1..61066da6f8 100644 --- a/tools/ruledit/tab_unit.cpp +++ b/tools/ruledit/tab_unit.cpp @@ -225,9 +225,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