diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index ff9e253ea9e..8ca5c57bf4b 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -259,6 +259,8 @@ QtcPlugin { "directoryfilter.ui", "executefilter.cpp", "executefilter.h", + "externaltoolsfilter.cpp", + "externaltoolsfilter.h", "filesystemfilter.cpp", "filesystemfilter.h", "filesystemfilter.ui", diff --git a/src/plugins/coreplugin/locator/externaltoolsfilter.cpp b/src/plugins/coreplugin/locator/externaltoolsfilter.cpp new file mode 100644 index 00000000000..29802cd03b9 --- /dev/null +++ b/src/plugins/coreplugin/locator/externaltoolsfilter.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "externaltoolsfilter.h" + +using namespace Core; +using namespace Core::Internal; + +ExternalToolsFilter::ExternalToolsFilter() +{ + setId("Run external tool"); + setDisplayName(tr("Run External Tool")); + setShortcutString(QLatin1String("x")); + setPriority(Medium); +} + +QList ExternalToolsFilter::matchesFor(QFutureInterface &, + const QString &) +{ + return m_results; +} + +void ExternalToolsFilter::accept(LocatorFilterEntry selection) const +{ + auto tool = selection.internalData.value(); + QTC_ASSERT(tool, return); + + auto runner = new ExternalToolRunner(tool); + if (runner->hasError()) + MessageManager::write(runner->errorString()); +} + +void ExternalToolsFilter::refresh(QFutureInterface &) +{ +} + +void ExternalToolsFilter::prepareSearch(const QString &entry) +{ + m_results.clear(); + + Qt::CaseSensitivity useCaseSensitivity = caseSensitivity(entry); + const QMap externalToolsById = ExternalToolManager::toolsById(); + auto end = externalToolsById.cend(); + for (auto it = externalToolsById.cbegin(); it != end; ++it) { + ExternalTool *tool = *it; + if (tool->description().contains(entry, useCaseSensitivity) || + tool->displayName().contains(entry, useCaseSensitivity)) { + + LocatorFilterEntry filterEntry(this, tool->displayName(), QVariant::fromValue(tool)); + filterEntry.extraInfo = tool->description(); + m_results.append(filterEntry); + } + } +} diff --git a/src/plugins/coreplugin/locator/externaltoolsfilter.h b/src/plugins/coreplugin/locator/externaltoolsfilter.h new file mode 100644 index 00000000000..7301c80d29b --- /dev/null +++ b/src/plugins/coreplugin/locator/externaltoolsfilter.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://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 http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef EXTERNALTOOLSFILTER_H +#define EXTERNALTOOLSFILTER_H + +#include "ilocatorfilter.h" + +namespace Core { +namespace Internal { + +class ExternalToolsFilter : public ILocatorFilter +{ + Q_OBJECT +public: + ExternalToolsFilter(); + + QList matchesFor(QFutureInterface &future, + const QString &entry) override; + void accept(LocatorFilterEntry selection) const override; + void refresh(QFutureInterface &future) override; + void prepareSearch(const QString &entry) override; + +private: + QList m_results; +}; + +} // namespace Internal +} // namespace Core + +#endif // EXTERNALTOOLSFILTER_H diff --git a/src/plugins/coreplugin/locator/locator.cpp b/src/plugins/coreplugin/locator/locator.cpp index f79043fd4bf..095ffa57ded 100644 --- a/src/plugins/coreplugin/locator/locator.cpp +++ b/src/plugins/coreplugin/locator/locator.cpp @@ -36,6 +36,7 @@ #include "opendocumentsfilter.h" #include "filesystemfilter.h" #include "locatorsettingspage.h" +#include "externaltoolsfilter.h" #include #include @@ -79,10 +80,12 @@ Locator::~Locator() m_corePlugin->removeObject(m_fileSystemFilter); m_corePlugin->removeObject(m_executeFilter); m_corePlugin->removeObject(m_settingsPage); + m_corePlugin->removeObject(m_externalToolsFilter); delete m_openDocumentsFilter; delete m_fileSystemFilter; delete m_executeFilter; delete m_settingsPage; + delete m_externalToolsFilter; qDeleteAll(m_customFilters); } @@ -122,6 +125,9 @@ void Locator::initialize(CorePlugin *corePlugin, const QStringList &, QString *) m_executeFilter = new ExecuteFilter(); m_corePlugin->addObject(m_executeFilter); + m_externalToolsFilter = new ExternalToolsFilter; + m_corePlugin->addObject(m_externalToolsFilter); + m_corePlugin->addAutoReleasedObject(new LocatorFiltersFilter(this, m_locatorWidget)); #ifdef Q_OS_OSX m_corePlugin->addAutoReleasedObject(new SpotlightLocatorFilter); diff --git a/src/plugins/coreplugin/locator/locator.h b/src/plugins/coreplugin/locator/locator.h index 6c115be7eb6..72cbf41a1d5 100644 --- a/src/plugins/coreplugin/locator/locator.h +++ b/src/plugins/coreplugin/locator/locator.h @@ -50,6 +50,7 @@ class LocatorWidget; class OpenDocumentsFilter; class FileSystemFilter; class LocatorSettingsPage; +class ExternalToolsFilter; class Locator : public QObject { @@ -97,6 +98,7 @@ private: FileSystemFilter *m_fileSystemFilter; ExecuteFilter *m_executeFilter; CorePlugin *m_corePlugin; + ExternalToolsFilter *m_externalToolsFilter; }; template diff --git a/src/plugins/coreplugin/locator/locator.pri b/src/plugins/coreplugin/locator/locator.pri index f687c0bd813..c697437d693 100644 --- a/src/plugins/coreplugin/locator/locator.pri +++ b/src/plugins/coreplugin/locator/locator.pri @@ -12,7 +12,8 @@ HEADERS += \ $$PWD/basefilefilter.h \ $$PWD/executefilter.h \ $$PWD/locatorsearchutils.h \ - $$PWD/locatorsettingspage.h + $$PWD/locatorsettingspage.h \ + $$PWD/externaltoolsfilter.h SOURCES += \ $$PWD/locator.cpp \ @@ -27,7 +28,8 @@ SOURCES += \ $$PWD/ilocatorfilter.cpp \ $$PWD/executefilter.cpp \ $$PWD/locatorsearchutils.cpp \ - $$PWD/locatorsettingspage.cpp + $$PWD/locatorsettingspage.cpp \ + $$PWD/externaltoolsfilter.cpp FORMS += \ $$PWD/filesystemfilter.ui \