From 87caf487e1fd3c6b72dd0b982fe7a6c1a38662d1 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 19 Apr 2010 20:44:57 +0000 Subject: [PATCH] Extend Alert::prompt such that 4 buttons are possible. Thus, when exporting, the extra dialog appearing when choosing to overwrite a file is not necessary anymore. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34222 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Exporter.cpp | 25 +++++++------------------ src/frontends/alert.h | 4 +++- src/frontends/qt4/GuiAlert.cpp | 27 +++++++++++++++++++-------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Exporter.cpp b/src/Exporter.cpp index 32fd07c453..16ff2a3a8a 100644 --- a/src/Exporter.cpp +++ b/src/Exporter.cpp @@ -40,26 +40,15 @@ namespace Alert = frontend::Alert; static int checkOverwrite(FileName const & filename) { if (!filename.exists()) - return 0; + return 1; docstring text = bformat(_("The file %1$s already exists.\n\n" "Do you want to overwrite that file?"), makeDisplayPath(filename.absFilename())); - int choice = Alert::prompt(_("Overwrite file?"), - text, 0, 2, + return Alert::prompt(_("Overwrite file?"), + text, 0, 3, _("&Keep file"), _("&Overwrite"), - _("&Cancel export")); - - if (choice == 0) - return -1; - - if (choice == 1) { - text = _("Should I continue asking for overwriting files?"); - return Alert::prompt(_("Overwrite all files?"), - text, 0, 0, - _("Continue &asking"), _("&Overwrite all")); - } - return choice; + _("Overwrite &all"), _("&Cancel export")); } @@ -89,12 +78,12 @@ CopyStatus copyFile(string const & format, if (!force) { switch(checkOverwrite(destFile)) { - case -1: - return SUCCESS; case 0: + return SUCCESS; + case 1: ret = SUCCESS; break; - case 1: + case 2: ret = FORCE; break; default: diff --git a/src/frontends/alert.h b/src/frontends/alert.h index 433369d1b9..4f05234297 100644 --- a/src/frontends/alert.h +++ b/src/frontends/alert.h @@ -32,7 +32,9 @@ namespace Alert { */ int prompt(docstring const & title, docstring const & question, int default_button, int cancel_button, - docstring const & b1, docstring const & b2, docstring const & b3 = docstring()); + docstring const & b1, docstring const & b2, + docstring const & b3 = docstring(), + docstring const & b4 = docstring()); /** * 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 f4d4309f70..70bca4151e 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -125,7 +126,8 @@ namespace Alert { int prompt(docstring const & title0, docstring const & question, int default_button, int cancel_button, - docstring const & b1, docstring const & b2, docstring const & b3) + docstring const & b1, docstring const & b2, + docstring const & b3, docstring const & b4) { //lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl; if (!use_gui || lyxerr.debugging()) { @@ -138,6 +140,7 @@ int prompt(docstring const & title0, docstring const & question, case 0: lyxerr << b1 << endl; case 1: lyxerr << b2 << endl; case 2: lyxerr << b3 << endl; + case 3: lyxerr << b4 << endl; } if (!use_gui) return default_button; @@ -151,13 +154,21 @@ int prompt(docstring const & title0, docstring const & question, // FIXME replace that with guiApp->currentView() //LYXERR0("FOCUS: " << qApp->focusWidget()); - int res = QMessageBox::information(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(question)), - toqstr(b1), - toqstr(b2), - b3.empty() ? QString::null : toqstr(b3), - default_button, cancel_button); + QPushButton * b[4] = { 0, 0, 0, 0 }; + QMessageBox msg_box(QMessageBox::Information, + toqstr(title), toqstr(formatted(question)), + QMessageBox::NoButton, qApp->focusWidget()); + b[0] = msg_box.addButton(b1.empty() ? "OK" : toqstr(b1), + QMessageBox::ActionRole); + if (!b2.empty()) + b[1] = msg_box.addButton(toqstr(b2), QMessageBox::ActionRole); + if (!b3.empty()) + b[2] = msg_box.addButton(toqstr(b3), QMessageBox::ActionRole); + if (!b4.empty()) + b[3] = msg_box.addButton(toqstr(b4), QMessageBox::ActionRole); + msg_box.setDefaultButton(b[default_button]); + msg_box.setEscapeButton(static_cast(b[cancel_button])); + int res = msg_box.exec(); qApp->restoreOverrideCursor(); -- 2.39.5