From ef31f02ca5aeab34f7ad2e838dbbf90b8b773d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Fri, 5 Jun 2009 05:06:17 +0000 Subject: [PATCH] backport rev. 29324: Timestamp: 04/19/09 13:57:52 Author: spitz Message: Implement a warning dialog with a "Do not show this warning again!" checkbox. Since Qt does not provide this, we have to roll our own dialog. Hidden warnings are stored in sessions. The dialog is currently only used in the case where an included file has a different textclass then the master (bug 3218). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@29941 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 1 + src/frontends/alert.h | 5 +- src/frontends/qt4/GuiAlert.cpp | 50 ++++++++- src/frontends/qt4/Makefile.am | 1 + src/frontends/qt4/ui/ToggleWarningUi.ui | 135 ++++++++++++++++++++++++ src/insets/InsetInclude.cpp | 2 +- status.16x | 5 + 7 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 src/frontends/qt4/ui/ToggleWarningUi.ui diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 5cdfe60806..3d61873885 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -950,6 +950,7 @@ src_frontends_qt4_ui_files = Split(''' TextLayoutUi.ui ThesaurusUi.ui TocUi.ui + ToggleWarningUi.ui VSpaceUi.ui ViewSourceUi.ui WrapUi.ui diff --git a/src/frontends/alert.h b/src/frontends/alert.h index b4e123731c..433369d1b9 100644 --- a/src/frontends/alert.h +++ b/src/frontends/alert.h @@ -37,8 +37,11 @@ int prompt(docstring const & title, docstring const & question, /** * Display a warning to the user. Title should be a short (general) summary. * Only use this if the user cannot perform some remedial action. + * \p askshowagain will display a check box where the user can turn off the + * warning for future cases. Ponder carefully if this is feasible. */ -void warning(docstring const & title, docstring const & message); +void warning(docstring const & title, docstring const & message, + bool const & askshowagain = false); /** * Display a warning to the user. Title should be a short (general) summary. diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index e399835a7b..1aed9eb325 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Jürgen Spitzmüller * \author Abdelrazak Younes * * Full author contact details are available in file CREDITS. @@ -18,6 +19,7 @@ #include "qt_helpers.h" #include "LyX.h" // for lyx::use_gui #include "ui_AskForTextUi.h" +#include "ui_ToggleWarningUi.h" #include "support/gettext.h" #include "support/debug.h" @@ -25,9 +27,11 @@ #include "support/lstrings.h" #include +#include #include #include #include +#include #include #include @@ -39,6 +43,17 @@ namespace lyx { namespace frontend { +class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi +{ +public: + GuiToggleWarningDialog(QWidget * parent) : QDialog(parent) + { + Ui::ToggleWarningUi::setupUi(this); + QDialog::setModal(true); + } +}; + + static docstring const formatted(docstring const & text) { const int w = 80; @@ -99,6 +114,29 @@ static docstring const formatted(docstring const & text) } +void toggleWarning(docstring const & title, docstring const & msg) +{ + if (!use_gui) + return; + + QSettings settings; + if (settings.value("hidden_warnings/" + toqstr(msg), false).toBool()) + return; + + GuiToggleWarningDialog * dlg = + new GuiToggleWarningDialog(qApp->focusWidget()); + + dlg->setWindowTitle(toqstr(title)); + dlg->messageLA->setText(toqstr(formatted(msg))); + dlg->dontShowAgainCB->setChecked(false); + + if (dlg->exec() == QDialog::Accepted) + if (dlg->dontShowAgainCB->isChecked()) + settings.setValue("hidden_warnings/" + + toqstr(msg), true); +} + + namespace Alert { int prompt(docstring const & title0, docstring const & question, @@ -145,7 +183,8 @@ int prompt(docstring const & title0, docstring const & question, } -void warning(docstring const & title0, docstring const & message) +void warning(docstring const & title0, docstring const & message, + bool const & askshowagain) { lyxerr << "Warning: " << title0 << '\n' << "----------------------------------------\n" @@ -165,9 +204,12 @@ void warning(docstring const & title0, docstring const & message) toqstr(formatted(message))); return; } - QMessageBox::warning(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + if (!askshowagain) + QMessageBox::warning(qApp->focusWidget(), + toqstr(title), + toqstr(formatted(message))); + else + toggleWarning(title, message); } diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 5b1919c10a..f0ad135341 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -301,6 +301,7 @@ UIFILES = \ TextLayoutUi.ui \ ThesaurusUi.ui \ TocUi.ui \ + ToggleWarningUi.ui \ ViewSourceUi.ui \ VSpaceUi.ui \ WrapUi.ui diff --git a/src/frontends/qt4/ui/ToggleWarningUi.ui b/src/frontends/qt4/ui/ToggleWarningUi.ui new file mode 100644 index 0000000000..a0d917a20d --- /dev/null +++ b/src/frontends/qt4/ui/ToggleWarningUi.ui @@ -0,0 +1,135 @@ + + + ToggleWarningUi + + + + 0 + 0 + 310 + 140 + + + + LyX: Enter text + + + true + + + + 9 + + + 6 + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 247 + 16 + + + + + + + + If you check this, LyX will not warn you again in the given case. + + + &Do not show this warning again! + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 247 + 16 + + + + + + + + Qt::Horizontal + + + + 81 + 20 + + + + + + + + &OK + + + true + + + + + + + Qt::Horizontal + + + + 81 + 20 + + + + + + + + qt_i18n.h + + + + + okPB + clicked() + ToggleWarningUi + accept() + + + 134 + 116 + + + 134 + 69 + + + + + diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index cef1b65702..edc8f2af64 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -497,7 +497,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const included_file.displayName(), from_utf8(tmp->params().documentClass().name()), from_utf8(masterBuffer->params().documentClass().name())); - Alert::warning(_("Different textclasses"), text); + Alert::warning(_("Different textclasses"), text, true); } // Make sure modules used in child are all included in master diff --git a/status.16x b/status.16x index b36daa8e3a..ac576019b3 100644 --- a/status.16x +++ b/status.16x @@ -34,6 +34,11 @@ What's new * USER INTERFACE +- LyX's warning about different textclasses in master and child now has a + "Do not show this warning again!" checkbox. Checking it will disable the + warning for this specific master/child constellation over sessions + (bug 3218). + - Tooltips for footnotes and some other insets now wrap, so they can actually be seen.