<commit_before>
#include <QPlainTextEdit>
#include <QScrollBar>

#include "../base/dialog.h"
#include "wd.h"
#include "editm.h"
#include "form.h"
#include "pane.h"
#include "cmd.h"

// ---------------------------------------------------------------------
Editm::Editm(string n, string s, Form *f, Pane *p) : Child(n,s,f,p)
{
  type="editm";
  QPlainTextEdit *w=new QPlainTextEdit(p);
  widget=(QWidget*) w;
  QString qn=s2q(n);
  QStringList opt=qsplit(s);
  w->setObjectName(qn);
  if (opt.contains("readonly"))
    w->setReadOnly(true);
}

// ---------------------------------------------------------------------
void Editm::cmd(string p,string v)
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QStringList opt=qsplit(v);
  if (p=="print") {
    initprinter();
    w->print(Printer);
  } else Child::set(p,v);
}

// ---------------------------------------------------------------------
void Editm::set(string p,string v)
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QStringList opt=qsplit(v);
  if (opt.isEmpty()) return;
  if (p=="limit")
    w->setMaximumBlockCount(c_strtoi(q2s(opt.at(0))));
  else if (p=="text")
    w->setPlainText(s2q(v));
  else Child::set(p,v);
}

// ---------------------------------------------------------------------
string Editm::state()
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QTextCursor c=w->textCursor();
  int b,e;
  b=c.selectionStart();
  e=c.selectionEnd();
  QScrollBar *h=w->horizontalScrollBar();
  QScrollBar *v=w->verticalScrollBar();
  string r;
  r+=spair(id,q2s(w->toPlainText()));
  r+=spair(id+"_select",i2s(b)+" "+i2s(e));
  r+=spair(id+"_scroll",i2s(h->value())+" "+i2s(v->value()));
  return r;
}<commit_msg>editm wip<commit_after>
#include <QPlainTextEdit>
#include <QScrollBar>

#include "../base/dialog.h"
#include "wd.h"
#include "editm.h"
#include "form.h"
#include "pane.h"
#include "cmd.h"

// ---------------------------------------------------------------------
Editm::Editm(string n, string s, Form *f, Pane *p) : Child(n,s,f,p)
{
  type="editm";
  QPlainTextEdit *w=new QPlainTextEdit(p);
  widget=(QWidget*) w;
  QString qn=s2q(n);
  QStringList opt=qsplit(s);
  w->setObjectName(qn);
  if (opt.contains("readonly"))
    w->setReadOnly(true);
}

// ---------------------------------------------------------------------
void Editm::cmd(string p,string v)
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QStringList opt=qsplit(v);
  if (p=="print") {
    initprinter();
    w->print(Printer);
  } else Child::set(p,v);
}

// ---------------------------------------------------------------------
void Editm::set(string p,string v)
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QStringList opt=qsplit(v);
  if (opt.isEmpty()) return;
  if (p=="limit")
    w->setMaximumBlockCount(c_strtoi(q2s(opt.at(0))));
  else if (p=="text")
    w->setPlainText(s2q(v));
  else if (p=="select")
// TODO setselect
    ;
  else if (p=="scroll")
// TODO setscroll
    ;
  else if (p=="wrap")
// TODO not work
    w->setLineWrapMode((remquotes(v)!="0")?QPlainTextEdit::WidgetWidth:QPlainTextEdit::NoWrap);
  else Child::set(p,v);
}

// ---------------------------------------------------------------------
string Editm::state()
{
  QPlainTextEdit *w=(QPlainTextEdit*) widget;
  QTextCursor c=w->textCursor();
  int b,e;
  b=c.selectionStart();
  e=c.selectionEnd();
  QScrollBar *h=w->horizontalScrollBar();
  QScrollBar *v=w->verticalScrollBar();
  string r;
  r+=spair(id,q2s(w->toPlainText()));
  r+=spair(id+"_select",i2s(b)+" "+i2s(e));
  r+=spair(id+"_scroll",i2s(h->value())+" "+i2s(v->value()));
  return r;
}
{'fraction_non_alphanumeric': 0.33389121338912137, 'fraction_numerical': 0.005299860529986053, 'mean_word_length': 2.3482726423902895, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3550892', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1317, 'n_words': 218}