Transfer some LFUNs from LyXFunc::getStatus() to BufferView::getStatus(). What a mess!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20902 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-11 13:20:21 +00:00
parent a9c2a907c0
commit 70b938bf5a
2 changed files with 68 additions and 75 deletions

View File

@ -932,6 +932,60 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
flag.enabled(false);
break;
case LFUN_LAYOUT_TABULAR:
flag.enabled(cur.innerInsetOfType(Inset::TABULAR_CODE));
break;
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:
flag.enabled(cur.inset().forceDefaultParagraphs(cur.idx()));
break;
case LFUN_INSET_SETTINGS: {
Inset::Code code = cur.inset().lyxCode();
bool enable = false;
switch (code) {
case Inset::TABULAR_CODE:
enable = cmd.argument() == "tabular";
break;
case Inset::ERT_CODE:
enable = cmd.argument() == "ert";
break;
case Inset::FLOAT_CODE:
enable = cmd.argument() == "float";
break;
case Inset::WRAP_CODE:
enable = cmd.argument() == "wrap";
break;
case Inset::NOTE_CODE:
enable = cmd.argument() == "note";
break;
case Inset::BRANCH_CODE:
enable = cmd.argument() == "branch";
break;
case Inset::BOX_CODE:
enable = cmd.argument() == "box";
break;
case Inset::LISTINGS_CODE:
enable = cmd.argument() == "listings";
break;
default:
break;
}
flag.enabled(enable);
break;
}
case LFUN_DIALOG_SHOW_NEW_INSET:
flag.enabled(cur.inset().lyxCode() != Inset::ERT_CODE &&
cur.inset().lyxCode() != Inset::LISTINGS_CODE);
if (cur.inset().lyxCode() == Inset::CAPTION_CODE) {
FuncStatus flag;
if (cur.inset().getStatus(cur, cmd, flag))
return flag;
}
break;
default:
flag.enabled(false);
}

View File

@ -486,8 +486,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
return flag;
}
Cursor * cur = view()? &view()->cursor(): 0;
// I would really like to avoid having this switch and rather try to
// encode this in the function itself.
// -- And I'd rather let an inset decide which LFUNs it is willing
@ -518,15 +516,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
enable = Exporter::isExportable(*buf, "program");
break;
case LFUN_LAYOUT_TABULAR:
enable = cur? cur->innerInsetOfType(Inset::TABULAR_CODE) : false;
break;
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:
enable = cur? !cur->inset().forceDefaultParagraphs(cur->idx()) : false;
break;
case LFUN_VC_REGISTER:
enable = !buf->lyxvc().inUse();
break;
@ -545,45 +534,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
&& (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
break;
case LFUN_INSET_SETTINGS: {
if (!cur) {
enable = false;
break;
}
Inset::Code code = cur->inset().lyxCode();
switch (code) {
case Inset::TABULAR_CODE:
enable = cmd.argument() == "tabular";
break;
case Inset::ERT_CODE:
enable = cmd.argument() == "ert";
break;
case Inset::FLOAT_CODE:
enable = cmd.argument() == "float";
break;
case Inset::WRAP_CODE:
enable = cmd.argument() == "wrap";
break;
case Inset::NOTE_CODE:
enable = cmd.argument() == "note";
break;
case Inset::BRANCH_CODE:
enable = cmd.argument() == "branch";
break;
case Inset::BOX_CODE:
enable = cmd.argument() == "box";
break;
case Inset::LISTINGS_CODE:
enable = cmd.argument() == "listings";
break;
default:
break;
}
break;
}
case LFUN_INSET_APPLY: {
if (!cur) {
if (!view()) {
enable = false;
break;
}
@ -592,7 +544,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
if (inset) {
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
FuncStatus fs;
if (!inset->getStatus(*cur, fr, fs)) {
if (!inset->getStatus(view()->cursor(), fr, fs)) {
// Every inset is supposed to handle this
BOOST_ASSERT(false);
}
@ -609,10 +561,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
flag.setOnOff(lyx_view_->getDialogs().visible(cmd.getArg(0)));
// fall through to set "enable"
case LFUN_DIALOG_SHOW: {
if (!cur) {
enable = false;
break;
}
string const name = cmd.getArg(0);
if (!buf)
enable = name == "aboutlyx"
@ -622,9 +570,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
else if (name == "print")
enable = Exporter::isExportable(*buf, "dvi")
&& lyxrc.print_command != "none";
else if (name == "character")
enable = cur->inset().lyxCode() != Inset::ERT_CODE &&
cur->inset().lyxCode() != Inset::LISTINGS_CODE;
else if (name == "character") {
if (!view())
enable = false;
else {
Inset::Code ic = view()->cursor().inset().lyxCode();
enable = ic != Inset::ERT_CODE && ic != Inset::LISTINGS_CODE;
}
}
else if (name == "latexlog")
enable = isFileReadable(FileName(buf->getLogName().second));
else if (name == "spellchecker")
@ -638,20 +591,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break;
}
case LFUN_DIALOG_SHOW_NEW_INSET:
if (!cur) {
enable = false;
break;
}
enable = cur->inset().lyxCode() != Inset::ERT_CODE &&
cur->inset().lyxCode() != Inset::LISTINGS_CODE;
if (cur->inset().lyxCode() == Inset::CAPTION_CODE) {
FuncStatus flag;
if (cur->inset().getStatus(*cur, cmd, flag))
return flag;
}
break;
case LFUN_DIALOG_UPDATE: {
string const name = cmd.getArg(0);
if (!buf)
@ -784,11 +723,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break;
default:
if (!cur) {
if (!view()) {
enable = false;
break;
}
if (!getLocalStatus(*cur, cmd, flag))
if (!getLocalStatus(view()->cursor(), cmd, flag))
flag = view()->getStatus(cmd);
}
@ -804,8 +743,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
}
// Are we in a DELETED change-tracking region?
if (buf && cur
&& lookupChangeType(*cur, true) == Change::DELETED
if (buf && view()
&& lookupChangeType(view()->cursor(), true) == Change::DELETED
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
flag.message(from_utf8(N_("This portion of the document is deleted.")));