On Tue, Mar 26, 2024 at 02:26:59PM -0400, Richard Kimberly Heck wrote: > On 3/25/24 17:46, Pavel Sanda wrote: > > On Mon, Mar 25, 2024 at 06:35:16PM +0100, Jean-Marc Lasgouttes wrote: > > > Actually, I am not sure how it helps. Knowing that you need to remove 140 > > > words is not useful in itself. > > The idea is that I set the difference value to the current count and > > I am aiming for -140. > > > > Which brings me to even simpler UI than I previously thought. > > Instead of entering some values as an argument I could simply > > have lfun that sets the difference to the current statistics > > value and be done with it. > > If you want to post it when/if it's done, I'll be happy to look at it.
Essentially the attached. Variables should be more hidden and I can add reset mechanism if this feature looks ok. I am happy even without context menu change, still less code out of the tree to maintain. Pavel
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 6d4fc75703..02a612e3a1 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -774,6 +774,7 @@ Menuset Item "Word Count|W" "ui-toggle statistics-w" Item "Character Count|C" "ui-toggle statistics-cb" Item "Character Count (No Blanks)|h" "ui-toggle statistics-c" + Item "Clamp statistics to the current value" "statistics-reference-clamp" End End diff --git a/po/cs.gmo b/po/cs.gmo index 77e6cdb0b6..a2e7997798 100644 Binary files a/po/cs.gmo and b/po/cs.gmo differ diff --git a/src/BufferView.cpp b/src/BufferView.cpp index ad534eae28..d9e0d3ac5d 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1241,6 +1241,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) case LFUN_BIBTEX_DATABASE_DEL: case LFUN_BIBTEX_DATABASE_LIST: case LFUN_STATISTICS: + case LFUN_STATISTICS_REFERENCE_CLAMP: case LFUN_KEYMAP_OFF: case LFUN_KEYMAP_PRIMARY: case LFUN_KEYMAP_SECONDARY: @@ -2008,6 +2009,20 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } break; + case LFUN_STATISTICS_REFERENCE_CLAMP: { + DocIterator from, to; + from = doc_iterator_begin(&buffer_); + to = doc_iterator_end(&buffer_); + buffer_.updateStatistics(from, to); + + buffer_.updateStatistics(from, to); + stats_ref_value_w = buffer_.wordCount(); + stats_ref_value_c = buffer_.charCount(true); + stats_ref_value_nb = buffer_.charCount(false); + break; + } + + case LFUN_SCREEN_UP: case LFUN_SCREEN_DOWN: { Point p = getPos(cur); diff --git a/src/BufferView.h b/src/BufferView.h index d239fdd360..b9e8e1d54d 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -395,6 +395,12 @@ public: /// Are we currently performing a selection with the mouse? bool mouseSelecting() const; + /// Reference value for statistics (essentially subtract this from the actual value to see relative counts) + /// (words/chars/chars no blanks) + int stats_ref_value_w = 0; + int stats_ref_value_c = 0; + int stats_ref_value_nb = 0; + private: /// noncopyable BufferView(BufferView const &); diff --git a/src/FuncCode.h b/src/FuncCode.h index 19f41295b1..a5f638d6d7 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -508,6 +508,7 @@ enum FuncCode LFUN_TAB_GROUP_NEXT, // daniel 20220130 LFUN_TAB_GROUP_PREVIOUS, // daniel 20220130 LFUN_BIBTEX_DATABASE_LIST, // bpiwowar, 20221218 + LFUN_STATISTICS_REFERENCE_CLAMP,// sanda, 20240324 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 19f12038a8..3d59aa8816 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3923,6 +3923,15 @@ void LyXAction::init() * \endvar */ { LFUN_STATISTICS, "statistics", ReadOnly, System }, +/*! + * \var lyx::FuncCode lyx::LFUN_STATISTICS_REFERENCE_CLAMP + * \li Action: Count statistics relative to the current value. + In other words all future values will be subtracted by this value. + * \li Syntax: statistics-reference-clamp + * \li Origin: sanda, Mar 28 2024 + * \endvar + */ + { LFUN_STATISTICS_REFERENCE_CLAMP, "statistics-reference-clamp", ReadOnly, System }, /*! * \var lyx::FuncCode lyx::LFUN_TABULAR_FEATURE diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index facdb81b67..0974534473 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -1483,23 +1483,23 @@ void GuiView::showStats() if (word_count_enabled_) { int const words = buf->wordCount(); if (words == 1) - stats << toqstr(bformat(_("%1$d Word"), words)); + stats << toqstr(bformat(_("%1$d Word"), words - bv->stats_ref_value_w)); else - stats << toqstr(bformat(_("%1$d Words"), words)); + stats << toqstr(bformat(_("%1$d Words"), words - bv->stats_ref_value_w)); } int const chars_with_blanks = buf->charCount(true); if (char_count_enabled_) { if (chars_with_blanks == 1) - stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks)); + stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks - bv->stats_ref_value_c)); else - stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks)); + stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks - bv->stats_ref_value_c)); } if (char_nb_count_enabled_) { int const chars = buf->charCount(false); if (chars == 1) - stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars)); + stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars - bv->stats_ref_value_nb)); else - stats << toqstr(bformat(_("%1$d Characters (no Blanks)"), chars)); + stats << toqstr(bformat(_("%1$d Characters (no Blanks)"), chars - bv->stats_ref_value_nb)); } stat_counts_->setText(stats.join(qt_(", [[stats separator]]"))); stat_counts_->show();
-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel