void BufferView::reload()
{
string const fn = buffer()->fileName();
- if (bufferlist.close(buffer()))
+ if (bufferlist.close(buffer(), false))
buffer(bufferlist.loadLyXFile(fn));
}
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * bufferlist.h:
+ * bufferlist.C: several UI fixes using Alert::prompt.
+ Fix the pointless looping quit code. Fix stupid revert
+ behaviour (bug 938)
+
+ * lyxvc.h:
+ * lyxvc.C:
+ * lyx_cb.C: use Alert::prompt
+
+ * lyx_main.C: remove a silly question
+
+ * lyxfunc.C: remove a couple of silly questions,
+ use Alert::prompt
+
2003-03-28 John Levon <levon@movementarian.org>
* text2.C: fix bug 974 (End on empty par)
-/* This file is part of
- * ======================================================
+/**
+ * \file bufferlist.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Word Processor
+ * \author Lars Gullik Bjønnes
*
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
- *
- * This file is Copyright 1996-2001
- * Lars Gullik Bjønnes
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
}
-bool BufferList::qwriteOne(Buffer * buf, string const & fname,
- string & unsaved_list)
+bool BufferList::quitWriteBuffer(Buffer * buf)
{
- bool reask = true;
- while (reask) {
- switch (Alert::askConfirmation(_("Changes in document:"),
- fname,
- _("Save document?"))) {
- case 1: // Yes
- // FIXME: WriteAs can be asynch !
- if (buf->isUnnamed())
- reask = !WriteAs(current_view, buf);
- else {
- reask = !MenuWrite(current_view, buf);
- }
- break;
- case 2: // No
- // if we crash after this we could
- // have no autosave file but I guess
- // this is really inprobable (Jug)
- if (buf->isUnnamed()) {
- removeAutosaveFile(buf->fileName());
- }
+ string file;
+ if (buf->isUnnamed())
+ file = OnlyFilename(buf->fileName());
+ else
+ file = MakeDisplayPath(buf->fileName(), 30);
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s has unsaved changes.\n\nDo you want to save the document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" has unsaved changes.\n\nDo you want to save the document?");
+#endif
+ int const ret = Alert::prompt(_("Save changed document?"),
+ text, 0, _("&Save"), _("&Discard"), _("&Cancel quit"));
- unsaved_list += MakeDisplayPath(fname, 50) + "\n";
- return true;
- case 3: // Cancel
+ if (ret == 0) {
+ // FIXME: WriteAs can be asynch !
+ // but not right now...maybe we should remove that
+
+ bool succeeded;
+
+ if (buf->isUnnamed())
+ succeeded = !WriteAs(current_view, buf);
+ else
+ succeeded = !MenuWrite(current_view, buf);
+
+ if (!succeeded)
return false;
- }
+ } else if (ret == 1) {
+ // if we crash after this we could
+ // have no autosave file but I guess
+ // this is really inprobable (Jug)
+ if (buf->isUnnamed())
+ removeAutosaveFile(buf->fileName());
+
+ } else {
+ return false;
}
+
return true;
}
-bool BufferList::qwriteAll()
+bool BufferList::quitWriteAll()
{
- string unsaved;
BufferStorage::iterator it = bstore.begin();
BufferStorage::iterator end = bstore.end();
for (; it != end; ++it) {
- if (!(*it)->isClean()) {
- string fname;
- if ((*it)->isUnnamed())
- fname = OnlyFilename((*it)->fileName());
- else
- fname = MakeDisplayPath((*it)->fileName(), 50);
- if (!qwriteOne(*it, fname, unsaved)) // cancel the request!
- return false;
- }
+ if ((*it)->isClean())
+ continue;
+
+ if (!quitWriteBuffer(*it))
+ return false;
}
return true;
textcache.clear();
while (!bstore.empty()) {
- close(bstore.front());
+ close(bstore.front(), true);
}
}
-bool BufferList::close(Buffer * buf)
+bool BufferList::close(Buffer * buf, bool ask)
{
lyx::Assert(buf);
- if (!buf->paragraphs.empty() && !buf->isClean() && !quitting) {
- string fname;
- if (buf->isUnnamed())
- fname = OnlyFilename(buf->fileName());
- else
- fname = MakeDisplayPath(buf->fileName(), 50);
- bool reask = true;
- while (reask) {
- switch (Alert::askConfirmation(_("Changes in document:"),
- fname,
- _("Save document?"))) {
- case 1: // Yes
- if (buf->isUnnamed())
- reask = !WriteAs(current_view, buf);
- else if (buf->save()) {
- lastfiles->newFile(buf->fileName());
- reask = false;
- } else {
- return false;
- }
- break;
- case 2:
- if (buf->isUnnamed()) {
- removeAutosaveFile(buf->fileName());
- }
- reask = false;
- break;
- case 3: // Cancel
+ if (!ask || buf->isClean() || quitting || buf->paragraphs.empty()) {
+ release(buf);
+ return true;
+ }
+
+ string fname;
+ if (buf->isUnnamed())
+ fname = OnlyFilename(buf->fileName());
+ else
+ fname = MakeDisplayPath(buf->fileName(), 30);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s has unsaved changes.\n\nDo you want to save the document?"));
+ fmt % fname;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += fname + _(" has unsaved changes.\n\nDo you want to save the document?");
+#endif
+ int const ret = Alert::prompt(_("Save changed document?"),
+ text, 0, _("&Save"), _("&Discard"));
+
+ if (ret == 0) {
+ if (buf->isUnnamed()) {
+ if (!WriteAs(current_view, buf))
return false;
- }
+ } else if (buf->save()) {
+ lastfiles->newFile(buf->fileName());
+ } else {
+ return false;
}
}
+
+ if (buf->isUnnamed()) {
+ removeAutosaveFile(buf->fileName());
+ }
release(buf);
return true;
if (fileInfoE.exist() && fileInfo2.exist()) {
if (fileInfoE.getModificationTime()
> fileInfo2.getModificationTime()) {
- if (Alert::askQuestion(_("An emergency save of this document exists!"),
- MakeDisplayPath(s, 50),
- _("Try to load that instead?"))) {
+ string const file = MakeDisplayPath(s, 20);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("An emergency save of the document %1$s exists.\n\nRecover emergency save?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("An emergency save of the document ");
+ text += file + _(" exists.\n\nRecover emergency save?");
+#endif
+ int const ret = Alert::prompt(_("Load emergency save?"),
+ text, 0, _("&Recover"), _("&Load original"));
+
+ if (ret == 0) {
ts = e;
// the file is not saved if we load the
// emergency file.
if (fileInfoA.exist() && fileInfo2.exist()) {
if (fileInfoA.getModificationTime()
> fileInfo2.getModificationTime()) {
- if (Alert::askQuestion(_("Autosave file is newer."),
- MakeDisplayPath(s, 50),
- _("Load that one instead?"))) {
+ string const file = MakeDisplayPath(s, 20);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The backup of the document %1$s is newer.\n\nLoad the backup instead?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The backup of the document ");
+ text += file + _(" is newer.\n\nLoad the backup instead?");
+#endif
+ int const ret = Alert::prompt(_("Load backup?"),
+ text, 0, _("&Load backup"), _("Load &original"));
+
+ if (ret == 0) {
ts = a;
// the file is not saved if we load the
// autosave file.
// file already open?
if (exists(s)) {
- if (Alert::askQuestion(_("Document is already open:"),
- MakeDisplayPath(s, 50),
- _("Do you want to reload that document?"))) {
- // Reload is accomplished by closing and then loading
- if (!close(getBuffer(s))) {
+ string const file = MakeDisplayPath(s, 20);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s is already loaded.\n\nDo you want to revert to the saved version?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" is already loaded.\n\nDo you want to revert to the saved version?");
+#endif
+ int const ret = Alert::prompt(_("Revert to saved document?"),
+ text, 1, _("&Revert"), _("&Switch to document"));
+
+ if (ret == 0) {
+ // FIXME: should be LFUN_REVERT
+ if (!close(getBuffer(s), false)) {
return 0;
}
// Fall through to new load. (Asger)
return getBuffer(s);
}
}
+
Buffer * b = 0;
bool ro = false;
switch (IsFileWriteable(s)) {
b->lyxvc.file_found_hook(s);
}
break; //fine- it's r/w
- case -1:
+ case -1: {
+ string const file = MakeDisplayPath(s, 20);
// Here we probably should run
if (LyXVC::file_not_found_hook(s)) {
- // Ask if the file should be checked out for
- // viewing/editing, if so: load it.
- if (Alert::askQuestion(_("Do you want to retrieve file under version control?"))) {
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Do you want to retrieve the document %1$s from version control?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("Do you want to retrieve the document ");
+ text += file + _(" from version control?");
+#endif
+ int const ret = Alert::prompt(_("Retrieve from version control?"),
+ text, 0, _("&Retrieve"), _("&Cancel"));
+
+ if (ret == 0) {
// How can we know _how_ to do the checkout?
// With the current VC support it has to be,
// a RCS file since CVS do not have special ,v files.
return loadLyXFile(filename, tolastfiles);
}
}
- if (Alert::askQuestion(_("Cannot open specified file:"),
- MakeDisplayPath(s, 50),
- _("Create new document with this name?")))
- {
- // Find a free buffer
- b = newFile(s, string(), true);
- }
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s does not yet exist. Do you want to create a new document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" does not yet exist. Do you want to create a new document?");
+#endif
+ int const ret = Alert::prompt(_("Create new document?"),
+ text, 0, _("&Create"), _("Cancel"));
+
+ if (ret == 0)
+ b = newFile(s, string(), true);
+
break;
+ }
}
if (b && tolastfiles)
// -*- C++ -*-
-/** \file
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+/**
+ * \file bufferlist.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
*
- * \author Lars Gullik Bjønnes
-*/
+ * Full author contact details are available in file CREDITS
+ */
#ifndef BUFFER_LIST_H
#define BUFFER_LIST_H
Buffer * loadLyXFile(string const & filename,
bool tolastfiles = true);
- /// write all buffers, asking the user
- bool qwriteAll();
+ /// write all buffers, asking the user, returns false if cancelled
+ bool quitWriteAll();
/// create a new buffer
Buffer * newBuffer(string const & s, bool ronly = false);
void emergencyWriteAll();
/// close buffer. Returns false if cancelled by user
- bool close(Buffer * buf);
+ bool close(Buffer * buf, bool ask);
/// return true if no buffers loaded
bool empty() const;
void setCurrentAuthor(string const & name, string const & email);
private:
- /// ask to save a buffer on quit
- bool qwriteOne(Buffer * buf, string const & fname,
- string & unsaved_list);
+ /// ask to save a buffer on quit, returns false if should cancel
+ bool quitWriteBuffer(Buffer * buf);
typedef std::vector<Buffer *> BufferStorage;
}
-bool Alert::askQuestion(string const & s1, string const & s2,
- string const & s3, bool default_value)
+int Alert::prompt(string const & title, string const & question,
+ int default_button,
+ string const & b1, string const & b2, string const & b3)
{
- if (!lyxrc.use_gui) {
- lyxerr << "----------------------------------------" << endl
- << s1 << endl;
- if (!s2.empty())
- lyxerr << s2 << endl;
- if (!s3.empty())
- lyxerr << s3 << endl;
- lyxerr << "Assuming answer is "
- << (default_value ? "yes" : "no")
- << endl
- << "----------------------------------------" << endl;
- return default_value;
- } else {
- return askQuestion_pimpl(s1, s2, s3);
- }
-}
-
-
-int Alert::askConfirmation(string const & s1, string const & s2,
- string const & s3, int default_value)
-{
- if (!lyxrc.use_gui) {
- lyxerr << "----------------------------------------" << endl
- << s1 << endl;
- if (!s2.empty())
- lyxerr << s2 << endl;
- if (!s3.empty())
- lyxerr << s3 << endl;
- lyxerr << "Assuming answer is ";
- if (default_value == 1)
- lyxerr << "yes";
- else if (default_value == 2)
- lyxerr << "no";
- else
- lyxerr << "cancel";
- lyxerr << endl
- << "----------------------------------------" << endl;
- return default_value;
- } else {
- return askConfirmation_pimpl(s1, s2, s3);
+ if (lyxrc.use_gui)
+ return prompt_pimpl(title, question, default_button, b1, b2, b3);
+
+ lyxerr << title << endl;
+ lyxerr << "----------------------------------------" << endl;
+ lyxerr << question << endl;
+ lyxerr << "Assuming answer is ";
+ switch (default_button) {
+ case 0: lyxerr << b1 << endl;
+ case 1: lyxerr << b2 << endl;
+ case 2: lyxerr << b3 << endl;
}
+ return default_button;
}
namespace Alert {
+/**
+ * Prompt for a question. Returns 0-2 for the chosen button.
+ * Set default_button to a reasonable value. b1-b3 should have
+ * accelerators marked with an '&'. title should be a short summary.
+ * Strings should be gettextised. Please think about the poor user.
+ *
+ * Remember to use boost::format. If you make any of these buttons
+ * "Yes" or "No", I will personally come around to your house and
+ * slap you with fish, and not in an enjoyable way either.
+ */
+int prompt(string const & title, string const & question,
+ int default_button,
+ string const & b1, string const & b2, string const & b3 = string());
+
/// show an alert message
void alert(string const & title, string const & s1 = string(),
string const & s2 = string());
/// show an alert message and strerror(errno)
void err_alert(string const & s1, string const & s2 = string());
-/// ask a question
-bool askQuestion(string const & s1, string const & s2 = string(),
- string const & s3 = string(), bool default_value = true);
-
-/// Returns 1 for yes, 2 for no, 3 for cancel.
-int askConfirmation(string const & s1, string const & s2 = string(),
- string const & s3 = string(), int default_value = 1);
-
/// Asks for a text
std::pair<bool, string> const
askForText(string const & msg,
#include "debug.h"
// GUI-specific implementations
+
void alert_pimpl(string const & s1, string const & s2, string const & s3);
-bool askQuestion_pimpl(string const & s1, string const & s2, string const & s3);
-int askConfirmation_pimpl(string const & s1, string const & s2, string const & s3);
+
+int prompt_pimpl(string const & title, string const & question,
+ int default_button,
+ string const & b1, string const & b2, string const & b3);
+
std::pair<bool, string> const askForText_pimpl(string const & msg, string const & dflt);
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert.h:
+ * Alert.C:
+ * Alert_pimpl.h: fix up askQuestion/askConfirmation
+ into prompt, to discourage Yes/No questions.
+
2003-03-26 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove showThesaurus.
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * ControlDocument.C: comment out seemingly silly question
+
2003-03-27 Lars Gullik Bjønnes <larsbj@gullik.net>
* ControlDialog.tmpl (show): qualify emergency_exit_ with this->
void ControlDocument::saveAsDefault()
{
+// Can somebody justify this ? I think it should be removed - jbl
+#if 0
if (!Alert::askQuestion(_("Do you want to save the current settings"),
_("for the document layout as default?"),
_("(they will be valid for any new document)")))
return;
+#endif
lv_.buffer()->params.preamble = bp_->preamble;
}
-bool askQuestion_pimpl(string const & s1, string const & s2, string const & s3)
+int prompt_pimpl(string const & tit, string const & question,
+ int default_button,
+ string const & b1, string const & b2, string const & b3)
{
- return !(QMessageBox::information(0, "LyX", toqstr(s1 + '\n' + s2 + '\n' + s3),
- qt_("&Yes"), qt_("&No"), 0, 1));
-}
-
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("LyX: %1$s"));
+ fmt % tit;
+ string const title = fmt.str();
+#else
+ string const title = _("LyX: ") + tit;
+#endif
-int askConfirmation_pimpl(string const & s1, string const & s2, string const & s3)
-{
- return (QMessageBox::information(0, "LyX", toqstr(s1 + '\n' + s2 + '\n' + s3),
- qt_("&Yes"), qt_("&No"), qt_("&Cancel"), 0, 2)) + 1;
+ return QMessageBox::information(0, toqstr(title), toqstr(formatted(question)),
+ toqstr(b1), toqstr(b2), b3.empty() ? QString::null : toqstr(b3),
+ default_button);
}
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert_pimpl.C: implement prompt()
+
2003-03-29 John Levon <levon@movementarian.org>
* QDocument.C:
using std::pair;
using std::make_pair;
+using std::min;
string makeFontName(string const & family, string const & foundry)
{
char const * tmpcstr = tmpstr;
return tmpcstr;
}
+
+
+string const formatted(string const & text, int w)
+{
+ string sout;
+
+ if (text.empty())
+ return sout;
+
+ string::size_type curpos = 0;
+ string line;
+
+ for (;;) {
+ string::size_type const nxtpos1 = text.find(' ', curpos);
+ string::size_type const nxtpos2 = text.find('\n', curpos);
+ string::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
+
+ string const word = nxtpos == string::npos ?
+ text.substr(curpos) : text.substr(curpos, nxtpos-curpos);
+
+ bool const newline = (nxtpos2 != string::npos &&
+ nxtpos2 < nxtpos1);
+
+ string const line_plus_word =
+ line.empty() ? word : line + ' ' + word;
+
+ // FIXME: make w be size_t
+ if (line_plus_word.length() >= w) {
+ sout += line + '\n';
+ if (newline) {
+ sout += word + '\n';
+ line.erase();
+ } else {
+ line = word;
+ }
+
+ } else if (newline) {
+ sout += line_plus_word + '\n';
+ line.erase();
+
+ } else {
+ if (!line.empty())
+ line += ' ';
+ line += word;
+ }
+
+ if (nxtpos == string::npos) {
+ if (!line.empty())
+ sout += line;
+ break;
+ }
+
+ curpos = nxtpos + 1;
+ }
+
+ return sout;
+}
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
string const & len, LyXLength::UNIT default_unit);
+/// format a string to the given width
+string const formatted(string const & text, int w = 80);
+
/**
* toqstr - convert char * into unicode
*
}
-bool askQuestion_pimpl(string const & s1, string const & s2, string const & s3)
-{
- fl_set_resource("flQuestion.yes.label", idex(_("Yes|#y")).c_str());
- fl_set_resource("flQuestion.no.label", idex(_("No|#n")).c_str());
- return fl_show_question((s1 + "\n" + s2 + "\n" + s3).c_str(), 0);
-}
-
+#warning error needs fixing up
+#warning a "&Save" -> "Save|#S" is whats needed
+#warning and a format maybe, and fixup default_button ?
-int askConfirmation_pimpl(string const & s1, string const & s2, string const & s3)
+int prompt_pimpl(string const & title, string const & question,
+ int default_button,
+ string const & b1, string const & b2, string const & b3);
{
- string const yes = _("Yes|#Y");
- string const no = _("No|#N");
- string const cancel = _("Cancel|^[");
-
- fl_set_choices_shortcut(scex(yes).c_str(), scex(no).c_str(),
- scex(cancel).c_str());
- return fl_show_choice(s1.c_str(), s2.c_str(), s3.c_str(),
- 3, idex(yes).c_str(), idex(no).c_str(),
- idex(cancel).c_str(), 3);
+ if (b3.empty()) {
+ return fl_show_choice(title.c_str(), question.c_str(), "",
+ 2, b1.c_str(), b2.c_str(), 2);
+ } else {
+ return fl_show_choice(title.c_str(), question.c_str(), "",
+ 3, b1.c_str(), b2.c_str(), b3.c_str(), 3);
+ }
}
+2003-03-29 John Levon <levon@movementarian.org>
+
+ * Alert_pimpl.C: implement prompt()
+
2003-03-26 Angus Leeming <leeming@lyx.org>
* combox.C (show):
// Menu callbacks
//
-//
-// File menu
-//
-// should be moved to lyxfunc.C
bool MenuWrite(BufferView * bv, Buffer * buffer)
{
- if (!buffer->save()) {
- if (Alert::askQuestion(_("Save failed. Rename and try again?"),
- MakeDisplayPath(buffer->fileName(), 50),
- _("(If not, document is not saved.)"))) {
- return WriteAs(bv, buffer);
- }
- return false;
- } else
+ if (buffer->save()) {
lastfiles->newFile(buffer->fileName());
- return true;
+ return true;
+ }
+
+ // FIXME: we don't tell the user *WHY* the save failed !!
+
+ string const file = MakeDisplayPath(buffer->fileName(), 30);
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s could not be saved.\n\nDo you want to rename the document and try again?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" could not be saved.\n\nDo you want to rename the document and try again?");
+#endif
+ int const ret = Alert::prompt(_("Rename and save?"),
+ text, 0, _("&Rename"), _("&Cancel"));
+
+ if (ret == 0)
+ return WriteAs(bv, buffer);
+ return false;
}
-// should be moved to BufferView.C
-// Half of this func should be in LyXView, the rest in BufferView.
bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
{
string fname = buffer->fileName();
} else
fname = filename;
- // Same name as we have already?
- if (!buffer->isUnnamed() && fname == oldname) {
- if (!Alert::askQuestion(_("Same name as document already has:"),
- MakeDisplayPath(fname, 50),
- _("Save anyway?")))
- return false;
- // Falls through to name change and save
- }
- // No, but do we have another file with this name open?
- else if (!buffer->isUnnamed() && bufferlist.exists(fname)) {
- if (Alert::askQuestion(_("Another document with same name open!"),
- MakeDisplayPath(fname, 50),
- _("Replace with current document?")))
- {
- bufferlist.close(bufferlist.getBuffer(fname));
-
- // Ok, change the name of the buffer, but don't save!
- buffer->setFileName(fname);
- buffer->markDirty();
-
- ShowMessage(buffer, _("Document renamed to '"),
- MakeDisplayPath(fname), _("', but not saved..."));
- }
- return false;
- } // Check whether the file exists
- else {
- FileInfo const myfile(fname);
- if (myfile.isOK() && !Alert::askQuestion(_("Document already exists:"),
- MakeDisplayPath(fname, 50),
- _("Replace file?")))
+ FileInfo const myfile(fname);
+ if (myfile.isOK()) {
+ string const file = MakeDisplayPath(fname, 30);
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s already exists.\n\nDo you want to over-write that document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" already exists.\n\nDo you want to over-write that document?");
+#endif
+ int const ret = Alert::prompt(_("Over-write document?"),
+ text, 1, _("&Over-write"), _("&Cancel"));
+
+ if (ret == 1)
return false;
}
buffer->setUnnamed(false);
if (!MenuWrite(bv, buffer)) {
- buffer->setFileName(oldname);
- buffer->setUnnamed(unnamed);
- ShowMessage(buffer, _("Document could not be saved!"),
- _("Holding the old name."), MakeDisplayPath(oldname));
- return false;
+ buffer->setFileName(oldname);
+ buffer->setUnnamed(unnamed);
+ return false;
}
- // now remove the oldname autosave file if existant!
+
removeAutosaveFile(oldname);
return true;
}
lyxerr[Debug::INFO] << "Running QuitLyX." << endl;
if (lyxrc.use_gui) {
- if (!bufferlist.qwriteAll())
+ if (!bufferlist.quitWriteAll())
return;
lastfiles->writeFile(lyxrc.lastfiles);
first_start = !explicit_userdir;
- // If the user specified explicitly a directory, ask whether
- // to create it (otherwise, always create it)
- if (explicit_userdir &&
- !Alert::askQuestion(_("You have specified an invalid LyX directory."),
- _("It is needed to keep your own configuration."),
- _("Should I try to set it up for you (recommended)?"))) {
- lyxerr << _("Running without personal LyX directory.") << endl;
- // No, let's use $HOME instead.
- user_lyxdir = GetEnvPath("HOME");
- return;
- }
-
#if USE_BOOST_FORMAT
lyxerr << boost::format(_("LyX: Creating directory %1$s"
" and running configure..."))
// 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);
view()->buffer(buffer);
// Check if the document already is open
if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
- switch (Alert::askConfirmation(_("Document is already open:"),
- MakeDisplayPath(lyxfile, 50),
- _("Do you want to close that document now?\n"
- "('No' will just switch to the open version)")))
- {
- case 1:
- // If close is canceled, we cancel here too.
- if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
- return;
- break;
- case 2:
- view()->buffer(bufferlist.getBuffer(lyxfile));
- return;
- case 3:
- owner->message(_("Canceled."));
- return;
- }
+ string const file = MakeDisplayPath(lyxfile, 30);
+
+ // FIXME: sucky UI !
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s is already open.\n\nDo you want to close that document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" is already open.\n\nDo you want to close that document?");
+#endif
+ int const ret = Alert::prompt(_("Close open document?"),
+ text, 1, _("&Close"), _("&Cancel"));
+
+ if (ret == 0 || !bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
+ owner->message(_("Canceled."));
+ return;
+ }
}
// if the file exists already, and we didn't do
// -i lyx thefile.lyx, warn
if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
- if (!Alert::askQuestion(_("A document by the name"),
- MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
+ string const file = MakeDisplayPath(lyxfile, 30);
+
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s already exists.\n\nDo you want to over-write that document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" already exists.\n\nDo you want to over-write that document?");
+#endif
+ int const ret = Alert::prompt(_("Over-write document?"),
+ text, 1, _("&Over-write"), _("&Cancel"));
+
+ if (ret == 1) {
owner->message(_("Canceled."));
return;
}
void LyXFunc::closeBuffer()
{
- if (bufferlist.close(owner->buffer()) && !quitting) {
+ if (bufferlist.close(owner->buffer(), true) && !quitting) {
if (bufferlist.empty()) {
// need this otherwise SEGV may occur while trying to
// set variables that don't exist
#include "support/filetools.h"
#include "support/lyxlib.h"
+#include "BoostFormat.h"
#include <unistd.h>
}
+bool LyXVC::ensureClean()
+{
+ if (owner_->isClean())
+ return true;
+
+ string const file = MakeDisplayPath(owner_->fileName(), 30);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("The document %1$s has unsaved changes.\n\nDo you want to save the document?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("The document ");
+ text += file + _(" has unsaved changes.\n\nDo you want to save the document?");
+#endif
+ int const ret = Alert::prompt(_("Save changed document?"),
+ text, 0, _("&Save"), _("&Cancel"));
+
+ if (ret == 0) {
+ vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
+ }
+
+ return owner_->isClean();
+}
+
+
void LyXVC::registrer()
{
string const filename = owner_->fileName();
vcs->owner(owner_);
}
- // If the document is changed, we might want to save it
- if (!vcs->owner()->isClean() &&
- Alert::askQuestion(_("Changes in document:"),
- MakeDisplayPath(filename, 50),
- _("Save document and proceed?"))) {
- vcs->owner()->getUser()->owner()
- ->dispatch(FuncRequest(LFUN_MENUWRITE));
- }
-
// Maybe the save fails, or we answered "no". In both cases,
// the document will be dirty, and we abort.
- if (!vcs->owner()->isClean())
+ if (!ensureClean())
return;
lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
void LyXVC::checkIn()
{
// If the document is changed, we might want to save it
- if (!vcs->owner()->isClean() &&
- Alert::askQuestion(_("Changes in document:"),
- MakeDisplayPath(vcs->owner()->fileName(), 50),
- _("Save document and proceed?"))) {
+ if (!vcs->owner()->isClean()) {
vcs->owner()->getUser()->owner()
->dispatch(FuncRequest(LFUN_MENUWRITE));
}
void LyXVC::checkOut()
{
lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
- if (!vcs->owner()->isClean()
- && !Alert::askQuestion(_("Changes in document:"),
- MakeDisplayPath(vcs->owner()->fileName(), 50),
- _("Ignore changes and proceed with check out?"))) {
+ if (!ensureClean())
return;
- }
vcs->checkOut();
}
void LyXVC::revert()
{
lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
- // Here we should check if the buffer is dirty. And if it is
- // we should warn the user that reverting will discard all
- // changes made since the last check in.
- if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
- _("to the document since the last check in."),
- _("Do you still want to do it?"))) {
+ string const file = MakeDisplayPath(owner_->fileName(), 20);
+#if USE_BOOST_FORMAT
+ boost::format fmt(_("Reverting to the stored version of the document %1$s will "
+ "lose all current changes.\n\nDo you want to revert to the saved version?"));
+ fmt % file;
+ string text = fmt.str();
+#else
+ string text = _("Reverting to the stored version of the document ");
+ text += file + _(" will lose all current changes.\n\nDo you want to revert to the saved version?");
+#endif
+ int const ret = Alert::prompt(_("Revert to stored version of document?"),
+ text, 1, _("&Revert"), _("&Cancel"));
+
+ if (ret == 0)
vcs->revert();
- }
}
string const & locker() const;
private:
+ /// returns false if still not clean
+ bool ensureClean();
+
///
Buffer * owner_;