]> git.lyx.org Git - features.git/commitdiff
Extend Alert::prompt such that 4 buttons are possible. Thus, when
authorEnrico Forestieri <forenr@lyx.org>
Mon, 19 Apr 2010 20:44:57 +0000 (20:44 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 19 Apr 2010 20:44:57 +0000 (20:44 +0000)
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
src/frontends/alert.h
src/frontends/qt4/GuiAlert.cpp

index 32fd07c45399f11078a21b044115c65f2804d20c..16ff2a3a8ad55f3d9197456e97f4ad1a8f739e23 100644 (file)
@@ -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:
index 433369d1b9bdecd73ee0e9bdd4837182ae59839f..4f052342974b9e48d1646214b208a06daaf6c4a9 100644 (file)
@@ -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.
index f4d4309f702d6e405e85d9d3bb3752ebf7475b50..70bca4151e83df79e3eb8161710f0b1c6a990f26 100644 (file)
@@ -31,6 +31,7 @@
 #include <QMessageBox>
 #include <QLineEdit>
 #include <QInputDialog>
+#include <QPushButton>
 #include <QSettings>
 
 #include <iomanip>
@@ -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<QAbstractButton *>(b[cancel_button]));
+       int res = msg_box.exec();
 
        qApp->restoreOverrideCursor();