]> git.lyx.org Git - lyx.git/blobdiff - src/callback.cpp
Update po directory, new Portuguese translation
[lyx.git] / src / callback.cpp
index d3337ae4d917124ddafe79b91ae290dec83c7af4..7cda91a367ae74e0a04ef1308d7faa41f81046fc 100644 (file)
@@ -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 "