Restore reslist popup function with webengine.

Have popup copy path create a baclslash-separated path on Windows
This commit is contained in:
Jean-Francois Dockes 2022-06-13 12:46:58 +01:00
parent 5b20e64e96
commit 45f387e791
2 changed files with 27 additions and 32 deletions

View File

@ -224,11 +224,17 @@ string QtGuiResListPager::prevUrl()
string QtGuiResListPager::headerContent() string QtGuiResListPager::headerContent()
{ {
return prefs.htmlHeaderContents(); string out;
#if defined(USING_WEBENGINE)
out += "<script type=\"text/javascript\">\n";
out += locdetailscript;
out += "</script>\n";
#endif
return out + prefs.htmlHeaderContents();
} }
void QtGuiResListPager::suggest(const vector<string>uterms, void QtGuiResListPager::suggest(const vector<string>uterms, map<string, vector<string> >& sugg)
map<string, vector<string> >& sugg)
{ {
sugg.clear(); sugg.clear();
bool issimple = m_reslist && m_reslist->m_rclmain && bool issimple = m_reslist && m_reslist->m_rclmain &&
@ -1106,7 +1112,7 @@ void ResList::onPopupJsDone(const QVariant &jr)
QString nm = qsl[i].left(eq).trimmed(); QString nm = qsl[i].left(eq).trimmed();
QString value = qsl[i].right(qsl[i].size() - (eq+1)).trimmed(); QString value = qsl[i].right(qsl[i].size() - (eq+1)).trimmed();
if (!nm.compare("rcldocnum")) { if (!nm.compare("rcldocnum")) {
m_popDoc = pageFirstDocNum() + atoi(qs2utf8s(value).c_str()); m_popDoc = pageFirstDocNum() + value.toInt();
} else { } else {
LOGERR("onPopupJsDone: unknown key: " << qs2utf8s(nm) << "\n"); LOGERR("onPopupJsDone: unknown key: " << qs2utf8s(nm) << "\n");
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005-2020 J.F.Dockes /* Copyright (C) 2005-2022 J.F.Dockes
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,11 +31,11 @@
#include "appformime.h" #include "appformime.h"
#include "rclmain_w.h" #include "rclmain_w.h"
#include "utf8iter.h" #include "utf8iter.h"
#include "rclutil.h"
namespace ResultPopup { namespace ResultPopup {
QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source, QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source, Rcl::Doc& doc)
Rcl::Doc& doc)
{ {
QMenu *popup = new QMenu(me); QMenu *popup = new QMenu(me);
@ -70,8 +70,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
act->setData(v); act->setData(v);
sub->addAction(act); sub->addAction(act);
} }
sub->connect(sub, SIGNAL(triggered(QAction *)), me, sub->connect(sub, SIGNAL(triggered(QAction *)), me, SLOT(menuOpenWith(QAction *)));
SLOT(menuOpenWith(QAction *)));
} }
} }
@ -88,8 +87,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
act->setData(v); act->setData(v);
sub->addAction(act); sub->addAction(act);
} }
sub->connect(sub, SIGNAL(triggered(QAction *)), me, sub->connect(sub, SIGNAL(triggered(QAction *)), me, SLOT(menuOpenWith(QAction *)));
SLOT(menuOpenWith(QAction *)));
} }
} }
delete ddb; delete ddb;
@ -103,12 +101,10 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
popup->addAction(QWidget::tr("Copy Text"), me, SLOT(menuCopyText())); popup->addAction(QWidget::tr("Copy Text"), me, SLOT(menuCopyText()));
if ((opts&showSaveOne) && !(isFsTop)) if ((opts&showSaveOne) && !(isFsTop))
popup->addAction(QWidget::tr("&Write to File"), me, popup->addAction(QWidget::tr("&Write to File"), me, SLOT(menuSaveToFile()));
SLOT(menuSaveToFile()));
if ((opts&showSaveSel)) if ((opts&showSaveSel))
popup->addAction(QWidget::tr("Save selection to files"), popup->addAction(QWidget::tr("Save selection to files"), me, SLOT(menuSaveSelection()));
me, SLOT(menuSaveSelection()));
// We now separate preview/open parent, which only makes sense for // We now separate preview/open parent, which only makes sense for
@ -117,25 +113,21 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr<DocSequence> source,
Rcl::Doc pdoc; Rcl::Doc pdoc;
bool isEnclosed = source && source->getEnclosing(doc, pdoc); bool isEnclosed = source && source->getEnclosing(doc, pdoc);
if (isEnclosed) { if (isEnclosed) {
popup->addAction(QWidget::tr("Preview P&arent document/folder"), popup->addAction(QWidget::tr("Preview P&arent document/folder"),
me, SLOT(menuPreviewParent())); me, SLOT(menuPreviewParent()));
popup->addAction(QWidget::tr("&Open Parent document"), popup->addAction(QWidget::tr("&Open Parent document"), me, SLOT(menuOpenParent()));
me, SLOT(menuOpenParent()));
} }
if (doc.isFsFile()) if (doc.isFsFile())
popup->addAction(QWidget::tr("&Open Parent Folder"), popup->addAction(QWidget::tr("&Open Parent Folder"), me, SLOT(menuOpenFolder()));
me, SLOT(menuOpenFolder()));
if (opts & showExpand) if (opts & showExpand)
popup->addAction(QWidget::tr("Find &similar documents"), popup->addAction(QWidget::tr("Find &similar documents"), me, SLOT(menuExpand()));
me, SLOT(menuExpand()));
if (doc.haspages && source && source->snippetsCapable()) if (doc.haspages && source && source->snippetsCapable())
popup->addAction(QWidget::tr("Open &Snippets window"), popup->addAction(QWidget::tr("Open &Snippets window"), me, SLOT(menuShowSnippets()));
me, SLOT(menuShowSnippets()));
if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc)) if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc))
popup->addAction(QWidget::tr("Show subdocuments / attachments"), popup->addAction(QWidget::tr("Show subdocuments / attachments"),
me, SLOT(menuShowSubDocs())); me, SLOT(menuShowSubDocs()));
return popup; return popup;
@ -163,13 +155,10 @@ Rcl::Doc getFolder(Rcl::Doc& doc)
static const std::string twoslash{"//"}; static const std::string twoslash{"//"};
void copyPath(const Rcl::Doc &doc) void copyPath(const Rcl::Doc &doc)
{ {
auto pos = doc.url.find(twoslash); auto path = fileurltolocalpath(doc.url);
std::string path; #ifdef _WIN32
if (pos == std::string::npos) { path_backslashize(path);
path = doc.url; // ?? #endif
} else {
path = doc.url.substr(pos+2);
}
// Problem: setText expects a QString. Passing a (const char*) as // Problem: setText expects a QString. Passing a (const char*) as
// we used to do causes an implicit conversion from latin1. File // we used to do causes an implicit conversion from latin1. File
// are binary and the right approach would be no conversion, but // are binary and the right approach would be no conversion, but