add <pre style="white-space: pre-wrap"> to plain text HTML display options

This commit is contained in:
"Jean-Francois Dockes ext:(%22) 2012-08-22 09:36:08 +02:00
parent 0ebfc496d8
commit d24a3afdf8
6 changed files with 82 additions and 34 deletions

View File

@ -122,10 +122,8 @@ void rwSettings(bool writing)
"/Recoll/prefs/showResultsAsTable", Bool, false);
SETTING_RW(prefs.maxhltextmbs, "/Recoll/prefs/preview/maxhltextmbs", Int, 3);
// The default is true because I find it more often useful to keep
// indentation than to fold lines. Mileage may vary.
SETTING_RW(prefs.previewPlainPre,
"/Recoll/prefs/preview/plainPre", Bool, true);
"/Recoll/prefs/preview/plainPre", Int, PrefsPack::PP_PREWRAP);
SETTING_RW(prefs.qtermcolor, "/Recoll/prefs/qtermcolor", String, "blue");
if (!writing && prefs.qtermcolor == "")
prefs.qtermcolor = "blue";

View File

@ -76,7 +76,8 @@ class PrefsPack {
bool previewHtml;
// Use <pre> tag to display highlighted text/plain inside html (else
// we use <br> at end of lines, which lets textedit wrap lines).
bool previewPlainPre;
enum PlainPre {PP_BR, PP_PRE, PP_PREWRAP};
int previewPlainPre;
bool collapseDuplicates;
bool showResultsAsTable;

View File

@ -82,23 +82,21 @@ public:
virtual string header()
{
if (m_inputhtml) {
return cstr_null;
} else {
if (prefs.previewPlainPre) {
m_eolbr = false;
return string("<qt><head><title></title></head><body>"
"<pre>");
// Note: we could also use the following for
// line-folding instead of <br>s This would be
// possible without recomputing the whole text, much
// better perfs for toggling wrap/no-wrap:
// <pre style=\"white-space: pre-wrap\">
} else {
if (!m_inputhtml) {
switch (prefs.previewPlainPre) {
case PrefsPack::PP_BR:
m_eolbr = true;
return string("<qt><head><title></title></head><body>");
return "<qt><head><title></title></head><body>";
case PrefsPack::PP_PRE:
m_eolbr = false;
return "<qt><head><title></title></head><body><pre>";
case PrefsPack::PP_PREWRAP:
m_eolbr = false;
return "<qt><head><title></title></head><body>"
"<pre style=\"white-space: pre-wrap\">";
}
}
return cstr_null;
}
virtual string startMatch(unsigned int grpidx)
@ -673,7 +671,18 @@ bool Preview::makeDocCurrent(const Rcl::Doc& doc, int docnum, bool sametab)
}
void Preview::togglePlainPre()
{
prefs.previewPlainPre = !prefs.previewPlainPre;
switch (prefs.previewPlainPre) {
case PrefsPack::PP_BR:
prefs.previewPlainPre = PrefsPack::PP_PRE;
break;
case PrefsPack::PP_PRE:
prefs.previewPlainPre = PrefsPack::PP_BR;
break;
case PrefsPack::PP_PREWRAP:
default:
prefs.previewPlainPre = PrefsPack::PP_PRE;
break;
}
PreviewTextEdit *editor = currentEditor();
if (editor)

View File

@ -133,17 +133,39 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="previewPlainPreCB">
<property name="toolTip">
<string>Lines in PRE text are not folded. Using BR loses some indentation.</string>
</property>
<property name="text">
<string>Use &lt;PRE&gt; tags instead of &lt;BR&gt;to display plain text as html in preview.</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Plain text to HTML line style</string>
</property>
<property name="toolTip">
<string>Lines in PRE text are not folded. Using BR loses some indentation. PRE + Wrap style may be what you want.</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainBRRB">
<property name="text">
<string>&lt;BR&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPRERB">
<property name="text">
<string>&lt;PRE&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="plainPREWRAPRB">
<property name="text">
<string>&lt;PRE&gt; + wrap</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="useDesktopOpenCB">

View File

@ -105,7 +105,18 @@ void UIPrefsDialog::setFromPrefs()
keepSortCB->setChecked(prefs.keepSort);
previewHtmlCB->setChecked(prefs.previewHtml);
previewPlainPreCB->setChecked(prefs.previewPlainPre);
switch (prefs.previewPlainPre) {
case PrefsPack::PP_BR:
plainBRRB->setChecked(1);
break;
case PrefsPack::PP_PRE:
plainPRERB->setChecked(1);
break;
case PrefsPack::PP_PREWRAP:
default:
plainPREWRAPRB->setChecked(1);
break;
}
// Query terms color
qtermColorLE->setText(prefs.qtermcolor);
// Abstract snippet separator string
@ -233,7 +244,14 @@ void UIPrefsDialog::accept()
prefs.useDesktopOpen = useDesktopOpenCB->isChecked();
prefs.keepSort = keepSortCB->isChecked();
prefs.previewHtml = previewHtmlCB->isChecked();
prefs.previewPlainPre = previewPlainPreCB->isChecked();
if (plainBRRB->isChecked()) {
prefs.previewPlainPre = PrefsPack::PP_BR;
} else if (plainPRERB->isChecked()) {
prefs.previewPlainPre = PrefsPack::PP_PRE;
} else {
prefs.previewPlainPre = PrefsPack::PP_PREWRAP;
}
prefs.syntAbsLen = syntlenSB->value();
prefs.syntAbsCtx = syntctxSB->value();

View File

@ -182,12 +182,12 @@ bool DocSequenceDb::setQuery()
m_rescnt = -1;
m_needSetQuery = !m_q->setQuery(m_fsdata);
if (0) {
#if 0
HighlightData hld;
m_fsdata->getTerms(hld);
string str;
hld.toString(str);
fprintf(stderr, "DocSequenceDb::setQuery: terms: %s\n", str.c_str());
}
#endif
return !m_needSetQuery;
}