]> git.lyx.org Git - lyx.git/commitdiff
#7149 fix a crash on file-open with having some view but no current one
authorStephan Witt <switt@lyx.org>
Tue, 18 Jan 2011 15:22:10 +0000 (15:22 +0000)
committerStephan Witt <switt@lyx.org>
Tue, 18 Jan 2011 15:22:10 +0000 (15:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37248 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h

index 63a5a46e9a4f295410a568f42eef07b46f3035ae..ab10518ac7ece87074d144d82eccdd5f0ace60b4 100644 (file)
@@ -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<int, GuiView *>::const_iterator it = d->views_.begin();
+               QHash<int, GuiView *>::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
index c7ab77bc152c2cb52bcf9d2c5fb5b1b25440d80e..d1a10784b8bf4c476e04590919a30ade0468aaa5 100644 (file)
@@ -182,6 +182,8 @@ private Q_SLOTS:
        void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
 
 private:
+       ///
+       void validateCurrentView();
        ///
        bool closeAllViews();
        /// read the given ui (menu/toolbar) file