From 323cafa18c2315759087d976e800aebd894fb40f Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 22 Apr 2005 08:57:22 +0000 Subject: [PATCH] implement missing getStatus methods git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9853 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/ChangeLog | 11 ++++++++++ src/insets/insetbase.h | 26 ++++++++++++----------- src/insets/insetbox.C | 17 +++++++++++++++ src/insets/insetbox.h | 2 ++ src/insets/insetbranch.C | 40 +++++++++++++++++++++++++++++++++++ src/insets/insetbranch.h | 2 ++ src/insets/insetcollapsable.C | 22 ++++++++++++++++++- src/insets/insetcollapsable.h | 4 +++- src/insets/insetcommand.C | 22 +++++++++++++++++++ src/insets/insetcommand.h | 2 ++ src/insets/insetert.C | 6 ++++++ src/insets/insetexternal.C | 18 ++++++++++++++++ src/insets/insetexternal.h | 2 ++ src/insets/insetfloat.C | 18 ++++++++++++++++ src/insets/insetfloat.h | 2 ++ src/insets/insetgraphics.C | 17 +++++++++++++++ src/insets/insetgraphics.h | 2 ++ src/insets/insetinclude.C | 18 ++++++++++++++++ src/insets/insetinclude.h | 2 ++ src/insets/insetnote.C | 17 +++++++++++++++ src/insets/insetnote.h | 2 ++ src/insets/insetwrap.C | 16 ++++++++++++++ src/insets/insetwrap.h | 2 ++ 23 files changed, 256 insertions(+), 14 deletions(-) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index c4faedf9d8..cf8d41e279 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2005-04-22 Georg Baum + + * 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 * insetcollapsable.C (doDispatch): pass through double/triple diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 99ca468281..887879481d 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -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 &, diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index 1007564430..27d41f4014 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -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 { diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index f953ff72ae..80efa336d8 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -92,6 +92,8 @@ public: /// InsetBoxParams const & params() const { return params_; } /// + bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const; + /// enum BoxType { Frameless, Boxed, diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 8eae1a7a0a..c2fc42df2c 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -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(); diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index d74a06b21f..dae9a5bf8d 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -75,6 +75,8 @@ public: \c branchlist. */ bool isBranchSelected(BranchList const & branchlist) const; + /// + bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const; protected: InsetBranch(InsetBranch const &); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index e22c1d63bc..657569d7fb 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 763b5b49f0..9b9e84ed13 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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: /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 4d351abc66..66d049448c 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -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) diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 27e37e05e8..a798796ec2 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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(); } diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 72ac3ef684..712a1c0ddc 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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: { diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 24885b5178..3fcd5902e4 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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()) diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 06583514dc..1f09b82fe6 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -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 &); diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index f5d31686d3..3c8cf34837 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -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'; diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 8683a76cad..26458a6e48 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -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: diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index f203b75cf3..e9c1105cd8 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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()); diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 8cc3128880..140a1f9d21 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -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 &); /// diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index ca4a6af20b..129fd7cc93 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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_; diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index ff3307fbfc..0a519ecbe5 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -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 &); /// diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index e317aa1d19..faa31ab0e4 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -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 { diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index e0aa3ac58e..95948c4cac 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -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 &); /// diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index b43ba83cf7..a08c43cc57 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -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'; diff --git a/src/insets/insetwrap.h b/src/insets/insetwrap.h index eaea6bce3a..722acce017 100644 --- a/src/insets/insetwrap.h +++ b/src/insets/insetwrap.h @@ -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); -- 2.39.5