]> git.lyx.org Git - lyx.git/commitdiff
split LyXFunc::getStatus() into inset specific chunks
authorAndré Pönitz <poenitz@gmx.net>
Thu, 18 Mar 2004 13:57:20 +0000 (13:57 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 18 Mar 2004 13:57:20 +0000 (13:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8500 a592a061-630c-0410-9148-cb99ea01b6c8

25 files changed:
src/FuncStatus.C
src/FuncStatus.h
src/MenuBackend.C
src/bufferview_funcs.C
src/bufferview_funcs.h
src/cursor.C
src/frontends/LyXView.C
src/frontends/qt2/QLPopupMenu.C
src/frontends/qt2/QLToolbar.C
src/frontends/xforms/XFormsMenubar.C
src/frontends/xforms/XFormsToolbar.C
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/lyxfunc.C
src/lyxtext.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/text2.C
src/text3.C

index 1998db67d1d0a9f81311606931c334c578d9137e..3e0c615096db04054d8f63173b824a315c20c5a5 100644 (file)
@@ -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);
 }
 
 
index 80613c26478479fb97e232b07ea26a6ffe0a0011..c9629112de4b76f7cbc6671779190e5de40077e3 100644 (file)
@@ -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);
index 8c03ab0cb1acc9636f1351e23d6dfa27f3a27689..180a98fbb93f41c2917dddb46fd6d909fb74dbc3 100644 (file)
@@ -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);
        }
index 0cbb5ae1b91adca0e0e4bf4ccab220f17a2d15ed..2e1c6212c9fa2f093b16c78223987fb6dc8b0c4b 100644 (file)
@@ -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
index 743559b6421c916ea10e40d834d76ced5368c944..c8665daa71412c4bdc9eb946889038e04571c5f7 100644 (file)
@@ -16,9 +16,7 @@
 
 #include <string>
 
-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
index d8c6fb823adc694deac4d7f7c489f06b5ed974b5..85b7956e56855f7edfe0334a812d4911d623278c 100644 (file)
@@ -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;
 }
 
index 8db0e5cfec278d2e07b145896312d4b81933201c..6a18ffc032792eb63f2a77f40d5f6b24b619e4e6 100644 (file)
@@ -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);
 }
 
index ea7c8cd3275ca97e792c34812f816bf64ba8ca07..490435026c17c43a20384c98c44f24b0d10272f0 100644 (file)
@@ -93,8 +93,7 @@ void QLPopupMenu::populate(Menu * menu)
                        insertSeparator();
                } else if (m->kind() == MenuItem::Submenu) {
                        pair<int, QLPopupMenu *> 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));
                }
        }
index a1f75666153c4125336d3cef3b9390524e4bc27c..07fa9829e7e9f6b4379cc8d49558fe467567527d 100644 (file)
@@ -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
index fec33840e8b697b3b9cc71d1cd491a99f85908e3..e8a3c0f4216fbb4a1e0471e8b8b58e854a4937ba 100644 (file)
@@ -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
index 2025257c26709135f7e7218383d5cb3f353a86c3..d288cd7b97fac90700c5bdf5b58aad148cfb5ae4 100644 (file)
@@ -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);
        }
 }
 
index b24bb93356217a65ee3feb35961d723b07d5f107..a6ded266b995356dd4bb3370cc4629c6b143c386 100644 (file)
@@ -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;
 }
index e9a045c8a87da8e51270acb8a5b6c15793e6664a..6e93ae8728785dc0e0f583fd211434fd79784d54 100644 (file)
@@ -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);
index 3b61fdfd6bb6120ae865e0640c5457fe5278c181..0c8a5bef1b166d02abd3712134ca0a32047ec63c 100644 (file)
@@ -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);
index c4866a1dcc6ab450b4b5e7c179a7913871f93470..aa0ee77abc374dfe7691911dd4950610cdeab53c 100644 (file)
@@ -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;
index 1f45315603f1d6286b14d32295b4ec9b7fd3402e..2ee3c69ddd61343c7b9197fb088bf1b7393532b8 100644 (file)
@@ -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<InsetTabular *>
+                               (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();
 }
+       
index c37d692fe8f248a7000b25214c952671b69304e1..804f32ae9ad56ffe820d16de03d28833660ae5ab 100644 (file)
@@ -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,
index 92adcd34a4fc2bb358894ff51065bd2b4dcdc594..4c3b7005ce5b193cbe3bb1c33033c6a2cc0fed05 100644 (file)
@@ -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
 {
index 04985a1d5fc555852e0b49c37942aeb1b98dcac8..c4b5ef06ce01e8359274743009892cd9cfabd6ac 100644 (file)
@@ -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); };
index 41a3772a69a5ceecb0080de73080b66c006f865e..87802db1a4d10a1dbbf76609286a527b1b0a995a 100644 (file)
@@ -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<InsetTabular *>
-                               (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();
index e463e46a3f56ed29ceed4502e7f9aad4f038ab1b..01d0c7a61bad22f34a3d58de4eb6a71231716f36 100644 (file)
@@ -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();
index f20ef1914deeb537e7b69110dc6f3e6ae2446445..1ed309e98109c9702c810cbee318523b6e3174e0 100644 (file)
@@ -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);
index 4eae6eeaf061f532cb7232fd5fc36455a8482815..4b52ecb219370ba9e5a4e51123ee5f637fb94584 100644 (file)
@@ -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);
index fbd42cd6fd316f3ca20d4aade4b803af15c1eee1..889cbfed51981ccb39ac7f888b788d70c6c8a19a 100644 (file)
@@ -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<LyXText&>(*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);
index ffc121ef12de0baafa29241bdf9e246abfa8ef99..a27743718528f81cb8b7176218feb666df81d695 100644 (file)
@@ -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;
 }