Crash fix. I don't know why this is triggered only now... I guess someone changed the way toolbars are initialized. The changes are safer anyway.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20895 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-11 09:57:52 +00:00
parent 57a8d370d4
commit a2bc74bca8

View File

@ -419,8 +419,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl; //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
FuncStatus flag; FuncStatus flag;
Cursor & cur = view()->cursor();
/* In LyX/Mac, when a dialog is open, the menus of the /* In LyX/Mac, when a dialog is open, the menus of the
application can still be accessed without giving focus to application can still be accessed without giving focus to
the main window. In this case, we want to disable the menu the main window. In this case, we want to disable the menu
@ -472,6 +470,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
return flag; return flag;
} }
Cursor * cur = view()? &view()->cursor(): 0;
// I would really like to avoid having this switch and rather try to // I would really like to avoid having this switch and rather try to
// encode this in the function itself. // encode this in the function itself.
// -- And I'd rather let an inset decide which LFUNs it is willing // -- And I'd rather let an inset decide which LFUNs it is willing
@ -503,12 +503,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break; break;
case LFUN_LAYOUT_TABULAR: case LFUN_LAYOUT_TABULAR:
enable = cur.innerInsetOfType(Inset::TABULAR_CODE); enable = cur? cur->innerInsetOfType(Inset::TABULAR_CODE) : false;
break; break;
case LFUN_LAYOUT: case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH: case LFUN_LAYOUT_PARAGRAPH:
enable = !cur.inset().forceDefaultParagraphs(cur.idx()); enable = cur? !cur->inset().forceDefaultParagraphs(cur->idx()) : false;
break; break;
case LFUN_VC_REGISTER: case LFUN_VC_REGISTER:
@ -533,7 +533,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
enable = false; enable = false;
if (!cur) if (!cur)
break; break;
Inset::Code code = cur.inset().lyxCode(); Inset::Code code = cur->inset().lyxCode();
switch (code) { switch (code) {
case Inset::TABULAR_CODE: case Inset::TABULAR_CODE:
enable = cmd.argument() == "tabular"; enable = cmd.argument() == "tabular";
@ -566,12 +566,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
} }
case LFUN_INSET_APPLY: { case LFUN_INSET_APPLY: {
enable = false;
if (!cur)
break;
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
Inset * inset = lyx_view_->getDialogs().getOpenInset(name); Inset * inset = lyx_view_->getDialogs().getOpenInset(name);
if (inset) { if (inset) {
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
FuncStatus fs; FuncStatus fs;
if (!inset->getStatus(cur, fr, fs)) { if (!inset->getStatus(*cur, fr, fs)) {
// Every inset is supposed to handle this // Every inset is supposed to handle this
BOOST_ASSERT(false); BOOST_ASSERT(false);
} }
@ -588,6 +591,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
flag.setOnOff(lyx_view_->getDialogs().visible(cmd.getArg(0))); flag.setOnOff(lyx_view_->getDialogs().visible(cmd.getArg(0)));
// fall through to set "enable" // fall through to set "enable"
case LFUN_DIALOG_SHOW: { case LFUN_DIALOG_SHOW: {
enable = false;
if (!cur)
break;
string const name = cmd.getArg(0); string const name = cmd.getArg(0);
if (!buf) if (!buf)
enable = name == "aboutlyx" enable = name == "aboutlyx"
@ -598,8 +604,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
enable = Exporter::isExportable(*buf, "dvi") enable = Exporter::isExportable(*buf, "dvi")
&& lyxrc.print_command != "none"; && lyxrc.print_command != "none";
else if (name == "character") else if (name == "character")
enable = cur.inset().lyxCode() != Inset::ERT_CODE && enable = cur->inset().lyxCode() != Inset::ERT_CODE &&
cur.inset().lyxCode() != Inset::LISTINGS_CODE; cur->inset().lyxCode() != Inset::LISTINGS_CODE;
else if (name == "latexlog") else if (name == "latexlog")
enable = isFileReadable(FileName(buf->getLogName().second)); enable = isFileReadable(FileName(buf->getLogName().second));
else if (name == "spellchecker") else if (name == "spellchecker")
@ -614,11 +620,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
} }
case LFUN_DIALOG_SHOW_NEW_INSET: case LFUN_DIALOG_SHOW_NEW_INSET:
enable = cur.inset().lyxCode() != Inset::ERT_CODE && enable = false;
cur.inset().lyxCode() != Inset::LISTINGS_CODE; if (!cur)
if (cur.inset().lyxCode() == Inset::CAPTION_CODE) { break;
enable = cur->inset().lyxCode() != Inset::ERT_CODE &&
cur->inset().lyxCode() != Inset::LISTINGS_CODE;
if (cur->inset().lyxCode() == Inset::CAPTION_CODE) {
FuncStatus flag; FuncStatus flag;
if (cur.inset().getStatus(cur, cmd, flag)) if (cur->inset().getStatus(*cur, cmd, flag))
return flag; return flag;
} }
break; break;
@ -755,7 +764,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break; break;
default: default:
if (!getLocalStatus(cur, cmd, flag)) enable = false;
if (!cur)
break;
if (!getLocalStatus(*cur, cmd, flag))
flag = view()->getStatus(cmd); flag = view()->getStatus(cmd);
} }
@ -771,7 +783,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
} }
// Are we in a DELETED change-tracking region? // Are we in a DELETED change-tracking region?
if (buf && lookupChangeType(cur, true) == Change::DELETED if (buf && cur
&& lookupChangeType(*cur, true) == Change::DELETED
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly) && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) { && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
flag.message(from_utf8(N_("This portion of the document is deleted."))); flag.message(from_utf8(N_("This portion of the document is deleted.")));