Now "New..." and "New from template..." does not request a filename anymore!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@926 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2000-07-26 13:43:16 +00:00
parent d5cd17770d
commit fcaee30687
7 changed files with 153 additions and 61 deletions

View File

@ -1,3 +1,18 @@
2000-07-26 Juergen Vigna <jug@sad.it>
* src/buffer.h: added functions setUnnamed(bool) and isUnnamed().
* src/lyx_cb.C (MenuWriteAs): Changed to react right for unnamed docs
and return a bool if it did actual save the file.
(AutoSave): don't autosave a unnamed doc.
* src/bufferlist.C (close) (QwriteAll) (emergencyWriteAll):
check if this is an UNNAMED new file and react to it.
(newFile): set buffer to unnamed and change to not mark a new
buffer dirty if I didn't do anything with it.
* src/lyxfunc.C (MenuNew): Changed to not ask for filename on new.
2000-07-26 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/frontends/Menubar.h: make "struct Pimpl;" public + the

View File

@ -34,6 +34,11 @@ src/frontends/xforms/FormPreferences.C
src/frontends/xforms/form_preferences.C
src/frontends/xforms/FormPrint.C
src/frontends/xforms/form_print.C
src/frontends/xforms/forms/form_citation.C
src/frontends/xforms/forms/form_copyright.C
src/frontends/xforms/forms/form_preferences.C
src/frontends/xforms/forms/form_print.C
src/frontends/xforms/forms/form_tabular.C
src/frontends/xforms/FormTabular.C
src/frontends/xforms/form_tabular.C
src/frontends/xforms/Menubar_pimpl.C

View File

