]> git.lyx.org Git - lyx.git/blobdiff - src/callback.cpp
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.git] / src / callback.cpp
index d730e99746ece4729d9cd6ad4e97fc2dc5feb55a..2a41494be6f48791f17427a676d0799f278fc0ef 100644 (file)
@@ -66,7 +66,7 @@ using std::ios;
 using std::istream_iterator;
 
 using boost::shared_ptr;
-
+namespace fs = boost::filesystem;
 
 namespace lyx {
 
@@ -87,9 +87,9 @@ using support::split;
 using support::Systemcall;
 using support::tempName;
 using support::unlink;
+using frontend::LyXView;
 
 namespace Alert = frontend::Alert;
-namespace fs = boost::filesystem;
 
 // this should be static, but I need it in Buffer.cpp
 bool quitting; // flag, that we are quitting the program
@@ -131,32 +131,9 @@ bool menuWrite(Buffer * buffer)
     If 'newname' is empty (the default), the user is asked via a
     dialog for the buffer's new name and location.
 
-    If 'newname' is not empty, FileName::makeAbsPath() will indirectly
-    produce the following behaviour:
-
-    * If 'newname' has an absolute path, use that.
-
-    * If 'newname' has a relative path (or no path) and the buffer has
-      a path, that path is used as the base for 'newname'. Typically
-      this means that 'M-x buffer-write-as newname.lyx' will write to
-      the same directory as the original file.
-
-    * Otherwise use CWD as the base directory for 'newname'.
-      This behavour is arguably a bug, perhaps a system depedenant
-      "document directory" shoul be used instead. Note that CWD
-      isn't actually used according to a simple test on Linux.
-      Instead, it's based on '~', contrar to the documentation of
-      makeAbsPath(). Don't know what to do. *shrug*
-
-    Note: No checks are done on the extension etc of 'newname' when
-    it's non-empty. This may arguably also be a bug.
-
-    Note: The code may not code check that 'newname' is a valid for
-    the relevant file system?
-
-    Note: In Linux, it doesn't work with e.g. '~/file.lyx'. If it's
-    done from e.g. a buffer '/tmp/buf.lyx', it instead tries to write
-    to '/tmp/~/file.lyx'.
+    If 'newname' is non-empty and has an absolute path, that is used.
+    Otherwise the base directory of the buffer is used as the base
+    for any relative path in 'newname'.
 */
 
 bool writeAs(Buffer * buffer, string const & newname)
@@ -218,10 +195,12 @@ bool writeAs(Buffer * buffer, string const & newname)
        buffer->markDirty();
        bool unnamed = buffer->isUnnamed();
        buffer->setUnnamed(false);
+       buffer->saveCheckSum(fname);
 
        if (!menuWrite(buffer)) {
                buffer->setFileName(oldname);
                buffer->setUnnamed(unnamed);
+               buffer->saveCheckSum(oldname);
                return false;
        }
 
@@ -276,7 +255,7 @@ int AutoSaveBuffer::generateChild()
 
                FileName const tmp_ret(tempName(FileName(), "lyxauto"));
                if (!tmp_ret.empty()) {
-                       bv_.buffer()->writeFile(tmp_ret);
+                       bv_.buffer().writeFile(tmp_ret);
                        // assume successful write of tmp_ret
                        if (!rename(tmp_ret, fname_)) {
                                failed = true;
@@ -292,12 +271,11 @@ int AutoSaveBuffer::generateChild()
 
                if (failed) {
                        // failed to write/rename tmp_ret so try writing direct
-                       if (!bv_.buffer()->writeFile(fname_)) {
+                       if (!bv_.buffer().writeFile(fname_)) {
                                // It is dangerous to do this in the child,
                                // but safe in the parent, so...
                                if (pid == -1) // emit message signal.
-                                       bv_.buffer()
-                                         ->message(_("Autosave failed!"));
+                                       bv_.buffer().message(_("Autosave failed!"));
                        }
                }
                if (pid == 0) { // we are the child so...
@@ -314,29 +292,26 @@ void autoSave(BufferView * bv)
        // should probably be moved into BufferList (Lgb)
        // Perfect target for a thread...
 {
-       if (!bv->buffer())
-               return;
-
-       if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
+       if (bv->buffer().isBakClean() || bv->buffer().isReadonly()) {
                // We don't save now, but we'll try again later
-               bv->buffer()->resetAutosaveTimers();
+               bv->buffer().resetAutosaveTimers();
                return;
        }
 
        // emit message signal.
-       bv->buffer()->message(_("Autosaving current document..."));
+       bv->buffer().message(_("Autosaving current document..."));
 
        // create autosave filename
-       string fname = bv->buffer()->filePath();
+       string fname = bv->buffer().filePath();
        fname += '#';
-       fname += onlyFilename(bv->buffer()->fileName());
+       fname += onlyFilename(bv->buffer().fileName());
        fname += '#';
 
        AutoSaveBuffer autosave(*bv, FileName(fname));
        autosave.start();
 
-       bv->buffer()->markBakClean();
-       bv->buffer()->resetAutosaveTimers();
+       bv->buffer().markBakClean();
+       bv->buffer().resetAutosaveTimers();
 }
 
 
@@ -347,7 +322,7 @@ void autoSave(BufferView * bv)
 // create new file with template
 // SERVERCMD !
 //
-void newFile(BufferView * bv, string const & filename)
+void newFile(LyXView & lv, string const & filename)
 {
        // Split argument by :
        string name;
@@ -358,16 +333,13 @@ void newFile(BufferView * bv, string const & filename)
 
        Buffer * const b = newFile(name, tmpname);
        if (b)
-               bv->setBuffer(b);
+               lv.setBuffer(b);
 }
 
 
 // Insert plain text file (if filename is empty, prompt for one)
 void insertPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
 {
-       if (!bv->buffer())
-               return;
-
        docstring const tmpstr =
          getContentsOfPlaintextFile(bv, f, asParagraph);
 
@@ -396,7 +368,7 @@ docstring const getContentsOfPlaintextFile(BufferView * bv, string const & f,
                                     : LFUN_FILE_INSERT_PLAINTEXT) );
 
                FileDialog::Result result =
-                       fileDlg.open(from_utf8(bv->buffer()->filePath()),
+                       fileDlg.open(from_utf8(bv->buffer().filePath()),
                                     FileFilterList(), docstring());
 
                if (result.first == FileDialog::Later)