X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferView.cpp;h=fc7c7bb80828f9a977d39c12ef906120a7c6a56c;hb=7c63b4f2603f2bccb00a9266fed08a14dcc0fb9c;hp=4c57dfd479683af405ca5c8d00ae274a0289c758;hpb=07924ac300f68eaf4825951af6a6ac3c14d6edd6;p=lyx.git diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 4c57dfd479..fc7c7bb808 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -107,10 +107,7 @@ T * getInsetByCode(Cursor const & cur, InsetCode code) return 0; } - -bool findInset(DocIterator & dit, vector const & codes, - bool same_content); - +/// Note that comparing contents can only be used for InsetCommand bool findNextInset(DocIterator & dit, vector const & codes, docstring const & contents) { @@ -118,15 +115,17 @@ bool findNextInset(DocIterator & dit, vector const & codes, while (tmpdit) { Inset const * inset = tmpdit.nextInset(); - if (inset - && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() - && (contents.empty() || - //FIXME: This static_cast seems very dangerous. Does this - // mean that if contents is not empty, we must only be - // looking for InsetCommand's ?? - static_cast(inset)->getFirstNonOptParam() == contents)) { - dit = tmpdit; - return true; + if (inset) { + bool const valid_code = std::find(codes.begin(), codes.end(), + inset->lyxCode()) != codes.end(); + InsetCommand const * ic = inset->asInsetCommand(); + bool const same_or_no_contents = contents.empty() + || (ic && (ic->getFirstNonOptParam() == contents)); + + if (valid_code && same_or_no_contents) { + dit = tmpdit; + return true; + } } tmpdit.forwardInset(); } @@ -136,6 +135,7 @@ bool findNextInset(DocIterator & dit, vector const & codes, /// Looks for next inset with one of the given codes. +/// Note that same_content can only be used for InsetCommand bool findInset(DocIterator & dit, vector const & codes, bool same_content) { @@ -145,14 +145,14 @@ bool findInset(DocIterator & dit, vector const & codes, if (!tmpdit) return false; - if (same_content) { - Inset const * inset = tmpdit.nextInset(); - if (inset - && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) { - //FIXME: This static_cast seems very dangerous. Does this - // mean that if contents is not empty, we must only be - // looking for InsetCommand's ?? - contents = static_cast(inset)->getFirstNonOptParam(); + Inset const * inset = tmpdit.nextInset(); + if (same_content && inset) { + InsetCommand const * ic = inset->asInsetCommand(); + if (ic) { + bool const valid_code = std::find(codes.begin(), codes.end(), + ic->lyxCode()) != codes.end(); + if (valid_code) + contents = ic->getFirstNonOptParam(); } } @@ -269,7 +269,7 @@ struct BufferView::Private /** kept to send setMouseHover(false). * Not owned, so don't delete. */ - Inset * last_inset_; + Inset const * last_inset_; /// are we hovering something that we can click bool clickable_inset_; @@ -308,8 +308,7 @@ BufferView::BufferView(Buffer & buf) d->cursor_.resetAnchor(); d->cursor_.setCurrentFont(); - if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) - thePreviews().generateBufferPreviews(buffer_); + buffer_.updatePreviews(); } @@ -1126,7 +1125,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) if (cur.inset().lyxCode() == CAPTION_CODE) return cur.inset().getStatus(cur, cmd, flag); // FIXME we should consider passthru paragraphs too. - flag.setEnabled(!cur.inset().getLayout().isPassThru()); + flag.setEnabled(!(cur.inTexted() && cur.paragraph().isPassThru())); break; case LFUN_CITATION_INSERT: { @@ -1540,8 +1539,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) FindAndReplaceOptions opt; istringstream iss(to_utf8(cmd.argument())); iss >> opt; - if (findAdv(this, opt)) + if (findAdv(this, opt)) { dr.screenUpdate(Update::Force | Update::FitCursor); + cur.dispatched(); + dispatched = true; + } else { + cur.undispatched(); + dispatched = false; + } break; } @@ -1746,7 +1751,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) Inset * ins = cur.nextInset(); if (!ins) break; - docstring insname = ins->name(); + docstring insname = ins->layoutName(); while (!insname.empty()) { if (insname == name || name == from_utf8("*")) { cur.recordUndo(); @@ -1846,7 +1851,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) icp["key"] = from_utf8(arg); if (!opt1.empty()) icp["before"] = from_utf8(opt1); - string icstr = InsetCommand::params2string("citation", icp); + string icstr = InsetCommand::params2string(icp); FuncRequest fr(LFUN_INSET_INSERT, icstr); lyx::dispatch(fr); break; @@ -1874,13 +1879,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } default: - dispatched = false; + // OK, so try the Buffer itself... + buffer_.dispatch(cmd, dr); + dispatched = dr.dispatched(); break; } buffer_.undo().endUndoGroup(); dr.dispatched(dispatched); - return; } @@ -1985,14 +1991,12 @@ void BufferView::updateHoveredInset() const d->last_inset_ = 0; } - // const_cast because of setMouseHover(). - Inset * inset = const_cast(covering_inset); - if (inset && inset->setMouseHover(this, true)) { + if (covering_inset && covering_inset->setMouseHover(this, true)) { need_redraw = true; // Only the insets that accept the hover state, do // clear the last_inset_, so only set the last_inset_ // member if the hovered setting is accepted. - d->last_inset_ = inset; + d->last_inset_ = covering_inset; } if (need_redraw) { @@ -2239,6 +2243,7 @@ TextMetrics const & BufferView::textMetrics(Text const * t) const TextMetrics & BufferView::textMetrics(Text const * t) { + LASSERT(t, /**/); TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t); if (tmc_it == d->text_metrics_.end()) { tmc_it = d->text_metrics_.insert( @@ -2358,6 +2363,42 @@ void BufferView::putSelectionAt(DocIterator const & cur, } +bool BufferView::selectIfEmpty(DocIterator & cur) +{ + if (!cur.paragraph().empty()) + return false; + + pit_type const beg_pit = cur.pit(); + if (beg_pit > 0) { + // The paragraph associated to this item isn't + // the first one, so it can be selected + cur.backwardPos(); + } else { + // We have to resort to select the space between the + // end of this item and the begin of the next one + cur.forwardPos(); + } + if (cur.empty()) { + // If it is the only item in the document, + // nothing can be selected + return false; + } + pit_type const end_pit = cur.pit(); + pos_type const end_pos = cur.pos(); + d->cursor_.clearSelection(); + d->cursor_.reset(); + d->cursor_.setCursor(cur); + d->cursor_.pit() = beg_pit; + d->cursor_.pos() = 0; + d->cursor_.setSelection(false); + d->cursor_.resetAnchor(); + d->cursor_.pit() = end_pit; + d->cursor_.pos() = end_pos; + d->cursor_.setSelection(); + return true; +} + + Cursor & BufferView::cursor() { return d->cursor_; @@ -2512,8 +2553,8 @@ void BufferView::insertLyXFile(FileName const & fname) message(bformat(_("Inserting document %1$s..."), disp_fn)); docstring res; - Buffer buf("", false); - if (buf.loadLyXFile(filename) == Buffer::ReadSuccess) { + Buffer buf(filename.absFileName(), false); + if (buf.loadLyXFile() == Buffer::ReadSuccess) { ErrorList & el = buffer_.errorList("Parse"); // Copy the inserted document error list into the current buffer one. el = buf.errorList("Parse"); @@ -2528,7 +2569,6 @@ void BufferView::insertLyXFile(FileName const & fname) buffer_.changed(true); // emit message signal. message(bformat(res, disp_fn)); - buffer_.errors("Parse"); } @@ -2855,6 +2895,12 @@ DocIterator const & BufferView::inlineCompletionPos() const } +void BufferView::resetInlineCompletionPos() +{ + d->inlineCompletionPos_ = DocIterator(); +} + + bool samePar(DocIterator const & a, DocIterator const & b) { if (a.empty() && b.empty())