Properly set up paste and textstyle-apply MenuButtons when no buffer is open.

This commit is contained in:
Juergen Spitzmueller 2018-12-28 14:34:14 +01:00
parent 4d010d97fa
commit a65f1e54dc

View File

@ -336,6 +336,9 @@ void DynamicMenuButton::updateTriggered()
LASSERT(m, return); LASSERT(m, return);
GuiView const & owner = bar_->owner(); GuiView const & owner = bar_->owner();
BufferView const * bv = owner.currentBufferView(); BufferView const * bv = owner.currentBufferView();
string const & menutype = tbitem_.name_;
if (menutype == "dynamic-custom-insets" || menutype == "dynamic-char-styles") {
if (!bv) { if (!bv) {
m->clear(); m->clear();
setEnabled(false); setEnabled(false);
@ -344,9 +347,6 @@ void DynamicMenuButton::updateTriggered()
d->inset_ = nullptr; d->inset_ = nullptr;
return; return;
} }
string const & menutype = tbitem_.name_;
if (menutype == "dynamic-custom-insets" || menutype == "dynamic-char-styles") {
DocumentClassConstPtr text_class = DocumentClassConstPtr text_class =
bv->buffer().params().documentClassPtr(); bv->buffer().params().documentClassPtr();
InsetText const * inset = &(bv->cursor().innerText()->inset()); InsetText const * inset = &(bv->cursor().innerText()->inset());
@ -367,6 +367,12 @@ void DynamicMenuButton::updateTriggered()
&& inset->insetAllowed(FLEX_CODE)); && inset->insetAllowed(FLEX_CODE));
} else if (menutype == "textstyle-apply") { } else if (menutype == "textstyle-apply") {
m->clear(); m->clear();
setPopupMode(QToolButton::MenuButtonPopup);
QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
if (!bv) {
setEnabled(false);
return;
}
vector<docstring> ffList = bv->cursor().innerText()->getFreeFonts(); vector<docstring> ffList = bv->cursor().innerText()->getFreeFonts();
unsigned int i = 0; unsigned int i = 0;
Action * default_act = nullptr; Action * default_act = nullptr;
@ -390,14 +396,19 @@ void DynamicMenuButton::updateTriggered()
m->addAction(reset_act); m->addAction(reset_act);
if (default_act) if (default_act)
QToolButton::setDefaultAction(default_act); QToolButton::setDefaultAction(default_act);
QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
setPopupMode(QToolButton::MenuButtonPopup);
setEnabled(lyx::getStatus(FuncRequest(LFUN_TEXTSTYLE_APPLY)).enabled() setEnabled(lyx::getStatus(FuncRequest(LFUN_TEXTSTYLE_APPLY)).enabled()
|| lyx::getStatus(FuncRequest(LFUN_FONT_DEFAULT)).enabled()); || lyx::getStatus(FuncRequest(LFUN_FONT_DEFAULT)).enabled());
} else if (menutype == "paste") { } else if (menutype == "paste") {
m->clear(); m->clear();
setPopupMode(QToolButton::MenuButtonPopup);
Action * default_action = new Action(FuncRequest(LFUN_PASTE),
getIcon(FuncRequest(LFUN_PASTE), false),
qt_("Paste"), qt_("Paste"), this);
if (!bv) {
setEnabled(false);
QToolButton::setDefaultAction(default_action);
return;
}
docstring_list const sel = cap::availableSelections(&bv->buffer()); docstring_list const sel = cap::availableSelections(&bv->buffer());
docstring_list::const_iterator cit = sel.begin(); docstring_list::const_iterator cit = sel.begin();
@ -412,11 +423,7 @@ void DynamicMenuButton::updateTriggered()
Action * act = new Action(func, QIcon(), toqstr(lb), toqstr(s), this); Action * act = new Action(func, QIcon(), toqstr(lb), toqstr(s), this);
m->addAction(act); m->addAction(act);
} }
Action * default_action = new Action(FuncRequest(LFUN_PASTE),
getIcon(FuncRequest(LFUN_PASTE), false),
qt_("Paste"), qt_("Paste"), this);
QToolButton::setDefaultAction(default_action); QToolButton::setDefaultAction(default_action);
setPopupMode(QToolButton::MenuButtonPopup);
setEnabled(lyx::getStatus(FuncRequest(LFUN_PASTE)).enabled()); setEnabled(lyx::getStatus(FuncRequest(LFUN_PASTE)).enabled());
} }
} }