From 1a1c9dba4caa4c2dfe9c0f22ebf3c57ea4c835c3 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Tue, 18 Jan 2011 15:22:10 +0000 Subject: [PATCH] #7149 fix a crash on file-open with having some view but no current one git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37248 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.cpp | 20 ++++++++++++++++++++ src/frontends/qt4/GuiApplication.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 63a5a46e9a..ab10518ac7 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1237,6 +1237,23 @@ void GuiApplication::reconfigure(string const & option) "updated document class specifications.")); } +void GuiApplication::validateCurrentView() +{ + if (!d->views_.empty() && !current_view_) { + // currently at least one view exists but no view has the focus. + // choose a view to open the document in it. + // a view without any open document is preferred. + GuiView * candidate = 0; + QHash::const_iterator it = d->views_.begin(); + QHash::const_iterator end = d->views_.end(); + for (; it != end; ++it) { + candidate = *it; + if (!candidate->documentBufferView()) + break; + } + setCurrentView(candidate); + } +} void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) { @@ -1307,6 +1324,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_BUFFER_NEW: + validateCurrentView(); if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) { createView(QString(), false); // keep hidden @@ -1319,6 +1337,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; case LFUN_BUFFER_NEW_TEMPLATE: + validateCurrentView(); if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) { createView(); @@ -1331,6 +1350,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; case LFUN_FILE_OPEN: { + validateCurrentView(); // FIXME: create a new method shared with LFUN_HELP_OPEN. string const fname = to_utf8(cmd.argument()); if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index c7ab77bc15..d1a10784b8 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -182,6 +182,8 @@ private Q_SLOTS: void slotProcessFuncRequestQueue() { processFuncRequestQueue(); } private: + /// + void validateCurrentView(); /// bool closeAllViews(); /// read the given ui (menu/toolbar) file -- 2.39.5