]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
reorder.
[lyx.git] / src / BufferView.cpp
index c75b115fadc9891fb17f33d9d021fdec965c737c..3be5cf7cf283969c8408786d61bc1f72416c5880 100644 (file)
@@ -729,7 +729,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
                        // 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;
                                }
@@ -895,10 +895,8 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool recenter)
 }
 
 
-FuncStatus BufferView::getStatus(FuncRequest const & cmd)
+bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 {
-       FuncStatus flag;
-
        Cursor & cur = d->cursor_;
 
        switch (cmd.action) {
@@ -916,6 +914,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                // 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:
@@ -944,7 +943,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                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();
@@ -983,6 +982,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
 
        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
@@ -1017,60 +1017,19 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                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: {
-               BranchList const & branchList = buffer_.params().branchlist();
-               docstring const branchName = cmd.argument();
-               flag.setEnabled(!branchName.empty()
-                               && branchList.find(branchName));
-               break;
-       }
-
        default:
                flag.setEnabled(false);
+               return false;
        }
 
-       return flag;
+       return true;
 }
 
 
@@ -1119,7 +1078,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                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
@@ -1227,9 +1186,15 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // 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");
                }
@@ -1237,23 +1202,23 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
        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;
@@ -1296,19 +1261,17 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
        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")));
@@ -1328,7 +1291,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                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);
@@ -1340,7 +1303,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_BIBTEX_DATABASE_DEL: {
-               Cursor tmpcur = d->cursor_;
+               Cursor tmpcur = cur;
                findInset(tmpcur, BIBTEX_CODE, false);
                InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
                                                BIBTEX_CODE);
@@ -1394,9 +1357,12 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // 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);
@@ -1408,6 +1374,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                processUpdateFlags(Update::SinglePar | Update::FitCursor);
                break;
        }
+
        case LFUN_NEXT_INSET_MODIFY: {
                // create the the real function we want to invoke
                FuncRequest tmpcmd = cmd;
@@ -1436,14 +1403,16 @@ bool BufferView::dispatch(FuncRequest const & 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_);
@@ -1452,7 +1421,8 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                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();
@@ -1499,14 +1469,6 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                break;
        }
 
-       case LFUN_BRANCH_ACTIVATE:
-       case LFUN_BRANCH_DEACTIVATE:
-               if (cmd.argument().empty())
-                       return false;
-               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: {
@@ -1956,6 +1918,7 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
        bool update = leftinset;
        if (!do_selection && d->cursor_.inTexted())
                update |= checkDepm(cur, d->cursor_);
+       d->cursor_.macroModeClose();
 
        d->cursor_.setCursor(cur);
        d->cursor_.boundary(cur.boundary());