using std::istream_iterator;
using boost::shared_ptr;
-
+namespace fs = boost::filesystem;
namespace lyx {
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
+/** 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"),
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 "
// 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;
Buffer * const b = newFile(name, tmpname);
if (b)
- bv->setBuffer(b);
+ lv.setBuffer(b);
}