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); "/Recoll/prefs/showResultsAsTable", Bool, false);
SETTING_RW(prefs.maxhltextmbs, "/Recoll/prefs/preview/maxhltextmbs", Int, 3); 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, 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"); SETTING_RW(prefs.qtermcolor, "/Recoll/prefs/qtermcolor", String, "blue");
if (!writing && prefs.qtermcolor == "") if (!writing && prefs.qtermcolor == "")
prefs.qtermcolor = "blue"; prefs.qtermcolor = "blue";

View File

@ -76,7 +76,8 @@ class PrefsPack {
bool previewHtml; bool previewHtml;
// Use <pre> tag to display highlighted text/plain inside html (else // Use <pre> tag to display highlighted text/plain inside html (else
// we use <br> at end of lines, which lets textedit wrap lines). // 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 collapseDuplicates;
bool showResultsAsTable; bool showResultsAsTable;

View File

@ -82,23 +82,21 @@ public:
virtual string header() virtual string header()
{ {
if (m_inputhtml) { if (!m_inputhtml) {
return cstr_null; switch (prefs.previewPlainPre) {
} else { case PrefsPack::PP_BR:
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 {
m_eolbr = true; 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) virtual string startMatch(unsigned int grpidx)
@ -673,7 +671,18 @@ bool Preview::makeDocCurrent(const Rcl::Doc& doc, int docnum, bool sametab)
} }
void Preview::togglePlainPre() 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(); PreviewTextEdit *editor = currentEditor();
if (editor) if (editor)

View File

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

View File

@ -105,7 +105,18 @@ void UIPrefsDialog::setFromPrefs()
keepSortCB->setChecked(prefs.keepSort); keepSortCB->setChecked(prefs.keepSort);
previewHtmlCB->setChecked(prefs.previewHtml); 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 // Query terms color
qtermColorLE->setText(prefs.qtermcolor); qtermColorLE->setText(prefs.qtermcolor);
// Abstract snippet separator string // Abstract snippet separator string
@ -233,7 +244,14 @@ void UIPrefsDialog::accept()
prefs.useDesktopOpen = useDesktopOpenCB->isChecked(); prefs.useDesktopOpen = useDesktopOpenCB->isChecked();
prefs.keepSort = keepSortCB->isChecked(); prefs.keepSort = keepSortCB->isChecked();
prefs.previewHtml = previewHtmlCB->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.syntAbsLen = syntlenSB->value();
prefs.syntAbsCtx = syntctxSB->value(); prefs.syntAbsCtx = syntctxSB->value();

View File

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