]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
* src/LyXRC.{cpp,h}:
[lyx.git] / src / BufferView.cpp
index ca7e4bc7a7764eb720531c425946f8523f650170..eee61d6b93631f6b6f9422b4d72575066e7c0b71 100644 (file)
@@ -25,6 +25,7 @@
 #include "CutAndPaste.h"
 #include "debug.h"
 #include "DispatchResult.h"
+#include "EmbeddedFiles.h"
 #include "ErrorList.h"
 #include "factory.h"
 #include "FloatList.h"
@@ -50,7 +51,6 @@
 #include "TextClass.h"
 #include "TextMetrics.h"
 #include "TexRow.h"
-#include "Undo.h"
 #include "VSpace.h"
 #include "WordLangTuple.h"
 
@@ -107,8 +107,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;
@@ -133,7 +131,7 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content);
 
 bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
-       string const & contents)
+       docstring const & contents)
 {
        DocIterator tmpdit = dit;
 
@@ -142,7 +140,7 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
                if (inset
                    && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
                    && (contents.empty() ||
-                   static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
+                   static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
                        dit = tmpdit;
                        return true;
                }
@@ -153,11 +151,11 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
 }
 
 
-/// Looks for next inset with one of the the given code
+/// Looks for next inset with one of the given codes.
 bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        bool same_content)
 {
-       string contents;
+       docstring contents;
        DocIterator tmpdit = dit;
        tmpdit.forwardInset();
        if (!tmpdit)
@@ -167,7 +165,7 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
                Inset const * inset = tmpdit.nextInset();
                if (inset
                    && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
-                       contents = static_cast<InsetCommand const *>(inset)->getContents();
+                       contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
                }
        }
 
@@ -273,7 +271,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 +303,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 +311,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 +321,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) {
@@ -423,7 +421,7 @@ BufferView::~BufferView()
        // That is to say, if a cursor is in a nested inset, it will be
        // restore to the left of the top level inset.
        LyX::ref().session().lastFilePos().save(
-               support::FileName(buffer_.fileName()),
+               support::FileName(buffer_.absFileName()),
                boost::tie(d->cursor_.bottom().pit(), d->cursor_.bottom().pos()) );
 
        delete d;
@@ -470,7 +468,7 @@ bool BufferView::fitCursor()
 {
        if (cursorStatus(d->cursor_) == CUR_INSIDE) {
                frontend::FontMetrics const & fm =
-                       theFontMetrics(d->cursor_.getFont());
+                       theFontMetrics(d->cursor_.getFont().fontInfo());
                int const asc = fm.maxAscent();
                int const des = fm.maxDescent();
                Point const p = getPos(d->cursor_, d->cursor_.boundary());
@@ -509,7 +507,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
 
        // Update macro store
        if (!(cursor().inMathed() && cursor().inMacroMode()))
-               buffer_.buildMacros();
+               buffer_.updateMacros();
 
        // Now do the first drawing step if needed. This consists on updating
        // the CoordCache in updateMetrics().
@@ -724,7 +722,7 @@ void BufferView::saveBookmark(unsigned int idx)
        // pit and pos will be updated with bottom level pit/pos
        // when lyx exits.
        LyX::ref().session().bookmarks().save(
-               FileName(buffer_.fileName()),
+               FileName(buffer_.absFileName()),
                d->cursor_.bottom().pit(),
                d->cursor_.bottom().pos(),
                d->cursor_.paragraph().id(),
@@ -853,10 +851,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:
@@ -920,6 +918,11 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                flag.setOnOff(buffer_.params().compressed);
                break;
        }
+       
+       case LFUN_BUFFER_TOGGLE_EMBEDDING: {
+               flag.setOnOff(buffer_.params().embedded);
+               break;
+       }
 
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_DOWN:
@@ -1018,7 +1021,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 +1030,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;
                }
@@ -1089,7 +1092,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                                LYXERR(Debug::INFO)
                                        << "Paragraph " << par->id()
                                        << " found in buffer `"
-                                       << b->fileName() << "'." << endl;
+                                       << b->absFileName() << "'." << endl;
 
                                if (b == &buffer_) {
                                        // Set the cursor
@@ -1097,7 +1100,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                                } else {
                                        // Switch to other buffer view and resend cmd
                                        theLyXFunc().dispatch(FuncRequest(
-                                               LFUN_BUFFER_SWITCH, b->fileName()));
+                                               LFUN_BUFFER_SWITCH, b->absFileName()));
                                        theLyXFunc().dispatch(cmd);
                                        updateFlags = Update::None;
                                }
