GUI: show line numbers in the snippets window if available and no page number

This commit is contained in:
Jean-Francois Dockes 2022-06-21 16:34:25 +02:00
parent 8b129f6058
commit 6f7f1238f7
5 changed files with 21 additions and 12 deletions

View File

@ -169,7 +169,7 @@ static bool termNeeded(const std::string& cmd)
return cmd.find("%s") != std::string::npos; return cmd.find("%s") != std::string::npos;
} }
void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString qterm) void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString qterm, int linenum)
{ {
std::string term = qs2utf8s(qterm); std::string term = qs2utf8s(qterm);
string apptag; string apptag;
@ -401,12 +401,11 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString qterm)
pagenum = 1; pagenum = 1;
} }
int line = 1; if (linenum < 1 && m_source && !term.empty() && linenumNeeded(cmd)) {
if (m_source && !term.empty() && linenumNeeded(cmd)) {
if (doc.text.empty()) { if (doc.text.empty()) {
rcldb->getDocRawText(doc); rcldb->getDocRawText(doc);
} }
line = m_source->getFirstMatchLine(doc, term); linenum = m_source->getFirstMatchLine(doc, term);
} }
// Substitute %xx inside arguments // Substitute %xx inside arguments
@ -426,7 +425,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString qterm)
subs["f"] = fn; subs["f"] = fn;
subs["F"] = fn; subs["F"] = fn;
subs["i"] = FileInterner::getLastIpathElt(doc.ipath); subs["i"] = FileInterner::getLastIpathElt(doc.ipath);
subs["l"] = ulltodecstr(line); subs["l"] = ulltodecstr(linenum);
subs["M"] = doc.mimetype; subs["M"] = doc.mimetype;
subs["p"] = ulltodecstr(pagenum); subs["p"] = ulltodecstr(pagenum);
subs["s"] = term; subs["s"] = term;

View File

@ -464,8 +464,8 @@ void RclMain::showSnippets(Rcl::Doc doc)
return; return;
if (!m_snippets) { if (!m_snippets) {
m_snippets = new SnippetsW(doc, m_source); m_snippets = new SnippetsW(doc, m_source);
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)), connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString, int)),
this, SLOT(startNativeViewer(Rcl::Doc, int, QString))); this, SLOT(startNativeViewer(Rcl::Doc, int, QString, int)));
connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()), connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()),
this, SLOT (fileExit())); this, SLOT (fileExit()));
connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()), connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()),

View File

@ -141,7 +141,8 @@ public slots:
virtual void showActionsSearch(); virtual void showActionsSearch();
virtual void startPreview(int docnum, Rcl::Doc doc, int keymods); virtual void startPreview(int docnum, Rcl::Doc doc, int keymods);
virtual void startPreview(Rcl::Doc); virtual void startPreview(Rcl::Doc);
virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, QString term = QString()); virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, QString term = QString(),
int line = -1);
virtual void openWith(Rcl::Doc, string); virtual void openWith(Rcl::Doc, string);
virtual void saveDocToFile(Rcl::Doc); virtual void saveDocToFile(Rcl::Doc);
virtual void populateSideFilters(bool init = false); virtual void populateSideFilters(bool init = false);

View File

@ -253,6 +253,9 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
if (snippet.page > 0) { if (snippet.page > 0) {
oss << "<a href=\"http://h/P" << snippet.page << "T" << snippet.term << "\">" << oss << "<a href=\"http://h/P" << snippet.page << "T" << snippet.term << "\">" <<
"P.&nbsp;" << snippet.page << "</a>"; "P.&nbsp;" << snippet.page << "</a>";
} else if (snippet.line > 0) {
oss << "<a href=\"http://h/L" << snippet.line << "T" << snippet.term << "\">" <<
"L.&nbsp;" << snippet.line << "</a>";
} }
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << "\n"; oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << "\n";
} }
@ -332,16 +335,22 @@ void SnippetsW::onLinkClicked(const QUrl &url)
int what = ascurl[0]; int what = ascurl[0];
switch (what) { switch (what) {
case 'P': case 'P':
case 'L':
{ {
string::size_type numpos = ascurl.find_first_of("0123456789"); string::size_type numpos = ascurl.find_first_of("0123456789");
if (numpos == string::npos) if (numpos == string::npos)
return; return;
int page = atoi(ascurl.c_str() + numpos); int page = -1, line = -1;
if (what == 'P') {
page = atoi(ascurl.c_str() + numpos);
} else {
line = atoi(ascurl.c_str() + numpos);
}
string::size_type termpos = ascurl.find_first_of("T"); string::size_type termpos = ascurl.find_first_of("T");
string term; string term;
if (termpos != string::npos) if (termpos != string::npos)
term = ascurl.substr(termpos+1); term = ascurl.substr(termpos+1);
emit startNativeViewer(m_doc, page, u8s2qs(term)); emit startNativeViewer(m_doc, page, u8s2qs(term), line);
return; return;
} }
} }

View File

@ -60,7 +60,7 @@ protected slots:
virtual void reloadByPage(); virtual void reloadByPage();
signals: signals:
void startNativeViewer(Rcl::Doc, int pagenum, QString term); void startNativeViewer(Rcl::Doc, int pagenum, QString term, int line);
private: private:
void init(); void init();