@ -128,6 +128,7 @@ Buffer::Buffer(string const & file, bool ronly)
bak_clean = true;
dep_clean = 0;
read_only = ronly;
unnamed = false;
users = 0;
lyxvc.buffer(this);
if (read_only || (lyxrc.use_tempdir)) {

View File

@ -223,7 +223,13 @@ public:
///
void markNwDirty() { nw_clean = false; }
///
void setUnnamed(bool flag=true) { unnamed = flag; }
///
bool isUnnamed() { return unnamed; }
///
void markDirty() {
if (lyx_clean) {
@ -397,6 +403,9 @@ private:
/// do we need to run weave/tangle
bool nw_clean;
/// is this a unnamed file (New...)
bool unnamed;
/// is regenerating .tex necessary
DEPCLEAN * dep_clean;

View File

@ -89,6 +89,7 @@ bool BufferList::empty() const
extern void MenuWrite(Buffer *);
extern bool MenuWriteAs(Buffer *);
bool BufferList::QwriteAll()
{
@ -97,21 +98,31 @@ bool BufferList::QwriteAll()
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if (!(*it)->isLyxClean()) {
switch(AskConfirmation(_("Changes in document:"),
MakeDisplayPath((*it)->fileName(),
50),
_("Save document?"))) {
case 1: // Yes
MenuWrite((*it));
break;
case 2: // No
askMoreConfirmation = true;
unsaved += MakeDisplayPath((*it)->fileName(),
50);
unsaved += "\n";
break;
case 3: // Cancel
return false;
string fname;
if ((*it)->isUnnamed())
fname = OnlyFilename((*it)->fileName());
else
fname = MakeDisplayPath((*it)->fileName(), 50);
bool reask = true;
while(reask) {
switch(AskConfirmation(_("Changes in document:"),
fname,
_("Save document?"))) {
case 1: // Yes
if ((*it)->isUnnamed())
reask = !MenuWriteAs((*it));
else
MenuWrite((*it));
break;
case 2: // No
askMoreConfirmation = true;
unsaved += MakeDisplayPath(fname, 50);
unsaved += "\n";
reask = false;
break;
case 3: // Cancel
return false;
}
}
}
}
@ -157,23 +168,40 @@ bool BufferList::close(Buffer * buf)
if (buf->getUser()) buf->getUser()->insetUnlock();
if (buf->paragraph && !buf->isLyxClean() && !quitting) {
if (buf->getUser()) ProhibitInput(buf->getUser());
switch(AskConfirmation(_("Changes in document:"),
MakeDisplayPath(buf->fileName(), 50),
_("Save document?"))){
case 1: // Yes
if (buf->save()) {
lastfiles->newFile(buf->fileName());
} else {
if (buf->getUser()) AllowInput(buf->getUser());
if (buf->getUser())
ProhibitInput(buf->getUser());
string fname;
if (buf->isUnnamed())
fname = OnlyFilename(buf->fileName());
else
fname = MakeDisplayPath(buf->fileName(), 50);
bool reask = true;
while(reask) {
switch(AskConfirmation(_("Changes in document:"),
fname,
_("Save document?"))){
case 1: // Yes
if (buf->isUnnamed())
reask = !MenuWriteAs(buf);
else if (buf->save()) {
lastfiles->newFile(buf->fileName());
} else {
if (buf->getUser())
AllowInput(buf->getUser());
return false;
}
break;
case 2:
reask = false;
break;
case 3: // Cancel
if (buf->getUser())
AllowInput(buf->getUser());
return false;
}
break;
case 3: // Cancel
if (buf->getUser()) AllowInput(buf->getUser());
return false;
}
if (buf->getUser()) AllowInput(buf->getUser());
}
if (buf->getUser())
AllowInput(buf->getUser());
}
bstore.release(buf);
@ -245,9 +273,12 @@ void BufferList::emergencyWriteAll()
bool madeit = false;
lyxerr <<_("lyx: Attempting to save"
" document ")
<< (*it)->fileName()
<< _(" as...") << endl;
" document ");
if ((*it)->isUnnamed())
lyxerr << OnlyFilename((*it)->fileName());
else
lyxerr << (*it)->fileName();
lyxerr << _(" as...") << endl;
for (int i = 0; i < 3 && !madeit; ++i) {
string s;
@ -257,6 +288,8 @@ void BufferList::emergencyWriteAll()
// 2) In HOME directory.
// 3) In "/tmp" directory.
if (i == 0) {
if ((*it)->isUnnamed())
continue;
s = (*it)->fileName();
} else if (i == 1) {
s = AddName(GetEnvPath("HOME"),
@ -418,7 +451,12 @@ Buffer * BufferList::newFile(string const & name, string tname)
b->paragraph = new LyXParagraph;
}
#ifdef NEW_WITH_FILENAME
b->markDirty();
#else
#warning Why mark a new document dirty? I deactivate this for unnamed docs! (Jug)
b->setUnnamed();
#endif
b->setReadonly(false);
return b;

View File

@ -160,7 +160,7 @@ void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
int RunLinuxDoc(BufferView *, int, string const &);
int RunDocBook(int, string const &);
void MenuWrite(Buffer * buf);
void MenuWriteAs(Buffer * buffer);
bool MenuWriteAs(Buffer * buffer);
void MenuReload(Buffer * buf);
void MenuLayoutSave();
@ -208,7 +208,7 @@ void MenuWrite(Buffer * buffer)
// should be moved to BufferView.C
// Half of this func should be in LyXView, the rest in BufferView.
void MenuWriteAs(Buffer * buffer)
bool MenuWriteAs(Buffer * buffer)
{
// Why do we require BufferView::text to be able to write a
// document? I see no point in that. (Lgb)
@ -225,14 +225,21 @@ void MenuWriteAs(Buffer * buffer)
if (!IsLyXFilename(fname))
fname += ".lyx";
fname = fileDlg.Select(_("Enter Filename to Save Document as"),
OnlyPath(fname),
"*.lyx",
OnlyFilename(fname));
if (buffer->isUnnamed()) {
fname = fileDlg.Select(_("Enter Filename to Save Document as"),
"",
"*.lyx",
"");
} else {
fname = fileDlg.Select(_("Enter Filename to Save Document as"),
OnlyPath(fname),
"*.lyx",
OnlyFilename(fname));
}
AllowInput(current_view);
if (fname.empty()) {
return;
return false;
}
// Make sure the absolute filename ends with appropriate suffix
string s = MakeAbsPath(fname);
@ -244,7 +251,7 @@ void MenuWriteAs(Buffer * buffer)
if (!AskQuestion(_("Same name as document already has:"),
MakeDisplayPath(s, 50),
_("Save anyway?")))
return;
return false;
// Falls through to name change and save
}
// No, but do we have another file with this name open?
@ -262,23 +269,25 @@ void MenuWriteAs(Buffer * buffer)
ShowMessage(buffer, _("Document renamed to '"),
MakeDisplayPath(s), _("', but not saved..."));
}
return;
return false;
} // Check whether the file exists
else {
FileInfo myfile(s);
if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
MakeDisplayPath(s, 50),
_("Replace file?")))
return;
return false;
}
// Ok, change the name of the buffer
buffer->fileName(s);
buffer->markDirty();
buffer->setUnnamed(false);
// And save
// Small bug: If the save fails, we have irreversible changed the name
// of the document.
MenuWrite(buffer);
return true;
}
@ -974,8 +983,8 @@ void AutoSave(BufferView * bv)
if (!bv->available())
return;
if (bv->buffer()->isBakClean()
|| bv->buffer()->isReadonly()) {
if (bv->buffer()->isBakClean() ||
bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
// We don't save now, but we'll try again later
bv->owner()->resetAutosaveTimer();
return;

View File

@ -113,7 +113,7 @@ extern bool selection_possible;
extern kb_keymap * toplevel_keymap;
extern void MenuWrite(Buffer *);
extern void MenuWriteAs(Buffer *);
extern bool MenuWriteAs(Buffer *);
extern int MenuRunLaTeX(Buffer *);
extern int MenuBuildProg(Buffer *);
extern int MenuRunChktex(Buffer *);
@ -775,16 +775,20 @@ string LyXFunc::Dispatch(int ac,
break;
case LFUN_MENUWRITE:
owner->getMiniBuffer()->Set(_("Saving document"),
MakeDisplayPath(owner->buffer()->fileName()),
"...");
MenuWrite(owner->buffer());
//owner->getMiniBuffer()-> {
// Set(_("Document saved as"),
// MakeDisplayPath(owner->buffer()->fileName()));
//} else {
//owner->getMiniBuffer()->Set(_("Save failed!"));
//}
if (!owner->buffer()->isUnnamed()) {
owner->getMiniBuffer()->Set(_("Saving document"),
MakeDisplayPath(owner->buffer()->fileName()),
"...");
MenuWrite(owner->buffer());
//owner->getMiniBuffer()-> {
// Set(_("Document saved as"),
// MakeDisplayPath(owner->buffer()->fileName()));
//} else {
//owner->getMiniBuffer()->Set(_("Save failed!"));
//}
} else {
MenuWriteAs(owner->buffer());
}
break;
case LFUN_MENUWRITEAS:
@ -2183,7 +2187,7 @@ string LyXFunc::Dispatch(int ac,
// Do we have a locking inset...
if (owner->view()->the_locking_inset) {
lyxerr << "Locking inset code: "
<< owner->view()->the_locking_inset->LyxCode();
<< static_cast<int>(owner->view()->the_locking_inset->LyxCode());
InsetCaption * new_inset = new InsetCaption;
new_inset->setOwner(owner->view()->the_locking_inset);
new_inset->SetAutoBreakRows(true);
@ -2883,6 +2887,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
initpath = trypath;
}
#ifdef NEW_WITH_FILENAME
ProhibitInput(owner->view());
fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
@ -2895,7 +2900,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
lyxerr.debug() << "New Document Cancelled." << endl;
return;
}
// get absolute path of file and make sure the filename ends
// with .lyx
string s = MakeAbsPath(fname);
@ -2903,7 +2908,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
s += ".lyx";
// Check if the document already is open
if (bufferlist.exists(s)){
if (bufferlist.exists(s)) {
switch(AskConfirmation(_("Document is already open:"),
MakeDisplayPath(s, 50),
_("Do you want to close that document now?\n"
@ -2922,7 +2927,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
return;
}
}
// Check whether the file already exists
if (IsLyXFilename(s)) {
FileInfo fi(s);
@ -2942,6 +2947,16 @@ void LyXFunc::MenuNew(bool fromTemplate)
return;
}
}
#else
static int newfile_number = 0;
string s = "/lyx/dummy/dirname/newfile ["+tostr(++newfile_number)+"]";
FileInfo fi(s);
while (bufferlist.exists(s) || fi.readable()) {
++newfile_number;
s = "/lyx/dummy/dirname/newfile ["+tostr(newfile_number)+"]";
fi.newFile(s);
}
#endif
// The template stuff
string templname;