mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 18:24:48 +00:00
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:
parent
e3ffc06f1e
commit
9940ca7730
@ -49,8 +49,6 @@ public:
|
|||||||
virtual ~LyXView() {}
|
virtual ~LyXView() {}
|
||||||
///
|
///
|
||||||
virtual int id() const = 0;
|
virtual int id() const = 0;
|
||||||
///
|
|
||||||
virtual void close() = 0;
|
|
||||||
|
|
||||||
/// show busy cursor
|
/// show busy cursor
|
||||||
virtual void setBusy(bool) = 0;
|
virtual void setBusy(bool) = 0;
|
||||||
|
@ -251,9 +251,6 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
|
|||||||
// update bookmark pit of the current buffer before window close
|
// update bookmark pit of the current buffer before window close
|
||||||
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
|
for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
|
||||||
theLyXFunc().gotoBookmark(i+1, false, false);
|
theLyXFunc().gotoBookmark(i+1, false, false);
|
||||||
// ask the user for saving changes or cancel quit
|
|
||||||
if (!current_view_->quitWriteAll())
|
|
||||||
break;
|
|
||||||
current_view_->close();
|
current_view_->close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -261,8 +258,8 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
|
|||||||
// quitting is triggered by the gui code
|
// quitting is triggered by the gui code
|
||||||
// (leaving the event loop).
|
// (leaving the event loop).
|
||||||
current_view_->message(from_utf8(N_("Exiting.")));
|
current_view_->message(from_utf8(N_("Exiting.")));
|
||||||
if (current_view_->quitWriteAll())
|
if (closeAllViews())
|
||||||
closeAllViews();
|
quit();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_SCREEN_FONT_UPDATE: {
|
case LFUN_SCREEN_FONT_UPDATE: {
|
||||||
@ -548,8 +545,9 @@ void GuiApplication::commitData(QSessionManager & sm)
|
|||||||
/// The default implementation sends a close event to all
|
/// The default implementation sends a close event to all
|
||||||
/// visible top level widgets when session managment allows
|
/// visible top level widgets when session managment allows
|
||||||
/// interaction.
|
/// interaction.
|
||||||
/// We are changing that to write all unsaved buffers...
|
/// We are changing that to close all wiew one by one.
|
||||||
if (sm.allowsInteraction() && !current_view_->quitWriteAll())
|
/// FIXME: verify if the default implementation is enough now.
|
||||||
|
if (sm.allowsInteraction() && !closeAllViews())
|
||||||
sm.cancel();
|
sm.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,20 +579,14 @@ bool GuiApplication::unregisterView(int id)
|
|||||||
bool GuiApplication::closeAllViews()
|
bool GuiApplication::closeAllViews()
|
||||||
{
|
{
|
||||||
updateIds(views_, view_ids_);
|
updateIds(views_, view_ids_);
|
||||||
if (views_.empty()) {
|
if (views_.empty())
|
||||||
// quit in CloseEvent will not be triggert
|
|
||||||
qApp->quit();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
map<int, GuiView*> const cmap = views_;
|
map<int, GuiView*> const cmap = views_;
|
||||||
map<int, GuiView*>::const_iterator it;
|
map<int, GuiView*>::const_iterator it;
|
||||||
for (it = cmap.begin(); it != cmap.end(); ++it) {
|
for (it = cmap.begin(); it != cmap.end(); ++it) {
|
||||||
// TODO: return false when close event was ignored
|
if (!it->second->close())
|
||||||
// e.g. quitWriteAll()->'Cancel'
|
return false;
|
||||||
// maybe we need something like 'bool closeView()'
|
|
||||||
it->second->close();
|
|
||||||
// unregisterd by the CloseEvent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
views_.clear();
|
views_.clear();
|
||||||
|
@ -145,8 +145,8 @@ typedef boost::shared_ptr<Dialog> DialogPtr;
|
|||||||
struct GuiView::GuiViewPrivate
|
struct GuiView::GuiViewPrivate
|
||||||
{
|
{
|
||||||
GuiViewPrivate()
|
GuiViewPrivate()
|
||||||
: current_work_area_(0), layout_(0),
|
: current_work_area_(0), layout_(0), autosave_timeout_(5000),
|
||||||
quitting_by_menu_(false), autosave_timeout_(5000), in_show_(false)
|
in_show_(false)
|
||||||
{
|
{
|
||||||
// hardcode here the platform specific icon size
|
// hardcode here the platform specific icon size
|
||||||
smallIconSize = 14; // scaling problems
|
smallIconSize = 14; // scaling problems
|
||||||
@ -263,8 +263,6 @@ public:
|
|||||||
unsigned int bigIconSize;
|
unsigned int bigIconSize;
|
||||||
///
|
///
|
||||||
QTimer statusbar_timer_;
|
QTimer statusbar_timer_;
|
||||||
/// are we quitting by the menu?
|
|
||||||
bool quitting_by_menu_;
|
|
||||||
/// auto-saving of buffers
|
/// auto-saving of buffers
|
||||||
Timeout autosave_timeout_;
|
Timeout autosave_timeout_;
|
||||||
/// flag against a race condition due to multiclicks, see bug #1119
|
/// 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()
|
void GuiView::setFocus()
|
||||||
{
|
{
|
||||||
if (d.current_work_area_)
|
if (d.current_work_area_)
|
||||||
@ -381,15 +365,6 @@ void GuiView::showEvent(QShowEvent * e)
|
|||||||
|
|
||||||
void GuiView::closeEvent(QCloseEvent * close_event)
|
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()) {
|
while (Buffer * b = buffer()) {
|
||||||
if (b->parent()) {
|
if (b->parent()) {
|
||||||
// This is a child document, just close the tab after saving
|
// 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) {
|
for (int i = 0; i != ids.size(); ++i) {
|
||||||
if (id_ == ids[i])
|
if (id_ == ids[i])
|
||||||
continue;
|
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
|
// FIXME 1: should we put an alert box here that the buffer
|
||||||
// is viewed elsewhere?
|
// is viewed elsewhere?
|
||||||
// FIXME 2: should we try to save this buffer in any case?
|
// FIXME 2: should we try to save this buffer in any case?
|
||||||
@ -1627,6 +1602,10 @@ bool GuiView::closeBuffer(Buffer & buf)
|
|||||||
else
|
else
|
||||||
file = buf.fileName().displayName(30);
|
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."
|
docstring const text = bformat(_("The document %1$s has unsaved changes."
|
||||||
"\n\nDo you want to save the document or discard the changes?"), file);
|
"\n\nDo you want to save the document or discard the changes?"), file);
|
||||||
int const ret = Alert::prompt(_("Save changed document?"),
|
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)
|
bool GuiView::dispatch(FuncRequest const & cmd)
|
||||||
{
|
{
|
||||||
BufferView * bv = view();
|
BufferView * bv = view();
|
||||||
|
@ -62,7 +62,6 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
int id() const { return id_; }
|
int id() const { return id_; }
|
||||||
void close();
|
|
||||||
void setFocus();
|
void setFocus();
|
||||||
void setBusy(bool);
|
void setBusy(bool);
|
||||||
/// returns true if this view has the focus.
|
/// returns true if this view has the focus.
|
||||||
@ -99,8 +98,6 @@ public:
|
|||||||
void importDocument(std::string const &);
|
void importDocument(std::string const &);
|
||||||
///
|
///
|
||||||
void newDocument(std::string const & filename, bool fromTemplate);
|
void newDocument(std::string const & filename, bool fromTemplate);
|
||||||
/// write all buffers, asking the user, returns false if cancelled
|
|
||||||
bool quitWriteAll();
|
|
||||||
|
|
||||||
/// GuiBufferDelegate.
|
/// GuiBufferDelegate.
|
||||||
///@{
|
///@{
|
||||||
|
Loading…
Reference in New Issue
Block a user