GUI: show line numbers in the snippets window if available and no page number
This commit is contained in:
parent
8b129f6058
commit
6f7f1238f7
@ -169,7 +169,7 @@ static bool termNeeded(const std::string& cmd)
|
||||
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);
|
||||
string apptag;
|
||||
@ -401,12 +401,11 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString qterm)
|
||||
pagenum = 1;
|
||||
}
|
||||
|
||||
int line = 1;
|
||||
if (m_source && !term.empty() && linenumNeeded(cmd)) {
|
||||
if (linenum < 1 && m_source && !term.empty() && linenumNeeded(cmd)) {
|
||||
if (doc.text.empty()) {
|
||||
rcldb->getDocRawText(doc);
|
||||
}
|
||||
line = m_source->getFirstMatchLine(doc, term);
|
||||
linenum = m_source->getFirstMatchLine(doc, term);
|
||||
}
|
||||
|
||||
// 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["i"] = FileInterner::getLastIpathElt(doc.ipath);
|
||||
subs["l"] = ulltodecstr(line);
|
||||
subs["l"] = ulltodecstr(linenum);
|
||||
subs["M"] = doc.mimetype;
|
||||
subs["p"] = ulltodecstr(pagenum);
|
||||
subs["s"] = term;
|
||||
|
||||
@ -464,8 +464,8 @@ void RclMain::showSnippets(Rcl::Doc doc)
|
||||
return;
|
||||
if (!m_snippets) {
|
||||
m_snippets = new SnippetsW(doc, m_source);
|
||||
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
|
||||
this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
|
||||
connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString, int)),
|
||||
this, SLOT(startNativeViewer(Rcl::Doc, int, QString, int)));
|
||||
connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()),
|
||||
this, SLOT (fileExit()));
|
||||
connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()),
|
||||
|
||||
@ -141,7 +141,8 @@ public slots:
|
||||
virtual void showActionsSearch();
|
||||
virtual void startPreview(int docnum, Rcl::Doc doc, int keymods);
|
||||
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 saveDocToFile(Rcl::Doc);
|
||||
virtual void populateSideFilters(bool init = false);
|
||||
|
||||
@ -253,6 +253,9 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
|
||||
if (snippet.page > 0) {
|
||||
oss << "<a href=\"http://h/P" << snippet.page << "T" << snippet.term << "\">" <<
|
||||
"P. " << snippet.page << "</a>";
|
||||
} else if (snippet.line > 0) {
|
||||
oss << "<a href=\"http://h/L" << snippet.line << "T" << snippet.term << "\">" <<
|
||||
"L. " << snippet.line << "</a>";
|
||||
}
|
||||
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << "\n";
|
||||
}
|
||||
@ -331,17 +334,23 @@ void SnippetsW::onLinkClicked(const QUrl &url)
|
||||
if (ascurl.size() > 3) {
|
||||
int what = ascurl[0];
|
||||
switch (what) {
|
||||
case 'P':
|
||||
case 'P':
|
||||
case 'L':
|
||||
{
|
||||
string::size_type numpos = ascurl.find_first_of("0123456789");
|
||||
if (numpos == string::npos)
|
||||
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 term;
|
||||
if (termpos != string::npos)
|
||||
term = ascurl.substr(termpos+1);
|
||||
emit startNativeViewer(m_doc, page, u8s2qs(term));
|
||||
emit startNativeViewer(m_doc, page, u8s2qs(term), line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ protected slots:
|
||||
virtual void reloadByPage();
|
||||
|
||||
signals:
|
||||
void startNativeViewer(Rcl::Doc, int pagenum, QString term);
|
||||
void startNativeViewer(Rcl::Doc, int pagenum, QString term, int line);
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user