mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
fix for open of non-existent file, writeFile() change
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4832 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d91ffd8d78
commit
b14e9baa57
@ -1,3 +1,14 @@
|
|||||||
|
2002-08-01 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
|
* buffer.h:
|
||||||
|
* buffer.C (writeFile): don't output alerts, caller
|
||||||
|
handles this
|
||||||
|
|
||||||
|
* bufferlist.C:
|
||||||
|
* lyx_cb.C: from above
|
||||||
|
|
||||||
|
* lyxfunc.C: allow to open non-existent files
|
||||||
|
|
||||||
2002-07-31 John Levon <levon@movementarian.org>
|
2002-07-31 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
* lyxserver.C: don't let incidental errors get
|
* lyxserver.C: don't let incidental errors get
|
||||||
|
31
src/buffer.C
31
src/buffer.C
@ -1812,7 +1812,7 @@ bool Buffer::save() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeFile(fileName(), false)) {
|
if (writeFile(fileName())) {
|
||||||
markLyxClean();
|
markLyxClean();
|
||||||
removeAutosaveFile(fileName());
|
removeAutosaveFile(fileName());
|
||||||
} else {
|
} else {
|
||||||
@ -1826,46 +1826,19 @@ bool Buffer::save() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns false if unsuccesful
|
bool Buffer::writeFile(string const & fname) const
|
||||||
bool Buffer::writeFile(string const & fname, bool flag) const
|
|
||||||
{
|
{
|
||||||
// if flag is false writeFile will not create any GUI
|
|
||||||
// warnings, only cerr.
|
|
||||||
// Needed for autosave in background or panic save (Matthias 120496)
|
|
||||||
|
|
||||||
if (read_only && (fname == fileName())) {
|
if (read_only && (fname == fileName())) {
|
||||||
// Here we should come with a question if we should
|
|
||||||
// perform the write anyway.
|
|
||||||
if (flag)
|
|
||||||
lyxerr << _("Error! Document is read-only: ")
|
|
||||||
<< fname << endl;
|
|
||||||
else
|
|
||||||
Alert::alert(_("Error! Document is read-only: "),
|
|
||||||
fname);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo finfo(fname);
|
FileInfo finfo(fname);
|
||||||
if (finfo.exist() && !finfo.writable()) {
|
if (finfo.exist() && !finfo.writable()) {
|
||||||
// Here we should come with a question if we should
|
|
||||||
// try to do the save anyway. (i.e. do a chmod first)
|
|
||||||
if (flag)
|
|
||||||
lyxerr << _("Error! Cannot write file: ")
|
|
||||||
<< fname << endl;
|
|
||||||
else
|
|
||||||
Alert::err_alert(_("Error! Cannot write file: "),
|
|
||||||
fname);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ofstream ofs(fname.c_str());
|
ofstream ofs(fname.c_str());
|
||||||
if (!ofs) {
|
if (!ofs) {
|
||||||
if (flag)
|
|
||||||
lyxerr << _("Error! Cannot open file: ")
|
|
||||||
<< fname << endl;
|
|
||||||
else
|
|
||||||
Alert::err_alert(_("Error! Cannot open file: "),
|
|
||||||
fname);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public:
|
|||||||
bool save() const;
|
bool save() const;
|
||||||
|
|
||||||
/// Write file. Returns \c false if unsuccesful.
|
/// Write file. Returns \c false if unsuccesful.
|
||||||
bool writeFile(string const &, bool) const;
|
bool writeFile(string const &) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
void writeFileAscii(string const & , int);
|
void writeFileAscii(string const & , int);
|
||||||
|
@ -315,7 +315,7 @@ void BufferList::emergencyWrite(Buffer * buf)
|
|||||||
string s = buf->fileName();
|
string s = buf->fileName();
|
||||||
s += ".emergency";
|
s += ".emergency";
|
||||||
lyxerr << " " << s << endl;
|
lyxerr << " " << s << endl;
|
||||||
if (buf->writeFile(s, true)) {
|
if (buf->writeFile(s)) {
|
||||||
buf->markLyxClean();
|
buf->markLyxClean();
|
||||||
lyxerr << _(" Save seems successful. Phew.") << endl;
|
lyxerr << _(" Save seems successful. Phew.") << endl;
|
||||||
return;
|
return;
|
||||||
@ -328,7 +328,7 @@ void BufferList::emergencyWrite(Buffer * buf)
|
|||||||
string s = AddName(GetEnvPath("HOME"), buf->fileName());
|
string s = AddName(GetEnvPath("HOME"), buf->fileName());
|
||||||
s += ".emergency";
|
s += ".emergency";
|
||||||
lyxerr << " " << s << endl;
|
lyxerr << " " << s << endl;
|
||||||
if (buf->writeFile(s, true)) {
|
if (buf->writeFile(s)) {
|
||||||
buf->markLyxClean();
|
buf->markLyxClean();
|
||||||
lyxerr << _(" Save seems successful. Phew.") << endl;
|
lyxerr << _(" Save seems successful. Phew.") << endl;
|
||||||
return;
|
return;
|
||||||
@ -342,7 +342,7 @@ void BufferList::emergencyWrite(Buffer * buf)
|
|||||||
s = AddName(MakeAbsPath("/tmp/"), buf->fileName());
|
s = AddName(MakeAbsPath("/tmp/"), buf->fileName());
|
||||||
s += ".emergency";
|
s += ".emergency";
|
||||||
lyxerr << " " << s << endl;
|
lyxerr << " " << s << endl;
|
||||||
if (buf->writeFile(s, true)) {
|
if (buf->writeFile(s)) {
|
||||||
buf->markLyxClean();
|
buf->markLyxClean();
|
||||||
lyxerr << _(" Save seems successful. Phew.") << endl;
|
lyxerr << _(" Save seems successful. Phew.") << endl;
|
||||||
return;
|
return;
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
2002-08-01 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
|
* ControlSendto.C: writeFile() change
|
||||||
|
|
||||||
2002-08-01 John Levon <levon@movementarian.org>
|
2002-08-01 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
* ControlSpellchecker.h:
|
* ControlSpellchecker.h:
|
||||||
|
@ -122,7 +122,7 @@ void ControlSendto::apply()
|
|||||||
if (!lv_.buffer()->tmppath.empty())
|
if (!lv_.buffer()->tmppath.empty())
|
||||||
filename = AddName(lv_.buffer()->tmppath, filename);
|
filename = AddName(lv_.buffer()->tmppath, filename);
|
||||||
|
|
||||||
lv_.buffer()->writeFile(filename, true);
|
lv_.buffer()->writeFile(filename);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Exporter::Export(lv_.buffer(), format_->name(), true, filename);
|
Exporter::Export(lv_.buffer(), format_->name(), true, filename);
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
2002-08-01 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
|
* FormDocument.C: writeFile() change
|
||||||
|
|
||||||
2002-08-01 John Levon <levon@movementarian.org>
|
2002-08-01 John Levon <levon@movementarian.org>
|
||||||
|
|
||||||
* FormPreferences.h:
|
* FormPreferences.h:
|
||||||
|
@ -407,7 +407,7 @@ bool saveParamsAsDefault(BufferParams const ¶ms)
|
|||||||
// add an empty paragraph. Is this enough?
|
// add an empty paragraph. Is this enough?
|
||||||
defaults.paragraph = new Paragraph;
|
defaults.paragraph = new Paragraph;
|
||||||
|
|
||||||
return defaults.writeFile(defaults.fileName(), false);
|
return defaults.writeFile(defaults.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
@ -278,7 +278,7 @@ void AutoSave(BufferView * bv)
|
|||||||
|
|
||||||
string const tmp_ret = lyx::tempName(string(), "lyxauto");
|
string const tmp_ret = lyx::tempName(string(), "lyxauto");
|
||||||
if (!tmp_ret.empty()) {
|
if (!tmp_ret.empty()) {
|
||||||
bv->buffer()->writeFile(tmp_ret, 1);
|
bv->buffer()->writeFile(tmp_ret);
|
||||||
// assume successful write of tmp_ret
|
// assume successful write of tmp_ret
|
||||||
if (!lyx::rename(tmp_ret, fname)) {
|
if (!lyx::rename(tmp_ret, fname)) {
|
||||||
failed = true;
|
failed = true;
|
||||||
@ -293,7 +293,7 @@ void AutoSave(BufferView * bv)
|
|||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
// failed to write/rename tmp_ret so try writing direct
|
// failed to write/rename tmp_ret so try writing direct
|
||||||
if (!bv->buffer()->writeFile(fname, 1)) {
|
if (!bv->buffer()->writeFile(fname)) {
|
||||||
// It is dangerous to do this in the child,
|
// It is dangerous to do this in the child,
|
||||||
// but safe in the parent, so...
|
// but safe in the parent, so...
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
|
@ -1687,16 +1687,26 @@ void LyXFunc::open(string const & fname)
|
|||||||
// get absolute path of file and add ".lyx" to the filename if
|
// get absolute path of file and add ".lyx" to the filename if
|
||||||
// necessary
|
// necessary
|
||||||
string const fullpath = FileSearch(string(), filename, "lyx");
|
string const fullpath = FileSearch(string(), filename, "lyx");
|
||||||
if (fullpath.empty()) {
|
if (!fullpath.empty()) {
|
||||||
Alert::alert(_("Error"), _("Could not find file"), filename);
|
filename = fullpath;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = fullpath;
|
|
||||||
|
|
||||||
// loads document
|
|
||||||
string const disp_fn(MakeDisplayPath(filename));
|
string const disp_fn(MakeDisplayPath(filename));
|
||||||
|
|
||||||
|
// if the file doesn't exist, let the user create one
|
||||||
|
FileInfo const f(filename, true);
|
||||||
|
if (!f.exist()) {
|
||||||
|
if (!Alert::askQuestion(_("No such file"), disp_fn,
|
||||||
|
_("Start a new document with this filename ?"))) {
|
||||||
|
owner->message(_("Canceled"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// the user specifically chose this name. Believe them.
|
||||||
|
Buffer * buffer = bufferlist.newFile(filename, "", true);
|
||||||
|
owner->view()->buffer(buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ostringstream str;
|
ostringstream str;
|
||||||
str << _("Opening document") << ' ' << disp_fn << "...";
|
str << _("Opening document") << ' ' << disp_fn << "...";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user