Subtract value for word/character count
Pavel Sanda
sanda at lyx.org
Thu Apr 4 21:15:00 UTC 2024
On Tue, Apr 02, 2024 at 10:23:10PM -0400, Richard Kimberly Heck 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.
>
> I can easily imagine using this. I'd say go ahead, for 2.4.1.
Good, I fixed the scope of variables and added reset mechanism.
Will commit the attached to 2.4.1 if there is no other feedback.
Pavel
-------------- next part --------------
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index 32d76e603e..24e51fd685 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -774,6 +774,8 @@ 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"
+ OptItem "Reset statistics to the absolute value" "statistics-reference-clamp reset"
End
End
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 39fffed68e..7386c79a75 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -298,6 +298,12 @@ struct BufferView::Private
frontend::CaretGeometry caret_geometry_;
///
bool mouse_selecting_ = false;
+ /// 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;
+
};
@@ -1337,6 +1343,17 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
flag.setEnabled(cur.selection());
break;
+ case LFUN_STATISTICS_REFERENCE_CLAMP: {
+ // disable optitem reset if clamp not used
+ if (cmd.argument() == "reset" && d->stats_ref_value_c_ == 0) {
+ flag.setEnabled(false);
+ break;
+ }
+ flag.setEnabled(true);
+ break;
+
+ }
+
default:
return false;
}
@@ -2008,6 +2025,24 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
}
break;
+ case LFUN_STATISTICS_REFERENCE_CLAMP: {
+ if (cmd.argument() == "reset") {
+ d->stats_ref_value_w_ = d->stats_ref_value_c_ = d->stats_ref_value_nb_ = 0;
+ break;
+ }
+
+ DocIterator from, to;
+ from = doc_iterator_begin(&buffer_);
+ to = doc_iterator_end(&buffer_);
+ buffer_.updateStatistics(from, to);
+
+ d->stats_ref_value_w_ = buffer_.wordCount();
+ d->stats_ref_value_c_ = buffer_.charCount(true);
+ d->stats_ref_value_nb_ = buffer_.charCount(false);
+ break;
+ }
+
+
case LFUN_SCREEN_UP:
case LFUN_SCREEN_DOWN: {
Point p = getPos(cur);
@@ -2615,6 +2650,24 @@ bool BufferView::mouseSelecting() const
}
+int BufferView::stats_ref_value_w() const
+{
+ return d->stats_ref_value_w_;
+}
+
+
+int BufferView::stats_ref_value_c() const
+{
+ return d->stats_ref_value_c_;
+}
+
+
+int BufferView::stats_ref_value_nb() const
+{
+ return d->stats_ref_value_nb_;
+}
+
+
void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
{
//lyxerr << "[ cmd0 " << cmd0 << "]" << endl;
diff --git a/src/BufferView.h b/src/BufferView.h
index b46ade3df5..eed48209bb 100644
--- a/src/BufferView.h
+++ b/src/BufferView.h
@@ -398,6 +398,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() const;
+ int stats_ref_value_c() const;
+ int stats_ref_value_nb() const;
+
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 b6bb52152c..1c75c5fb4c 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3925,6 +3925,16 @@ 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 [reset]
+ * \li Params: reset: remove the clamp, i.e. count in the absolute numbers again
+ * \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..ac0606e985 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -1481,7 +1481,7 @@ void GuiView::showStats()
QStringList stats;
if (word_count_enabled_) {
- int const words = buf->wordCount();
+ int const words = buf->wordCount() - bv->stats_ref_value_w();
if (words == 1)
stats << toqstr(bformat(_("%1$d Word"), words));
else
@@ -1489,13 +1489,14 @@ void GuiView::showStats()
}
int const chars_with_blanks = buf->charCount(true);
if (char_count_enabled_) {
+ int const chars_with_blanks_disp = chars_with_blanks - bv->stats_ref_value_c();
if (chars_with_blanks == 1)
- stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks));
+ stats << toqstr(bformat(_("%1$d Character"), chars_with_blanks_disp));
else
- stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks));
+ stats << toqstr(bformat(_("%1$d Characters"), chars_with_blanks_disp));
}
if (char_nb_count_enabled_) {
- int const chars = buf->charCount(false);
+ int const chars = buf->charCount(false) - bv->stats_ref_value_nb();
if (chars == 1)
stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars));
else
More information about the lyx-devel
mailing list