forked from qt-creator/qt-creator
UrlLocatorFilter: Use Acceptor for LocatorFilterEntry
Change-Id: Id4b97a10bc01ab4392d7e7fc6e5890dcd3d42be9 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/stringutils.h>
|
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@@ -19,7 +18,6 @@
|
|||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -176,26 +174,19 @@ QList<Core::LocatorFilterEntry> UrlLocatorFilter::matchesFor(
|
|||||||
if (future.isCanceled())
|
if (future.isCanceled())
|
||||||
break;
|
break;
|
||||||
const QString name = url.arg(entry);
|
const QString name = url.arg(entry);
|
||||||
Core::LocatorFilterEntry filterEntry(this, name);
|
Core::LocatorFilterEntry filterEntry;
|
||||||
|
filterEntry.displayName = name;
|
||||||
|
filterEntry.acceptor = [name] {
|
||||||
|
if (!name.isEmpty())
|
||||||
|
QDesktopServices::openUrl(name);
|
||||||
|
return AcceptResult();
|
||||||
|
};
|
||||||
filterEntry.highlightInfo = {int(name.lastIndexOf(entry)), int(entry.length())};
|
filterEntry.highlightInfo = {int(name.lastIndexOf(entry)), int(entry.length())};
|
||||||
entries.append(filterEntry);
|
entries.append(filterEntry);
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UrlLocatorFilter::accept(const 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())
|
|
||||||
QDesktopServices::openUrl(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char kDisplayNameKey[] = "displayName";
|
const char kDisplayNameKey[] = "displayName";
|
||||||
const char kRemoteUrlsKey[] = "remoteUrls";
|
const char kRemoteUrlsKey[] = "remoteUrls";
|
||||||
|
|
||||||
|
@@ -30,8 +30,6 @@ public:
|
|||||||
// ILocatorFilter
|
// ILocatorFilter
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
|
||||||
void restoreState(const QByteArray &state) override;
|
void restoreState(const QByteArray &state) override;
|
||||||
bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;
|
bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user