]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
next ones
[lyx.git] / src / BufferView.cpp
index a7a38b723c30197734a1830b04f1a0a407c67299..180c2b1aa768476a5a483e836d483eff9eb4bfc3 100644 (file)
@@ -20,7 +20,6 @@
 #include "buffer_funcs.h"
 #include "BufferList.h"
 #include "BufferParams.h"
-#include "callback.h" // added for Dispatch functions
 #include "CoordCache.h"
 #include "CutAndPaste.h"
 #include "debug.h"
 #include "support/filetools.h"
 #include "support/Package.h"
 #include "support/types.h"
+#include "support/fs_extras.h"
 
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 #include <boost/next_prior.hpp>
+#include <boost/filesystem/operations.hpp>
 
+#include <cerrno>
+#include <fstream>
 #include <functional>
 #include <vector>
 
 using std::distance;
 using std::endl;
+using std::ifstream;
 using std::istringstream;
+using std::istream_iterator;
 using std::make_pair;
 using std::min;
 using std::max;
@@ -90,6 +95,7 @@ using std::mem_fun_ref;
 using std::string;
 using std::vector;
 
+namespace fs = boost::filesystem;
 
 namespace lyx {
 
@@ -101,6 +107,7 @@ using support::fileSearch;
 using support::isDirWriteable;
 using support::isFileReadable;
 using support::makeDisplayPath;
+using support::makeAbsPath;
 using support::package;
 
 namespace Alert = frontend::Alert;
@@ -894,12 +901,12 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_FILE_INSERT_PLAINTEXT_PARA:
                // FIXME UNICODE
-               insertPlaintextFile(this, to_utf8(cmd.argument()), true);
+               insertPlaintextFile(to_utf8(cmd.argument()), true);
                break;
 
        case LFUN_FILE_INSERT_PLAINTEXT:
                // FIXME UNICODE
-               insertPlaintextFile(this, to_utf8(cmd.argument()), false);
+               insertPlaintextFile(to_utf8(cmd.argument()), false);
                break;
 
        case LFUN_FONT_STATE:
@@ -1308,7 +1315,7 @@ Inset const * BufferView::getCoveringInset(Text const & text, int x, int y)
 }
 
 
-bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
+void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
 {
        //lyxerr << BOOST_CURRENT_FUNCTION << "[ cmd0 " << cmd0 << "]" << endl;
 
@@ -1333,7 +1340,7 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
                        getCoveringInset(buffer_.text(), cmd.x, cmd.y);
                if (covering_inset == last_inset_)
                        // Same inset, no need to do anything...
-                       return false;
+                       return;
 
                bool need_redraw = false;
                // const_cast because of setMouseHover().
@@ -1346,7 +1353,7 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
                        need_redraw |= inset->setMouseHover(true);
                last_inset_ = inset;
                if (!need_redraw)
-                       return false;
+                       return;
 
                // if last metrics update was in singlepar mode, WorkArea::redraw() will
                // not expose the button for redraw. We adjust here the metrics dimension
@@ -1368,7 +1375,8 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
 
                // This event (moving without mouse click) is not passed further.
                // This should be changed if it is further utilized.
-               return true;
+               buffer_.changed();
+               return;
        }
 
        // Build temporary cursor.
@@ -1381,9 +1389,8 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
        // via the temp cursor. If the inset wishes to change the real
        // cursor it has to do so explicitly by using
        //  cur.bv().cursor() = cur;  (or similar)
-       if (inset) {
+       if (inset)
                inset->dispatch(cur, cmd);
-       }
 
        // Now dispatch to the temporary cursor. If the real cursor should
        // be modified, the inset's dispatch has to do so explicitly.
@@ -1393,11 +1400,14 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
        //Do we have a selection?
        theSelection().haveSelection(cursor().selection());
 
-       // Redraw if requested and necessary.
-       if (cur.result().dispatched() && cur.result().update())
-               return update(cur.result().update());
-
-       return false;
+       // If the command has been dispatched,
+       if (cur.result().dispatched()
+               // an update is asked,
+               && cur.result().update()
+               // and redraw is needed,
+               && update(cur.result().update()))
+               // then trigger a redraw.
+               buffer_.changed();
 }
 
 
@@ -2019,7 +2029,8 @@ void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui)
 }
 
 
-static docstring contentsOfPlaintextFile(BufferView * bv, string const & f,
+// FIXME: Move this out of BufferView again
+docstring BufferView::contentsOfPlaintextFile(string const & f,
        bool asParagraph)
 {
        FileName fname(f);
@@ -2031,7 +2042,7 @@ static docstring contentsOfPlaintextFile(BufferView * bv, string const & f,
                                     : LFUN_FILE_INSERT_PLAINTEXT) );
 
                FileDialog::Result result =
-                       fileDlg.open(from_utf8(bv->buffer().filePath()),
+                       fileDlg.open(from_utf8(buffer().filePath()),
                                     FileFilterList(), docstring());
 
                if (result.first == FileDialog::Later)
@@ -2064,7 +2075,7 @@ static docstring contentsOfPlaintextFile(BufferView * bv, string const & f,
                return docstring();
        }
 
-       ifs.unsetf(ios::skipws);
+       ifs.unsetf(std::ios::skipws);
        istream_iterator<char> ii(ifs);
        istream_iterator<char> end;
 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
@@ -2096,11 +2107,10 @@ static docstring contentsOfPlaintextFile(BufferView * bv, string const & f,
        return normalize_c(file_content);
 }
 
-// Insert plain text file (if filename is empty, prompt for one)
+
 void BufferView::insertPlaintextFile(string const & f, bool asParagraph)
 {
-       docstring const tmpstr =
-         contentsOfPlaintextFile(this, f, asParagraph);
+       docstring const tmpstr = contentsOfPlaintextFile(f, asParagraph);
 
        if (tmpstr.empty())
                return;