implement missing getStatus methods

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9853 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2005-04-22 08:57:22 +00:00
parent b45cbe936e
commit 323cafa18c
23 changed files with 256 additions and 14 deletions

View 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> 2005-04-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* insetcollapsable.C (doDispatch): pass through double/triple * insetcollapsable.C (doDispatch): pass through double/triple

View File

@ -97,6 +97,8 @@ public:
* These need to be handled in the doDispatch() methods of the * These need to be handled in the doDispatch() methods of the
* derived insets, since InsetBase::doDispatch() has not enough * derived insets, since InsetBase::doDispatch() has not enough
* information to handle them. * 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, virtual bool getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & status) const; FuncStatus & status) const;
@ -325,37 +327,37 @@ public:
*/ */
static Code translate(std::string const & name); 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; } virtual bool insetAllowed(Code) const { return false; }
// if this inset has paragraphs should they be output all as default /// if this inset has paragraphs should they be output all as default
// paragraphs with "Standard" layout? /// paragraphs with "Standard" layout?
virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; } virtual bool forceDefaultParagraphs(InsetBase const *) const { return false; }
/// ///
virtual std::string const & getInsetName() const; virtual std::string const & getInsetName() const;
/// used to toggle insets /// used to toggle insets
// is the inset open? /// is the inset open?
virtual bool isOpen() const { return false; } virtual bool isOpen() const { return false; }
/// open the inset /// open the inset
virtual void open() {} virtual void open() {}
/// close the inset /// close the inset
virtual void close() {} 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; } virtual bool isChar() const { return false; }
// is this equivalent to a letter? /// is this equivalent to a letter?
virtual bool isLetter() const { return false; } virtual bool isLetter() const { return false; }
// is this equivalent to a space (which is BTW different from /// is this equivalent to a space (which is BTW different from
// a line separator)? /// a line separator)?
virtual bool isSpace() const { return false; } 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; } 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; } virtual bool isLineSeparator() const { return false; }
/// dumps content to lyxerr /// dumps content to lyxerr
virtual void dump() const; virtual void dump() const;
/// /// write inset in .lyx format
virtual void write(Buffer const &, std::ostream &) const {} virtual void write(Buffer const &, std::ostream &) const {}
/// /// read inset in .lyx format
virtual void read(Buffer const &, LyXLex &) {} virtual void read(Buffer const &, LyXLex &) {}
/// returns the number of rows (\n's) of generated tex code. /// returns the number of rows (\n's) of generated tex code.
virtual int latex(Buffer const &, std::ostream &, virtual int latex(Buffer const &, std::ostream &,

View File

@ -17,6 +17,7 @@
#include "cursor.h" #include "cursor.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "debug.h" #include "debug.h"
#include "FuncStatus.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.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, int InsetBox::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {

View File

@ -92,6 +92,8 @@ public:
/// ///
InsetBoxParams const & params() const { return params_; } InsetBoxParams const & params() const { return params_; }
/// ///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
///
enum BoxType { enum BoxType {
Frameless, Frameless,
Boxed, Boxed,

View File

@ -18,6 +18,7 @@
#include "cursor.h" #include "cursor.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LColor.h" #include "LColor.h"
#include "lyxlex.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 bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
{ {
BranchList::const_iterator const end = branchlist.end(); BranchList::const_iterator const end = branchlist.end();

View File

@ -75,6 +75,8 @@ public:
\c branchlist. \c branchlist.
*/ */
bool isBranchSelected(BranchList const & branchlist) const; bool isBranchSelected(BranchList const & branchlist) const;
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
InsetBranch(InsetBranch const &); InsetBranch(InsetBranch const &);

View File

@ -19,6 +19,7 @@
#include "cursor.h" #include "cursor.h"
#include "debug.h" #include "debug.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "FuncStatus.h"
#include "LColor.h" #include "LColor.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "funcrequest.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); 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 InsetCollapsable::scroll(bool recursive) const
{ {
int sx = UpdatableInset::scroll(false); int sx = UpdatableInset::scroll(false);

View File

@ -55,7 +55,7 @@ public:
/// return x,y of given position relative to the inset's baseline /// return x,y of given position relative to the inset's baseline
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; 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; std::string const getNewLabel(std::string const & l) const;
/// ///
@ -88,6 +88,8 @@ public:
void close(); void close();
/// ///
bool allowSpellCheck() const { return true; } bool allowSpellCheck() const { return true; }
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
/// ///

View File

@ -16,6 +16,7 @@
#include "BufferView.h" #include "BufferView.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "metricsinfo.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, InsetCommandMailer::InsetCommandMailer(string const & name,
InsetCommand & inset) InsetCommand & inset)
: name_(name), inset_(inset) : name_(name), inset_(inset)

View File

@ -78,6 +78,8 @@ protected:
/// ///
virtual void doDispatch(LCursor & cur, FuncRequest & cmd); 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 getCommand() const { return p_.getCommand(); }
/// ///
std::string const & getCmdName() const { return p_.getCmdName(); } std::string const & getCmdName() const { return p_.getCmdName(); }

View File

@ -341,6 +341,12 @@ bool InsetERT::getStatus(LCursor & cur, FuncRequest const & cmd,
status.enabled(false); status.enabled(false);
return true; 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 // this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence // solution, we consider only the first action of the sequence
case LFUN_SEQUENCE: { case LFUN_SEQUENCE: {

View 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) void InsetExternal::edit(LCursor & cur, bool)
{ {
InsetExternalMailer(*this).showDialog(&cur.bv()); InsetExternalMailer(*this).showDialog(&cur.bv());
@ -732,6 +749,7 @@ void InsetExternal::validate(LaTeXFeatures & features) const
return; return;
external::Template const & et = *et_ptr; external::Template const & et = *et_ptr;
// FIXME: This is wrong if we export to PDFLaTeX
external::Template::Formats::const_iterator cit = external::Template::Formats::const_iterator cit =
et.formats.find("LaTeX"); et.formats.find("LaTeX");
if (cit == et.formats.end()) if (cit == et.formats.end())

View File

@ -146,6 +146,8 @@ public:
void addPreview(lyx::graphics::PreviewLoader &) const; void addPreview(lyx::graphics::PreviewLoader &) const;
/// ///
void edit(LCursor & cur, bool left); void edit(LCursor & cur, bool left);
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
InsetExternal(InsetExternal const &); InsetExternal(InsetExternal const &);

View File

@ -22,6 +22,7 @@
#include "Floating.h" #include "Floating.h"
#include "FloatList.h" #include "FloatList.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "LColor.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 void InsetFloatParams::write(ostream & os) const
{ {
os << "Float " << type << '\n'; os << "Float " << type << '\n';

View File

@ -80,6 +80,8 @@ public:
bool showInsetDialog(BufferView *) const; bool showInsetDialog(BufferView *) const;
/// ///
InsetFloatParams const & params() const { return params_; } InsetFloatParams const & params() const { return params_; }
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
virtual void doDispatch(LCursor & cur, FuncRequest & cmd); virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
private: private:

View File

@ -61,6 +61,7 @@ TODO
#include "exporter.h" #include "exporter.h"
#include "format.h" #include "format.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "lyx_main.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) void InsetGraphics::edit(LCursor & cur, bool)
{ {
InsetGraphicsMailer(*this).showDialog(&cur.bv()); InsetGraphicsMailer(*this).showDialog(&cur.bv());

View File

@ -76,6 +76,8 @@ public:
void edit(LCursor & cur, bool left); void edit(LCursor & cur, bool left);
/// ///
void editGraphics(InsetGraphicsParams const &, Buffer const &) const; void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
InsetGraphics(InsetGraphics const &); InsetGraphics(InsetGraphics const &);
/// ///

View File

@ -22,6 +22,7 @@
#include "dispatchresult.h" #include "dispatchresult.h"
#include "exporter.h" #include "exporter.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "lyx_main.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 InsetCommandParams const & InsetInclude::params() const
{ {
return params_; return params_;

View File

@ -77,6 +77,8 @@ public:
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
void addPreview(lyx::graphics::PreviewLoader &) const; void addPreview(lyx::graphics::PreviewLoader &) const;
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
InsetInclude(InsetInclude const &); InsetInclude(InsetInclude const &);
/// ///

View File

@ -19,6 +19,7 @@
#include "debug.h" #include "debug.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "LColor.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, int InsetNote::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {

View File

@ -70,6 +70,8 @@ public:
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
/// ///
InsetNoteParams const & params() const { return params_; } InsetNoteParams const & params() const { return params_; }
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
InsetNote(InsetNote const &); InsetNote(InsetNote const &);
/// ///

View File

@ -21,6 +21,7 @@
#include "Floating.h" #include "Floating.h"
#include "FloatList.h" #include "FloatList.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "LColor.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 void InsetWrapParams::write(ostream & os) const
{ {
os << "Wrap " << type << '\n'; os << "Wrap " << type << '\n';

View File

@ -65,6 +65,8 @@ public:
bool showInsetDialog(BufferView *) const; bool showInsetDialog(BufferView *) const;
/// ///
InsetWrapParams const & params() const { return params_; } InsetWrapParams const & params() const { return params_; }
///
bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
protected: protected:
/// ///
virtual void doDispatch(LCursor & cur, FuncRequest & cmd); virtual void doDispatch(LCursor & cur, FuncRequest & cmd);