From: Jürgen Vigna Date: Tue, 8 Aug 2000 11:08:07 +0000 (+0000) Subject: Added new lyxrc tag new_ask_filename for New... behaviour and fixed errors X-Git-Tag: 1.6.10~22048 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e8c2cd02e3340b8bb951e44215bcaf8e3ecff121;p=lyx.git Added new lyxrc tag new_ask_filename for New... behaviour and fixed errors with automatically assigned filename. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@959 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 8b9d4a4f10..c28baaf11e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-08-08 Juergen Vigna + + * src/bufferlist.C (newFile): + * src/lyxfunc.C (MenuNew): use the new_ask_filename tag from lyxrc. + + * src/lyxrc.C: added new_ask_filename tag + 2000-08-07 Baruch Even * src/graphics/Renderer.h: diff --git a/lib/lyxrc.example b/lib/lyxrc.example index 82e96da2df..411d8fd940 100644 --- a/lib/lyxrc.example +++ b/lib/lyxrc.example @@ -83,6 +83,11 @@ # We recommend to keep the confirmation, though. #\exit_confirmation false +# This sets the behaviour if you want to be asked for a filename when +# creating a new document or wait until you save it and be asked then. +# The default for now is ask on save. +# \new_ask_filename false + # LyX continously displays names of last command executed, along with a list # of defined short-cuts for it in the minibuffer. # It requires some horsepower to function, so you can turn it off, if LyX diff --git a/src/bufferlist.C b/src/bufferlist.C index e180a015d6..d88a2a7e03 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -453,12 +453,11 @@ 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 +#warning Why mark a new document dirty? I deactivate this (Jug) + if (!lyxrc.new_ask_filename) { +// b->markDirty(); + b->setUnnamed(); + } b->setReadonly(false); return b; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 56bc0d84ba..fe0b186c8c 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -2962,32 +2962,35 @@ 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); - fname = fileDlg.Select(_("Enter Filename for new document"), - initpath, "*.lyx", _("newfile")); - AllowInput(owner->view()); + static int newfile_number = 0; + string s = "newfile"+tostr(++newfile_number); + + if (lyxrc.new_ask_filename) { + ProhibitInput(owner->view()); + fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); + fileDlg.SetButton(1, _("Templates"), lyxrc.template_path); + fname = fileDlg.Select(_("Enter Filename for new document"), + initpath, "*.lyx", _("newfile")); + AllowInput(owner->view()); - if (fname.empty()) { - owner->getMiniBuffer()->Set(_("Canceled.")); - lyxerr.debug() << "New Document Cancelled." << endl; - return; - } + if (fname.empty()) { + owner->getMiniBuffer()->Set(_("Canceled.")); + lyxerr.debug() << "New Document Cancelled." << endl; + return; + } - // get absolute path of file and make sure the filename ends - // with .lyx - string s = MakeAbsPath(fname); - if (!IsLyXFilename(s)) - s += ".lyx"; - - // Check if the document already is open - if (bufferlist.exists(s)) { - switch(AskConfirmation(_("Document is already open:"), - MakeDisplayPath(s, 50), - _("Do you want to close that document now?\n" - "('No' will just switch to the open version)"))) + // get absolute path of file and make sure the filename ends + // with .lyx + string s = MakeAbsPath(fname); + if (!IsLyXFilename(s)) + s += ".lyx"; + + // Check if the document already is open + if (bufferlist.exists(s)) { + switch(AskConfirmation(_("Document is already open:"), + MakeDisplayPath(s, 50), + _("Do you want to close that document now?\n" + "('No' will just switch to the open version)"))) { case 1: // Yes: close the document if (!bufferlist.close(bufferlist.getBuffer(s))) @@ -3001,37 +3004,34 @@ void LyXFunc::MenuNew(bool fromTemplate) owner->getMiniBuffer()->Set(_("Canceled.")); return; } - } - - // Check whether the file already exists - if (IsLyXFilename(s)) { + } + // Check whether the file already exists + if (IsLyXFilename(s)) { + FileInfo fi(s); + if (fi.readable() && + AskQuestion(_("File already exists:"), + MakeDisplayPath(s, 50), + _("Do you want to open the document?"))) { + // loads document + owner->getMiniBuffer()->Set(_("Opening document"), + MakeDisplayPath(s), "..."); + XFlush(fl_display); + owner->view()->buffer( + bufferlist.loadLyXFile(s)); + owner->getMiniBuffer()->Set(_("Document"), + MakeDisplayPath(s), + _("opened.")); + return; + } + } + } else { FileInfo fi(s); - if (fi.readable() && - AskQuestion(_("File already exists:"), - MakeDisplayPath(s, 50), - _("Do you want to open the document?"))) { - // loads document - owner->getMiniBuffer()->Set(_("Opening document"), - MakeDisplayPath(s), "..."); - XFlush(fl_display); - owner->view()->buffer( - bufferlist.loadLyXFile(s)); - owner->getMiniBuffer()->Set(_("Document"), - MakeDisplayPath(s), - _("opened.")); - return; + while (bufferlist.exists(s) || fi.readable()) { + ++newfile_number; + s = "newfile"+tostr(newfile_number); + fi.newFile(s); } } -#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; diff --git a/src/lyxrc.C b/src/lyxrc.C index 145899be65..1cdf1a51f2 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -155,6 +155,7 @@ enum LyXRCTags { RC_DOCBOOK_TO_HTML_COMMAND, RC_DOCBOOK_TO_PDF_COMMAND, RC_WHEEL_JUMP, + RC_NEW_ASK_FILENAME, RC_LAST }; @@ -211,6 +212,7 @@ keyword_item lyxrcTags[] = { { "\\literate_extension", RC_LITERATE_EXTENSION }, { "\\make_backup", RC_MAKE_BACKUP }, { "\\mark_foreign_language", RC_MARK_FOREIGN_LANGUAGE }, + { "\\new_ask_filename", RC_NEW_ASK_FILENAME }, { "\\num_lastfiles", RC_NUMLASTFILES }, { "\\override_x_deadkeys", RC_OVERRIDE_X_DEADKEYS }, { "\\pdf_mode", RC_PDF_MODE }, @@ -376,6 +378,8 @@ void LyXRC::setDefaults() { language_auto_end = true; language_command_begin = "\\selectlanguage{$$lang}"; language_command_end = "\\selectlanguage{$$lang}"; + /// + new_ask_filename = false; /// date_insert_format = "%A, %e %B %Y"; @@ -1097,6 +1101,11 @@ int LyXRC::read(string const & filename) if ( lexrc.next()) docbook_to_pdf_command = lexrc.GetString(); break; + + case RC_NEW_ASK_FILENAME: + if ( lexrc.next()) + new_ask_filename = lexrc.GetBool(); + break; case RC_LAST: break; // this is just a dummy } diff --git a/src/lyxrc.h b/src/lyxrc.h index 79a08efd84..b6694c5aaf 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -259,6 +259,8 @@ public: string docbook_to_html_command; /// string docbook_to_pdf_command; + /// + bool new_ask_filename; }; ///