mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Allow relative statistics values in statusbar.
https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg221311.html
This commit is contained in:
parent
9fd397ac1c
commit
7976cc2dac
@ -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 "Start Statistics Relative to Current Count|R" "statistics-reference-clamp"
|
||||
OptItem "Reset to Absolute Statistics Count|A" "statistics-reference-clamp reset"
|
||||
End
|
||||
|
||||
End
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -1343,6 +1349,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;
|
||||
}
|
||||
@ -2014,6 +2031,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);
|
||||
@ -2623,6 +2658,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;
|
||||
|
@ -401,6 +401,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 &);
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user