From 95900844891385382d84a1158641b49d704c7a7b Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Fri, 26 Mar 2004 17:49:08 +0000 Subject: [PATCH] add a 'cancel' button to the two alert dialogs triggered in File->Open git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8534 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++ src/buffer_funcs.C | 101 ++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ec916b78c0..6ac277306f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ + +2004-03-26 Alfredo Braunstein + + * buffer_funcs.C (readFile): add cancel button to two prompt dialogs + 2004-03-26 Jean-Marc Lasgouttes * kbsequence.C (print): adjust diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index bcbd98dce0..b1d5068081 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -49,13 +49,9 @@ namespace { bool readFile(Buffer * b, string const & s) { - string ts(s); - string e = OnlyPath(s); - string a = e; // File information about normal file - FileInfo fileInfo(s); - - if (!fileInfo.exist()) { + FileInfo fileN(s); + if (!fileN.exist()) { string const file = MakeDisplayPath(s, 50); string text = bformat(_("The specified document\n%1$s" "\ncould not be read."), file); @@ -64,58 +60,59 @@ bool readFile(Buffer * b, string const & s) } // Check if emergency save file exists and is newer. - e += OnlyFilename(s) + ".emergency"; - FileInfo fileInfoE(e); - - bool use_emergency = false; - - if (fileInfoE.exist() && fileInfo.exist()) { - if (fileInfoE.getModificationTime() - > fileInfo.getModificationTime()) { - string const file = MakeDisplayPath(s, 20); - string text = bformat(_("An emergency save of the document %1$s exists.\n" - "\nRecover emergency save?"), file); - int const ret = Alert::prompt(_("Load emergency save?"), - text, 0, 1, _("&Recover"), _("&Load Original")); + string const e = OnlyPath(s) + OnlyFilename(s) + ".emergency"; + FileInfo fileE(e); - if (ret == 0) { - ts = e; - // the file is not saved if we load the - // emergency file. - b->markDirty(); - use_emergency = true; - } + if (fileE.exist() && fileN.exist() + && fileE.getModificationTime() > fileN.getModificationTime()) + { + string const file = MakeDisplayPath(s, 20); + string text = bformat(_("An emergency save of the document " + "%1$s exists.\n\n" + "Recover emergency save?"), file); + switch (Alert::prompt(_("Load emergency save?"), text, 0, 2, + _("&Recover"), _("&Load Original"), + _("&Cancel"))) + { + case 0: + // the file is not saved if we load the emergency file. + b->markDirty(); + return b->readFile(e); + case 1: + break; + default: + return false; } } - if (!use_emergency) { - // Now check if autosave file is newer. - a += '#'; - a += OnlyFilename(s); - a += '#'; - FileInfo fileInfoA(a); - if (fileInfoA.exist() && fileInfo.exist()) { - if (fileInfoA.getModificationTime() - > fileInfo.getModificationTime()) { - string const file = MakeDisplayPath(s, 20); - string text = bformat(_("The backup of the document %1$s is newer.\n\n" - "Load the backup instead?"), file); - int const ret = Alert::prompt(_("Load backup?"), - text, 0, 1, _("&Load backup"), _("Load &original")); - - if (ret == 0) { - ts = a; - // the file is not saved if we load the - // autosave file. - b->markDirty(); - } else { - // Here, we should delete the autosave - unlink(a); - } - } + // Now check if autosave file is newer. + string const a = OnlyPath(s) + '#' + OnlyFilename(s) + '#'; + FileInfo fileA(a); + + if (fileA.exist() && fileN.exist() + && fileA.getModificationTime() > fileN.getModificationTime()) + { + string const file = MakeDisplayPath(s, 20); + string text = bformat(_("The backup of the document " + "%1$s is newer.\n\nLoad the " + "backup instead?"), file); + switch (Alert::prompt(_("Load backup?"), text, 0, 2, + _("&Load backup"), _("Load &original"), + _("&Cancel") )) + { + case 0: + // the file is not saved if we load the autosave file. + b->markDirty(); + return b->readFile(a); + case 1: + // Here we delete the autosave + unlink(a); + break; + default: + return false; } } - return b->readFile(ts); + return b->readFile(s); } -- 2.39.2