Cleanup app quitting and window closing now that there is a clean separation between the frontend and the core.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23271 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-02-27 10:35:28 +00:00
parent e3ffc06f1e
commit 9940ca7730
4 changed files with 15 additions and 60 deletions

View File

@ -49,8 +49,6 @@ public:
virtual ~LyXView() {}
///
virtual int id() const = 0;
///
virtual void close() = 0;
/// show busy cursor
virtual void setBusy(bool) = 0;

View File

@ -251,9 +251,6 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
// 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;
@ -261,8 +258,8 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
// 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: {
@ -548,8 +545,9 @@ void GuiApplication::commitData(QSessionManager & sm)
/// 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();
}
@ -581,20 +579,14 @@ bool GuiApplication::unregisterView(int id)
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();

View File

@ -145,8 +145,8 @@ typedef boost::shared_ptr<Dialog> DialogPtr;
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
@ -263,8 +263,6 @@ public:
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
@ -336,20 +334,6 @@ GuiView::~GuiView()
}
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_)
@ -381,15 +365,6 @@ void GuiView::showEvent(QShowEvent * e)
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
@ -406,7 +381,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
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?
@ -1627,6 +1602,10 @@ bool GuiView::closeBuffer(Buffer & buf)
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?"),
@ -1658,17 +1637,6 @@ bool GuiView::closeBuffer(Buffer & buf)
}
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();

View File

@ -62,7 +62,6 @@ public:
///
int id() const { return id_; }
void close();
void setFocus();
void setBusy(bool);
/// returns true if this view has the focus.
@ -99,8 +98,6 @@ public:
void importDocument(std::string const &);
///
void newDocument(std::string const & filename, bool fromTemplate);
/// write all buffers, asking the user, returns false if cancelled
bool quitWriteAll();
/// GuiBufferDelegate.
///@{