X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferView.cpp;h=daa05a60d939b033bea992e36c88eabd920a3eb7;hb=ef04549d8d0337573d5d856929a108c3132f93b7;hp=31c95cf764e0803ebe061c6e840bb37c6226e35e;hpb=aafd52f44167d5510be1ddcb974daa9dae486933;p=lyx.git diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 31c95cf764..daa05a60d9 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -54,6 +54,7 @@ #include "WordLangTuple.h" #include "insets/InsetBibtex.h" +#include "insets/InsetCitation.h" #include "insets/InsetCommand.h" // ChangeRefs #include "insets/InsetExternal.h" #include "insets/InsetGraphics.h" @@ -875,7 +876,7 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool recenter) if (tm.contains(bot_pit)) { ParagraphMetrics const & pm = tm.parMetrics(bot_pit); - LASSERT(!pm.rows().empty(), /**/); + LBUFERR(!pm.rows().empty()); // FIXME: smooth scrolling doesn't work in mathed. CursorSlice const & cs = dit.innerTextSlice(); int offset = coordOffset(dit).y_; @@ -1185,22 +1186,6 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; } - // FIXME We do not really want this here, but at present we need to - // handle their dispatch here, for reasons explained there, so we'll - // handle this here, too, for consistency. - case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: - case LFUN_BRANCH_MASTER_ACTIVATE: - case LFUN_BRANCH_MASTER_DEACTIVATE: { - bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE - || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE); - BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist() - : buffer().params().branchlist(); - docstring const branchName = cmd.argument(); - flag.setEnabled(!branchName.empty() && branchList.find(branchName)); - break; - } - default: return false; } @@ -1274,7 +1259,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_LAYOUT_MODULE_ADD: { BufferParams const & params = buffer_.params(); - if (!params.moduleCanBeAdded(argument)) { + if (!params.layoutModuleCanBeAdded(argument)) { LYXERR0("Module `" << argument << "' cannot be added due to failed requirements or " "conflicts with installed modules."); @@ -1544,7 +1529,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) if (lyxfind(this, req)) dr.screenUpdate(Update::Force | Update::FitCursor); else - message(_("String not found!")); + message(_("String not found.")); d->search_request_cache_ = req; break; } @@ -1808,7 +1793,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) cur.forwardInset(); cur.beginUndoGroup(); while(cur && iterations < max_iter) { - Inset * ins = cur.nextInset(); + Inset * const ins = cur.nextInset(); if (!ins) break; docstring insname = ins->layoutName(); @@ -1824,7 +1809,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; insname = insname.substr(0, i); } - cur.forwardInset(); + // if we did not delete the inset, skip it + if (!cur.nextInset() || cur.nextInset() == ins) + cur.forwardInset(); } cur.endUndoGroup(); cur = savecur; @@ -1907,6 +1894,23 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) arg = token(argument, '|', 0); opt1 = token(argument, '|', 1); } + + // if our cursor is directly in front of or behind a citation inset, + // we will instead add the new key to it. + Inset * inset = cur.nextInset(); + if (!inset || inset->lyxCode() != CITE_CODE) + inset = cur.prevInset(); + if (inset && inset->lyxCode() == CITE_CODE) { + InsetCitation * icite = static_cast(inset); + if (icite->addKey(arg)) { + dr.forceBufferUpdate(); + dr.screenUpdate(Update::FitCursor | Update::SinglePar); + if (!opt1.empty()) + LYXERR0("Discarding optional argument to citation-insert."); + } + dispatched = true; + break; + } InsetCommandParams icp(CITE_CODE); icp["key"] = from_utf8(arg); if (!opt1.empty()) @@ -1968,48 +1972,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; } - // FIXME We do not really want this here, but it has to be at present - // because we need a cursor for the recordUndoFullDocument call. What - // we would really like is a recordUndoBufferParams call that did not - // need a cursor, but we do not have that yet. - // So, if this does get fixed, this code can be moved back to Buffer.cpp, - // and the corresponding code in getStatus() should be moved back, too. - case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: - case LFUN_BRANCH_MASTER_ACTIVATE: - case LFUN_BRANCH_MASTER_DEACTIVATE: { - bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE - || cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE); - Buffer * buf = master ? const_cast(buffer().masterBuffer()) - : &buffer(); - - docstring const branch_name = cmd.argument(); - // the case without a branch name is handled elsewhere - if (branch_name.empty()) { - dispatched = false; - break; - } - Branch * branch = buf->params().branchlist().find(branch_name); - if (!branch) { - LYXERR0("Branch " << branch_name << " does not exist."); - dr.setError(true); - docstring const msg = - bformat(_("Branch \"%1$s\" does not exist."), branch_name); - dr.setMessage(msg); - break; - } - bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE - || cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE); - if (branch->isSelected() != activate) { - branch->setSelected(activate); - cur.recordUndoFullDocument(); - dr.setError(false); - dr.screenUpdate(Update::Force); - dr.forceBufferUpdate(); - } - break; - } - default: // OK, so try the Buffer itself... buffer_.dispatch(cmd, dr); @@ -2149,7 +2111,7 @@ void BufferView::clearLastInset(Inset * inset) const { if (d->last_inset_ != inset) { LYXERR0("Wrong last_inset!"); - LASSERT(false, /**/); + LATTEST(false); } d->last_inset_ = 0; } @@ -2381,7 +2343,7 @@ TextMetrics const & BufferView::textMetrics(Text const * t) const TextMetrics & BufferView::textMetrics(Text const * t) { - LASSERT(t, /**/); + LBUFERR(t); TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t); if (tmc_it == d->text_metrics_.end()) { tmc_it = d->text_metrics_.insert( @@ -2447,7 +2409,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old) bool BufferView::mouseSetCursor(Cursor & cur, bool select) { - LASSERT(&cur.bv() == this, /**/); + LASSERT(&cur.bv() == this, return false); if (!select) // this event will clear selection so we save selection for @@ -2688,7 +2650,7 @@ void BufferView::updateMetrics() void BufferView::insertLyXFile(FileName const & fname) { - LASSERT(d->cursor_.inTexted(), /**/); + LASSERT(d->cursor_.inTexted(), return); // Get absolute path of file and add ".lyx" // to the filename if necessary @@ -2771,7 +2733,8 @@ Point BufferView::coordOffset(DocIterator const & dit) const CursorSlice const & sl = dit[0]; TextMetrics const & tm = textMetrics(sl.text()); ParagraphMetrics const & pm = tm.parMetrics(sl.pit()); - LASSERT(!pm.rows().empty(), /**/); + + LBUFERR(!pm.rows().empty()); y -= pm.rows()[0].ascent(); #if 1 // FIXME: document this mess