From d82e6d2bf0558397238e30b0a95086914af81168 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 5 Jan 2025 14:14:06 +0100 Subject: [PATCH] Let errors-show open with the next error from current curson selected --- src/frontends/Delegates.h | 3 ++- src/frontends/qt/GuiErrorList.cpp | 9 ++++++++- src/frontends/qt/GuiErrorList.h | 2 ++ src/frontends/qt/GuiView.cpp | 30 +++++++++++++++++++----------- src/frontends/qt/GuiView.h | 13 ++++++++++--- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/frontends/Delegates.h b/src/frontends/Delegates.h index 715505edc6..a67ccec65c 100644 --- a/src/frontends/Delegates.h +++ b/src/frontends/Delegates.h @@ -64,7 +64,8 @@ public: /// This function is called when the buffer structure has been updated. virtual void updateTocItem(std::string const &, DocIterator const &) = 0; /// This function is called when some parsing error shows up. - virtual void errors(std::string const &, bool from_master = false) = 0; + virtual void errors(std::string const &, bool from_master = false, + int const item = -1) = 0; /// This function is called when some message shows up. virtual void message(docstring const &) = 0; /// This function is called when the buffer busy status change. diff --git a/src/frontends/qt/GuiErrorList.cpp b/src/frontends/qt/GuiErrorList.cpp index 68e6a3e7eb..61b72da8b3 100644 --- a/src/frontends/qt/GuiErrorList.cpp +++ b/src/frontends/qt/GuiErrorList.cpp @@ -24,6 +24,7 @@ #include "Text.h" #include "TexRow.h" +#include "support/convert.h" #include "support/debug.h" #include "support/gettext.h" #include "support/lstrings.h" @@ -125,7 +126,7 @@ void GuiErrorList::paramsToDialog() ErrorList::const_iterator const en = el.end(); for (; it != en; ++it) errorsLW->addItem(toqstr(it->error)); - errorsLW->setCurrentRow(0); + errorsLW->setCurrentRow(item_); showAnywayPB->setEnabled( lyx::getStatus(FuncRequest(LFUN_BUFFER_VIEW_CACHE)).enabled()); } @@ -149,6 +150,12 @@ bool GuiErrorList::initialiseParams(string const & sdata) string error_type = sdata; if (from_master_) error_type = split(sdata, '|'); + if (contains(error_type, "@")) { + string tmp; + string const s = split(error_type, tmp, '@'); + error_type = tmp; + item_ = convert(s); + } error_type_ = error_type; buf_ = from_master_ ? bufferview()->buffer().masterBuffer() diff --git a/src/frontends/qt/GuiErrorList.h b/src/frontends/qt/GuiErrorList.h index cc20ac9d73..83eb05b93f 100644 --- a/src/frontends/qt/GuiErrorList.h +++ b/src/frontends/qt/GuiErrorList.h @@ -65,6 +65,8 @@ private: docstring name_; /// bool from_master_; + /// + int item_ = 0; }; } // namespace frontend diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index c4da265564..c121a10f82 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -2172,7 +2172,7 @@ void GuiView::disconnectBufferView() } -void GuiView::errors(string const & error_type, bool from_master) +void GuiView::errors(string const & error_type, bool from_master, int const item) { BufferView const * const bv = currentBufferView(); if (!bv) @@ -2188,15 +2188,18 @@ void GuiView::errors(string const & error_type, bool from_master) string err = error_type; if (from_master) err = "from_master|" + error_type; + if (item != -1) + err += "@" + convert(item); showDialog("errorlist", err); } -bool GuiView::nextError(string const & error_type, bool from_master, bool testonly) +int GuiView::nextError(string const & error_type, bool from_master, + bool navigateto, bool atcursor) { BufferView const * const bv = currentBufferView(); if (!bv) - return false; + return -1; Buffer const & buf = from_master ? *(bv->buffer().masterBuffer()) @@ -2205,19 +2208,24 @@ bool GuiView::nextError(string const & error_type, bool from_master, bool teston ErrorList const & el = buf.errorList(error_type); if (el.empty()) - return false; + return -1; + int item = 0; for (auto const & err : el) { - if (TexRow::isNone(err.start) || TexRow::getDocIteratorsFromEntries(err.start, err.end, buf).first <= bv->cursor()) + if (TexRow::isNone(err.start) + || (atcursor && TexRow::getDocIteratorsFromEntries(err.start, err.end, buf).first < bv->cursor()) + || (!atcursor && TexRow::getDocIteratorsFromEntries(err.start, err.end, buf).first <= bv->cursor())) { + ++item; continue; - if (!testonly) { + } + if (navigateto) { DispatchResult dr; dispatch(TexRow::goToFunc(err.start, err.end), dr); } - return true; + return item; } - return false; + return -1; } @@ -2716,7 +2724,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) } // We guess it's from master if the single buffer list is empty bool const from_master = currentBufferView()->buffer().errorList(d.last_export_format).empty(); - enable = nextError(d.last_export_format, from_master, true); + enable = nextError(d.last_export_format, from_master) != -1; break; } @@ -4966,14 +4974,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_ERRORS_SHOW: { // We guess it's from master if the single buffer list is empty bool const from_master = bv->buffer().errorList(d.last_export_format).empty(); - errors(d.last_export_format, from_master); + errors(d.last_export_format, from_master, nextError(d.last_export_format, from_master, false, true)); break; } case LFUN_ERROR_NEXT: { // We guess it's from master if the single buffer list is empty bool const from_master = bv->buffer().errorList(d.last_export_format).empty(); - if (nextError(d.last_export_format, from_master)) { + if (nextError(d.last_export_format, from_master, true) != -1) { dr.forceBufferUpdate(); dr.screenUpdate(Update::Force); } diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index e026fb51ea..a202279b20 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -172,13 +172,20 @@ public: void resetAutosaveTimers() override; // shows an error list // if from_master is true, show master's error list - void errors(std::string const &, bool from_master = false) override; + void errors(std::string const &, bool from_master = false, + int const item = -1) override; void structureChanged() override; void updateTocItem(std::string const &, DocIterator const &) override; //@} - /// move to next error - bool nextError(std::string const &, bool from_master = false, bool testonly = false); + /** Find the next error from current cursor position. + * \return the error item position in the error list + * with \param navigateto the cursor moves to the error + * with \param atcursor the error at current cursor position + * is considered as well, otherwise only those who follow. + */ + int nextError(std::string const & error_type, bool from_master = false, + bool navigateto = false, bool atcursor = false); /// TocModels & tocModels();