X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfunc.C;h=ff526d5968dab7ef08868c7e5c70bf392af54565;hb=cd4033aef3a3f1efdb5a676b8bab3d367f53a830;hp=a631c42d356c095f792f983eb5dff2f30f06a154;hpb=4c1fb15143fb203b763f3dcdeee55567bbad8b1f;p=lyx.git diff --git a/src/lyxfunc.C b/src/lyxfunc.C index a631c42d35..ff526d5968 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -232,7 +232,7 @@ void LyXFunc::handleKeyFunc(kb_action action) c = 0; lyx_view_->view()->getIntl().getTransManager().deadkey( - c, get_accent(action).accent, view()->getLyXText(), view()->cursor()); + c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor()); // Need to clear, in case the minibuffer calls these // actions keyseq->clear(); @@ -242,6 +242,42 @@ void LyXFunc::handleKeyFunc(kb_action action) } +void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) +{ + BOOST_ASSERT(lyx_view_); + if (!LyX::ref().session().bookmarks().isValid(idx)) + return; + 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)) { + if (openFile) + dispatch(FuncRequest(LFUN_FILE_OPEN, file)); + else + return; + } + // open may fail, so we need to test it again + if (theBufferList().exists(file)) { + // if the current buffer is not that one, switch to it. + if (lyx_view_->buffer()->fileName() != file) { + if (switchToBuffer) + dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file)); + else + return; + } + // moveToPosition use par_id, and par_pit and return new par_id. + pit_type new_pit; + int new_id; + boost::tie(new_pit, new_id) = view()->moveToPosition(bm.par_pit, bm.par_id, bm.par_pos); + // if par_id or pit has been changed, reset par_pit and par_id + // see http://bugzilla.lyx.org/show_bug.cgi?id=3092 + if (bm.par_pit != new_pit || bm.par_id != new_id) + const_cast(bm).setPos(new_pit, new_id); + } +} + + void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state) { lyxerr[Debug::KEY] << "KeySym is " << keysym->getSymbolName() << endl; @@ -260,7 +296,9 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state) //Encoding const * encoding = view()->cursor().getEncoding(); //encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : ""); - size_t encoded_last_key = keysym->getUCSEncoded(); + // FIXME: encoded_last_key shadows the member variable of the same + // name. Is that intended? + char_type encoded_last_key = keysym->getUCSEncoded(); // Do a one-deep top-level lookup for // cancel and meta-fake keys. RVDK_PATCH_5 @@ -350,24 +388,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const //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(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 @@ -557,6 +577,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_DIALOG_SHOW_NEW_INSET: enable = cur.inset().lyxCode() != InsetBase::ERT_CODE; + if (cur.inset().lyxCode() == InsetBase::CAPTION_CODE) { + FuncStatus flag; + if (cur.inset().getStatus(cur, cmd, flag)) + return flag; + } break; case LFUN_DIALOG_UPDATE: { @@ -578,6 +603,22 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } + case LFUN_BOOKMARK_GOTO: { + const unsigned int num = convert(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 +682,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_BUFFER_PREVIOUS: case LFUN_WINDOW_NEW: case LFUN_WINDOW_CLOSE: + case LFUN_LYX_QUIT: // these are handled in our dispatch() break; @@ -804,7 +846,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (view()->buffer()) // cancel any selection dispatch(FuncRequest(LFUN_MARK_OFF)); - setMessage(_("Cancel")); + setMessage(from_ascii(N_("Cancel"))); break; case LFUN_META_PREFIX: @@ -843,8 +885,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) lyx_view_->message(str); menuWrite(lyx_view_->buffer()); lyx_view_->message(str + _(" done.")); - } else - writeAs(lyx_view_->buffer()); + } else { + writeAs(lyx_view_->buffer()); + } updateFlags = Update::None; break; @@ -863,7 +906,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) text, 0, 1, _("&Revert"), _("&Cancel")); if (ret == 0) - view()->reload(); + reloadBuffer(); break; } @@ -1017,9 +1060,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } else { // case 1: print to a file + FileName const filename(makeAbsPath(target_name, path)); + if (fs::exists(filename.toFilesystemEncoding())) { + docstring text = bformat( + _("The file %1$s already exists.\n\n" + "Do you want to over-write that file?"), + makeDisplayPath(filename.absFilename())); + if (Alert::prompt(_("Over-write file?"), + text, 0, 1, _("&Over-write"), _("&Cancel")) != 0) + break; + } command += lyxrc.print_to_file - + quoteName(makeAbsPath(target_name, - path).toFilesystemEncoding()) + + quoteName(filename.toFilesystemEncoding()) + ' ' + quoteName(dviname); res = one.startscript(Systemcall::DontWait, @@ -1038,6 +1090,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) 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; @@ -1063,7 +1116,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) BOOST_ASSERT(lyx_view_); string const arg = argument; if (arg.empty()) { - setErrorMessage(_("Missing argument")); + setErrorMessage(from_ascii(N_("Missing argument"))); break; } FileName const fname = i18nLibFileSearch("doc", arg, "lyx"); @@ -1085,8 +1138,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; if (!lyx_view_->buffer()->lyxvc().inUse()) { lyx_view_->buffer()->lyxvc().registrer(); - view()->reload(); + reloadBuffer(); } + updateFlags = Update::Force; break; case LFUN_VC_CHECK_IN: @@ -1096,7 +1150,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (lyx_view_->buffer()->lyxvc().inUse() && !lyx_view_->buffer()->isReadonly()) { lyx_view_->buffer()->lyxvc().checkIn(); - view()->reload(); + reloadBuffer(); } break; @@ -1107,20 +1161,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (lyx_view_->buffer()->lyxvc().inUse() && lyx_view_->buffer()->isReadonly()) { lyx_view_->buffer()->lyxvc().checkOut(); - view()->reload(); + reloadBuffer(); } break; case LFUN_VC_REVERT: BOOST_ASSERT(lyx_view_ && lyx_view_->buffer()); lyx_view_->buffer()->lyxvc().revert(); - view()->reload(); + reloadBuffer(); break; case LFUN_VC_UNDO_LAST: BOOST_ASSERT(lyx_view_ && lyx_view_->buffer()); lyx_view_->buffer()->lyxvc().undoLast(); - view()->reload(); + reloadBuffer(); break; // --- buffers ---------------------------------------- @@ -1197,8 +1251,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->setCursorFromRow(row); - view()->center(); - // see BufferView::center() + updateFlags = Update::FitCursor; break; } @@ -1346,9 +1399,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) BOOST_ASSERT(lyx_view_); FileName const filename = makeAbsPath(argument, lyx_view_->buffer()->filePath()); - // FIXME Should use bformat - setMessage(_("Opening child document ") + - makeDisplayPath(filename.absFilename()) + "..."); + setMessage(bformat(_("Opening child document %1$s..."), + makeDisplayPath(filename.absFilename()))); view()->saveBookmark(false); string const parentfilename = lyx_view_->buffer()->fileName(); if (theBufferList().exists(filename.absFilename())) @@ -1425,16 +1477,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // handle the screen font changes. lyxrc.set_font_norm_type(); theFontLoader().update(); - // All visible buffers will need resize - view()->resize(); + /// FIXME: only the current view will be updated. the Gui + /// class is able to furnish the list of views. + updateFlags = Update::Force; break; case LFUN_SET_COLOR: { string lyx_name; string const x11_name = split(argument, lyx_name, ' '); if (lyx_name.empty() || x11_name.empty()) { - setErrorMessage(_("Syntax: set-color " - " ")); + setErrorMessage(from_ascii(N_( + "Syntax: set-color " + " "))); break; } @@ -1559,11 +1613,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } if (defaults.writeFile(FileName(defaults.fileName()))) - // FIXME Should use bformat - setMessage(_("Document defaults saved in ") - + makeDisplayPath(fname)); + setMessage(bformat(_("Document defaults saved in %1$s"), + makeDisplayPath(fname))); else - setErrorMessage(_("Unable to save document defaults")); + setErrorMessage(from_ascii(N_("Unable to save document defaults"))); break; } @@ -1654,6 +1707,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } actOnUpdatedPrefs(lyxrc_orig, lyxrc); + + /// We force the redraw in any case because there might be + /// some screen font changes. + /// FIXME: only the current view will be updated. the Gui + /// class is able to furnish the list of views. + updateFlags = Update::Force; break; } @@ -1664,31 +1723,19 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_WINDOW_CLOSE: BOOST_ASSERT(lyx_view_); BOOST_ASSERT(theApp()); + // update bookmark pit of the current buffer before window close + for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) + gotoBookmark(i+1, false, false); // ask the user for saving changes or cancel quit if (!theBufferList().quitWriteAll()) break; lyx_view_->close(); return; - case LFUN_BOOKMARK_GOTO: { - BOOST_ASSERT(lyx_view_); - unsigned int idx = convert(to_utf8(cmd.argument())); - 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)) - dispatch(FuncRequest(LFUN_FILE_OPEN, file)); - // open may fail, so we need to test it again - if (theBufferList().exists(file)) { - // if the current buffer is not that one, switch to it. - if (lyx_view_->buffer()->fileName() != file) - dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file)); - // BOOST_ASSERT(lyx_view_->buffer()->fileName() != file); - view()->moveToPosition(bm.par_id, bm.par_pos); - } + case LFUN_BOOKMARK_GOTO: + // go to bookmark, open unopened file and switch to buffer if necessary + gotoBookmark(convert(to_utf8(cmd.argument())), true, true); break; - } case LFUN_BOOKMARK_CLEAR: LyX::ref().session().bookmarks().clear(); @@ -1703,8 +1750,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->cursor().dispatch(cmd); updateFlags = view()->cursor().result().update(); if (!view()->cursor().result().dispatched()) - if (view()->dispatch(cmd)) - updateFlags = Update::Force | Update::FitCursor; + updateFlags = view()->dispatch(cmd); break; } } @@ -1725,8 +1771,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // if we executed a mutating lfun, mark the buffer as dirty if (flag.enabled() - && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) - && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)) + && !lyxaction.funcHasFlag(action, LyXAction::NoBuffer) + && !lyxaction.funcHasFlag(action, LyXAction::ReadOnly)) view()->buffer()->markDirty(); if (view()->cursor().inTexted()) { @@ -1737,7 +1783,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (!quitting) { lyx_view_->updateMenubar(); lyx_view_->updateToolbars(); - sendDispatchMessage(getMessage(), cmd); + // Some messages may already be translated, so we cannot use _() + sendDispatchMessage(translateIfPossible(getMessage()), cmd); } } @@ -1999,6 +2046,9 @@ void LyXFunc::closeBuffer() // save current cursor position LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()), boost::tie(view()->cursor().pit(), view()->cursor().pos()) ); + // goto bookmark to update bookmark pit. + for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) + gotoBookmark(i+1, false, false); if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) { if (theBufferList().empty()) { // need this otherwise SEGV may occur while @@ -2012,6 +2062,13 @@ void LyXFunc::closeBuffer() } +void LyXFunc::reloadBuffer() +{ + FileName filename(lyx_view_->buffer()->fileName()); + closeBuffer(); + lyx_view_->loadLyXFile(filename); +} + // Each "lyx_view_" should have it's own message method. lyxview and // the minibuffer would use the minibuffer, but lyxserver would // send an ERROR signal to its client. Alejandro 970603 @@ -2075,8 +2132,8 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) switch (tag) { case LyXRC::RC_ACCEPT_COMPOUND: case LyXRC::RC_ALT_LANG: - case LyXRC::RC_ASCIIROFF_COMMAND: - case LyXRC::RC_ASCII_LINELEN: + case LyXRC::RC_PLAINTEXT_ROFF_COMMAND: + case LyXRC::RC_PLAINTEXT_LINELEN: case LyXRC::RC_AUTOREGIONDELETE: case LyXRC::RC_AUTORESET_OPTIONS: case LyXRC::RC_AUTOSAVE: