]> git.lyx.org Git - lyx.git/commitdiff
implement missing getStatus methods
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 22 Apr 2005 08:57:22 +0000 (08:57 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 22 Apr 2005 08:57:22 +0000 (08:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9853 a592a061-630c-0410-9148-cb99ea01b6c8

23 files changed:
src/insets/ChangeLog
src/insets/insetbase.h
src/insets/insetbox.C
src/insets/insetbox.h
src/insets/insetbranch.C
src/insets/insetbranch.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetert.C
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetfloat.C
src/insets/insetfloat.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/insetnote.C
src/insets/insetnote.h
src/insets/insetwrap.C
src/insets/insetwrap.h

index c4faedf9d8372b95e28a27b8b3489634a0885337..cf8d41e279607a977e208e721fc1a552a8f308ad 100644 (file)
@@ -1,3 +1,14 @@
+2005-04-22  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insetbase.h: document a bit more
+       * insetbox.[Ch], insetbranch.[Ch], insetcollapsable.[Ch],
+       insetcommand.[Ch], insetexternal.[Ch], insetfloat.[Ch],
+       insetgraphics.[Ch], insetinclude.[Ch], insetnote.[Ch], insetwrap.[Ch]
+       (getStatus): implement
+       * insetcollapsable.[Ch] (hitButton): take a const argument
+       * insetert.C (getStatus): enable LFUN_INSET_MODIFY, LFUN_PASTE and
+       LFUN_PASTE_SELECTION
+
 2005-04-19  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * insetcollapsable.C (doDispatch): pass through double/triple
index 99ca4682814690a9b9242fb02435b9ecbaecc5ae..887879481d1d2346a2a8784f6527df0710755c8d 100644 (file)
@@ -97,6 +97,8 @@ public:
         *   These need to be handled in the doDispatch() methods of the
         *   derived insets, since InsetBase::doDispatch() has not enough
         *   information to handle them.
+        * - LFUN_MOUSE_* need not to be handled in getStatus(), because these
+        *   are dispatched directly
         */
        virtual bool getStatus(LCursor & cur, FuncRequest const & cmd,
                FuncStatus & status) const;
@@ -325,37 +327,37 @@ public:
         */
        static Code translate(std::string const & name);
 
-       /// returns true the inset can hold an inset of given type
+       /// returns true if the inset can hold an inset of given type
        virtual bool insetAllowed(Code) const { return false; }
-       // if this inset has paragraphs should they be output all as default
-       // paragraphs with "Standard" layout?
+       /// if this inset has paragraphs should they be output all as default
+       /// paragraphs with "Standard" layout?
        virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
 
        ///
        virtual std::string const & getInsetName() const;
        /// used to toggle insets
-       // is the inset open?
+       /// is the inset open?
        virtual bool isOpen() const { return false; }
        /// open the inset
        virtual void open() {}
        /// close the inset
        virtual void close() {}
-       // should this inset be handled like a normal charater
+       /// should this inset be handled like a normal charater
        virtual bool isChar() const { return false; }
-       // is this equivalent to a letter?
+       /// is this equivalent to a letter?
        virtual bool isLetter() const { return false; }
-       // is this equivalent to a space (which is BTW different from
-       // a line separator)?
+       /// is this equivalent to a space (which is BTW different from
+       /// a line separator)?
        virtual bool isSpace() const { return false; }
-       // should we have a non-filled line before this inset?
+       /// should we have a non-filled line before this inset?
        virtual bool display() const { return false; }
-       // should we break lines after this inset?
+       /// should we break lines after this inset?
        virtual bool isLineSeparator() const { return false; }
        /// dumps content to lyxerr
        virtual void dump() const;
-       ///
+       /// write inset in .lyx format
        virtual void write(Buffer const &, std::ostream &) const {}
-       ///
+       /// read inset in .lyx format
        virtual void read(Buffer const &, LyXLex &) {}
        /// returns the number of rows (\n's) of generated tex code.
        virtual int latex(Buffer const &, std::ostream &,
index 1007564430f7bf6d9f704a4d65fddcb21386bfd7..27d41f401456529a5d9e74c749ba90fd855bee91 100644 (file)
@@ -17,6 +17,7 @@
 #include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
+#include "FuncStatus.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
@@ -200,6 +201,22 @@ void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+}
+
+
 int InsetBox::latex(Buffer const & buf, ostream & os,
                                OutputParams const & runparams) const
 {
index f953ff72aec2283be34634be0d4fc2b999966a42..80efa336d8d87dd5e3a4608ef1125b67f9ad71ab 100644 (file)
@@ -92,6 +92,8 @@ public:
        ///
        InsetBoxParams const & params() const { return params_; }
        ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
+       ///
        enum BoxType {
                Frameless,
                Boxed,
index 8eae1a7a0af5fb0548cf096914111db9231f3e27..c2fc42df2ca42e1301f3ab9e3e60d1d134b5dee7 100644 (file)
@@ -18,6 +18,7 @@
 #include "cursor.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LColor.h"
 #include "lyxlex.h"
@@ -184,6 +185,45 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               break;
+
+       case LFUN_INSET_TOGGLE:
+               if (cmd.argument == "open" || cmd.argument == "close" ||
+                   cmd.argument == "toggle")
+                       flag.enabled(true);
+               else if (cmd.argument == "assign"
+                          || cmd.argument.empty()) {
+                       BranchList const & branchlist =
+                               cur.buffer().params().branchlist();
+                       if (isBranchSelected(branchlist)) {
+                               if (status() != Open)
+                                       flag.enabled(true);
+                               else
+                                       flag.enabled(false);
+                       } else {
+                               if (status() != Collapsed)
+                                       flag.enabled(true);
+                               else
+                                       flag.enabled(false);
+                       }
+               } else
+                       flag.enabled(true);
+               break;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+       return true;
+}
+
+
 bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
 {
        BranchList::const_iterator const end = branchlist.end();
index d74a06b21fa922e87a7205e3116e718b97a5a004..dae9a5bf8d99e788543b882cb80d4962b2ff7c71 100644 (file)
@@ -75,6 +75,8 @@ public:
            \c branchlist.
         */
        bool isBranchSelected(BranchList const & branchlist) const;
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 
 protected:
        InsetBranch(InsetBranch const &);
index e22c1d63bc8efd186f0b7a10ca90719a7926bea2..657569d7fb1c81d3523bd60a5b02263488b88bbf 100644 (file)
@@ -19,6 +19,7 @@
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "FuncStatus.h"
 #include "LColor.h"
 #include "lyxlex.h"
 #include "funcrequest.h"
@@ -235,7 +236,7 @@ bool InsetCollapsable::descendable() const
 }
 
 
-bool InsetCollapsable::hitButton(FuncRequest & cmd) const
+bool InsetCollapsable::hitButton(FuncRequest const & cmd) const
 {
        return button_dim.contains(cmd.x, cmd.y);
 }
@@ -365,6 +366,25 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_TOGGLE:
+               if (cmd.argument == "open" || cmd.argument == "close" ||
+                   cmd.argument == "toggle")
+                       flag.enabled(true);
+               else
+                       flag.enabled(false);
+               return true;
+
+       default:
+               return InsetText::getStatus(cur, cmd, flag);
+       }
+}
+
+
 int InsetCollapsable::scroll(bool recursive) const
 {
        int sx = UpdatableInset::scroll(false);
index 763b5b49f08a8d27c8188e7287394f611652550c..9b9e84ed13c3a99a860f6718faefc9676f42cd9a 100644 (file)
@@ -55,7 +55,7 @@ public:
        /// return x,y of given position relative to the inset's baseline
        void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
        ///
-       bool hitButton(FuncRequest &) const;
+       bool hitButton(FuncRequest const &) const;
        ///
        std::string const getNewLabel(std::string const & l) const;
        ///
@@ -88,6 +88,8 @@ public:
        void close();
        ///
        bool allowSpellCheck() const { return true; }
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 
 protected:
        ///
index 4d351abc6681a5b87caa14f8357d9076339a260c..66d049448ce619c5da30b5c7054951ed038cc571 100644 (file)
@@ -16,6 +16,7 @@
 #include "BufferView.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "lyxlex.h"
 #include "metricsinfo.h"
 
@@ -136,6 +137,27 @@ void InsetCommand::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetCommand::getStatus(LCursor & cur, FuncRequest const & cmd,
+       FuncStatus & status) const
+{
+       switch (cmd.action) {
+       // suppress these
+       case LFUN_INSET_ERT:
+               status.enabled(false);
+               return true;
+       // we handle these
+       case LFUN_INSET_REFRESH:
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+       case LFUN_INSET_DIALOG_SHOW:
+               status.enabled(true);
+               return true;
+       default:
+               return InsetBase::getStatus(cur, cmd, status);
+       }
+}
+
+
 InsetCommandMailer::InsetCommandMailer(string const & name,
                                       InsetCommand & inset)
        : name_(name), inset_(inset)
index 27e37e05e8824adb9fd2b893802c72c791a579a9..a798796ec298cdd0b4ac1fe4accb0911e0d169af 100644 (file)
@@ -78,6 +78,8 @@ protected:
        ///
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
        ///
+       bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
+       ///
        std::string const getCommand() const { return p_.getCommand(); }
        ///
        std::string const & getCmdName() const { return p_.getCmdName(); }
index 72ac3ef684cb602b440736753d78c61868342dca..712a1c0ddc09b3348d613d2f4c4a866d2913bd3c 100644 (file)
@@ -341,6 +341,12 @@ bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd,
                        status.enabled(false);
                        return true;
 
+               case LFUN_INSET_MODIFY:
+               case LFUN_PASTE:
+               case LFUN_PASTESELECTION:
+                       status.enabled(true);
+                       return true;
+
                // this one is difficult to get right. As a half-baked
                // solution, we consider only the first action of the sequence
                case LFUN_SEQUENCE: {
index 24885b51786d42c675f70630bd1bca02a83ba1dd..3fcd5902e432143b803d68c7f1c2968a3478101d 100644 (file)
@@ -466,6 +466,23 @@ void InsetExternal::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetExternal::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_EXTERNAL_EDIT:
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetBase::getStatus(cur, cmd, flag);
+       }
+}
+
+
 void InsetExternal::edit(LCursor & cur, bool)
 {
        InsetExternalMailer(*this).showDialog(&cur.bv());
@@ -732,6 +749,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const
                return;
        external::Template const & et = *et_ptr;
 
+       // FIXME: This is wrong if we export to PDFLaTeX
        external::Template::Formats::const_iterator cit =
                et.formats.find("LaTeX");
        if (cit == et.formats.end())
index 06583514dc9fccdbb691f5ad17e93d99022fabe3..1f09b82fe6133405cdfdbbd4754129e84cd5b07a 100644 (file)
@@ -146,6 +146,8 @@ public:
        void addPreview(lyx::graphics::PreviewLoader &) const;
        ///
        void edit(LCursor & cur, bool left);
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 
 protected:
        InsetExternal(InsetExternal const &);
index f5d31686d37d8892003c7015ec109636e38bdc7b..3c8cf348375ce8d262dd11ad5cc5cbf46c712733 100644 (file)
@@ -22,6 +22,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
@@ -184,6 +185,23 @@ void InsetFloat::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetFloat::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               break;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+               break;
+       }
+}
+
+
 void InsetFloatParams::write(ostream & os) const
 {
        os << "Float " << type << '\n';
index 8683a76cad45edc6a82d72a44f09c882cf8b83e3..26458a6e48bb66f365f482ebcff807de038bdf42 100644 (file)
@@ -80,6 +80,8 @@ public:
        bool  showInsetDialog(BufferView *) const;
        ///
        InsetFloatParams const & params() const { return params_; }
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
 private:
index f203b75cf3b70fea8d1944efd146ee58d8f0fffe..e9c1105cd824d4d0892de044d5b8cfd80a78fd1f 100644 (file)
@@ -61,6 +61,7 @@ TODO
 #include "exporter.h"
 #include "format.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "lyx_main.h"
@@ -218,6 +219,22 @@ void InsetGraphics::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetGraphics::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+       case LFUN_GRAPHICS_EDIT:
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetBase::getStatus(cur, cmd, flag);
+       }
+}
+
+
 void InsetGraphics::edit(LCursor & cur, bool)
 {
        InsetGraphicsMailer(*this).showDialog(&cur.bv());
index 8cc3128880a13839374988af43634992c17e35e1..140a1f9d217d3a72a14d93026c553a160097fde3 100644 (file)
@@ -76,6 +76,8 @@ public:
        void edit(LCursor & cur, bool left);
        ///
        void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
        InsetGraphics(InsetGraphics const &);
        ///
index ca4a6af20bab402692eb955111818a91696cd7b3..129fd7cc93f7b07100a6a3d8f31b6c33033784be 100644 (file)
@@ -22,6 +22,7 @@
 #include "dispatchresult.h"
 #include "exporter.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "lyx_main.h"
@@ -150,6 +151,23 @@ void InsetInclude::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetInclude::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+       case LFUN_INSET_DIALOG_SHOW:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetBase::getStatus(cur, cmd, flag);
+       }
+}
+
+
 InsetCommandParams const & InsetInclude::params() const
 {
        return params_;
index ff3307fbfcd6d4f34e2fe71d0f4357ccf3321420..0a519ecbe5c25a8bf046462a1fb46e29187c0e3b 100644 (file)
@@ -77,6 +77,8 @@ public:
        void validate(LaTeXFeatures &) const;
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
        InsetInclude(InsetInclude const &);
        ///
index e317aa1d191d04ba252cf62a328ff3002fe966c3..faa31ab0e4186d3dfc2e17ae3395ecf48df678af 100644 (file)
@@ -19,6 +19,7 @@
 #include "debug.h"
 #include "dispatchresult.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
@@ -212,6 +213,22 @@ void InsetNote::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetNote::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+}
+
+
 int InsetNote::latex(Buffer const & buf, ostream & os,
                     OutputParams const & runparams) const
 {
index e0aa3ac58efb76ca7296309624b01df65bbc3698..95948c4caced8a80b922ee1df933d37026f1e322 100644 (file)
@@ -70,6 +70,8 @@ public:
        void validate(LaTeXFeatures &) const;
        ///
        InsetNoteParams const & params() const { return params_; }
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
        InsetNote(InsetNote const &);
        ///
index b43ba83cf7faf7c6f7be7d7019ca19fe432b6036..a08c43cc57ee33208d13111c89bf0d316e25fe5c 100644 (file)
@@ -21,6 +21,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
@@ -106,6 +107,21 @@ void InsetWrap::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
+bool InsetWrap::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+}
+
+
 void InsetWrapParams::write(ostream & os) const
 {
        os << "Wrap " << type << '\n';
index eaea6bce3a3ed46eb35d354df799b8ae3032e924..722acce017c7eed1de69813dd96bb9a8dac8414b 100644 (file)
@@ -65,6 +65,8 @@ public:
        bool showInsetDialog(BufferView *) const;
        ///
        InsetWrapParams const & params() const { return params_; }
+       ///
+       bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
 protected:
        ///
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);