#include "support/debug.h"
#include "support/lstrings.h"
+#include <QDialogButtonBox>
+
using namespace std;
using namespace lyx::support;
InsetParamsDialog::InsetParamsDialog(GuiView & lv, InsetParamsWidget * widget)
: DialogView(lv, toqstr(insetName(widget->insetCode())),
- toqstr(insetName(widget->insetCode()))), d(new Private)
+ widget->dialogTitle()), d(new Private)
{
setupUi(this);
setInsetParamsWidget(widget);
synchronizedCB->setChecked(true);
on_immediateApplyCB_stateChanged(false);
setFocusProxy(widget);
+ newPB = buttonBox->addButton(qt_("Ne&w Inset"),
+ QDialogButtonBox::ActionRole);
}
InsetParamsDialog::~InsetParamsDialog()
}
-bool InsetParamsDialog::initialiseParams(std::string const & data)
+bool InsetParamsDialog::initialiseParams(std::string const & sdata)
{
- if (!d->widget_->initialiseParams(data))
- on_restorePB_clicked();
+ if (!d->widget_->initialiseParams(sdata))
+ resetDialog();
return true;
}
}
-void InsetParamsDialog::on_restorePB_clicked()
+void InsetParamsDialog::on_buttonBox_clicked(QAbstractButton * button)
{
- updateView(true);
- restorePB->setEnabled(false);
- d->changed_ = false;
- d->inset_ = inset(d->widget_->insetCode());
+ switch (buttonBox->buttonRole(button)) {
+ case QDialogButtonBox::AcceptRole: {// OK
+ Inset const * i = inset(d->widget_->insetCode());
+ if (i)
+ applyView();
+ else
+ newInset();
+ hide();
+ break;
+ }
+ case QDialogButtonBox::ApplyRole:
+ applyView();
+ break;
+ case QDialogButtonBox::RejectRole:// Cancel or Close
+ hide();
+ break;
+ case QDialogButtonBox::ResetRole: {
+ resetDialog();
+ break;
+ }
+ case QDialogButtonBox::ActionRole:// New Inset
+ newInset();
+ break;
+ default:
+ break;
+ }
}
-void InsetParamsDialog::on_okPB_clicked()
+void InsetParamsDialog::resetDialog()
{
- Inset const * i = inset(d->widget_->insetCode());
- if (i)
- applyView();
- else
- newInset();
- hide();
+ updateView(true);
+ buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
+ d->changed_ = false;
+ d->inset_ = inset(d->widget_->insetCode());
}
}
-void InsetParamsDialog::on_newPB_clicked()
+bool InsetParamsDialog::newInsetAllowed() const
{
- newInset();
-}
-
-
-void InsetParamsDialog::on_applyPB_clicked()
-{
- applyView();
-}
-
-
-void InsetParamsDialog::on_closePB_clicked()
-{
- hide();
+ docstring const argument = d->widget_->dialogToParams();
+ FuncRequest const fr = FuncRequest(d->widget_->creationCode(), argument);
+ FuncStatus const fs(getStatus(fr));
+ return fs.enabled();
}
docstring InsetParamsDialog::checkWidgets(bool immediate)
{
- bool const widget_ok = d->widget_->checkWidgets();
+ bool const read_only = buffer().isReadonly();
+ bool const widget_ok = d->widget_->checkWidgets(read_only);
Inset const * ins = inset(d->widget_->insetCode());
docstring const argument = d->widget_->dialogToParams();
bool valid_argument = !argument.empty();
FuncCode const code = immediate
? d->widget_->creationCode() : LFUN_INSET_MODIFY;
bool const lfun_ok = lyx::getStatus(FuncRequest(code, argument)).enabled();
- bool const read_only = buffer().isReadonly();
- okPB->setEnabled(!immediate && widget_ok && !read_only && valid_argument);
+ buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!immediate && widget_ok
+ && !read_only && valid_argument);
bool const can_be_restored = !immediate && !read_only
&& ins && (ins != d->inset_ || d->changed_);
- restorePB->setEnabled(can_be_restored);
- applyPB->setEnabled(!immediate && lfun_ok && widget_ok && !read_only && valid_argument);
- d->widget_->setEnabled(!read_only);
+ buttonBox->button(QDialogButtonBox::Reset)->setEnabled(can_be_restored);
+ buttonBox->button(QDialogButtonBox::Apply)->setEnabled(ins && !immediate
+ && lfun_ok && widget_ok
+ && !read_only && valid_argument);
+ immediateApplyCB->setEnabled(ins && !read_only);
+ // This seems to be the only way to access custom buttons
+ QList<QAbstractButton*> buttons = buttonBox->buttons();
+ for (int i = 0; i < buttons.size(); ++i) {
+ if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::ActionRole)
+ buttons.at(i)->setEnabled(widget_ok && !read_only
+ && valid_argument
+ && newInsetAllowed());
+ }
synchronizedCB->setEnabled(!immediate);
return argument;
}
{
d->changed_ = true;
docstring const argument = checkWidgets(immediateApplyCB->isChecked());
- if (immediateApplyCB->isChecked())
+ if (immediateApplyCB->isChecked()
+ && d->widget_->checkWidgets(buffer().isReadonly()))
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
}
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);
}