#include "insets/InsetCommand.h" // ChangeRefs
#include "insets/InsetExternal.h"
#include "insets/InsetGraphics.h"
+#include "insets/InsetNote.h"
#include "insets/InsetRef.h"
#include "insets/InsetText.h"
-#include "insets/InsetNote.h"
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
-#include "graphics/Previews.h"
-
#include "support/convert.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/Package.h"
#include "support/types.h"
return 0;
}
-
-bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
- bool same_content);
-
+/// Note that comparing contents can only be used for InsetCommand
bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
docstring const & contents)
{
while (tmpdit) {
Inset const * inset = tmpdit.nextInset();
- if (inset
- && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
- && (contents.empty() ||
- static_cast<InsetCommand const *>(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();
}
/// 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<InsetCode> const & codes,
bool same_content)
{
if (!tmpdit)
return false;
- if (same_content) {
- Inset const * inset = tmpdit.nextInset();
- if (inset
- && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
- contents = static_cast<InsetCommand const *>(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();
}
}
Private(BufferView & bv): wh_(0), cursor_(bv),
anchor_pit_(0), anchor_ypos_(0),
inlineCompletionUniqueChars_(0),
- last_inset_(0), mouse_position_cache_(),
+ last_inset_(0), clickable_inset_(false),
+ mouse_position_cache_(),
bookmark_edit_position_(-1), gui_(0)
{}
/** 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_;
/// position of the mouse at the time of the last mouse move
/// This is used to update the hovering status of inset in
d->cursor_.resetAnchor();
d->cursor_.setCurrentFont();
- if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
- thePreviews().generateBufferPreviews(buffer_);
+ buffer_.updatePreviews();
}
// FIXME: Care about the d->cursor_ flags to redraw if needed
Cursor old = d->cursor_;
mouseSetCursor(cur);
- bool badcursor = notifyCursorLeavesOrEnters(old, d->cursor_);
+ // the DEPM call in mouseSetCursor() might have destroyed the
+ // paragraph the cursor is in.
+ bool badcursor = old.fixIfBroken();
+ badcursor |= notifyCursorLeavesOrEnters(old, d->cursor_);
if (badcursor)
d->cursor_.fixIfBroken();
}
case LFUN_FONT_STATE:
case LFUN_LABEL_INSERT:
- case LFUN_LINE_INSERT:
case LFUN_INFO_INSERT:
case LFUN_PARAGRAPH_GOTO:
case LFUN_NOTE_NEXT:
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: {
// We are most certainly here because of a change in the document
// It is then better to make sure that all dialogs are in sync with
// current document settings.
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
break;
}
buffer_.params().clearLayoutModules();
buffer_.params().makeDocumentClass();
updateDocumentClass(oldClass);
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force);
dr.forceBufferUpdate();
break;
}
buffer_.params().addLayoutModule(argument);
buffer_.params().makeDocumentClass();
updateDocumentClass(oldClass);
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force);
dr.forceBufferUpdate();
break;
}
buffer_.params().setBaseClass(argument);
buffer_.params().makeDocumentClass();
updateDocumentClass(oldDocClass);
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force);
dr.forceBufferUpdate();
break;
}
buffer_.params().setBaseClass(bc);
buffer_.params().makeDocumentClass();
updateDocumentClass(oldClass);
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force);
dr.forceBufferUpdate();
break;
}
if (!cur.textUndo())
dr.setMessage(_("No further undo information"));
else
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
break;
if (!cur.textRedo())
dr.setMessage(_("No further redo information"));
else
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
break;
saveBookmark(0);
}
}
- if (!label.empty())
+ if (!label.empty()) {
gotoLabel(label);
+ // at the moment, this is redundant, since gotoLabel will
+ // eventually call LFUN_PARAGRAPH_GOTO, but it seems best
+ // to have it here.
+ dr.screenUpdate(Update::Force | Update::FitCursor);
+ }
break;
}
// Set the cursor
dit.pos() = pos;
setCursor(dit);
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
} else {
// Switch to other buffer view and resend cmd
lyx::dispatch(FuncRequest(
case LFUN_CHANGE_NEXT:
findNextChange(this);
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
break;
case LFUN_CHANGE_PREVIOUS:
findPreviousChange(this);
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
break;
case LFUN_CHANGES_MERGE:
if (findNextChange(this) || findPreviousChange(this)) {
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
showDialog("changes");
}
buffer_.text().cursorBottom(cur);
// accept everything in a single step to support atomic undo
buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
+ cur.resetAnchor();
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
break;
// reject everything in a single step to support atomic undo
// Note: reject does not work recursively; the user may have to repeat the operation
buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
+ cur.resetAnchor();
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
break;
bool const fw = act == LFUN_WORD_FIND_FORWARD;
docstring const data =
find2string(searched_string, true, false, fw);
- find(this, FuncRequest(LFUN_WORD_FIND, data));
+ bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
+ if (found)
+ dr.screenUpdate(Update::Force | Update::FitCursor);
break;
}
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
break;
}
- if (find(this, req))
- showCursor();
+ if (lyxfind(this, req))
+ dr.screenUpdate(Update::Force | Update::FitCursor);
else
message(_("String not found!"));
d->search_request_cache_ = req;
DocIterator end = cur.selectionEnd();
if (beg.pit() == end.pit()) {
for (pos_type p = beg.pos() ; p < end.pos() ; ++p) {
- if (!cur.inMathed()
- && cur.paragraph().isDeleted(p))
+ if (!cur.inMathed() && cur.paragraph().isDeleted(p)) {
has_deleted = true;
+ break;
+ }
}
}
}
- replace(this, cmd, has_deleted);
- dr.forceBufferUpdate();
+ if (lyxreplace(this, cmd, has_deleted)) {
+ dr.forceBufferUpdate();
+ dr.screenUpdate(Update::Force | Update::FitCursor);
+ }
break;
}
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();
- else
+ dispatched = true;
+ } else {
cur.undispatched();
+ dispatched = false;
+ }
break;
}
d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
true, act == LFUN_SCREEN_UP);
+ cur.resetAnchor();
//FIXME: what to do with cur.x_target()?
bool update = in_texted && cur.bv().checkDepm(cur, old);
cur.finishUndo();
if (update) {
- dr.update(Update::Force | Update::FitCursor);
+ dr.screenUpdate(Update::Force | Update::FitCursor);
dr.forceBufferUpdate();
}
break;
y = getPos(cur).y_;
cur.finishUndo();
- dr.update(Update::SinglePar | Update::FitCursor);
+ dr.screenUpdate(Update::SinglePar | Update::FitCursor);
break;
}
y = getPos(cur).y_;
cur.finishUndo();
- dr.update(Update::SinglePar | Update::FitCursor);
+ dr.screenUpdate(Update::SinglePar | Update::FitCursor);
break;
}
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();
cur.endUndoGroup();
cur = savecur;
cur.fixIfBroken();
- dr.update(Update::Force);
+ dr.screenUpdate(Update::Force);
dr.forceBufferUpdate();
if (iterations >= max_iter) {
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;
cur.recordUndo();
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
inset->dispatch(cur, fr);
- dr.update(Update::SinglePar | Update::FitCursor);
- dr.forceBufferUpdate();
+ dr.screenUpdate(cur.result().screenUpdate());
+ if (cur.result().needBufferUpdate())
+ dr.forceBufferUpdate();
break;
}
default:
- dispatched = false;
+ // OK, so try the Buffer itself...
+ buffer_.dispatch(cmd, dr);
+ dispatched = dr.dispatched();
break;
}
buffer_.undo().endUndoGroup();
dr.dispatched(dispatched);
- return;
}
void BufferView::updateHoveredInset() const
{
// Get inset under mouse, if there is one.
- Inset const * covering_inset = getCoveringInset(buffer_.text(),
- d->mouse_position_cache_.x_, d->mouse_position_cache_.y_);
+ int const x = d->mouse_position_cache_.x_;
+ int const y = d->mouse_position_cache_.y_;
+ Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+
+ d->clickable_inset_ = covering_inset && covering_inset->clickable(x, y);
+
if (covering_inset == d->last_inset_)
// Same inset, no need to do anything...
return;
d->last_inset_ = 0;
}
- // const_cast because of setMouseHover().
- Inset * inset = const_cast<Inset *>(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) {
// Do we have a selection?
theSelection().haveSelection(cursor().selection());
+ if (cur.needBufferUpdate()) {
+ cur.clearBufferUpdate();
+ buffer().updateBuffer();
+ }
+
// If the command has been dispatched,
- if (cur.result().dispatched() || cur.result().update())
- processUpdateFlags(cur.result().update());
+ if (cur.result().dispatched() || cur.result().screenUpdate())
+ processUpdateFlags(cur.result().screenUpdate());
}
void BufferView::setCursorFromRow(int row)
{
- int tmpid = -1;
- int tmppos = -1;
+ int tmpid;
+ int tmppos;
+ pit_type newpit = 0;
+ pos_type newpos = 0;
buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
+ bool posvalid = (tmpid != -1);
+ if (posvalid) {
+ // we need to make sure that the row and position
+ // we got back are valid, because the buffer may well
+ // have changed since we last generated the LaTeX.
+ DocIterator const dit = buffer_.getParFromID(tmpid);
+ if (dit == doc_iterator_end(&buffer_))
+ posvalid = false;
+ else {
+ newpit = dit.pit();
+ // now have to check pos.
+ newpos = tmppos;
+ Paragraph const & par = buffer_.text().getPar(newpit);
+ if (newpos > par.size()) {
+ LYXERR0("Requested position no longer valid.");
+ newpos = par.size() - 1;
+ }
+ }
+ }
+ if (!posvalid) {
+ frontend::Alert::error(_("Inverse Search Failed"),
+ _("Invalid position requested by inverse search.\n"
+ "You need to update the viewed document."));
+ return;
+ }
d->cursor_.reset();
- if (tmpid == -1)
- buffer_.text().setCursor(d->cursor_, 0, 0);
- else
- buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos);
+ buffer_.text().setCursor(d->cursor_, newpit, newpos);
+ d->cursor_.setSelection(false);
+ d->cursor_.resetAnchor();
recenter();
}
void BufferView::gotoLabel(docstring const & label)
{
- std::vector<Buffer const *> bufs = buffer().allRelatives();
- std::vector<Buffer const *>::iterator it = bufs.begin();
+ ListOfBuffers bufs = buffer().allRelatives();
+ ListOfBuffers::iterator it = bufs.begin();
for (; it != bufs.end(); ++it) {
Buffer const * buf = *it;
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(
d->cursor_.setCursor(dit);
d->cursor_.setSelection(false);
+ // FIXME
+ // It seems on general grounds as if this is probably needed, but
+ // it is not yet clear.
+ // See bug #7394 and r38388.
+ // d->cursor.resetAnchor();
}
d->cursor_.macroModeClose();
// Has the cursor just left the inset?
- bool leftinset = (&d->cursor_.inset() != &cur.inset());
+ bool const leftinset = (&d->cursor_.inset() != &cur.inset());
if (leftinset)
d->cursor_.fixIfBroken();
// FIXME: shift-mouse selection doesn't work well across insets.
- bool do_selection = select && &d->cursor_.normalAnchor().inset() == &cur.inset();
+ bool const do_selection =
+ select && &d->cursor_.normalAnchor().inset() == &cur.inset();
// do the dEPM magic if needed
// FIXME: (1) move this to InsetText::notifyCursorLeaves?
} else
d->cursor_.setSelection(d->cursor_, length);
}
- // Ensure a redraw happens in any case because the new selection could
- // possibly be on the same screen as the previous selection.
- processUpdateFlags(Update::Force | Update::FitCursor);
+}
+
+
+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;
}
message(bformat(_("Inserting document %1$s..."), disp_fn));
docstring res;
- Buffer buf("", false);
- if (buf.loadLyXFile(filename)) {
+ 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");
buffer_.changed(true);
// emit message signal.
message(bformat(res, disp_fn));
- buffer_.errors("Parse");
}
}
+void BufferView::resetInlineCompletionPos()
+{
+ d->inlineCompletionPos_ = DocIterator();
+}
+
+
bool samePar(DocIterator const & a, DocIterator const & b)
{
if (a.empty() && b.empty())
// set update flags
if (changed) {
- if (singlePar && !(cur.result().update() & Update::Force))
- cur.screenUpdateFlags(cur.result().update() | Update::SinglePar);
+ if (singlePar && !(cur.result().screenUpdate() & Update::Force))
+ cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
else
- cur.screenUpdateFlags(cur.result().update() | Update::Force);
+ cur.screenUpdateFlags(cur.result().screenUpdate() | Update::Force);
}
}
+
+bool BufferView::clickableInset() const
+{
+ return d->clickable_inset_;
+}
+
} // namespace lyx