]> git.lyx.org Git - lyx.git/blobdiff - src/callback.cpp
Streamlining CollapseStatus stuff
[lyx.git] / src / callback.cpp
index d3337ae4d917124ddafe79b91ae290dec83c7af4..d0ee831216d7674a38ebb0bcf2d3b13f47a3e1c1 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
@@ -122,12 +122,26 @@ bool menuWrite(Buffer * buffer)
 
 
 
+/** Write a buffer to a new file name and rename the buffer
+    according to the new file name.
+
+    This function is e.g. used by menu callbacks and
+    LFUN_BUFFER_WRITE_AS.
+
+    If 'newname' is empty (the default), the user is asked via a
+    dialog for the buffer's new name and location.
+
+    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)
 {
        string fname = buffer->fileName();
        string const oldname = fname;
 
-       if (newname.empty()) {
+       if (newname.empty()) {  /// No argument? Ask user through dialog
 
                // FIXME UNICODE
                FileDialog fileDlg(_("Choose a filename to save document as"),
@@ -159,11 +173,11 @@ bool writeAs(Buffer * buffer, string const & newname)
                fname = makeAbsPath(fname).absFilename();
                if (!isLyXFilename(fname))
                        fname += ".lyx";
-       } else
-               fname = newname;
 
-       FileName const filename(fname);
-       if (fs::exists(filename.toFilesystemEncoding())) {
+       } else 
+               fname = makeAbsPath(newname, onlyPath(oldname)).absFilename();
+
+       if (fs::exists(FileName(fname).toFilesystemEncoding())) {
                docstring const file = makeDisplayPath(fname, 30);
                docstring text = bformat(_("The document %1$s already "
                                           "exists.\n\nDo you want to "
@@ -310,7 +324,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;
@@ -321,7 +335,7 @@ void newFile(BufferView * bv, string const & filename)
 
        Buffer * const b = newFile(name, tmpname);
        if (b)
-               bv->setBuffer(b);
+               lv.setBuffer(b);
 }