// insets.
size_t const n = dit.depth();
for (size_t i = 0; i < n; ++i)
- if (dit[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
+ if (!dit[i].inset().editable()) {
dit.resize(i);
break;
}
}
-FuncStatus BufferView::getStatus(FuncRequest const & cmd)
+bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
{
- FuncStatus flag;
-
Cursor & cur = d->cursor_;
switch (cmd.action) {
// FIXME: Actually, these LFUNS should be moved to Text
flag.setEnabled(cur.inTexted());
break;
+
case LFUN_FONT_STATE:
case LFUN_LABEL_INSERT:
case LFUN_INFO_INSERT:
case LFUN_NOTES_MUTATE:
case LFUN_ALL_INSETS_TOGGLE:
case LFUN_STATISTICS:
+ case LFUN_BRANCH_ADD_INSERT:
flag.setEnabled(true);
break;
flag.setEnabled(! this->cursor().inRegexped());
break;
- case LFUN_COPY_LABEL_AS_REF: {
+ case LFUN_LABEL_COPY_AS_REF: {
// if there is an inset at cursor, see whether it
// handles the lfun
Inset * inset = cur.nextInset();
case LFUN_CHANGES_MERGE:
case LFUN_CHANGE_NEXT:
+ case LFUN_CHANGE_PREVIOUS:
case LFUN_ALL_CHANGES_ACCEPT:
case LFUN_ALL_CHANGES_REJECT:
// TODO: context-sensitive enabling of LFUNs
flag.setEnabled(cur.inset().allowParagraphCustomization(cur.idx()));
break;
- case LFUN_INSET_SETTINGS: {
- InsetCode code = cur.inset().lyxCode();
- if (cmd.getArg(0) == insetName(code)) {
- flag.setEnabled(true);
- break;
- }
- bool enable = false;
- InsetCode next_code = cur.nextInset()
- ? cur.nextInset()->lyxCode() : NO_CODE;
- //FIXME: remove these special cases:
- switch (next_code) {
- case TABULAR_CODE:
- case ERT_CODE:
- case FLOAT_CODE:
- case WRAP_CODE:
- case NOTE_CODE:
- case BRANCH_CODE:
- case PHANTOM_CODE:
- case BOX_CODE:
- case LISTINGS_CODE:
- enable = (cmd.argument().empty() ||
- cmd.getArg(0) == insetName(next_code));
- break;
- default:
- break;
- }
- flag.setEnabled(enable);
- break;
- }
-
case LFUN_DIALOG_SHOW_NEW_INSET:
+ if (cur.inset().lyxCode() == CAPTION_CODE)
+ return cur.inset().getStatus(cur, cmd, flag);
flag.setEnabled(cur.inset().lyxCode() != ERT_CODE &&
cur.inset().lyxCode() != LISTINGS_CODE);
- if (cur.inset().lyxCode() == CAPTION_CODE) {
- FuncStatus flag;
- if (cur.inset().getStatus(cur, cmd, flag))
- return flag;
- }
- break;
-
- case LFUN_BRANCH_ACTIVATE:
- case LFUN_BRANCH_DEACTIVATE: {
- bool enable = false;
- docstring const branchName = cmd.argument();
- if (!branchName.empty())
- enable = buffer_.params().branchlist().find(branchName);
- flag.setEnabled(enable);
break;
- }
default:
flag.setEnabled(false);
+ return false;
}
- return flag;
+ return true;
}
docstring label = cmd.argument();
if (label.empty()) {
InsetRef * inset =
- getInsetByCode<InsetRef>(d->cursor_, REF_CODE);
+ getInsetByCode<InsetRef>(cur, REF_CODE);
if (inset) {
label = inset->getParam("reference");
// persistent=false: use temp_bookmark
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
processUpdateFlags(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:
+ processUpdateFlags(Update::Force | Update::FitCursor);
+ break;
case LFUN_CHANGES_MERGE:
- if (findNextChange(this)) {
+ if (findNextChange(this) || findPreviousChange(this)) {
processUpdateFlags(Update::Force | Update::FitCursor);
showDialog("changes");
}
case LFUN_ALL_CHANGES_ACCEPT:
// select complete document
- d->cursor_.reset(buffer_.inset());
- d->cursor_.selHandle(true);
- buffer_.text().cursorBottom(d->cursor_);
+ cur.reset(buffer_.inset());
+ cur.selHandle(true);
+ buffer_.text().cursorBottom(cur);
// accept everything in a single step to support atomic undo
- buffer_.text().acceptOrRejectChanges(d->cursor_, Text::ACCEPT);
+ buffer_.text().acceptOrRejectChanges(cur, Text::ACCEPT);
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
processUpdateFlags(Update::Force | Update::FitCursor);
break;
case LFUN_ALL_CHANGES_REJECT:
// select complete document
- d->cursor_.reset(buffer_.inset());
- d->cursor_.selHandle(true);
- buffer_.text().cursorBottom(d->cursor_);
+ cur.reset(buffer_.inset());
+ cur.selHandle(true);
+ buffer_.text().cursorBottom(cur);
// 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(d->cursor_, Text::REJECT);
+ buffer_.text().acceptOrRejectChanges(cur, Text::REJECT);
// FIXME: Move this LFUN to Buffer so that we don't have to do this:
processUpdateFlags(Update::Force | Update::FitCursor);
break;
case LFUN_MARK_OFF:
cur.clearSelection();
- cur.resetAnchor();
cur.message(from_utf8(N_("Mark off")));
break;
case LFUN_MARK_ON:
cur.clearSelection();
cur.setMark(true);
- cur.resetAnchor();
cur.message(from_utf8(N_("Mark on")));
break;
case LFUN_MARK_TOGGLE:
- cur.clearSelection();
+ cur.setSelection(false);
if (cur.mark()) {
cur.setMark(false);
cur.message(from_utf8(N_("Mark removed")));
break;
case LFUN_BIBTEX_DATABASE_ADD: {
- Cursor tmpcur = d->cursor_;
+ Cursor tmpcur = cur;
findInset(tmpcur, BIBTEX_CODE, false);
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
BIBTEX_CODE);
}
case LFUN_BIBTEX_DATABASE_DEL: {
- Cursor tmpcur = d->cursor_;
+ Cursor tmpcur = cur;
findInset(tmpcur, BIBTEX_CODE, false);
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
BIBTEX_CODE);
// turn compression on/off
buffer_.params().compressed = !buffer_.params().compressed;
break;
- case LFUN_COPY_LABEL_AS_REF: {
+
+ case LFUN_LABEL_COPY_AS_REF: {
// if there is an inset at cursor, try to copy it
- Inset * inset = cur.nextInset();
+ Inset * inset = &cur.inset();
+ if (!inset || !inset->asInsetMath())
+ inset = cur.nextInset();
if (inset) {
FuncRequest tmpcmd = cmd;
inset->dispatch(cur, tmpcmd);
processUpdateFlags(Update::SinglePar | Update::FitCursor);
break;
}
+
case LFUN_NEXT_INSET_MODIFY: {
// create the the real function we want to invoke
FuncRequest tmpcmd = cmd;
case LFUN_SCREEN_UP:
case LFUN_SCREEN_DOWN: {
Point p = getPos(cur, cur.boundary());
- if (p.y_ < 0 || p.y_ > height_) {
+ // This code has been commented out to enable to scroll down a
+ // document, even if there are large insets in it (see bug #5465).
+ /*if (p.y_ < 0 || p.y_ > height_) {
// The cursor is off-screen so recenter before proceeding.
showCursor();
p = getPos(cur, cur.boundary());
- }
+ }*/
int const scrolled = scroll(cmd.action == LFUN_SCREEN_UP
- ? - height_ : height_);
- if (cmd.action == LFUN_SCREEN_UP && scrolled > - height_)
+ ? -height_ : height_);
+ if (cmd.action == LFUN_SCREEN_UP && scrolled > -height_)
p = Point(0, 0);
if (cmd.action == LFUN_SCREEN_DOWN && scrolled < height_)
p = Point(width_, height_);
cur.reset(buffer_.inset());
updateMetrics();
buffer_.changed();
- d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
+ d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_,
+ true, cmd.action == LFUN_SCREEN_UP);
//FIXME: what to do with cur.x_target()?
bool update = in_texted && cur.bv().checkDepm(cur, old);
cur.finishUndo();
break;
}
- case LFUN_BRANCH_ACTIVATE:
- case LFUN_BRANCH_DEACTIVATE:
- buffer_.dispatch(cmd);
- processUpdateFlags(Update::Force);
- break;
-
// This could be rewriten using some command like forall <insetname> <command>
// once the insets refactoring is done.
case LFUN_NOTES_MUTATE: {
break;
}
+ case LFUN_BRANCH_ADD_INSERT: {
+ docstring branch_name = from_utf8(cmd.getArg(0));
+ if (branch_name.empty())
+ if (!Alert::askForText(branch_name, _("Branch name")) ||
+ branch_name.empty())
+ break;
+
+ DispatchResult drtmp;
+ buffer_.dispatch(FuncRequest(LFUN_BRANCH_ADD, branch_name), drtmp);
+ if (drtmp.error()) {
+ Alert::warning(_("Branch already exists"), drtmp.message());
+ break;
+ }
+ BranchList & branch_list = buffer_.params().branchlist();
+ Branch const * branch = branch_list.find(branch_name);
+ string const x11hexname = X11hexname(branch->color());
+ docstring const str = branch_name + ' ' + from_ascii(x11hexname);
+ lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
+ lyx::dispatch(FuncRequest(LFUN_BRANCH_INSERT, branch_name));
+ break;
+ }
+
+
default:
return false;
}
bool update = leftinset;
if (!do_selection && d->cursor_.inTexted())
update |= checkDepm(cur, d->cursor_);
+ d->cursor_.macroModeClose();
+ d->cursor_.resetAnchor();
d->cursor_.setCursor(cur);
d->cursor_.boundary(cur.boundary());
if (do_selection)
}
+void BufferView::cursorPosAndHeight(Point & p, int & h) const
+{
+ Cursor const & cur = cursor();
+ Font const font = cur.getFont();
+ frontend::FontMetrics const & fm = theFontMetrics(font);
+ int const asc = fm.maxAscent();
+ int const des = fm.maxDescent();
+ h = asc + des;
+ p = getPos(cur, cur.boundary());
+ p.y_ -= asc;
+}
+
+
+bool BufferView::cursorInView(Point const & p, int h) const
+{
+ Cursor const & cur = cursor();
+ // does the cursor touch the screen ?
+ if (p.y_ + h < 0 || p.y_ >= workHeight() || !paragraphVisible(cur))
+ return false;
+ return true;
+}
+
+
void BufferView::draw(frontend::Painter & pain)
{
if (height_ == 0 || width_ == 0)