forked from qt-creator/qt-creator
Move "Web Search" locator filter from Help to Core
It was invented as a "remote help" filter, but it actually doesn't have anything to do with help or documentation. Move it to more general place, also to enable future generalization to another custom filter type. Change-Id: Ib80eacd3c7cc33ae9f4d9353fa820272e3b0b25f Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -20,7 +20,6 @@ add_qtc_plugin(Help
|
||||
openpagesmanager.cpp openpagesmanager.h
|
||||
openpagesswitcher.cpp openpagesswitcher.h
|
||||
openpageswidget.cpp openpageswidget.h
|
||||
remotehelpfilter.cpp remotehelpfilter.h remotehelpfilter.ui
|
||||
searchtaskhandler.cpp searchtaskhandler.h
|
||||
searchwidget.cpp searchwidget.h
|
||||
textbrowserhelpviewer.cpp textbrowserhelpviewer.h
|
||||
|
||||
@@ -23,7 +23,6 @@ HEADERS += \
|
||||
openpagesmanager.h \
|
||||
openpagesswitcher.h \
|
||||
openpageswidget.h \
|
||||
remotehelpfilter.h \
|
||||
searchwidget.h \
|
||||
xbelsupport.h \
|
||||
searchtaskhandler.h \
|
||||
@@ -44,7 +43,6 @@ SOURCES += \
|
||||
openpagesmanager.cpp \
|
||||
openpagesswitcher.cpp \
|
||||
openpageswidget.cpp \
|
||||
remotehelpfilter.cpp \
|
||||
searchwidget.cpp \
|
||||
xbelsupport.cpp \
|
||||
searchtaskhandler.cpp \
|
||||
@@ -53,8 +51,7 @@ SOURCES += \
|
||||
|
||||
FORMS += docsettingspage.ui \
|
||||
filtersettingspage.ui \
|
||||
generalsettingspage.ui \
|
||||
remotehelpfilter.ui
|
||||
generalsettingspage.ui
|
||||
|
||||
!isEmpty(QT.webenginewidgets.name) {
|
||||
QT += webenginewidgets
|
||||
|
||||
@@ -44,7 +44,6 @@ QtcPlugin {
|
||||
"openpagesmanager.cpp", "openpagesmanager.h",
|
||||
"openpagesswitcher.cpp", "openpagesswitcher.h",
|
||||
"openpageswidget.cpp", "openpageswidget.h",
|
||||
"remotehelpfilter.cpp", "remotehelpfilter.h", "remotehelpfilter.ui",
|
||||
"searchtaskhandler.cpp", "searchtaskhandler.h",
|
||||
"searchwidget.cpp", "searchwidget.h",
|
||||
"textbrowserhelpviewer.cpp", "textbrowserhelpviewer.h",
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "helpwidget.h"
|
||||
#include "localhelpmanager.h"
|
||||
#include "openpagesmanager.h"
|
||||
#include "remotehelpfilter.h"
|
||||
#include "searchtaskhandler.h"
|
||||
#include "searchwidget.h"
|
||||
#include "topicchooser.h"
|
||||
@@ -155,7 +154,6 @@ public:
|
||||
LocalHelpManager m_localHelpManager;
|
||||
|
||||
HelpIndexFilter helpIndexFilter;
|
||||
RemoteHelpFilter remoteHelpFilter;
|
||||
};
|
||||
|
||||
static HelpPluginPrivate *dd = nullptr;
|
||||
@@ -281,9 +279,6 @@ HelpPluginPrivate::HelpPluginPrivate()
|
||||
connect(&helpIndexFilter, &HelpIndexFilter::linksActivated,
|
||||
this, &HelpPluginPrivate::showLinksInCurrentViewer);
|
||||
|
||||
connect(&remoteHelpFilter, &RemoteHelpFilter::linkActivated,
|
||||
this, &QDesktopServices::openUrl);
|
||||
|
||||
QDesktopServices::setUrlHandler("qthelp", HelpManager::instance(), "showHelpUrl");
|
||||
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
||||
this, &HelpPluginPrivate::modeChanged);
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "remotehelpfilter.h"
|
||||
|
||||
#include <QMutexLocker>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
RemoteFilterOptions::RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_filter(filter)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
setWindowTitle(Core::ILocatorFilter::msgConfigureDialogTitle());
|
||||
m_ui.prefixLabel->setText(Core::ILocatorFilter::msgPrefixLabel());
|
||||
m_ui.prefixLabel->setToolTip(Core::ILocatorFilter::msgPrefixToolTip());
|
||||
m_ui.includeByDefault->setText(Core::ILocatorFilter::msgIncludeByDefault());
|
||||
m_ui.includeByDefault->setToolTip(Core::ILocatorFilter::msgIncludeByDefaultToolTip());
|
||||
m_ui.shortcutEdit->setText(m_filter->shortcutString());
|
||||
m_ui.includeByDefault->setChecked(m_filter->isIncludedByDefault());
|
||||
|
||||
const QStringList remoteUrls = m_filter->remoteUrls();
|
||||
for (const QString &url : remoteUrls) {
|
||||
auto item = new QListWidgetItem(url);
|
||||
m_ui.listWidget->addItem(item);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
}
|
||||
|
||||
connect(m_ui.add, &QPushButton::clicked,
|
||||
this, &RemoteFilterOptions::addNewItem);
|
||||
connect(m_ui.remove, &QPushButton::clicked,
|
||||
this, &RemoteFilterOptions::removeItem);
|
||||
connect(m_ui.moveUp, &QPushButton::clicked,
|
||||
this, &RemoteFilterOptions::moveItemUp);
|
||||
connect(m_ui.moveDown, &QPushButton::clicked,
|
||||
this, &RemoteFilterOptions::moveItemDown);
|
||||
connect(m_ui.listWidget, &QListWidget::currentItemChanged,
|
||||
this, &RemoteFilterOptions::updateActionButtons);
|
||||
updateActionButtons();
|
||||
}
|
||||
|
||||
void RemoteFilterOptions::addNewItem()
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(tr("Double-click to edit item."));
|
||||
m_ui.listWidget->addItem(item);
|
||||
item->setSelected(true);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
m_ui.listWidget->setCurrentItem(item);
|
||||
m_ui.listWidget->editItem(item);
|
||||
}
|
||||
|
||||
void RemoteFilterOptions::removeItem()
|
||||
{
|
||||
if (QListWidgetItem *item = m_ui.listWidget->currentItem()) {
|
||||
m_ui.listWidget->removeItemWidget(item);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteFilterOptions::moveItemUp()
|
||||
{
|
||||
const int row = m_ui.listWidget->currentRow();
|
||||
if (row > 0) {
|
||||
QListWidgetItem *item = m_ui.listWidget->takeItem(row);
|
||||
m_ui.listWidget->insertItem(row - 1, item);
|
||||
m_ui.listWidget->setCurrentRow(row - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteFilterOptions::moveItemDown()
|
||||
{
|
||||
const int row = m_ui.listWidget->currentRow();
|
||||
if (row >= 0 && row < m_ui.listWidget->count() - 1) {
|
||||
QListWidgetItem *item = m_ui.listWidget->takeItem(row);
|
||||
m_ui.listWidget->insertItem(row + 1, item);
|
||||
m_ui.listWidget->setCurrentRow(row + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteFilterOptions::updateActionButtons()
|
||||
{
|
||||
m_ui.remove->setEnabled(m_ui.listWidget->currentItem());
|
||||
const int row = m_ui.listWidget->currentRow();
|
||||
m_ui.moveUp->setEnabled(row > 0);
|
||||
m_ui.moveDown->setEnabled(row >= 0 && row < m_ui.listWidget->count() - 1);
|
||||
}
|
||||
|
||||
// -- RemoteHelpFilter
|
||||
|
||||
RemoteHelpFilter::RemoteHelpFilter()
|
||||
{
|
||||
setId("RemoteHelpFilter");
|
||||
setDisplayName(tr("Web Search"));
|
||||
setIncludedByDefault(false);
|
||||
setShortcutString("r");
|
||||
|
||||
m_remoteUrls.append("https://www.bing.com/search?q=%1");
|
||||
m_remoteUrls.append("https://www.google.com/search?q=%1");
|
||||
m_remoteUrls.append("https://search.yahoo.com/search?p=%1");
|
||||
m_remoteUrls.append("https://stackoverflow.com/search?q=%1");
|
||||
m_remoteUrls.append("http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=%1");
|
||||
m_remoteUrls.append("https://en.wikipedia.org/w/index.php?search=%1");
|
||||
}
|
||||
|
||||
RemoteHelpFilter::~RemoteHelpFilter() = default;
|
||||
|
||||
QList<Core::LocatorFilterEntry> RemoteHelpFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry)
|
||||
{
|
||||
QList<Core::LocatorFilterEntry> entries;
|
||||
const QStringList urls = remoteUrls();
|
||||
for (const QString &url : urls) {
|
||||
if (future.isCanceled())
|
||||
break;
|
||||
const QString name = url.arg(entry);
|
||||
Core::LocatorFilterEntry filterEntry(this, name, QVariant(), m_icon);
|
||||
filterEntry.highlightInfo = {name.lastIndexOf(entry), entry.length()};
|
||||
entries.append(filterEntry);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
void RemoteHelpFilter::accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const
|
||||
{
|
||||
Q_UNUSED(newText)
|
||||
Q_UNUSED(selectionStart)
|
||||
Q_UNUSED(selectionLength)
|
||||
const QString &url = selection.displayName;
|
||||
if (!url.isEmpty())
|
||||
emit linkActivated(url);
|
||||
}
|
||||
|
||||
void RemoteHelpFilter::refresh(QFutureInterface<void> &future)
|
||||
{
|
||||
Q_UNUSED(future)
|
||||
// Nothing to refresh
|
||||
}
|
||||
|
||||
QByteArray RemoteHelpFilter::saveState() const
|
||||
{
|
||||
QByteArray value;
|
||||
QDataStream out(&value, QIODevice::WriteOnly);
|
||||
out << m_remoteUrls.join('^');
|
||||
out << shortcutString();
|
||||
out << isIncludedByDefault();
|
||||
return value;
|
||||
}
|
||||
|
||||
void RemoteHelpFilter::restoreState(const QByteArray &state)
|
||||
{
|
||||
QDataStream in(state);
|
||||
|
||||
QString value;
|
||||
in >> value;
|
||||
m_remoteUrls = value.split('^', QString::SkipEmptyParts);
|
||||
|
||||
QString shortcut;
|
||||
in >> shortcut;
|
||||
setShortcutString(shortcut);
|
||||
|
||||
bool defaultFilter;
|
||||
in >> defaultFilter;
|
||||
setIncludedByDefault(defaultFilter);
|
||||
}
|
||||
|
||||
bool RemoteHelpFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
|
||||
{
|
||||
Q_UNUSED(needsRefresh)
|
||||
RemoteFilterOptions optionsDialog(this, parent);
|
||||
if (optionsDialog.exec() == QDialog::Accepted) {
|
||||
QMutexLocker lock(&m_mutex); Q_UNUSED(lock)
|
||||
m_remoteUrls.clear();
|
||||
setIncludedByDefault(optionsDialog.m_ui.includeByDefault->isChecked());
|
||||
setShortcutString(optionsDialog.m_ui.shortcutEdit->text().trimmed());
|
||||
for (int i = 0; i < optionsDialog.m_ui.listWidget->count(); ++i)
|
||||
m_remoteUrls.append(optionsDialog.m_ui.listWidget->item(i)->text());
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList RemoteHelpFilter::remoteUrls() const
|
||||
{
|
||||
QMutexLocker lock(&m_mutex); Q_UNUSED(lock)
|
||||
return m_remoteUrls;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
@@ -1,86 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ui_remotehelpfilter.h"
|
||||
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QMutex>
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
class RemoteHelpFilter : public Core::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RemoteHelpFilter();
|
||||
~RemoteHelpFilter() final;
|
||||
|
||||
// ILocatorFilter
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
void refresh(QFutureInterface<void> &future) override;
|
||||
QByteArray saveState() const override;
|
||||
void restoreState(const QByteArray &state) override;
|
||||
bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;
|
||||
|
||||
QStringList remoteUrls() const;
|
||||
|
||||
signals:
|
||||
void linkActivated(const QUrl &url) const;
|
||||
|
||||
private:
|
||||
QIcon m_icon;
|
||||
QStringList m_remoteUrls;
|
||||
mutable QMutex m_mutex;
|
||||
};
|
||||
|
||||
class RemoteFilterOptions : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class RemoteHelpFilter;
|
||||
|
||||
public:
|
||||
explicit RemoteFilterOptions(RemoteHelpFilter *filter, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void addNewItem();
|
||||
void removeItem();
|
||||
void moveItemUp();
|
||||
void moveItemDown();
|
||||
void updateActionButtons();
|
||||
|
||||
RemoteHelpFilter *m_filter = nullptr;
|
||||
Ui::RemoteFilterOptions m_ui;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Help
|
||||
@@ -1,187 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Help::Internal::RemoteFilterOptions</class>
|
||||
<widget class="QDialog" name="Help::Internal::RemoteFilterOptions">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Filter Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="prefixLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Prefix:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>shortcutEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="shortcutEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="includeByDefault">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Include by default</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="moveUp">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="moveDown">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>21</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Help::Internal::RemoteFilterOptions</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Help::Internal::RemoteFilterOptions</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user