Skip to content

Commit a8ef815

Browse files
committed
UX
inform user that closing options form leads to unsaved changes
1 parent 94745aa commit a8ef815

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

src/huggle_l10n/Localization/en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,4 +921,6 @@
921921
<string name="main-clear-talk-page-summary">Cleaned old templates from talk page</string>
922922
<string name="han-connected">You are now connected to Huggle anti-vandalism network</string>
923923
<string name="han-disconnected">Lost connection to anti-vandalism network</string>
924+
<string name="preferences-unsaved-title">Preferences</string>
925+
<string name="preferences-unsaved-text">Closing this form may lose unsaved changes. Do you want to close anyway?</string>
924926
</resources>

src/huggle_ui/hw.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Huggle
1919
{
20+
//! Huggle Window base class, it provides some basic save / restore layout functionality shared by all Huggle windows
2021
class HUGGLE_EX_UI HW : public QDialog
2122
{
2223
Q_OBJECT

src/huggle_ui/preferences.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QFile>
2121
#include <QDir>
2222
#include <QMenu>
23+
#include <QCloseEvent>
2324
#include <huggle_core/core.hpp>
2425
#include <huggle_core/configuration.hpp>
2526
#include <huggle_core/exception.hpp>
@@ -215,6 +216,25 @@ Preferences::~Preferences()
215216
delete this->ui;
216217
}
217218

219+
void Preferences::closeEvent(QCloseEvent *event)
220+
{
221+
if (this->forceClose)
222+
{
223+
event->accept();
224+
return;
225+
}
226+
227+
int result = UiGeneric::pMessageBox(this, _l("preferences-unsaved-title"),
228+
_l("preferences-unsaved-text"),
229+
MessageBoxStyleQuestion);
230+
if (result == QMessageBox::No)
231+
{
232+
event->ignore();
233+
return;
234+
}
235+
event->accept();
236+
}
237+
218238
static void SetValue(HuggleQueueFilterMatch matching, QComboBox *item)
219239
{
220240
switch (matching)
@@ -404,7 +424,7 @@ void Huggle::Preferences::on_checkBox_InstantReverts_clicked()
404424

405425
void Preferences::RecordKeys(int row, int column)
406426
{
407-
if (this->RewritingForm)
427+
if (this->shortcutsRewriting)
408428
return;
409429
if (column != 2)
410430
{
@@ -443,13 +463,13 @@ void Preferences::RecordKeys(int row, int column)
443463
}
444464
}
445465

446-
this->ModifiedForm = true;
447-
this->RewritingForm = true;
466+
this->shortcutsModified = true;
467+
this->shortcutsRewriting = true;
448468
this->IgnoreConflicts = false;
449469
hcfg->Shortcuts[id].Modified = true;
450470
hcfg->Shortcuts[id].QAccel = key;
451471
this->ui->tableWidget_2->setItem(row, column, new QTableWidgetItem(key));
452-
this->RewritingForm = false;
472+
this->shortcutsRewriting = false;
453473
return;
454474

455475
revert:
@@ -848,19 +868,22 @@ void Huggle::Preferences::on_pushButton_OK_clicked()
848868
{
849869
hcfg->UserConfig->GoNext = Configuration_OnNext_Next;
850870
}
851-
if (this->ModifiedForm)
871+
if (this->shortcutsModified)
852872
{
853873
// we need to reload the shortcuts in main form
854874
hcfg->ReloadOfMainformNeeded = true;
855875
}
856876
Configuration::SaveSystemConfig();
857877
MainWindow::HuggleMain->ReloadInterface();
878+
858879
this->hide();
859880
}
860881

861882
void Huggle::Preferences::on_pushButton_CloseWin_clicked()
862883
{
884+
this->forceClose = true;
863885
this->close();
886+
this->forceClose = false;
864887
}
865888

866889
void Huggle::Preferences::on_pushButton_QueueSave_clicked()
@@ -1047,4 +1070,4 @@ void Huggle::Preferences::on_pushButton_ResetConfig_clicked()
10471070
}
10481071
UiGeneric::MessageBox(_l("preferences-reset-config-done"), _l("preferences-reset-config-restart"));
10491072
MainWindow::HuggleMain->Exit();
1050-
}
1073+
}

src/huggle_ui/preferences.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QHash>
2121

2222
class QCheckBox;
23+
class QCloseEvent;
2324

2425
namespace Ui
2526
{
@@ -39,6 +40,9 @@ namespace Huggle
3940
~Preferences();
4041
void EnableQueues(bool enabled);
4142

43+
protected:
44+
void closeEvent(QCloseEvent *event) override;
45+
4246
private slots:
4347
void on_listWidget_itemSelectionChanged();
4448
void on_checkBox_clicked();
@@ -84,10 +88,11 @@ namespace Huggle
8488
WikiSite *Site;
8589
bool IgnoreConflicts = false;
8690
bool isNowReloadingFilters = false;
87-
bool RewritingForm = false;
88-
bool ModifiedForm = false;
91+
bool shortcutsRewriting = false;
92+
bool shortcutsModified = false;
8993
int queueID = 0;
9094
bool queueModified = false;
95+
bool forceClose = false;
9196
Ui::Preferences *ui;
9297
};
9398
}

0 commit comments

Comments
 (0)