// update bookmark pit of the current buffer before window close
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
theLyXFunc().gotoBookmark(i+1, false, false);
- // ask the user for saving changes or cancel quit
- if (!current_view_->quitWriteAll())
- break;
current_view_->close();
break;
// quitting is triggered by the gui code
// (leaving the event loop).
current_view_->message(from_utf8(N_("Exiting.")));
- if (current_view_->quitWriteAll())
- closeAllViews();
+ if (closeAllViews())
+ quit();
break;
case LFUN_SCREEN_FONT_UPDATE: {
/// The default implementation sends a close event to all
/// visible top level widgets when session managment allows
/// interaction.
- /// We are changing that to write all unsaved buffers...
- if (sm.allowsInteraction() && !current_view_->quitWriteAll())
+ /// We are changing that to close all wiew one by one.
+ /// FIXME: verify if the default implementation is enough now.
+ if (sm.allowsInteraction() && !closeAllViews())
sm.cancel();
}
bool GuiApplication::closeAllViews()
{
updateIds(views_, view_ids_);
- if (views_.empty()) {
- // quit in CloseEvent will not be triggert
- qApp->quit();
+ if (views_.empty())
return true;
- }
map<int, GuiView*> const cmap = views_;
map<int, GuiView*>::const_iterator it;
for (it = cmap.begin(); it != cmap.end(); ++it) {
- // TODO: return false when close event was ignored
- // e.g. quitWriteAll()->'Cancel'
- // maybe we need something like 'bool closeView()'
- it->second->close();
- // unregisterd by the CloseEvent
+ if (!it->second->close())
+ return false;
}
views_.clear();
struct GuiView::GuiViewPrivate
{
GuiViewPrivate()
- : current_work_area_(0), layout_(0),
- quitting_by_menu_(false), autosave_timeout_(5000), in_show_(false)
+ : current_work_area_(0), layout_(0), autosave_timeout_(5000),
+ in_show_(false)
{
// hardcode here the platform specific icon size
smallIconSize = 14; // scaling problems
unsigned int bigIconSize;
///
QTimer statusbar_timer_;
- /// are we quitting by the menu?
- bool quitting_by_menu_;
/// auto-saving of buffers
Timeout autosave_timeout_;
/// flag against a race condition due to multiclicks, see bug #1119
}
-void GuiView::close()
-{
- d.quitting_by_menu_ = true;
- d.current_work_area_ = 0;
- for (int i = 0; i != d.splitter_->count(); ++i) {
- TabWorkArea * twa = d.tabWorkArea(i);
- if (twa)
- twa->closeAll();
- }
- QMainWindow::close();
- d.quitting_by_menu_ = false;
-}
-
-
void GuiView::setFocus()
{
if (d.current_work_area_)
void GuiView::closeEvent(QCloseEvent * close_event)
{
- // we may have been called through the close window button
- // which bypasses the LFUN machinery.
- if (!d.quitting_by_menu_ && guiApp->viewCount() == 1) {
- if (!quitWriteAll()) {
- close_event->ignore();
- return;
- }
- }
-
while (Buffer * b = buffer()) {
if (b->parent()) {
// This is a child document, just close the tab after saving
for (int i = 0; i != ids.size(); ++i) {
if (id_ == ids[i])
continue;
- if (GuiWorkArea * wa = guiApp->view(ids[i]).workArea(*b)) {
+ if (guiApp->view(ids[i]).workArea(*b)) {
// FIXME 1: should we put an alert box here that the buffer
// is viewed elsewhere?
// FIXME 2: should we try to save this buffer in any case?
else
file = buf.fileName().displayName(30);
+ // Bring this window to top before asking questions.
+ raise();
+ activateWindow();
+
docstring const text = bformat(_("The document %1$s has unsaved changes."
"\n\nDo you want to save the document or discard the changes?"), file);
int const ret = Alert::prompt(_("Save changed document?"),
}
-bool GuiView::quitWriteAll()
-{
- while (!theBufferList().empty()) {
- Buffer * b = theBufferList().first();
- if (!closeBuffer(*b))
- return false;
- }
- return true;
-}
-
-
bool GuiView::dispatch(FuncRequest const & cmd)
{
BufferView * bv = view();