]> git.lyx.org Git - features.git/commitdiff
Refactor code showing error dialogs
authorScott Kostyshak <skostysh@lyx.org>
Sun, 8 Apr 2018 21:35:09 +0000 (17:35 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Sat, 14 Apr 2018 17:45:31 +0000 (13:45 -0400)
This commit follows 8d2b121e and is not expected to change
functionality (e.g., I confirmed that the cases of #7330 and #11106
are still fixed). The advantages of this refactoring are the
following:

- Remove some preprocessor directives:
  processingThreadFinished() is only called in the case that
  EXPORT_in_THREAD is 1, so by moving some code up in the call list,
  the directives are not needed.

- If errors() is called when there is no error, there will not be unexpected
  behavior (e.g., as was the case before 8d2b121e).
  Note that errors() is still only called by the code touched by this commit
  if there is an error, but that is for efficiency and readability.

- The "from_master" argument now has a constant meaning. Before, it
  could be the case that "from_master" was set to false but that the
  master's error dialog was shown.

src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index b63f1c7c90fb17aeafc1974fe8b0035255b6f53a..5cb6eea791da52ecd388b6ed7fc7587353f4167e 100644 (file)
@@ -725,9 +725,18 @@ void GuiView::processingThreadFinished()
                errors("Export");
                return;
        }
-       if (status != Buffer::ExportSuccess && status != Buffer::PreviewSuccess &&
-           status != Buffer::ExportCancel) {
-               errors(d.last_export_format);
+
+       bool const error = (status != Buffer::ExportSuccess &&
+                           status != Buffer::PreviewSuccess &&
+                           status != Buffer::ExportCancel);
+       if (error) {
+               ErrorList & el = bv->buffer().errorList(d.last_export_format);
+               // at this point, we do not know if buffer-view or
+               // master-buffer-view was called. If there was an export error,
+               // and the current buffer's error log is empty, we guess that
+               // it must be master-buffer-view that was called so we set
+               // from_master=true.
+               errors(d.last_export_format, el.empty());
        }
 }
 
@@ -1690,19 +1699,9 @@ void GuiView::errors(string const & error_type, bool from_master)
        if (!bv)
                return;
 
-#if EXPORT_in_THREAD
-       // We are called with from_master == false by default, so we
-       // have to figure out whether that is the case or not.
-       ErrorList & el = bv->buffer().errorList(error_type);
-       if (el.empty()) {
-               el = bv->buffer().masterBuffer()->errorList(error_type);
-               from_master = true;
-       }
-#else
        ErrorList const & el = from_master ?
                bv->buffer().masterBuffer()->errorList(error_type) :
                bv->buffer().errorList(error_type);
-#endif
 
        if (el.empty())
                return;
index 3ca4641ce0178cf4dd04a28662b6d963ca037d5b..2d0ad0097aabf87f3a318821ba1fd7680d2fcebf 100644 (file)
@@ -166,9 +166,8 @@ public:
        /// \name GuiBufferDelegate.
        //@{
        void resetAutosaveTimers();
-       // shows an error list (possibly master's)
-       // even if from_master is false, might show master's error list.
-       // this function should only be called if there was an error (#11106).
+       // shows an error list
+       // if from_master is true, show master's error list
        void errors(std::string const &, bool from_master = false);
        void structureChanged();
        void updateTocItem(std::string const &, DocIterator const &);