]> git.lyx.org Git - features.git/commitdiff
Maintain default status for all dialogs using ButtonController
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 20 Dec 2018 11:56:30 +0000 (12:56 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:52 +0000 (14:39 +0200)
Should fix rest of #11417

src/frontends/qt4/ButtonController.cpp
src/frontends/qt4/ButtonController.h
src/frontends/qt4/GuiInclude.cpp
src/frontends/qt4/GuiRef.cpp
src/frontends/qt4/InsetParamsDialog.cpp

index ccac674e4aa449f8a58edf2490663a7ee117fec1..25dcee7541145acec9a696ad54ed5500127ade34 100644 (file)
@@ -114,6 +114,7 @@ public:
        QPushButton * cancel_;
        QPushButton * restore_;
        QCheckBox * auto_apply_;
+       QPushButton * default_;
 
        typedef QList<QWidget *> Widgets;
        Widgets read_only_;
@@ -205,7 +206,7 @@ bool ButtonController::setReadOnly(bool ro)
        // refreshReadOnly(); This will enable all widgets in dialogs, no matter if
        //                    they allowed to be enabled, so when you plan to
        //                    reenable this call, read this before:
-    // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg128222.html
+       // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg128222.html
        refresh();
        return ro;
 }
@@ -243,7 +244,9 @@ void ButtonController::refresh() const
                bool const enabled = policy().buttonStatus(ButtonPolicy::AUTOAPPLY);
                d->auto_apply_->setEnabled(enabled);
        }
-
+       if (d->default_)
+               // Somewhere in the chain this can lose default status (#11417)
+               d->default_->setDefault(true);
 }
 
 
@@ -263,15 +266,19 @@ void ButtonController::addCheckedLineEdit(QLineEdit * input, QWidget * label)
 }
 
 
-void ButtonController::setOK(QPushButton * obj)
+void ButtonController::setOK(QPushButton * obj, bool const default_button)
 {
        d->okay_ = obj;
+       if (default_button)
+               d->default_ = obj;
 }
 
 
-void ButtonController::setApply(QPushButton * obj)
+void ButtonController::setApply(QPushButton * obj, bool const default_button)
 {
        d->apply_ = obj;
+       if (default_button)
+               d->default_ = obj;
 }
 
 
@@ -281,15 +288,19 @@ void ButtonController::setAutoApply(QCheckBox * obj)
 }
 
 
-void ButtonController::setCancel(QPushButton * obj)
+void ButtonController::setCancel(QPushButton * obj, bool const default_button)
 {
        d->cancel_ = obj;
+       if (default_button)
+               d->default_ = obj;
 }
 
 
-void ButtonController::setRestore(QPushButton * obj)
+void ButtonController::setRestore(QPushButton * obj, bool const default_button)
 {
        d->restore_ = obj;
+       if (default_button)
+               d->default_ = obj;
 }
 
 
index 8f07cfb0039c6eeab2bee3a0b053266fd517bb20..46e5d0d0e7a1778e17c63c29c03e21d4c80f36ee 100644 (file)
@@ -92,11 +92,13 @@ public:
        //
 
        //@{
-       /// Store pointers to these widgets.
-       void setOK(QPushButton * obj);
-       void setApply(QPushButton * obj);
-       void setCancel(QPushButton * obj);
-       void setRestore(QPushButton * obj);
+       /// Store pointers to these widgets. \param default_button determines
+       /// the default button of the dialog (bound to return). This is
+       /// OK by default.
+       void setOK(QPushButton * obj, bool const default_button = true);
+       void setApply(QPushButton * obj, bool const default_button = false);
+       void setCancel(QPushButton * obj, bool const default_button = false);
+       void setRestore(QPushButton * obj, bool const default_button = false);
        void setAutoApply(QCheckBox * obj);
        //@}
 
index 43f71d73441a2f392cd1ee72ddd683fa01e2dc36..c55d71fa7f21ddb116bef58f36c13e3cac16f3d8 100644 (file)
@@ -154,10 +154,6 @@ void GuiInclude::typeChanged(int v)
                        listingsGB->setEnabled(false);
                        break;
        }
-       //see this thread
-       //  http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg118471.html
-       //for the reason this is here.
-       buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
 }
 
 
index 94d2b5a2234c00a575c4f5a58ac681d4da65a22b..5d46a471c710bb980c0c062085c8f3a480d405b5 100644 (file)
@@ -385,8 +385,6 @@ void GuiRef::updateContents()
        // Activate OK/Apply buttons if the users inserts a new ref
        // and we have a valid pre-setting.
        bc().setValid(isValid() && new_inset);
-       // Somewhere in the chain this can lose default status (#11417)
-       buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
 }
 
 
index 5c86260ed91e1fa0017fc4cb12bfad625ff946cc..a36de56988a3f84bcc4877944a53a8d804f85411 100644 (file)
@@ -253,7 +253,7 @@ void InsetParamsDialog::updateView()
        bool const update_widget =
                (synchronizedCB->isChecked() || immediateApplyCB->isChecked());
        updateView(update_widget);
-       
+
        // Somewhere in the chain this can lose default status (#11417)
        buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
 }