From b634b3eb3b5cc1c47fd3bc63294e16536d4f7664 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 18 Mar 2004 13:57:20 +0000 Subject: [PATCH] split LyXFunc::getStatus() into inset specific chunks git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8500 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FuncStatus.C | 10 +- src/FuncStatus.h | 4 +- src/MenuBackend.C | 22 +- src/bufferview_funcs.C | 7 - src/bufferview_funcs.h | 12 - src/cursor.C | 14 +- src/frontends/LyXView.C | 2 +- src/frontends/qt2/QLPopupMenu.C | 5 +- src/frontends/qt2/QLToolbar.C | 5 +- src/frontends/xforms/XFormsMenubar.C | 2 +- src/frontends/xforms/XFormsToolbar.C | 12 +- src/insets/insetbase.C | 2 +- src/insets/insetbase.h | 2 +- src/insets/insetcollapsable.C | 7 + src/insets/insetcollapsable.h | 2 + src/insets/insettabular.C | 78 ++++- src/insets/insettabular.h | 2 + src/insets/insettext.C | 7 + src/insets/insettext.h | 2 + src/lyxfunc.C | 498 +++++++-------------------- src/lyxtext.h | 12 +- src/mathed/math_nestinset.C | 71 ++++ src/mathed/math_nestinset.h | 3 + src/text2.C | 17 +- src/text3.C | 352 ++++++++++++++++++- 25 files changed, 693 insertions(+), 457 deletions(-) diff --git a/src/FuncStatus.C b/src/FuncStatus.C index 1998db67d1..3e0c615096 100644 --- a/src/FuncStatus.C +++ b/src/FuncStatus.C @@ -45,18 +45,18 @@ bool FuncStatus::unknown() const } -void FuncStatus::disabled(bool b) +void FuncStatus::enabled(bool b) { if (b) - v_ |= DISABLED; - else v_ &= !DISABLED; + else + v_ |= DISABLED; } -bool FuncStatus::disabled() const +bool FuncStatus::enabled() const { - return (v_ & DISABLED); + return !(v_ & DISABLED); } diff --git a/src/FuncStatus.h b/src/FuncStatus.h index 80613c2647..c9629112de 100644 --- a/src/FuncStatus.h +++ b/src/FuncStatus.h @@ -46,9 +46,9 @@ public: bool unknown() const; /// - void disabled(bool b); + void enabled(bool b); /// - bool disabled() const; + bool enabled() const; /// void setOnOff(bool b); diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 8c03ab0cb1..180a98fbb9 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -160,44 +160,46 @@ Menu & Menu::add(MenuItem const & i, LyXView const * view) } switch (i.kind()) { - case MenuItem::Command: - { + + case MenuItem::Command: { FuncStatus status = view->getLyXFunc().getStatus(i.func()); if (status.unknown() - || (status.disabled() && i.optional())) + || (!status.enabled() && i.optional())) break; items_.push_back(i); items_.back().status(status); break; } - case MenuItem::Submenu: - { + + case MenuItem::Submenu: { if (i.submenu()) { - bool disabled = true; + bool enabled = false; for (const_iterator cit = i.submenu()->begin(); cit != i.submenu()->end(); ++cit) { if ((cit->kind() == MenuItem::Command || cit->kind() == MenuItem::Submenu) - && !cit->status().disabled()) { - disabled = false; + && cit->status().enabled()) { + enabled = true; break; } } - if (!disabled || !i.optional()) { + if (enabled || !i.optional()) { items_.push_back(i); - items_.back().status().disabled(disabled); + items_.back().status().enabled(enabled); } } else items_.push_back(i); break; } + case MenuItem::Separator: if (!items_.empty() && items_.back().kind() != MenuItem::Separator) items_.push_back(i); break; + default: items_.push_back(i); } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 0cbb5ae1b9..2e1c6212c9 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -144,11 +144,4 @@ bool string2font(string const & data, LyXFont & font, bool & toggle) return (nset > 0); } - -bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE type) -{ - return cur.bv().available() && text && text->changeDepthAllowed(cur, type); -} - - } // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 743559b642..c8665daa71 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -16,9 +16,7 @@ #include -class LCursor; class LyXFont; -class LyXText; namespace bv_funcs { @@ -34,16 +32,6 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle); */ std::string const freefont2string(); - -/// what type of depth change to make -enum DEPTH_CHANGE { - INC_DEPTH, - DEC_DEPTH -}; - -/// Returns whether something would be changed by changeDepth -bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE); - } // namespace bv_funcs #endif diff --git a/src/cursor.C b/src/cursor.C index d8c6fb823a..85b7956e56 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -95,9 +95,9 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) //lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; FuncRequest cmd = cmd0; nopop_ = false; - DocumentIterator safe = *this; + LCursor safe = *this; - for ( ; size(); pop_back()) { + for ( ; size(); pop()) { lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; BOOST_ASSERT(pos() <= lastpos()); BOOST_ASSERT(idx() <= lastidx()); @@ -115,16 +115,16 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) // it completely to get a 'bomb early' behaviour in case this // object will be used again. if (nopop_ || !disp_.dispatched()) - DocumentIterator::operator=(safe); + operator=(safe); return disp_; } bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status) { - lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl; - DocumentIterator safe = *this; - for ( ; size(); pop_back()) { + LCursor safe = *this; + for ( ; size(); pop()) { + //lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl; BOOST_ASSERT(pos() <= lastpos()); BOOST_ASSERT(idx() <= lastidx()); BOOST_ASSERT(par() <= lastpar()); @@ -136,7 +136,7 @@ bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status) if (inset().getStatus(*this, cmd, status)) break; } - DocumentIterator::operator=(safe); + operator=(safe); return true; } diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 8db0e5cfec..6a18ffc032 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -106,7 +106,7 @@ void LyXView::updateToolbar() { bool const math = bufferview_->cursor().inMathed(); bool const table = - !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled(); + getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled(); toolbar_->update(math, table); } diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index ea7c8cd327..490435026c 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -93,8 +93,7 @@ void QLPopupMenu::populate(Menu * menu) insertSeparator(); } else if (m->kind() == MenuItem::Submenu) { pair res = createMenu(this, &(*m), owner_); - setItemEnabled(res.first, - !m->status().disabled()); + setItemEnabled(res.first, m->status().enabled()); res.second->populate(m->submenu()); } else { FuncStatus const status = m->status(); @@ -104,7 +103,7 @@ void QLPopupMenu::populate(Menu * menu) int const index = distance(funcs_.begin(), fit); insertItem(toqstr(getLabel(*m)), index); - setItemEnabled(index, !status.disabled()); + setItemEnabled(index, status.enabled()); setItemChecked(index, status.onoff(true)); } } diff --git a/src/frontends/qt2/QLToolbar.C b/src/frontends/qt2/QLToolbar.C index a1f7566615..07fa9829e7 100644 --- a/src/frontends/qt2/QLToolbar.C +++ b/src/frontends/qt2/QLToolbar.C @@ -70,10 +70,11 @@ void QLToolbar::update() button->setToggleButton(true); button->setOn(status.onoff(true)); - button->setEnabled(!status.disabled()); + button->setEnabled(status.enabled()); } - bool const enable = !owner_->getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT)).disabled(); + bool const enable = owner_->getLyXFunc(). + getStatus(FuncRequest(LFUN_LAYOUT)).enabled(); // Workaround for Qt bug where setEnabled(true) closes // the popup diff --git a/src/frontends/xforms/XFormsMenubar.C b/src/frontends/xforms/XFormsMenubar.C index fec33840e8..e8a3c0f421 100644 --- a/src/frontends/xforms/XFormsMenubar.C +++ b/src/frontends/xforms/XFormsMenubar.C @@ -269,7 +269,7 @@ int XFormsMenubar::create_submenu(Window win, XFormsView * view, label += "%B"; if (flag.onoff(false)) label += "%b"; - if (flag.disabled()) + if (!flag.enabled()) label += "%i"; // Add the shortcut diff --git a/src/frontends/xforms/XFormsToolbar.C b/src/frontends/xforms/XFormsToolbar.C index 2025257c26..d288cd7b97 100644 --- a/src/frontends/xforms/XFormsToolbar.C +++ b/src/frontends/xforms/XFormsToolbar.C @@ -117,9 +117,9 @@ void XFormsToolbar::update() for (; p != end; ++p) { if (p->func.action == int(ToolbarBackend::LAYOUTS) && combox_) { LyXFunc const & lf = owner_->getLyXFunc(); - bool const disable = - lf.getStatus(FuncRequest(LFUN_LAYOUT)).disabled(); - setEnabled(combox_, !disable); + bool const enable = + lf.getStatus(FuncRequest(LFUN_LAYOUT)).enabled(); + setEnabled(combox_, enable); continue; } @@ -139,14 +139,14 @@ void XFormsToolbar::update() fl_set_object_color(p->icon, FL_MCOL, FL_BLUE); fl_set_object_boxtype(p->icon, FL_UP_BOX); } - if (status.disabled()) { + if (status.enabled()) { + fl_activate_object(p->icon); + } else { // Is there a way here to specify a // mask in order to show that the // button is disabled? (JMarc) fl_deactivate_object(p->icon); } - else - fl_activate_object(p->icon); } } diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index b24bb93356..a6ded266b9 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -40,7 +40,7 @@ void InsetBase::priv_dispatch(LCursor & cur, FuncRequest &) } -bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) +bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &) const { return false; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index e9a045c8a8..6e93ae8728 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -74,7 +74,7 @@ public: void dispatch(LCursor & cur, FuncRequest & cmd); /// do we want to handle this event? virtual bool getStatus(LCursor & cur, FuncRequest const & cmd, - FuncStatus & status); + FuncStatus & status) const; /// cursor enters virtual void edit(LCursor & cur, bool left); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 3b61fdfd6b..0c8a5bef1b 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -361,6 +361,13 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) } +bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + return inset.getStatus(cur, cmd, flag); +} + + void InsetCollapsable::validate(LaTeXFeatures & features) const { inset.validate(features); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index c4866a1dcc..aa0ee77abc 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -125,6 +125,8 @@ protected: /// void priv_dispatch(LCursor & cur, FuncRequest & cmd); /// + bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; + /// void dimension_collapsed(Dimension &) const; /// void draw_collapsed(PainterInfo & pi, int x, int y) const; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 1f45315603..2ee3c69ddd 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -703,6 +703,79 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd) } +bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + switch (cmd.action) { + case LFUN_TABULAR_FEATURE: +#if 0 + if (cur.inMathed()) { + // FIXME: check temporarily disabled + // valign code + char align = mathcursor::valign(); + if (align == '\0') { + enable = false; + break; + } + if (cmd.argument.empty()) { + flag.clear(); + break; + } + if (!contains("tcb", cmd.argument[0])) { + enable = false; + break; + } + flag.setOnOff(cmd.argument[0] == align); + } else { + enable = false; + + char const align = mathcursor::halign(); + if (align == '\0') { + enable = false; + break; + } + if (cmd.argument.empty()) { + flag.clear(); + break; + } + if (!contains("lcr", cmd.argument[0])) { + enable = false; + break; + } + flag.setOnOff(cmd.argument[0] == align); + + disable = !mathcursor::halign(); + break; + } + + FuncStatus ret; + //ret.disabled(true); + InsetTabular * tab = static_cast + (cur.innerInsetOfType(InsetBase::TABULAR_CODE)); + if (tab) { + ret = tab->getStatus(cmd.argument); + flag |= ret; + enable = true; + } else { + enable = false; + } + } else { + static InsetTabular inset(*buf, 1, 1); + enable = false; + FuncStatus ret = inset.getStatus(cmd.argument); + if (ret.onoff(true) || ret.onoff(false)) + flag.setOnOff(false); + } +#endif + return true; + + default: + // we try to handle this event in the insets dispatch function. + return cell(cur.idx()).getStatus(cur, cmd, flag); + } +} + + int InsetTabular::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { @@ -1382,7 +1455,7 @@ FuncStatus InsetTabular::getStatus(BufferView & bv, break; case LyXTabular::ALIGN_BLOCK: - status.disabled(tabular.getPWidth(actcell).zero()); + status.enabled(!tabular.getPWidth(actcell).zero()); status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK); break; @@ -1457,7 +1530,7 @@ FuncStatus InsetTabular::getStatus(BufferView & bv, default: status.clear(); - status.disabled(true); + status.enabled(false); break; } return status; @@ -1817,3 +1890,4 @@ string const InsetTabularMailer::params2string(InsetTabular const & inset) data << "\\end_inset\n"; return data.str(); } + diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index c37d692fe8..804f32ae9a 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -152,6 +152,8 @@ public: protected: /// void priv_dispatch(LCursor & cur, FuncRequest & cmd); + /// + bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; private: /// void drawCellLines(Painter &, int x, int baseline, diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 92adcd34a4..4c3b7005ce 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -332,6 +332,13 @@ void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd) } +bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & status) const +{ + return text_.getStatus(cur, cmd, status); +} + + int InsetText::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 04985a1d5f..c4b5ef06ce 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -126,6 +126,8 @@ public: } /// LyXText * getText(int) const; + /// + bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; /// mark as erased for change tracking void markErased() { clear(true); }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 41a3772a69..87802db1a4 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -82,9 +82,7 @@ #include "support/std_sstream.h" #include "support/os.h" -using bv_funcs::DEC_DEPTH; using bv_funcs::freefont2string; -using bv_funcs::INC_DEPTH; using lyx::support::AddName; using lyx::support::AddPath; @@ -257,13 +255,14 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state) FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const { + //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl; FuncStatus flag; Buffer * buf = owner->buffer(); LCursor & cur = view()->cursor(); if (cmd.action == LFUN_NOACTION) { setStatusMessage(N_("Nothing to do")); - flag.disabled(true); + flag.enabled(false); return flag; } @@ -273,7 +272,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_THESAURUS_ENTRY: #endif flag.unknown(true); - flag.disabled(true); + flag.enabled(false); break; default: flag |= lyx_gui::getStatus(cmd); @@ -298,148 +297,92 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const LyXAction::ReadOnly)) { // no setStatusMessage(N_("Document is read-only")); - flag.disabled(true); + flag.enabled(false); } } else { // no setStatusMessage(N_("Command not allowed with" "out any document open")); - flag.disabled(true); + flag.enabled(false); return flag; } } // I would really like to avoid having this switch and rather try to // encode this in the function itself. - bool disable = false; + // -- And I'd rather let an inset decide which LFUNs it is willing + // to handle (Andre') + bool enable = true; switch (cmd.action) { + case LFUN_TOOLTIPS_TOGGLE: + flag.setOnOff(owner->getDialogs().tooltipsEnabled()); + break; + + case LFUN_READ_ONLY_TOGGLE: + flag.setOnOff(buf->isReadonly()); + break; + + case LFUN_SWITCHBUFFER: + // toggle on the current buffer, but do not toggle off + // the other ones (is that a good idea?) + if (cmd.argument == buf->fileName()) + flag.setOnOff(true); + break; + + case LFUN_TRACK_CHANGES: + flag.setOnOff(buf->params().tracking_changes); + break; + case LFUN_EXPORT: - disable = cmd.argument != "custom" - && !Exporter::IsExportable(*buf, cmd.argument); + enable = cmd.argument == "custom" + || Exporter::IsExportable(*buf, cmd.argument); break; case LFUN_UNDO: - disable = buf->undostack().empty(); + enable = !buf->undostack().empty(); break; case LFUN_REDO: - disable = buf->redostack().empty(); + enable = !buf->redostack().empty(); break; case LFUN_CUT: case LFUN_COPY: - disable = !cur.selection(); + enable = cur.selection(); break; case LFUN_RUNCHKTEX: - disable = !buf->isLatex() || lyxrc.chktex_command == "none"; + enable = buf->isLatex() && lyxrc.chktex_command != "none"; break; case LFUN_BUILDPROG: - disable = !Exporter::IsExportable(*buf, "program"); + enable = Exporter::IsExportable(*buf, "program"); break; case LFUN_LAYOUT_TABULAR: - disable = !cur.innerInsetOfType(InsetBase::TABULAR_CODE); - break; - - case LFUN_DEPTH_MIN: - disable = !changeDepthAllowed(cur, view()->getLyXText(), DEC_DEPTH); - break; - - case LFUN_DEPTH_PLUS: - disable = !changeDepthAllowed(cur, view()->getLyXText(), INC_DEPTH); + enable = cur.innerInsetOfType(InsetBase::TABULAR_CODE); break; case LFUN_LAYOUT: case LFUN_LAYOUT_PARAGRAPH: - disable = cur.inset().forceDefaultParagraphs(&cur.inset()); - break; - - case LFUN_INSET_OPTARG: - disable = cur.inMathed() - || cur.paragraph().layout()->optionalargs == 0; - break; - - case LFUN_TABULAR_FEATURE: -#if 0 - if (cur.inMathed()) { - // FIXME: check temporarily disabled - // valign code - char align = mathcursor::valign(); - if (align == '\0') { - disable = true; - break; - } - if (cmd.argument.empty()) { - flag.clear(); - break; - } - if (!contains("tcb", cmd.argument[0])) { - disable = true; - break; - } - flag.setOnOff(cmd.argument[0] == align); - } else { - disable = true; - - char const align = mathcursor::halign(); - if (align == '\0') { - disable = true; - break; - } - if (cmd.argument.empty()) { - flag.clear(); - break; - } - if (!contains("lcr", cmd.argument[0])) { - disable = true; - break; - } - flag.setOnOff(cmd.argument[0] == align); - - disable = !mathcursor::halign(); - break; - } - - if (!cur.empty() && cur.inset().asUpdatableInset()) { - FuncStatus ret; - //ret.disabled(true); - InsetTabular * tab = static_cast - (cur.innerInsetOfType(InsetBase::TABULAR_CODE)); - if (tab) { - ret = tab->getStatus(cmd.argument); - flag |= ret; - disable = false; - } else { - disable = true; - } - } else { - static InsetTabular inset(*buf, 1, 1); - disable = true; - FuncStatus ret = inset.getStatus(cmd.argument); - if (ret.onoff(true) || ret.onoff(false)) - flag.setOnOff(false); - } -#endif + enable = !cur.inset().forceDefaultParagraphs(&cur.inset()); break; case LFUN_VC_REGISTER: - disable = buf->lyxvc().inUse(); + enable = !buf->lyxvc().inUse(); break; case LFUN_VC_CHECKIN: - disable = !buf->lyxvc().inUse() || buf->isReadonly(); + enable = buf->lyxvc().inUse() && !buf->isReadonly(); break; case LFUN_VC_CHECKOUT: - disable = !buf->lyxvc().inUse() || !buf->isReadonly(); + enable = buf->lyxvc().inUse() && buf->isReadonly(); break; case LFUN_VC_REVERT: case LFUN_VC_UNDO: - disable = !buf->lyxvc().inUse(); + enable = buf->lyxvc().inUse(); break; case LFUN_MENURELOAD: - disable = buf->isUnnamed() || buf->isClean(); + enable = !buf->isUnnamed() && !buf->isClean(); break; case LFUN_BOOKMARK_GOTO: - disable = !view()-> - isSavedPosition(strToUnsignedInt(cmd.argument)); + enable = view()->isSavedPosition(strToUnsignedInt(cmd.argument)); break; case LFUN_MERGE_CHANGES: @@ -447,12 +390,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_REJECT_CHANGE: case LFUN_ACCEPT_ALL_CHANGES: case LFUN_REJECT_ALL_CHANGES: - disable = !buf->params().tracking_changes; + enable = buf && buf->params().tracking_changes; break; case LFUN_INSET_SETTINGS: { - disable = true; + enable = false; + if (!cur.size()) + break; UpdatableInset * inset = cur.inset().asUpdatableInset(); + lyxerr << "inset: " << inset << endl; if (!inset) break; @@ -460,29 +406,32 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const // we get back to the InsetTabular or whatever if (inset->lyxCode() == InsetOld::TEXT_CODE) inset = inset->owner(); + lyxerr << "inset 2: " << inset << endl; + if (!inset) + break; InsetOld::Code code = inset->lyxCode(); switch (code) { case InsetOld::TABULAR_CODE: - disable = cmd.argument != "tabular"; + enable = cmd.argument == "tabular"; break; case InsetOld::ERT_CODE: - disable = cmd.argument != "ert"; + enable = cmd.argument == "ert"; break; case InsetOld::FLOAT_CODE: - disable = cmd.argument != "float"; + enable = cmd.argument == "float"; break; case InsetOld::WRAP_CODE: - disable = cmd.argument != "wrap"; + enable = cmd.argument == "wrap"; break; case InsetOld::NOTE_CODE: - disable = cmd.argument != "note"; + enable = cmd.argument == "note"; break; case InsetOld::BRANCH_CODE: - disable = cmd.argument != "branch"; + enable = cmd.argument == "branch"; break; case InsetOld::BOX_CODE: - disable = cmd.argument != "box"; + enable = cmd.argument == "box"; break; default: break; @@ -490,292 +439,81 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } - case LFUN_MATH_MUTATE: - if (cur.inMathed()) - //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument); - flag.setOnOff(false); - else - disable = true; - break; - - // we just need to be in math mode to enable that - case LFUN_MATH_SIZE: - case LFUN_MATH_SPACE: - case LFUN_MATH_LIMITS: - case LFUN_MATH_NONUMBER: - case LFUN_MATH_NUMBER: - case LFUN_MATH_EXTERN: - disable = cur.inTexted(); - break; - case LFUN_DIALOG_SHOW: { string const name = cmd.getArg(0); if (!buf) - disable = !(name == "aboutlyx" || - name == "file" || - name == "preferences" || - name == "texinfo"); + enable = name == "aboutlyx" + || name == "file" + || name == "forks" + || name == "preferences" + || name == "texinfo"; else if (name == "print") - disable = !Exporter::IsExportable(*buf, "dvi") || - lyxrc.print_command == "none"; + enable = Exporter::IsExportable(*buf, "dvi") + && lyxrc.print_command != "none"; else if (name == "character") - disable = cur.inset().lyxCode() == InsetOld::ERT_CODE; + enable = cur.inset().lyxCode() != InsetOld::ERT_CODE; else if (name == "vclog") - disable = !buf->lyxvc().inUse(); + enable = buf->lyxvc().inUse(); else if (name == "latexlog") - disable = !IsFileReadable(buf->getLogName().second); + enable = IsFileReadable(buf->getLogName().second); break; } - default: - break; - } - - // the functions which insert insets - InsetOld::Code code = InsetOld::NO_CODE; - switch (cmd.action) { + case LFUN_MENUNEW: + case LFUN_MENUNEWTMPLT: + case LFUN_WORDFINDFORWARD: + case LFUN_WORDFINDBACKWARD: + case LFUN_PREFIX: + case LFUN_EXEC_COMMAND: + case LFUN_CANCEL: + case LFUN_META_FAKE: + case LFUN_CLOSEBUFFER: + case LFUN_MENUWRITE: + case LFUN_WRITEAS: + case LFUN_UPDATE: + case LFUN_PREVIEW: + case LFUN_IMPORT: + case LFUN_QUIT: + case LFUN_TOCVIEW: + case LFUN_AUTOSAVE: + case LFUN_RECONFIGURE: + case LFUN_HELP_OPEN: + case LFUN_FILE_NEW: + case LFUN_FILE_OPEN: + case LFUN_DROP_LAYOUTS_CHOICE: + case LFUN_MENU_OPEN_BY_NAME: + case LFUN_GETNAME: + case LFUN_NOTIFY: + case LFUN_GOTOFILEROW: + case LFUN_GOTO_PARAGRAPH: case LFUN_DIALOG_SHOW_NEW_INSET: - if (cmd.argument == "bibitem") - code = InsetOld::BIBITEM_CODE; - else if (cmd.argument == "bibtex") - code = InsetOld::BIBTEX_CODE; - else if (cmd.argument == "box") - code = InsetOld::BOX_CODE; - else if (cmd.argument == "branch") - code = InsetOld::BRANCH_CODE; - else if (cmd.argument == "citation") - code = InsetOld::CITE_CODE; - else if (cmd.argument == "ert") - code = InsetOld::ERT_CODE; - else if (cmd.argument == "external") - code = InsetOld::EXTERNAL_CODE; - else if (cmd.argument == "float") - code = InsetOld::FLOAT_CODE; - else if (cmd.argument == "graphics") - code = InsetOld::GRAPHICS_CODE; - else if (cmd.argument == "include") - code = InsetOld::INCLUDE_CODE; - else if (cmd.argument == "index") - code = InsetOld::INDEX_CODE; - else if (cmd.argument == "label") - code = InsetOld::LABEL_CODE; - else if (cmd.argument == "note") - code = InsetOld::NOTE_CODE; - else if (cmd.argument == "ref") - code = InsetOld::REF_CODE; - else if (cmd.argument == "toc") - code = InsetOld::TOC_CODE; - else if (cmd.argument == "url") - code = InsetOld::URL_CODE; - else if (cmd.argument == "vspace") - code = InsetOld::VSPACE_CODE; - else if (cmd.argument == "wrap") - code = InsetOld::WRAP_CODE; + case LFUN_DIALOG_SHOW_NEXT_INSET: + case LFUN_DIALOG_UPDATE: + case LFUN_DIALOG_HIDE: + case LFUN_DIALOG_DISCONNECT_INSET: + case LFUN_CHILDOPEN: + case LFUN_TOGGLECURSORFOLLOW: + case LFUN_KMAP_OFF: + case LFUN_KMAP_PRIM: + case LFUN_KMAP_SEC: + case LFUN_KMAP_TOGGLE: + case LFUN_REPEAT: + case LFUN_SEQUENCE: + case LFUN_SAVEPREFERENCES: + case LFUN_SCREEN_FONT_UPDATE: + case LFUN_SET_COLOR: + case LFUN_MESSAGE: + case LFUN_FORKS_KILL: + case LFUN_EXTERNAL_EDIT: + // these are handled in our dispatch() break; - case LFUN_INSET_ERT: - code = InsetOld::ERT_CODE; - break; - case LFUN_INSET_FOOTNOTE: - code = InsetOld::FOOT_CODE; - break; - case LFUN_TABULAR_INSERT: - code = InsetOld::TABULAR_CODE; - break; - case LFUN_INSET_MARGINAL: - code = InsetOld::MARGIN_CODE; - break; - case LFUN_INSET_FLOAT: - case LFUN_INSET_WIDE_FLOAT: - code = InsetOld::FLOAT_CODE; - break; - case LFUN_INSET_WRAP: - code = InsetOld::WRAP_CODE; - break; - case LFUN_FLOAT_LIST: - code = InsetOld::FLOAT_LIST_CODE; - break; -#if 0 - case LFUN_INSET_LIST: - code = InsetOld::LIST_CODE; - break; - case LFUN_INSET_THEOREM: - code = InsetOld::THEOREM_CODE; - break; -#endif - case LFUN_INSET_CAPTION: - code = InsetOld::CAPTION_CODE; - break; - case LFUN_INSERT_NOTE: - code = InsetOld::NOTE_CODE; - break; - case LFUN_INSERT_CHARSTYLE: - code = InsetOld::CHARSTYLE_CODE; - if (buf->params().getLyXTextClass().charstyles().empty()) - disable = true; - break; - case LFUN_INSERT_BOX: - code = InsetOld::BOX_CODE; - break; - case LFUN_INSERT_BRANCH: - code = InsetOld::BRANCH_CODE; - if (buf->params().branchlist().empty()) - disable = true; - break; - case LFUN_INSERT_LABEL: - code = InsetOld::LABEL_CODE; - break; - case LFUN_INSET_OPTARG: - code = InsetOld::OPTARG_CODE; - break; - case LFUN_ENVIRONMENT_INSERT: - code = InsetOld::BOX_CODE; - break; - case LFUN_INDEX_INSERT: - code = InsetOld::INDEX_CODE; - break; - case LFUN_INDEX_PRINT: - code = InsetOld::INDEX_PRINT_CODE; - break; - case LFUN_TOC_INSERT: - code = InsetOld::TOC_CODE; - break; - case LFUN_HTMLURL: - case LFUN_URL: - code = InsetOld::URL_CODE; - break; - case LFUN_QUOTE: - // always allow this, since we will inset a raw quote - // if an inset is not allowed. - break; - case LFUN_HYPHENATION: - case LFUN_LIGATURE_BREAK: - case LFUN_HFILL: - case LFUN_MENU_SEPARATOR: - case LFUN_LDOTS: - case LFUN_END_OF_SENTENCE: - code = InsetOld::SPECIALCHAR_CODE; - break; - case LFUN_SPACE_INSERT: - // slight hack: we know this is allowed in math mode - if (cur.inTexted()) - code = InsetOld::SPACE_CODE; - break; - case LFUN_INSET_DIALOG_SHOW: { - InsetBase * inset = cur.nextInset(); - disable = !inset; - if (inset) { - code = inset->lyxCode(); - if (!(code == InsetOld::INCLUDE_CODE - || code == InsetOld::BIBTEX_CODE - || code == InsetOld::FLOAT_LIST_CODE - || code == InsetOld::TOC_CODE)) - disable = true; - } - break; - } - default: - break; - } - - if (code != InsetOld::NO_CODE - && (cur.empty() || !cur.inset().insetAllowed(code))) - disable = true; - - if (disable) - flag.disabled(true); - - // A few general toggles - switch (cmd.action) { - case LFUN_TOOLTIPS_TOGGLE: - flag.setOnOff(owner->getDialogs().tooltipsEnabled()); - break; - - case LFUN_READ_ONLY_TOGGLE: - flag.setOnOff(buf->isReadonly()); - break; - case LFUN_APPENDIX: - flag.setOnOff(cur.inTexted() - && cur.paragraph().params().startOfAppendix()); - break; - case LFUN_SWITCHBUFFER: - // toggle on the current buffer, but do not toggle off - // the other ones (is that a good idea?) - if (cmd.argument == buf->fileName()) - flag.setOnOff(true); - break; - case LFUN_TRACK_CHANGES: - flag.setOnOff(buf->params().tracking_changes); - break; default: - break; - } - -#ifdef LOCK - // the font related toggles - if (cur.inTexted()) { - LyXFont const & font = cur.text()->real_current_font; - switch (cmd.action) { - case LFUN_EMPH: - flag.setOnOff(font.emph() == LyXFont::ON); - break; - case LFUN_NOUN: - flag.setOnOff(font.noun() == LyXFont::ON); - break; - case LFUN_BOLD: - flag.setOnOff(font.series() == LyXFont::BOLD_SERIES); - break; - case LFUN_SANS: - flag.setOnOff(font.family() == LyXFont::SANS_FAMILY); - break; - case LFUN_ROMAN: - flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY); - break; - case LFUN_CODE: - flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY); - break; - default: - break; - } - } else { - string tc = mathcursor::getLastCode(); - switch (cmd.action) { - case LFUN_BOLD: - flag.setOnOff(tc == "mathbf"); - break; - case LFUN_SANS: - flag.setOnOff(tc == "mathsf"); - break; - case LFUN_EMPH: - flag.setOnOff(tc == "mathcal"); - break; - case LFUN_ROMAN: - flag.setOnOff(tc == "mathrm"); - break; - case LFUN_CODE: - flag.setOnOff(tc == "mathtt"); - break; - case LFUN_NOUN: - flag.setOnOff(tc == "mathbb"); - break; - case LFUN_DEFAULT: - flag.setOnOff(tc == "mathnormal"); - break; - default: - break; - } - } -#endif - - // this one is difficult to get right. As a half-baked - // solution, we consider only the first action of the sequence - if (cmd.action == LFUN_SEQUENCE) { - // argument contains ';'-terminated commands -#warning LyXAction arguments not handled here. - flag = getStatus(FuncRequest( - lyxaction.lookupFunc(token(cmd.argument, ';', 0)))); + cur.getStatus(cmd, flag); + return flag; } + flag.enabled(enable); return flag; } @@ -819,7 +557,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) selection_possible = false; // We cannot use this function here - if (getStatus(cmd).disabled()) { + if (!getStatus(cmd).enabled()) { lyxerr[Debug::ACTION] << "LyXFunc::dispatch: " << lyxaction.getActionName(action) << " [" << action << "] is disabled at this location" @@ -1378,7 +1116,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) view()->update(); view()->cursor().updatePos(); // if we executed a mutating lfun, mark the buffer as dirty - if (!getStatus(cmd).disabled() + if (getStatus(cmd).enabled() && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)) view()->buffer()->markDirty(); diff --git a/src/lyxtext.h b/src/lyxtext.h index e463e46a3f..01d0c7a61b 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -87,10 +87,15 @@ public: void setLayout(LCursor & cur, std::string const & layout); /// Increase or decrease the nesting depth of the selected paragraph(s) - void changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type); + /// what type of depth change to make + enum DEPTH_CHANGE { + INC_DEPTH, + DEC_DEPTH + }; + void changeDepth(LCursor & cur, DEPTH_CHANGE type); /// Returns whether something would be changed by changeDepth - bool changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type); + bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const; /// Set font over selection paragraphs and rebreak. void setFont(LCursor & cur, LyXFont const &, bool toggleall = false); @@ -129,7 +134,8 @@ public: /// try to handle that request void dispatch(LCursor & cur, FuncRequest & cmd); /// do we want to handle this event? - bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status); + bool getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & status) const; /// access to out BufferView. This should go... BufferView * bv(); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index f20ef1914d..1ed309e981 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -28,6 +28,7 @@ #include "math_unknowninset.h" #include "BufferView.h" +#include "FuncStatus.h" #include "bufferview_funcs.h" #include "cursor.h" #include "debug.h" @@ -819,6 +820,76 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) } +bool MathNestInset::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + // the font related toggles + //string tc = mathcursor::getLastCode(); + bool ret = true; + switch (cmd.action) { +#if 0 + case LFUN_TABULAR_FEATURE: + // FIXME: check temporarily disabled + // valign code + char align = mathcursor::valign(); + if (align == '\0') { + enable = false; + break; + } + if (cmd.argument.empty()) { + flag.clear(); + break; + } + if (!contains("tcb", cmd.argument[0])) { + enable = false; + break; + } + flag.setOnOff(cmd.argument[0] == align); + break; + case LFUN_BOLD: + flag.setOnOff(tc == "mathbf"); + break; + case LFUN_SANS: + flag.setOnOff(tc == "mathsf"); + break; + case LFUN_EMPH: + flag.setOnOff(tc == "mathcal"); + break; + case LFUN_ROMAN: + flag.setOnOff(tc == "mathrm"); + break; + case LFUN_CODE: + flag.setOnOff(tc == "mathtt"); + break; + case LFUN_NOUN: + flag.setOnOff(tc == "mathbb"); + break; + case LFUN_DEFAULT: + flag.setOnOff(tc == "mathnormal"); + break; +#endif + case LFUN_MATH_MUTATE: + //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument); + flag.setOnOff(false); + break; + + // we just need to be in math mode to enable that + case LFUN_MATH_SIZE: + case LFUN_MATH_SPACE: + case LFUN_MATH_LIMITS: + case LFUN_MATH_NONUMBER: + case LFUN_MATH_NUMBER: + case LFUN_MATH_EXTERN: + flag.enabled(true); + break; + + default: + ret = false; + break; + } + return ret; +} + void MathNestInset::edit(LCursor & cur, bool left) { cur.push(*this); diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 4eae6eeaf0..4b52ecb219 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -97,6 +97,9 @@ public: protected: /// void priv_dispatch(LCursor & cur, FuncRequest & cmd); + /// do we want to handle this event? + bool getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & status) const; /// void handleFont(LCursor & cur, std::string const & arg, std::string const & font); diff --git a/src/text2.C b/src/text2.C index fbd42cd6fd..889cbfed51 100644 --- a/src/text2.C +++ b/src/text2.C @@ -330,16 +330,15 @@ void getSelectionSpan(LCursor & cur, LyXText & text, } -bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type, - Paragraph const & par, - int max_depth) +bool changeDepthAllowed(LyXText::DEPTH_CHANGE type, + Paragraph const & par, int max_depth) { if (par.layout()->labeltype == LABEL_BIBLIO) return false; int const depth = par.params().depth(); - if (type == bv_funcs::INC_DEPTH && depth < max_depth) + if (type == LyXText::INC_DEPTH && depth < max_depth) return true; - if (type == bv_funcs::DEC_DEPTH && depth > 0) + if (type == LyXText::DEC_DEPTH && depth > 0) return true; return false; } @@ -348,11 +347,11 @@ bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type, } -bool LyXText::changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type) +bool LyXText::changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const { BOOST_ASSERT(this == cur.text()); ParagraphList::iterator beg, end; - getSelectionSpan(cur, *this, beg, end); + getSelectionSpan(cur, const_cast(*this), beg, end); int max_depth = 0; if (beg != paragraphs().begin()) max_depth = boost::prior(beg)->getMaxDepthAfter(); @@ -366,7 +365,7 @@ bool LyXText::changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type) } -void LyXText::changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type) +void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type) { BOOST_ASSERT(this == cur.text()); ParagraphList::iterator beg, end; @@ -380,7 +379,7 @@ void LyXText::changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type) for (ParagraphList::iterator pit = beg; pit != end; ++pit) { if (::changeDepthAllowed(type, *pit, max_depth)) { int const depth = pit->params().depth(); - if (type == bv_funcs::INC_DEPTH) + if (type == INC_DEPTH) pit->params().depth(depth + 1); else pit->params().depth(depth - 1); diff --git a/src/text3.C b/src/text3.C index ffc121ef12..a277437185 100644 --- a/src/text3.C +++ b/src/text3.C @@ -17,6 +17,8 @@ #include "lyxtext.h" +#include "FloatList.h" +#include "FuncStatus.h" #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" @@ -24,7 +26,6 @@ #include "debug.h" #include "dispatchresult.h" #include "factory.h" -#include "FloatList.h" #include "funcrequest.h" #include "gettext.h" #include "intl.h" @@ -375,6 +376,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl; //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl; + BOOST_ASSERT(cur.text() == this); BufferView * bv = &cur.bv(); CursorSlice sl = cur.top(); @@ -1270,12 +1272,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; case LFUN_DEPTH_MIN: - changeDepth(cur, bv_funcs::DEC_DEPTH); + changeDepth(cur, DEC_DEPTH); cur.update(); break; case LFUN_DEPTH_PLUS: - changeDepth(cur, bv_funcs::INC_DEPTH); + changeDepth(cur, INC_DEPTH); cur.update(); break; @@ -1568,7 +1570,347 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } -bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &) +bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const { - return false; + BOOST_ASSERT(cur.text() == this); + LyXFont const & font = real_current_font; + bool enable = true; + + switch (cmd.action) { + + case LFUN_DEPTH_MIN: + enable = changeDepthAllowed(cur, DEC_DEPTH); + break; + + case LFUN_DEPTH_PLUS: + enable = changeDepthAllowed(cur, INC_DEPTH); + break; + + case LFUN_INSET_OPTARG: + enable = cur.paragraph().layout()->optionalargs; + break; + + case LFUN_APPENDIX: + flag.setOnOff(cur.paragraph().params().startOfAppendix()); + break; + +#if 0 + // the functions which insert insets + InsetOld::Code code = InsetOld::NO_CODE; + switch (cmd.action) { + case LFUN_DIALOG_SHOW_NEW_INSET: + if (cmd.argument == "bibitem") + code = InsetOld::BIBITEM_CODE; + else if (cmd.argument == "bibtex") + code = InsetOld::BIBTEX_CODE; + else if (cmd.argument == "box") + code = InsetOld::BOX_CODE; + else if (cmd.argument == "branch") + code = InsetOld::BRANCH_CODE; + else if (cmd.argument == "citation") + code = InsetOld::CITE_CODE; + else if (cmd.argument == "ert") + code = InsetOld::ERT_CODE; + else if (cmd.argument == "external") + code = InsetOld::EXTERNAL_CODE; + else if (cmd.argument == "float") + code = InsetOld::FLOAT_CODE; + else if (cmd.argument == "graphics") + code = InsetOld::GRAPHICS_CODE; + else if (cmd.argument == "include") + code = InsetOld::INCLUDE_CODE; + else if (cmd.argument == "index") + code = InsetOld::INDEX_CODE; + else if (cmd.argument == "label") + code = InsetOld::LABEL_CODE; + else if (cmd.argument == "note") + code = InsetOld::NOTE_CODE; + else if (cmd.argument == "ref") + code = InsetOld::REF_CODE; + else if (cmd.argument == "toc") + code = InsetOld::TOC_CODE; + else if (cmd.argument == "url") + code = InsetOld::URL_CODE; + else if (cmd.argument == "vspace") + code = InsetOld::VSPACE_CODE; + else if (cmd.argument == "wrap") + code = InsetOld::WRAP_CODE; + break; + + case LFUN_INSET_ERT: + code = InsetOld::ERT_CODE; + break; + case LFUN_INSET_FOOTNOTE: + code = InsetOld::FOOT_CODE; + break; + case LFUN_TABULAR_INSERT: + code = InsetOld::TABULAR_CODE; + break; + case LFUN_INSET_MARGINAL: + code = InsetOld::MARGIN_CODE; + break; + case LFUN_INSET_FLOAT: + case LFUN_INSET_WIDE_FLOAT: + code = InsetOld::FLOAT_CODE; + break; + case LFUN_INSET_WRAP: + code = InsetOld::WRAP_CODE; + break; + case LFUN_FLOAT_LIST: + code = InsetOld::FLOAT_LIST_CODE; + break; +#if 0 + case LFUN_INSET_LIST: + code = InsetOld::LIST_CODE; + break; + case LFUN_INSET_THEOREM: + code = InsetOld::THEOREM_CODE; + break; +#endif + case LFUN_INSET_CAPTION: + code = InsetOld::CAPTION_CODE; + break; + case LFUN_INSERT_NOTE: + code = InsetOld::NOTE_CODE; + break; + case LFUN_INSERT_CHARSTYLE: + code = InsetOld::CHARSTYLE_CODE; + if (buf->params().getLyXTextClass().charstyles().empty()) + enable = false; + break; + case LFUN_INSERT_BOX: + code = InsetOld::BOX_CODE; + break; + case LFUN_INSERT_BRANCH: + code = InsetOld::BRANCH_CODE; + if (buf->params().branchlist().empty()) + enable = false; + break; + case LFUN_INSERT_LABEL: + code = InsetOld::LABEL_CODE; + break; + case LFUN_INSET_OPTARG: + code = InsetOld::OPTARG_CODE; + break; + case LFUN_ENVIRONMENT_INSERT: + code = InsetOld::BOX_CODE; + break; + case LFUN_INDEX_INSERT: + code = InsetOld::INDEX_CODE; + break; + case LFUN_INDEX_PRINT: + code = InsetOld::INDEX_PRINT_CODE; + break; + case LFUN_TOC_INSERT: + code = InsetOld::TOC_CODE; + break; + case LFUN_HTMLURL: + case LFUN_URL: + code = InsetOld::URL_CODE; + break; + case LFUN_QUOTE: + // always allow this, since we will inset a raw quote + // if an inset is not allowed. + break; + case LFUN_HYPHENATION: + case LFUN_LIGATURE_BREAK: + case LFUN_HFILL: + case LFUN_MENU_SEPARATOR: + case LFUN_LDOTS: + case LFUN_END_OF_SENTENCE: + code = InsetOld::SPECIALCHAR_CODE; + break; + case LFUN_SPACE_INSERT: + // slight hack: we know this is allowed in math mode + if (cur.inTexted()) + code = InsetOld::SPACE_CODE; + break; + case LFUN_INSET_DIALOG_SHOW: { + InsetBase * inset = cur.nextInset(); + enable = inset; + if (inset) { + code = inset->lyxCode(); + if (!(code == InsetOld::INCLUDE_CODE + || code == InsetOld::BIBTEX_CODE + || code == InsetOld::FLOAT_LIST_CODE + || code == InsetOld::TOC_CODE)) + enable = false; + } + break; + } + default: + break; + } + + if (code != InsetOld::NO_CODE + && (cur.empty() || !cur.inset().insetAllowed(code))) + enable = false; + +#endif + + case LFUN_DIALOG_SHOW_NEW_INSET: + case LFUN_INSET_ERT: + case LFUN_INSERT_BOX: + case LFUN_INSERT_BRANCH: + case LFUN_ENVIRONMENT_INSERT: + case LFUN_INDEX_INSERT: + case LFUN_INDEX_PRINT: + case LFUN_TOC_INSERT: + case LFUN_HTMLURL: + case LFUN_URL: + case LFUN_QUOTE: + case LFUN_HYPHENATION: + case LFUN_LIGATURE_BREAK: + case LFUN_HFILL: + case LFUN_MENU_SEPARATOR: + case LFUN_LDOTS: + case LFUN_END_OF_SENTENCE: + case LFUN_SPACE_INSERT: + case LFUN_INSET_DIALOG_SHOW: + break; + + case LFUN_EMPH: + flag.setOnOff(font.emph() == LyXFont::ON); + break; + + case LFUN_NOUN: + flag.setOnOff(font.noun() == LyXFont::ON); + break; + + case LFUN_BOLD: + flag.setOnOff(font.series() == LyXFont::BOLD_SERIES); + break; + + case LFUN_SANS: + flag.setOnOff(font.family() == LyXFont::SANS_FAMILY); + break; + + case LFUN_ROMAN: + flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY); + break; + + case LFUN_CODE: + flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY); + break; + + case LFUN_DELETE_WORD_FORWARD: + case LFUN_DELETE_WORD_BACKWARD: + case LFUN_DELETE_LINE_FORWARD: + case LFUN_WORDRIGHT: + case LFUN_WORDLEFT: + case LFUN_ENDBUF: + case LFUN_RIGHT: + case LFUN_RIGHTSEL: + case LFUN_LEFT: + case LFUN_LEFTSEL: + case LFUN_UP: + case LFUN_UPSEL: + case LFUN_DOWN: + case LFUN_DOWNSEL: + case LFUN_UP_PARAGRAPHSEL: + case LFUN_DOWN_PARAGRAPHSEL: + case LFUN_PRIORSEL: + case LFUN_NEXTSEL: + case LFUN_HOMESEL: + case LFUN_ENDSEL: + case LFUN_WORDRIGHTSEL: + case LFUN_WORDLEFTSEL: + case LFUN_WORDSEL: + case LFUN_UP_PARAGRAPH: + case LFUN_DOWN_PARAGRAPH: + case LFUN_PRIOR: + case LFUN_NEXT: + case LFUN_HOME: + case LFUN_END: + case LFUN_BREAKLINE: + case LFUN_DELETE: + case LFUN_DELETE_SKIP: + case LFUN_BACKSPACE: + case LFUN_BACKSPACE_SKIP: + case LFUN_BREAKPARAGRAPH: + case LFUN_BREAKPARAGRAPHKEEPLAYOUT: + case LFUN_BREAKPARAGRAPH_SKIP: + case LFUN_PARAGRAPH_SPACING: + case LFUN_INSET_APPLY: + case LFUN_INSET_INSERT: + case LFUN_INSET_TOGGLE: + case LFUN_UPCASE_WORD: + case LFUN_LOWCASE_WORD: + case LFUN_CAPITALIZE_WORD: + case LFUN_TRANSPOSE_CHARS: + case LFUN_PASTE: + case LFUN_CUT: + case LFUN_COPY: + case LFUN_GETXY: + case LFUN_SETXY: + case LFUN_GETFONT: + case LFUN_GETLAYOUT: + case LFUN_LAYOUT: + case LFUN_PASTESELECTION: + case LFUN_GOTOERROR: + case LFUN_GOTONOTE: + case LFUN_REFERENCE_GOTO: + case LFUN_DATE_INSERT: + case LFUN_SELFINSERT: + case LFUN_INSERT_LABEL: + case LFUN_INSERT_NOTE: + case LFUN_INSERT_CHARSTYLE: + case LFUN_INSERT_BIBITEM: + case LFUN_INSET_FLOAT: + case LFUN_INSET_FOOTNOTE: + case LFUN_INSET_MARGINAL: + case LFUN_INSET_WIDE_FLOAT: + case LFUN_INSET_WRAP: + case LFUN_TABULAR_INSERT: + case LFUN_INSERT_LINE: + case LFUN_INSERT_PAGEBREAK: + case LFUN_MATH_DISPLAY: + case LFUN_MATH_IMPORT_SELECTION: + case LFUN_MATH_MODE: + case LFUN_MATH_MACRO: + case LFUN_INSERT_MATH: + case LFUN_INSERT_MATRIX: + case LFUN_MATH_DELIM: + case LFUN_DEFAULT: + case LFUN_UNDERLINE: + case LFUN_FONT_SIZE: + case LFUN_LANGUAGE: + case LFUN_FREEFONT_APPLY: + case LFUN_FREEFONT_UPDATE: + case LFUN_LAYOUT_PARAGRAPH: + case LFUN_PARAGRAPH_UPDATE: + case LFUN_UMLAUT: + case LFUN_CIRCUMFLEX: + case LFUN_GRAVE: + case LFUN_ACUTE: + case LFUN_TILDE: + case LFUN_CEDILLA: + case LFUN_MACRON: + case LFUN_DOT: + case LFUN_UNDERDOT: + case LFUN_UNDERBAR: + case LFUN_CARON: + case LFUN_SPECIAL_CARON: + case LFUN_BREVE: + case LFUN_TIE: + case LFUN_HUNG_UMLAUT: + case LFUN_CIRCLE: + case LFUN_OGONEK: + case LFUN_FLOAT_LIST: + case LFUN_ACCEPT_CHANGE: + case LFUN_REJECT_CHANGE: + case LFUN_THESAURUS_ENTRY: + case LFUN_PARAGRAPH_APPLY: + case LFUN_ESCAPE: + // these are handled in our dispatch() + enable = true; + break; + + default: + enable = false; + break; + } + flag.enabled(enable); + return true; } -- 2.39.5