Allow relative statistics values in statusbar.

https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg221311.html
This commit is contained in:
Pavel Sanda 2024-04-05 19:34:29 +02:00
parent a2dbac8e07
commit ae07763abf
6 changed files with 77 additions and 4 deletions

View File

@ -774,6 +774,8 @@ Menuset
Item "Word Count|W" "ui-toggle statistics-w" Item "Word Count|W" "ui-toggle statistics-w"
Item "Character Count|C" "ui-toggle statistics-cb" Item "Character Count|C" "ui-toggle statistics-cb"
Item "Character Count (No Blanks)|h" "ui-toggle statistics-c" Item "Character Count (No Blanks)|h" "ui-toggle statistics-c"
Item "Start Statistics Relative to Current Count|R" "statistics-reference-clamp"
OptItem "Reset to Absolute Statistics Count|A" "statistics-reference-clamp reset"
End End
End End

View File

@ -298,6 +298,12 @@ struct BufferView::Private
frontend::CaretGeometry caret_geometry_; frontend::CaretGeometry caret_geometry_;
/// ///
bool mouse_selecting_ = false; 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()); flag.setEnabled(cur.selection());
break; 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: default:
return false; return false;
} }
@ -2008,6 +2025,24 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
} }
break; 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_UP:
case LFUN_SCREEN_DOWN: { case LFUN_SCREEN_DOWN: {
Point p = getPos(cur); 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) void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
{ {
//lyxerr << "[ cmd0 " << cmd0 << "]" << endl; //lyxerr << "[ cmd0 " << cmd0 << "]" << endl;

View File

@ -398,6 +398,12 @@ public:
/// Are we currently performing a selection with the mouse? /// Are we currently performing a selection with the mouse?
bool mouseSelecting() const; 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: private:
/// noncopyable /// noncopyable
BufferView(BufferView const &); BufferView(BufferView const &);

View File

@ -508,6 +508,7 @@ enum FuncCode
LFUN_TAB_GROUP_NEXT, // daniel 20220130 LFUN_TAB_GROUP_NEXT, // daniel 20220130
LFUN_TAB_GROUP_PREVIOUS, // daniel 20220130 LFUN_TAB_GROUP_PREVIOUS, // daniel 20220130
LFUN_BIBTEX_DATABASE_LIST, // bpiwowar, 20221218 LFUN_BIBTEX_DATABASE_LIST, // bpiwowar, 20221218
LFUN_STATISTICS_REFERENCE_CLAMP,// sanda, 20240324
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -3923,6 +3923,16 @@ void LyXAction::init()
* \endvar * \endvar
*/ */
{ LFUN_STATISTICS, "statistics", ReadOnly, System }, { 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 * \var lyx::FuncCode lyx::LFUN_TABULAR_FEATURE

View File

@ -1481,7 +1481,7 @@ void GuiView::showStats()
QStringList stats; QStringList stats;
if (word_count_enabled_) { if (word_count_enabled_) {
int const words = buf->wordCount(); int const words = buf->wordCount() - bv->stats_ref_value_w();
if (words == 1) if (words == 1)
stats << toqstr(bformat(_("%1$d Word"), words)); stats << toqstr(bformat(_("%1$d Word"), words));
else else
@ -1489,13 +1489,14 @@ void GuiView::showStats()
} }
int const chars_with_blanks = buf->charCount(true); int const chars_with_blanks = buf->charCount(true);
if (char_count_enabled_) { if (char_count_enabled_) {
int const chars_with_blanks_disp = chars_with_blanks - bv->stats_ref_value_c();
if (chars_with_blanks == 1) 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 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_) { 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) if (chars == 1)
stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars)); stats << toqstr(bformat(_("%1$d Character (no Blanks)"), chars));
else else