From 45f387e791223298f28b020cd8b6c047bef5c9e4 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 13 Jun 2022 12:46:58 +0100 Subject: [PATCH] Restore reslist popup function with webengine. Have popup copy path create a baclslash-separated path on Windows --- src/qtgui/reslist.cpp | 14 +++++++++---- src/qtgui/respopup.cpp | 45 ++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 0ec24700..575d4d1d 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -224,11 +224,17 @@ string QtGuiResListPager::prevUrl() string QtGuiResListPager::headerContent() { - return prefs.htmlHeaderContents(); + string out; +#if defined(USING_WEBENGINE) + out += "\n"; +#endif + + return out + prefs.htmlHeaderContents(); } -void QtGuiResListPager::suggest(const vectoruterms, - map >& sugg) +void QtGuiResListPager::suggest(const vectoruterms, map >& sugg) { sugg.clear(); 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 value = qsl[i].right(qsl[i].size() - (eq+1)).trimmed(); if (!nm.compare("rcldocnum")) { - m_popDoc = pageFirstDocNum() + atoi(qs2utf8s(value).c_str()); + m_popDoc = pageFirstDocNum() + value.toInt(); } else { LOGERR("onPopupJsDone: unknown key: " << qs2utf8s(nm) << "\n"); } diff --git a/src/qtgui/respopup.cpp b/src/qtgui/respopup.cpp index 1aa0aa56..04c9322d 100644 --- a/src/qtgui/respopup.cpp +++ b/src/qtgui/respopup.cpp @@ -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 * it under the terms of the GNU General Public License as published by @@ -31,11 +31,11 @@ #include "appformime.h" #include "rclmain_w.h" #include "utf8iter.h" +#include "rclutil.h" namespace ResultPopup { -QMenu *create(QWidget *me, int opts, std::shared_ptr source, - Rcl::Doc& doc) +QMenu *create(QWidget *me, int opts, std::shared_ptr source, Rcl::Doc& doc) { QMenu *popup = new QMenu(me); @@ -70,8 +70,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr source, act->setData(v); sub->addAction(act); } - sub->connect(sub, SIGNAL(triggered(QAction *)), me, - SLOT(menuOpenWith(QAction *))); + sub->connect(sub, SIGNAL(triggered(QAction *)), me, SLOT(menuOpenWith(QAction *))); } } @@ -88,8 +87,7 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr source, act->setData(v); sub->addAction(act); } - sub->connect(sub, SIGNAL(triggered(QAction *)), me, - SLOT(menuOpenWith(QAction *))); + sub->connect(sub, SIGNAL(triggered(QAction *)), me, SLOT(menuOpenWith(QAction *))); } } delete ddb; @@ -103,12 +101,10 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr source, popup->addAction(QWidget::tr("Copy Text"), me, SLOT(menuCopyText())); if ((opts&showSaveOne) && !(isFsTop)) - popup->addAction(QWidget::tr("&Write to File"), me, - SLOT(menuSaveToFile())); + popup->addAction(QWidget::tr("&Write to File"), me, SLOT(menuSaveToFile())); if ((opts&showSaveSel)) - popup->addAction(QWidget::tr("Save selection to files"), - me, SLOT(menuSaveSelection())); + popup->addAction(QWidget::tr("Save selection to files"), me, SLOT(menuSaveSelection())); // We now separate preview/open parent, which only makes sense for @@ -117,25 +113,21 @@ QMenu *create(QWidget *me, int opts, std::shared_ptr source, Rcl::Doc pdoc; bool isEnclosed = source && source->getEnclosing(doc, pdoc); if (isEnclosed) { - popup->addAction(QWidget::tr("Preview P&arent document/folder"), + popup->addAction(QWidget::tr("Preview P&arent document/folder"), me, SLOT(menuPreviewParent())); - popup->addAction(QWidget::tr("&Open Parent document"), - me, SLOT(menuOpenParent())); + popup->addAction(QWidget::tr("&Open Parent document"), me, SLOT(menuOpenParent())); } if (doc.isFsFile()) - popup->addAction(QWidget::tr("&Open Parent Folder"), - me, SLOT(menuOpenFolder())); + popup->addAction(QWidget::tr("&Open Parent Folder"), me, SLOT(menuOpenFolder())); if (opts & showExpand) - popup->addAction(QWidget::tr("Find &similar documents"), - me, SLOT(menuExpand())); + popup->addAction(QWidget::tr("Find &similar documents"), me, SLOT(menuExpand())); if (doc.haspages && source && source->snippetsCapable()) - popup->addAction(QWidget::tr("Open &Snippets window"), - me, SLOT(menuShowSnippets())); + popup->addAction(QWidget::tr("Open &Snippets window"), me, SLOT(menuShowSnippets())); if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc)) - popup->addAction(QWidget::tr("Show subdocuments / attachments"), + popup->addAction(QWidget::tr("Show subdocuments / attachments"), me, SLOT(menuShowSubDocs())); return popup; @@ -163,13 +155,10 @@ Rcl::Doc getFolder(Rcl::Doc& doc) static const std::string twoslash{"//"}; void copyPath(const Rcl::Doc &doc) { - auto pos = doc.url.find(twoslash); - std::string path; - if (pos == std::string::npos) { - path = doc.url; // ?? - } else { - path = doc.url.substr(pos+2); - } + auto path = fileurltolocalpath(doc.url); +#ifdef _WIN32 + path_backslashize(path); +#endif // Problem: setText expects a QString. Passing a (const char*) as // we used to do causes an implicit conversion from latin1. File // are binary and the right approach would be no conversion, but