]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Fix copy&paste bug.
[lyx.git] / src / BufferView.cpp
index af08fd62a52cbd59197bfad2718cee3888e0c6be..117ae94c40c5762faf5841f593b81d6f80389365 100644 (file)
@@ -50,7 +50,6 @@
 #include "TextClass.h"
 #include "TextMetrics.h"
 #include "TexRow.h"
-#include "Undo.h"
 #include "VSpace.h"
 #include "WordLangTuple.h"
 
@@ -107,8 +106,6 @@ using support::bformat;
 using support::FileFilterList;
 using support::FileName;
 using support::fileSearch;
-using support::isDirWriteable;
-using support::isFileReadable;
 using support::makeDisplayPath;
 using support::makeAbsPath;
 using support::package;
@@ -119,7 +116,7 @@ namespace {
 
 /// Return an inset of this class if it exists at the current cursor position
 template <class T>
-T * getInsetByCode(Cursor const & cur, Inset::Code code)
+T * getInsetByCode(Cursor const & cur, InsetCode code)
 {
        DocIterator it = cur;
        Inset * inset = it.nextInset();
@@ -129,10 +126,10 @@ T * getInsetByCode(Cursor const & cur, Inset::Code code)
 }
 
 
-bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content);
 
-bool findNextInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
        string const & contents)
 {
        DocIterator tmpdit = dit;
@@ -154,7 +151,7 @@ bool findNextInset(DocIterator & dit, vector<Inset_code> const & codes,
 
 
 /// Looks for next inset with one of the the given code
-bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content)
 {
        string contents;
@@ -186,14 +183,14 @@ bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
 
 
 /// Looks for next inset with the given code
-void findInset(DocIterator & dit, Inset_code code, bool same_content)
+void findInset(DocIterator & dit, InsetCode code, bool same_content)
 {
-       findInset(dit, vector<Inset_code>(1, code), same_content);
+       findInset(dit, vector<InsetCode>(1, code), same_content);
 }
 
 
 /// Moves cursor to the next inset with one of the given codes.
-void gotoInset(BufferView * bv, vector<Inset_code> const & codes,
+void gotoInset(BufferView * bv, vector<InsetCode> const & codes,
               bool same_content)
 {
        Cursor tmpcur = bv->cursor();
@@ -208,9 +205,9 @@ void gotoInset(BufferView * bv, vector<Inset_code> const & codes,
 
 
 /// Moves cursor to the next inset with given code.
-void gotoInset(BufferView * bv, Inset_code code, bool same_content)
+void gotoInset(BufferView * bv, InsetCode code, bool same_content)
 {
-       gotoInset(bv, vector<Inset_code>(1, code), same_content);
+       gotoInset(bv, vector<InsetCode>(1, code), same_content);
 }
 
 
@@ -273,7 +270,7 @@ void outline(OutlineOp mode, Cursor & cur)
                        pit_type const newpit = std::distance(bgn, dest);
                        pit_type const len = std::distance(start, finish);
                        pit_type const deletepit = pit + len;
-                       recordUndo(cur, Undo::ATOMIC, newpit, deletepit - 1);
+                       buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
                        pars.insert(dest, start, finish);
                        start = boost::next(pars.begin(), deletepit);
                        pit = newpit;
@@ -305,7 +302,7 @@ void outline(OutlineOp mode, Cursor & cur)
                        // One such was found:
                        pit_type newpit = std::distance(bgn, dest);
                        pit_type const len = std::distance(start, finish);
-                       recordUndo(cur, Undo::ATOMIC, pit, newpit - 1);
+                       buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
                        pars.insert(dest, start, finish);
                        start = boost::next(bgn, pit);
                        pit = newpit - len;
@@ -313,7 +310,7 @@ void outline(OutlineOp mode, Cursor & cur)
                        break;
                }
                case OutlineIn:
-                       recordUndo(cur);
+                       buf.undo().recordUndo(cur);
                        for (; lit != lend; ++lit) {
                                if ((*lit)->toclevel == thistoclevel + 1 &&
                                    start->layout()->labeltype == (*lit)->labeltype) {
@@ -323,7 +320,7 @@ void outline(OutlineOp mode, Cursor & cur)
                        }
                        break;
                case OutlineOut:
-                       recordUndo(cur);
+                       buf.undo().recordUndo(cur);
                        for (; lit != lend; ++lit) {
                                if ((*lit)->toclevel == thistoclevel - 1 &&
                                    start->layout()->labeltype == (*lit)->labeltype) {
@@ -853,10 +850,10 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        switch (cmd.action) {
 
        case LFUN_UNDO:
-               flag.enabled(!buffer_.undostack().empty());
+               flag.enabled(buffer_.undo().hasUndoStack());
                break;
        case LFUN_REDO:
-               flag.enabled(!buffer_.redostack().empty());
+               flag.enabled(buffer_.undo().hasRedoStack());
                break;
        case LFUN_FILE_INSERT:
        case LFUN_FILE_INSERT_PLAINTEXT_PARA:
@@ -891,7 +888,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
 
        case LFUN_LABEL_GOTO: {
                flag.enabled(!cmd.argument().empty()
-                   || getInsetByCode<InsetRef>(cur, Inset::REF_CODE));
+                   || getInsetByCode<InsetRef>(cur, REF_CODE));
                break;
        }
 
@@ -934,7 +931,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                break;
 
        case LFUN_LAYOUT_TABULAR:
-               flag.enabled(cur.innerInsetOfType(Inset::TABULAR_CODE));
+               flag.enabled(cur.innerInsetOfType(TABULAR_CODE));
                break;
 
        case LFUN_LAYOUT:
@@ -943,31 +940,31 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                break;
 
        case LFUN_INSET_SETTINGS: {
-               Inset::Code code = cur.inset().lyxCode();
+               InsetCode code = cur.inset().lyxCode();
                bool enable = false;
                switch (code) {
-                       case Inset::TABULAR_CODE:
+                       case TABULAR_CODE:
                                enable = cmd.argument() == "tabular";
                                break;
-                       case Inset::ERT_CODE:
+                       case ERT_CODE:
                                enable = cmd.argument() == "ert";
                                break;
-                       case Inset::FLOAT_CODE:
+                       case FLOAT_CODE:
                                enable = cmd.argument() == "float";
                                break;
-                       case Inset::WRAP_CODE:
+                       case WRAP_CODE:
                                enable = cmd.argument() == "wrap";
                                break;
-                       case Inset::NOTE_CODE:
+                       case NOTE_CODE:
                                enable = cmd.argument() == "note";
                                break;
-                       case Inset::BRANCH_CODE:
+                       case BRANCH_CODE:
                                enable = cmd.argument() == "branch";
                                break;
-                       case Inset::BOX_CODE:
+                       case BOX_CODE:
                                enable = cmd.argument() == "box";
                                break;
-                       case Inset::LISTINGS_CODE:
+                       case LISTINGS_CODE:
                                enable = cmd.argument() == "listings";
                                break;
                        default:
@@ -978,9 +975,9 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        }
 
        case LFUN_DIALOG_SHOW_NEW_INSET:
-               flag.enabled(cur.inset().lyxCode() != Inset::ERT_CODE &&
-                       cur.inset().lyxCode() != Inset::LISTINGS_CODE);
-               if (cur.inset().lyxCode() == Inset::CAPTION_CODE) {
+               flag.enabled(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;
@@ -1018,7 +1015,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
        case LFUN_UNDO:
                cur.message(_("Undo"));
                cur.clearSelection();
-               if (!textUndo(*this)) {
+               if (!cur.textUndo()) {
                        cur.message(_("No further undo information"));
                        updateFlags = Update::None;
                }
@@ -1027,7 +1024,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
        case LFUN_REDO:
                cur.message(_("Redo"));
                cur.clearSelection();
-               if (!textRedo(*this)) {
+               if (!cur.textRedo()) {
                        cur.message(_("No further redo information"));
                        updateFlags = Update::None;
                }
@@ -1061,7 +1058,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                if (label.empty()) {
                        InsetRef * inset =
                                getInsetByCode<InsetRef>(d->cursor_,
-                                                        Inset::REF_CODE);
+                                                        REF_CODE);
                        if (inset) {
                                label = inset->getParam("reference");
                                // persistent=false: use temp_bookmark
@@ -1128,13 +1125,13 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_NOTE_NEXT:
-               gotoInset(this, Inset::NOTE_CODE, false);
+               gotoInset(this, NOTE_CODE, false);
                break;
 
        case LFUN_REFERENCE_NEXT: {
-               vector<Inset_code> tmp;
-               tmp.push_back(Inset::LABEL_CODE);
-               tmp.push_back(Inset::REF_CODE);
+               vector<InsetCode> tmp;
+               tmp.push_back(LABEL_CODE);
+               tmp.push_back(REF_CODE);
                gotoInset(this, tmp, true);
                break;
        }
@@ -1245,9 +1242,9 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_BIBTEX_DATABASE_ADD: {
                Cursor tmpcur = d->cursor_;
-               findInset(tmpcur, Inset::BIBTEX_CODE, false);
+               findInset(tmpcur, BIBTEX_CODE, false);
                InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
-                                               Inset::BIBTEX_CODE);
+                                               BIBTEX_CODE);
                if (inset) {
                        if (inset->addDatabase(to_utf8(cmd.argument())))
                                buffer_.updateBibfilesCache();
@@ -1257,9 +1254,9 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_BIBTEX_DATABASE_DEL: {
                Cursor tmpcur = d->cursor_;
-               findInset(tmpcur, Inset::BIBTEX_CODE, false);
+               findInset(tmpcur, BIBTEX_CODE, false);
                InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
-                                               Inset::BIBTEX_CODE);
+                                               BIBTEX_CODE);
                if (inset) {
                        if (inset->delDatabase(to_utf8(cmd.argument())))
                                buffer_.updateBibfilesCache();
@@ -1346,7 +1343,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                cur.reset(buffer_.inset());
                d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
                //FIXME: what to do with cur.x_target()?
-               finishUndo();
+               cur.finishUndo();
                // The metrics are already up to date. see scroll()
                updateFlags = Update::None;
                break;
@@ -1361,7 +1358,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                // FIXME: We need to verify if the cursor stayed within an inset...
                //cur.reset(buffer_.inset());
                d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
-               finishUndo();
+               cur.finishUndo();
                while (cur.depth() > initial_depth) {
                        cur.forwardInset();
                }
@@ -1748,7 +1745,7 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
        else
                d->cursor_.clearSelection();
 
-       finishUndo();
+       d->cursor_.finishUndo();
        return update;
 }
 
@@ -1929,7 +1926,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
                string initpath = lyxrc.document_path;
                string const trypath = buffer_.filePath();
                // If directory is writeable, use this as default.
-               if (isDirWriteable(FileName(trypath)))
+               if (FileName(trypath).isDirWritable())
                        initpath = trypath;
 
                // FIXME UNICODE
@@ -1973,7 +1970,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
                ErrorList & el = buffer_.errorList("Parse");
                // Copy the inserted document error list into the current buffer one.
                el = buf.errorList("Parse");
-               recordUndo(d->cursor_);
+               buffer_.undo().recordUndo(d->cursor_);
                cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
                                             buf.params().getTextClassPtr(), el);
                res = _("Document %1$s inserted.");
@@ -2261,12 +2258,11 @@ void BufferView::insertPlaintextFile(string const & f, bool asParagraph)
 
        Cursor & cur = cursor();
        cap::replaceSelection(cur);
-       recordUndo(cur);
+       buffer_.undo().recordUndo(cur);
        if (asParagraph)
                cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
        else
                cur.innerText()->insertStringAsLines(cur, tmpstr);
 }
 
-
 } // namespace lyx