@@ -1301,6 +1304,11 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                // turn compression on/off
                buffer_.params().compressed = !buffer_.params().compressed;
                break;
+       
+       case LFUN_BUFFER_TOGGLE_EMBEDDING:
+               // turn embedding on/off
+               buffer_.embeddedFiles().enable(!buffer_.params().embedded);
+               break;
 
        case LFUN_NEXT_INSET_TOGGLE: {
                // this is the real function we want to invoke
@@ -1346,7 +1354,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 +1369,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 +1756,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
        else
                d->cursor_.clearSelection();
 
-       finishUndo();
+       d->cursor_.finishUndo();
+       d->cursor_.setCurrentFont();
        return update;
 }
 
@@ -1929,19 +1938,18 @@ 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
-               FileDialog fileDlg(_("Select LyX document to insert"),
-                       LFUN_FILE_INSERT,
-                       make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
-                       make_pair(_("Examples|#E#e"),
-                                   from_utf8(addPath(package().system_support().absFilename(),
-                                   "examples"))));
+               FileDialog dlg(_("Select LyX document to insert"), LFUN_FILE_INSERT);
+               dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+               dlg.setButton2(_("Examples|#E#e"),
+                       from_utf8(addPath(package().system_support().absFilename(),
+                       "examples")));
 
                FileDialog::Result result =
-                       fileDlg.open(from_utf8(initpath),
+                       dlg.open(from_utf8(initpath),
                                     FileFilterList(_("LyX Documents (*.lyx)")),
                                     docstring());
 
@@ -1969,16 +1977,17 @@ void BufferView::menuInsertLyXFile(string const & filenm)
 
        docstring res;
        Buffer buf("", false);
-       if (lyx::loadLyXFile(&buf, FileName(filename))) {
+       if (buf.loadLyXFile(FileName(filename))) {
                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.");
-       } else
+       } else {
                res = _("Could not insert document %1$s");
+       }
 
        // emit message signal.
        message(bformat(res, disp_fn));
@@ -2119,14 +2128,14 @@ void BufferView::draw(frontend::Painter & pain)
 //     lyxerr << "par ascent: " << text.getPar(d->metrics_info_.p1).ascent() << endl;
        if (d->metrics_info_.y1 > 0
                && d->metrics_info_.update_strategy == FullScreenUpdate)
-               pain.fillRectangle(0, 0, width_, d->metrics_info_.y1, Color::bottomarea);
+               pain.fillRectangle(0, 0, width_, d->metrics_info_.y1, Color_bottomarea);
 
        // and possibly grey out below
 //     lyxerr << "par descent: " << text.getPar(d->metrics_info_.p1).ascent() << endl;
        if (d->metrics_info_.y2 < height_
                && d->metrics_info_.update_strategy == FullScreenUpdate)
                pain.fillRectangle(0, d->metrics_info_.y2, width_,
-                       height_ - d->metrics_info_.y2, Color::bottomarea);
+                       height_ - d->metrics_info_.y2, Color_bottomarea);
 }
 
 
@@ -2180,13 +2189,13 @@ docstring BufferView::contentsOfPlaintextFile(string const & f,
        FileName fname(f);
 
        if (fname.empty()) {
-               FileDialog fileDlg(_("Select file to insert"),
+               FileDialog dlg(_("Select file to insert"),
                                   ( asParagraph
                                     ? LFUN_FILE_INSERT_PLAINTEXT_PARA 
                                     : LFUN_FILE_INSERT_PLAINTEXT) );
 
                FileDialog::Result result =
-                       fileDlg.open(from_utf8(buffer().filePath()),
+                       dlg.open(from_utf8(buffer().filePath()),
                                     FileFilterList(), docstring());
 
                if (result.first == FileDialog::Later)
@@ -2261,12 +2270,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