I started to look at bug 3062 (crash when pressing C-<) and found out seriously weird code in LyXFunc::getStatus. Bo, Peter, I think the code was yours. Do you see anything wrong with my rewrite? Basically, when a lfun can work without a buffer one just has to specify the NoBuffer flag in LyXAction.C.
I hope I did the rewrite correctly. Concerning the actually fix, it is done by the modification of isValid in session.C. Comments? JMarc
Index: src/LyXAction.C =================================================================== --- src/LyXAction.C (revision 16527) +++ src/LyXAction.C (working copy) @@ -100,9 +100,9 @@ void LyXAction::init() { LFUN_ACCENT_UNDERBAR, "accent-underbar", Noop }, { LFUN_ACCENT_UNDERDOT, "accent-underdot", Noop }, { LFUN_APPENDIX, "appendix", Noop }, - { LFUN_BOOKMARK_GOTO, "bookmark-goto", ReadOnly }, + { LFUN_BOOKMARK_GOTO, "bookmark-goto", NoBuffer }, { LFUN_BOOKMARK_SAVE, "bookmark-save", ReadOnly }, - { LFUN_BOOKMARK_CLEAR, "bookmark-clear", ReadOnly }, + { LFUN_BOOKMARK_CLEAR, "bookmark-clear", NoBuffer }, { LFUN_BREAK_LINE, "break-line", Noop }, { LFUN_BREAK_PARAGRAPH, "break-paragraph", Noop }, { LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT, "break-paragraph-keep-layout", Noop }, Index: src/session.C =================================================================== --- src/session.C (revision 16527) +++ src/session.C (working copy) @@ -297,7 +297,7 @@ void BookmarksSection::save(FileName con bool BookmarksSection::isValid(unsigned int i) const { // i == 0, or in the queue - return i <= bookmarks.size(); + return i <= bookmarks.size() && !bookmark(i).filename.empty(); } Index: src/lyxfunc.C =================================================================== --- src/lyxfunc.C (revision 16527) +++ src/lyxfunc.C (working copy) @@ -350,24 +350,6 @@ FuncStatus LyXFunc::getStatus(FuncReques //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl; FuncStatus flag; - if (cmd.action == LFUN_LYX_QUIT) { - flag.message(from_utf8(N_("Exiting"))); - flag.enabled(true); - return flag; - } else if (cmd.action == LFUN_BOOKMARK_GOTO) { - // bookmarks can be valid even if there is no opened buffer - flag.enabled(LyX::ref().session().bookmarks().isValid(convert<unsigned int>(to_utf8(cmd.argument())))); - return flag; - } else if (cmd.action == LFUN_BOOKMARK_CLEAR) { - flag.enabled(LyX::ref().session().bookmarks().size() > 0); - return flag; - } else if (cmd.action == LFUN_TOOLBAR_TOGGLE_STATE) { - ToolbarBackend::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument())); - if (!(flags & ToolbarBackend::AUTO)) - flag.setOnOff(flags & ToolbarBackend::ON); - return flag; - } - LCursor & cur = view()->cursor(); /* In LyX/Mac, when a dialog is open, the menus of the @@ -578,6 +560,23 @@ FuncStatus LyXFunc::getStatus(FuncReques break; } + case LFUN_BOOKMARK_GOTO: { + // bookmarks can be valid even if there is no opened buffer + const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument())); + enable = LyX::ref().session().bookmarks().isValid(num); + break; + } + + case LFUN_BOOKMARK_CLEAR: + enable = LyX::ref().session().bookmarks().size() > 0; + break; + + case LFUN_TOOLBAR_TOGGLE_STATE: { + ToolbarBackend::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument())); + if (!(flags & ToolbarBackend::AUTO)) + flag.setOnOff(flags & ToolbarBackend::ON); + break; + } // this one is difficult to get right. As a half-baked // solution, we consider only the first action of the sequence @@ -641,6 +640,7 @@ FuncStatus LyXFunc::getStatus(FuncReques case LFUN_BUFFER_PREVIOUS: case LFUN_WINDOW_NEW: case LFUN_WINDOW_CLOSE: + case LFUN_LYX_QUIT: // these are handled in our dispatch() break; @@ -1038,6 +1038,7 @@ void LyXFunc::dispatch(FuncRequest const case LFUN_LYX_QUIT: // quitting is triggered by the gui code // (leaving the event loop). + lyx_view_->message(from_utf8(N_("Exiting."))); if (theBufferList().quitWriteAll()) theApp()->gui().closeAllViews(); break; @@ -1673,8 +1674,8 @@ void LyXFunc::dispatch(FuncRequest const case LFUN_BOOKMARK_GOTO: { BOOST_ASSERT(lyx_view_); unsigned int idx = convert<unsigned int>(to_utf8(cmd.argument())); + BOOST_ASSERT(LyX::ref().session().bookmarks().isValid(idx)); BookmarksSection::Bookmark const bm = LyX::ref().session().bookmarks().bookmark(idx); - BOOST_ASSERT(!bm.filename.empty()); string const file = bm.filename.absFilename(); // if the file is not opened, open it. if (!theBufferList().exists(file))