forked from qt-creator/qt-creator
Core: simplify ILocator interface
Use data members instead of virtual functions for id, displayName and priority, use Core::Id, not QStrings for id, de-pimpl CommandLocator. Change-Id: Id8b41f184cb995138b2d76c923d6d3ae02b7e3f5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -45,6 +45,8 @@ using namespace Utils;
|
||||
|
||||
CMakeLocatorFilter::CMakeLocatorFilter()
|
||||
{
|
||||
setId("Build CMake target");
|
||||
setDisplayName(tr("Build CMake target"));
|
||||
setShortcutString(QLatin1String("cm"));
|
||||
|
||||
ProjectExplorer::SessionManager *sm = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
|
||||
|
@@ -45,10 +45,6 @@ public:
|
||||
CMakeLocatorFilter();
|
||||
~CMakeLocatorFilter();
|
||||
|
||||
QString displayName() const { return tr("Build CMake target"); }
|
||||
QString id() const { return QLatin1String("Build CMake target"); }
|
||||
Priority priority() const { return Medium; }
|
||||
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -270,9 +270,9 @@ public:
|
||||
// Helpers to sort by category. id
|
||||
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
|
||||
{
|
||||
if (const int cc = p1->category().toString().compare(p2->category().toString()))
|
||||
return cc < 0;
|
||||
return p1->id().toString().compare(p2->id().toString()) < 0;
|
||||
if (p1->category() != p2->category())
|
||||
return p1->category().alphabeticallyBefore(p2->category());
|
||||
return p1->id().alphabeticallyBefore(p2->id());
|
||||
}
|
||||
|
||||
static inline QList<Core::IOptionsPage*> sortedOptionsPages()
|
||||
|
@@ -323,4 +323,9 @@ CORE_EXPORT const char *nameForId(int id)
|
||||
return stringFromId.value(id).str;
|
||||
}
|
||||
|
||||
bool Id::alphabeticallyBefore(Id other) const
|
||||
{
|
||||
return toString().compare(other.toString(), Qt::CaseInsensitive) < 0;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
@@ -64,6 +64,7 @@ public:
|
||||
bool operator!=(const char *name) const { return !operator==(name); }
|
||||
bool operator<(Id id) const { return m_id < id.m_id; }
|
||||
bool operator>(Id id) const { return m_id > id.m_id; }
|
||||
bool alphabeticallyBefore(Id other) const;
|
||||
int uniqueIdentifier() const { return m_id; }
|
||||
static Id fromUniqueIdentifier(int uid) { return Id(uid); }
|
||||
static Id fromString(const QString &str); // FIXME: avoid.
|
||||
|
@@ -35,8 +35,10 @@ using namespace CppTools::Internal;
|
||||
CppClassesFilter::CppClassesFilter(CppModelManager *manager)
|
||||
: CppLocatorFilter(manager)
|
||||
{
|
||||
setId("Classes");
|
||||
setShortcutString(QLatin1String("c"));
|
||||
setIncludedByDefault(false);
|
||||
setDisplayName(tr("C++ Classes"));
|
||||
|
||||
search.setSymbolsToSearchFor(SymbolSearcher::Classes);
|
||||
search.setSeparateScope(true);
|
||||
|
@@ -42,10 +42,6 @@ class CPPTOOLS_EXPORT CppClassesFilter : public Internal::CppLocatorFilter
|
||||
public:
|
||||
CppClassesFilter(Internal::CppModelManager *manager);
|
||||
~CppClassesFilter();
|
||||
|
||||
QString displayName() const { return tr("C++ Classes"); }
|
||||
QString id() const { return QLatin1String("Classes"); }
|
||||
Priority priority() const { return Medium; }
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
@@ -40,6 +40,8 @@ using namespace CPlusPlus;
|
||||
CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager, Core::EditorManager *editorManager)
|
||||
: m_modelManager(manager)
|
||||
{
|
||||
setId("Methods in current Document");
|
||||
setDisplayName(tr("C++ Methods in Current Document"));
|
||||
setShortcutString(QString(QLatin1Char('.')));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
|
@@ -50,9 +50,6 @@ public:
|
||||
CppCurrentDocumentFilter(CppModelManager *manager, Core::EditorManager *editorManager);
|
||||
~CppCurrentDocumentFilter() {}
|
||||
|
||||
QString displayName() const { return tr("C++ Methods in Current Document"); }
|
||||
QString id() const { return QLatin1String("Methods in current Document"); }
|
||||
Priority priority() const { return Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -34,6 +34,8 @@ using namespace CppTools::Internal;
|
||||
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager)
|
||||
: CppLocatorFilter(manager)
|
||||
{
|
||||
setId("Methods");
|
||||
setDisplayName(tr("C++ Methods and Functions"));
|
||||
setShortcutString(QString(QLatin1Char('m')));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
|
@@ -42,10 +42,6 @@ class CppFunctionsFilter : public CppLocatorFilter
|
||||
public:
|
||||
CppFunctionsFilter(CppModelManager *manager);
|
||||
~CppFunctionsFilter();
|
||||
|
||||
QString displayName() const { return tr("C++ Methods and Functions"); }
|
||||
QString id() const { return QLatin1String("Methods"); }
|
||||
Priority priority() const { return Medium; }
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -43,6 +43,8 @@ CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
|
||||
: m_manager(manager),
|
||||
m_forceNewSearchList(true)
|
||||
{
|
||||
setId("Classes and Methods");
|
||||
setDisplayName(tr("C++ Classes and Methods"));
|
||||
setShortcutString(QString(QLatin1Char(':')));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
|
@@ -41,13 +41,11 @@ class CppModelManager;
|
||||
class CppLocatorFilter : public Locator::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CppLocatorFilter(CppModelManager *manager);
|
||||
~CppLocatorFilter();
|
||||
|
||||
QString displayName() const { return tr("C++ Classes and Methods"); }
|
||||
QString id() const { return QLatin1String("Classes and Methods"); }
|
||||
Priority priority() const { return Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -46,8 +46,11 @@ Q_DECLARE_METATYPE(ILocatorFilter*)
|
||||
|
||||
HelpIndexFilter::HelpIndexFilter()
|
||||
{
|
||||
setId("HelpIndexFilter");
|
||||
setDisplayName(tr("Help Index"));
|
||||
setIncludedByDefault(false);
|
||||
setShortcutString(QString(QLatin1Char('?')));
|
||||
|
||||
m_icon = QIcon(QLatin1String(":/help/images/bookmark.png"));
|
||||
}
|
||||
|
||||
@@ -55,21 +58,6 @@ HelpIndexFilter::~HelpIndexFilter()
|
||||
{
|
||||
}
|
||||
|
||||
QString HelpIndexFilter::displayName() const
|
||||
{
|
||||
return tr("Help Index");
|
||||
}
|
||||
|
||||
QString HelpIndexFilter::id() const
|
||||
{
|
||||
return QLatin1String("HelpIndexFilter");
|
||||
}
|
||||
|
||||
ILocatorFilter::Priority HelpIndexFilter::priority() const
|
||||
{
|
||||
return Medium;
|
||||
}
|
||||
|
||||
QList<FilterEntry> HelpIndexFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry)
|
||||
{
|
||||
QStringList keywords;
|
||||
|
@@ -46,9 +46,6 @@ public:
|
||||
~HelpIndexFilter();
|
||||
|
||||
// ILocatorFilter
|
||||
QString displayName() const;
|
||||
QString id() const;
|
||||
Priority priority() const;
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -80,8 +80,11 @@ void RemoteFilterOptions::updateRemoveButton()
|
||||
|
||||
RemoteHelpFilter::RemoteHelpFilter()
|
||||
{
|
||||
setId("RemoteHelpFilter");
|
||||
setDisplayName(tr("Web Search"));
|
||||
setIncludedByDefault(false);
|
||||
setShortcutString(QLatin1String("r"));
|
||||
|
||||
m_remoteUrls.append(QLatin1String("http://www.bing.com/search?q=%1"));
|
||||
m_remoteUrls.append(QLatin1String("http://www.google.com/search?q=%1"));
|
||||
m_remoteUrls.append(QLatin1String("http://search.yahoo.com/search?p=%1"));
|
||||
@@ -93,21 +96,6 @@ RemoteHelpFilter::~RemoteHelpFilter()
|
||||
{
|
||||
}
|
||||
|
||||
QString RemoteHelpFilter::displayName() const
|
||||
{
|
||||
return tr("Web Search");
|
||||
}
|
||||
|
||||
QString RemoteHelpFilter::id() const
|
||||
{
|
||||
return QLatin1String("RemoteHelpFilter");
|
||||
}
|
||||
|
||||
Locator::ILocatorFilter::Priority RemoteHelpFilter::priority() const
|
||||
{
|
||||
return Medium;
|
||||
}
|
||||
|
||||
QList<Locator::FilterEntry> RemoteHelpFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &pattern)
|
||||
{
|
||||
QList<Locator::FilterEntry> entries;
|
||||
|
@@ -47,9 +47,6 @@ public:
|
||||
~RemoteHelpFilter();
|
||||
|
||||
// ILocatorFilter
|
||||
QString displayName() const;
|
||||
QString id() const;
|
||||
Priority priority() const;
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -38,14 +39,8 @@
|
||||
|
||||
namespace Locator {
|
||||
|
||||
struct CommandLocatorPrivate {
|
||||
CommandLocatorPrivate(const QString &prefix,
|
||||
const QString &displayName) :
|
||||
m_prefix(prefix), m_displayName(displayName) {}
|
||||
|
||||
const QString m_prefix;
|
||||
const QString m_displayName;
|
||||
|
||||
struct CommandLocatorPrivate
|
||||
{
|
||||
QList<Core::Command *> commands;
|
||||
};
|
||||
|
||||
@@ -54,8 +49,10 @@ CommandLocator::CommandLocator(const QString &prefix,
|
||||
const QString &shortCutString,
|
||||
QObject *parent) :
|
||||
Locator::ILocatorFilter(parent),
|
||||
d(new CommandLocatorPrivate(prefix, displayName))
|
||||
d(new CommandLocatorPrivate)
|
||||
{
|
||||
setId(Core::Id::fromString(prefix));
|
||||
setDisplayName(displayName);
|
||||
setShortcutString(shortCutString);
|
||||
}
|
||||
|
||||
@@ -69,21 +66,6 @@ void CommandLocator::appendCommand(Core::Command *cmd)
|
||||
d->commands.push_back(cmd);
|
||||
}
|
||||
|
||||
QString CommandLocator::displayName() const
|
||||
{
|
||||
return d->m_displayName;
|
||||
}
|
||||
|
||||
QString CommandLocator::id() const
|
||||
{
|
||||
return d->m_prefix;
|
||||
}
|
||||
|
||||
ILocatorFilter::Priority CommandLocator::priority() const
|
||||
{
|
||||
return Medium;
|
||||
}
|
||||
|
||||
QList<Locator::FilterEntry> CommandLocator::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry)
|
||||
{
|
||||
QList<FilterEntry> filters;
|
||||
|
@@ -32,15 +32,8 @@
|
||||
|
||||
#include "locator_global.h"
|
||||
#include "ilocatorfilter.h"
|
||||
#include <QList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
class Command;
|
||||
}
|
||||
namespace Core { class Command; }
|
||||
|
||||
namespace Locator {
|
||||
/* Command locators: Provides completion for a set of
|
||||
@@ -57,27 +50,18 @@ public:
|
||||
const QString &displayName,
|
||||
const QString &shortCutString,
|
||||
QObject *parent = 0);
|
||||
virtual ~CommandLocator();
|
||||
~CommandLocator();
|
||||
|
||||
void appendCommand(Core::Command *cmd);
|
||||
|
||||
virtual QString displayName() const;
|
||||
virtual QString id() const;
|
||||
virtual Priority priority() const;
|
||||
virtual QList<FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
virtual void accept(FilterEntry selection) const;
|
||||
virtual void refresh(QFutureInterface<void> &future);
|
||||
QList<FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
||||
private:
|
||||
CommandLocatorPrivate *d;
|
||||
};
|
||||
|
||||
inline CommandLocator &operator<<(CommandLocator &locator, Core::Command *cmd)
|
||||
{
|
||||
locator.appendCommand(cmd);
|
||||
return locator;
|
||||
}
|
||||
|
||||
} // namespace Locator
|
||||
|
||||
#endif // COMMANDLOCATOR_H
|
||||
|
@@ -43,11 +43,16 @@ using namespace Locator::Internal;
|
||||
|
||||
DirectoryFilter::DirectoryFilter()
|
||||
: m_name(tr("Generic Directory Filter")),
|
||||
m_filters(QStringList() << QLatin1String("*.h") << QLatin1String("*.cpp")
|
||||
<< QLatin1String("*.ui") << QLatin1String("*.qrc")),
|
||||
m_dialog(0)
|
||||
{
|
||||
setId(Core::Id::fromString(m_name));
|
||||
setIncludedByDefault(true);
|
||||
setDisplayName(m_name);
|
||||
|
||||
m_filters.append(QLatin1String("*.h"));
|
||||
m_filters.append(QLatin1String("*.cpp"));
|
||||
m_filters.append(QLatin1String("*.ui"));
|
||||
m_filters.append(QLatin1String("*.qrc"));
|
||||
}
|
||||
|
||||
QByteArray DirectoryFilter::saveState() const
|
||||
|
@@ -48,9 +48,6 @@ class DirectoryFilter : public BaseFileFilter
|
||||
|
||||
public:
|
||||
DirectoryFilter();
|
||||
QString displayName() const { return m_name; }
|
||||
QString id() const { return m_name; }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Medium; }
|
||||
QByteArray saveState() const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
bool openConfigDialog(QWidget *parent, bool &needsRefresh);
|
||||
|
@@ -41,6 +41,8 @@ using namespace Locator::Internal;
|
||||
|
||||
ExecuteFilter::ExecuteFilter()
|
||||
{
|
||||
setId("Execute custom commands");
|
||||
setDisplayName(tr("Execute Custom Commands"));
|
||||
setShortcutString(QString(QLatin1Char('!')));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
|
@@ -53,9 +53,6 @@ class ExecuteFilter : public Locator::ILocatorFilter
|
||||
|
||||
public:
|
||||
ExecuteFilter();
|
||||
QString displayName() const { return tr("Execute Custom Commands"); }
|
||||
QString id() const { return QLatin1String("Execute custom commands"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future,
|
||||
const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
|
@@ -41,6 +41,8 @@ using namespace Locator::Internal;
|
||||
FileSystemFilter::FileSystemFilter(EditorManager *editorManager, LocatorWidget *locatorWidget)
|
||||
: m_editorManager(editorManager), m_locatorWidget(locatorWidget), m_includeHidden(true)
|
||||
{
|
||||
setId("Files in file system");
|
||||
setDisplayName(tr("Files in File System"));
|
||||
setShortcutString(QString(QLatin1Char('f')));
|
||||
setIncludedByDefault(false);
|
||||
}
|
||||
|
@@ -38,9 +38,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QFutureInterface>
|
||||
|
||||
namespace Core {
|
||||
class EditorManager;
|
||||
}
|
||||
namespace Core { class EditorManager; }
|
||||
|
||||
namespace Locator {
|
||||
namespace Internal {
|
||||
@@ -53,9 +51,6 @@ class FileSystemFilter : public Locator::ILocatorFilter
|
||||
|
||||
public:
|
||||
FileSystemFilter(Core::EditorManager *editorManager, LocatorWidget *locatorWidget);
|
||||
QString displayName() const { return tr("Files in File System"); }
|
||||
QString id() const { return QLatin1String("Files in file system"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
QByteArray saveState() const;
|
||||
|
@@ -40,9 +40,11 @@ using namespace Locator;
|
||||
|
||||
ILocatorFilter::ILocatorFilter(QObject *parent):
|
||||
QObject(parent),
|
||||
m_priority(Medium),
|
||||
m_includedByDefault(false),
|
||||
m_hidden(false),
|
||||
m_enabled(true)
|
||||
m_enabled(true),
|
||||
m_isConfigurable(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -114,9 +116,25 @@ bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ILocatorFilter::trimWildcards(const QString &str)
|
||||
{
|
||||
if (str.isEmpty())
|
||||
return str;
|
||||
int first = 0, last = str.size()-1;
|
||||
const QChar asterisk = QLatin1Char('*');
|
||||
const QChar question = QLatin1Char('?');
|
||||
while (first < str.size() && (str.at(first) == asterisk || str.at(first) == question))
|
||||
++first;
|
||||
while (last >= 0 && (str.at(last) == asterisk || str.at(last) == question))
|
||||
--last;
|
||||
if (first > last)
|
||||
return QString();
|
||||
return str.mid(first, last-first+1);
|
||||
}
|
||||
|
||||
bool ILocatorFilter::isConfigurable() const
|
||||
{
|
||||
return true;
|
||||
return m_isConfigurable;
|
||||
}
|
||||
|
||||
bool ILocatorFilter::isIncludedByDefault() const
|
||||
@@ -144,7 +162,42 @@ bool ILocatorFilter::isEnabled() const
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
Core::Id ILocatorFilter::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
QString ILocatorFilter::displayName() const
|
||||
{
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
ILocatorFilter::Priority ILocatorFilter::priority() const
|
||||
{
|
||||
return m_priority;
|
||||
}
|
||||
|
||||
void ILocatorFilter::setEnabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
void ILocatorFilter::setId(Core::Id id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
void ILocatorFilter::setPriority(Priority priority)
|
||||
{
|
||||
m_priority = priority;
|
||||
}
|
||||
|
||||
void ILocatorFilter::setDisplayName(const QString &displayString)
|
||||
{
|
||||
m_displayName = displayString;
|
||||
}
|
||||
|
||||
void ILocatorFilter::setConfigurable(bool configurable)
|
||||
{
|
||||
m_isConfigurable = configurable;
|
||||
}
|
||||
|
@@ -32,6 +32,8 @@
|
||||
|
||||
#include "locator_global.h"
|
||||
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QFutureInterface>
|
||||
#include <QIcon>
|
||||
@@ -88,14 +90,14 @@ public:
|
||||
ILocatorFilter(QObject *parent = 0);
|
||||
virtual ~ILocatorFilter() {}
|
||||
|
||||
/* Visible name. */
|
||||
virtual QString displayName() const = 0;
|
||||
/* Internal Id. */
|
||||
Core::Id id() const;
|
||||
|
||||
/* Internal name. */
|
||||
virtual QString id() const = 0;
|
||||
/* Visible name. */
|
||||
QString displayName() const;
|
||||
|
||||
/* Selection list order in case of multiple active filters (high goes on top). */
|
||||
virtual Priority priority() const = 0;
|
||||
Priority priority() const;
|
||||
|
||||
/* String to type to use this filter exclusively. */
|
||||
QString shortcutString() const;
|
||||
@@ -124,7 +126,7 @@ public:
|
||||
|
||||
/* If there is a configure dialog available for this filter. The default
|
||||
* implementation returns true. */
|
||||
virtual bool isConfigurable() const;
|
||||
bool isConfigurable() const;
|
||||
|
||||
/* Is this filter used also when the shortcutString is not used? */
|
||||
bool isIncludedByDefault() const;
|
||||
@@ -135,20 +137,7 @@ public:
|
||||
/* Returns whether the filter should be enabled and used in menus. */
|
||||
bool isEnabled() const;
|
||||
|
||||
static QString trimWildcards(const QString &str) {
|
||||
if (str.isEmpty())
|
||||
return str;
|
||||
int first = 0, last = str.size()-1;
|
||||
const QChar asterisk = QLatin1Char('*');
|
||||
const QChar question = QLatin1Char('?');
|
||||
while (first < str.size() && (str.at(first) == asterisk || str.at(first) == question))
|
||||
++first;
|
||||
while (last >= 0 && (str.at(last) == asterisk || str.at(last) == question))
|
||||
--last;
|
||||
if (first > last)
|
||||
return QString();
|
||||
return str.mid(first, last-first+1);
|
||||
}
|
||||
static QString trimWildcards(const QString &str);
|
||||
|
||||
public slots:
|
||||
/* Enable or disable the filter. */
|
||||
@@ -158,12 +147,20 @@ protected:
|
||||
void setShortcutString(const QString &shortcut);
|
||||
void setIncludedByDefault(bool includedByDefault);
|
||||
void setHidden(bool hidden);
|
||||
void setId(Core::Id id);
|
||||
void setPriority(Priority priority);
|
||||
void setDisplayName(const QString &displayString);
|
||||
void setConfigurable(bool configurable);
|
||||
|
||||
private:
|
||||
Core::Id m_id;
|
||||
QString m_shortcut;
|
||||
Priority m_priority;
|
||||
QString m_displayName;
|
||||
bool m_includedByDefault;
|
||||
bool m_hidden;
|
||||
bool m_enabled;
|
||||
bool m_isConfigurable;
|
||||
};
|
||||
|
||||
} // namespace Locator
|
||||
|
@@ -44,23 +44,12 @@ LocatorFiltersFilter::LocatorFiltersFilter(LocatorPlugin *plugin,
|
||||
m_locatorWidget(locatorWidget),
|
||||
m_icon(QIcon(QLatin1String(Core::Constants::ICON_NEXT)))
|
||||
{
|
||||
setId("FiltersFilter");
|
||||
setDisplayName(tr("Available filters"));
|
||||
setIncludedByDefault(true);
|
||||
setHidden(true);
|
||||
}
|
||||
|
||||
QString LocatorFiltersFilter::displayName() const
|
||||
{
|
||||
return tr("Available filters");
|
||||
}
|
||||
|
||||
QString LocatorFiltersFilter::id() const
|
||||
{
|
||||
return QLatin1String("FiltersFilter");
|
||||
}
|
||||
|
||||
ILocatorFilter::Priority LocatorFiltersFilter::priority() const
|
||||
{
|
||||
return High;
|
||||
setPriority(High);
|
||||
setConfigurable(false);
|
||||
}
|
||||
|
||||
QList<FilterEntry> LocatorFiltersFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry)
|
||||
@@ -104,8 +93,3 @@ void LocatorFiltersFilter::refresh(QFutureInterface<void> &future)
|
||||
Q_UNUSED(future)
|
||||
// Nothing to refresh
|
||||
}
|
||||
|
||||
bool LocatorFiltersFilter::isConfigurable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -53,13 +53,9 @@ public:
|
||||
LocatorWidget *locatorWidget);
|
||||
|
||||
// ILocatorFilter
|
||||
QString displayName() const;
|
||||
QString id() const;
|
||||
Priority priority() const;
|
||||
QList<FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
bool isConfigurable() const;
|
||||
|
||||
private:
|
||||
LocatorPlugin *m_plugin;
|
||||
|
@@ -74,9 +74,7 @@ namespace {
|
||||
return true;
|
||||
if (first->priority() > second->priority())
|
||||
return false;
|
||||
if (first->id().compare(second->id(), Qt::CaseInsensitive) < 0)
|
||||
return true;
|
||||
return false;
|
||||
return first->id().alphabeticallyBefore(second->id());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +198,7 @@ void LocatorPlugin::saveSettings()
|
||||
s->setValue(QLatin1String("RefreshInterval"), refreshInterval());
|
||||
foreach (ILocatorFilter *filter, m_filters) {
|
||||
if (!m_customFilters.contains(filter))
|
||||
s->setValue(filter->id(), filter->saveState());
|
||||
s->setValue(filter->id().toString(), filter->saveState());
|
||||
}
|
||||
s->beginGroup(QLatin1String("CustomFilters"));
|
||||
int i = 0;
|
||||
|
@@ -108,8 +108,8 @@ void LocatorPlugin::loadSettingsHelper(S *settings)
|
||||
m_refreshTimer.setInterval(settings->value(QLatin1String("RefreshInterval"), 60).toInt() * 60000);
|
||||
|
||||
foreach (ILocatorFilter *filter, m_filters) {
|
||||
if (settings->contains(filter->id())) {
|
||||
const QByteArray state = settings->value(filter->id()).toByteArray();
|
||||
if (settings->contains(filter->id().toString())) {
|
||||
const QByteArray state = settings->value(filter->id().toString()).toByteArray();
|
||||
if (!state.isEmpty())
|
||||
filter->restoreState(state);
|
||||
}
|
||||
|
@@ -317,37 +317,36 @@ void LocatorWidget::updateFilterList()
|
||||
m_filterMenu->clear();
|
||||
|
||||
// update actions and menu
|
||||
QMap<QString, QAction *> actionCopy = m_filterActionMap;
|
||||
QMap<Id, QAction *> actionCopy = m_filterActionMap;
|
||||
m_filterActionMap.clear();
|
||||
// register new actions, update existent
|
||||
foreach (ILocatorFilter *filter, m_locatorPlugin->filters()) {
|
||||
if (filter->shortcutString().isEmpty() || filter->isHidden())
|
||||
continue;
|
||||
Core::Id locatorId = Core::Id::fromString(QLatin1String("Locator.") + filter->id());
|
||||
Id filterId = filter->id();
|
||||
Id locatorId = filterId.withPrefix("Locator.");
|
||||
QAction *action = 0;
|
||||
Core::Command *cmd = 0;
|
||||
if (!actionCopy.contains(filter->id())) {
|
||||
Command *cmd = 0;
|
||||
if (!actionCopy.contains(filterId)) {
|
||||
// register new action
|
||||
action = new QAction(filter->displayName(), this);
|
||||
cmd = Core::ActionManager::registerAction(action, locatorId,
|
||||
Core::Context(Core::Constants::C_GLOBAL));
|
||||
cmd->setAttribute(Core::Command::CA_UpdateText);
|
||||
cmd = ActionManager::registerAction(action, locatorId,
|
||||
Context(Core::Constants::C_GLOBAL));
|
||||
cmd->setAttribute(Command::CA_UpdateText);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(filterSelected()));
|
||||
action->setData(qVariantFromValue(filter));
|
||||
} else {
|
||||
action = actionCopy.take(filter->id());
|
||||
action->setText(filter->displayName());
|
||||
cmd = Core::ActionManager::command(locatorId);
|
||||
action = actionCopy.take(filterId);
|
||||
action->setText(filterId.toString());
|
||||
cmd = ActionManager::command(locatorId);
|
||||
}
|
||||
m_filterActionMap.insert(filter->id(), action);
|
||||
m_filterActionMap.insert(filterId, action);
|
||||
m_filterMenu->addAction(cmd->action());
|
||||
}
|
||||
|
||||
// unregister actions that are deleted now
|
||||
foreach (const QString &id, actionCopy.keys()) {
|
||||
Core::ActionManager::unregisterAction(actionCopy.value(id),
|
||||
Core::Id::fromString(QLatin1String("Locator.") + id));
|
||||
}
|
||||
foreach (const Id id, actionCopy.keys())
|
||||
ActionManager::unregisterAction(actionCopy.value(id), id.withPrefix("Locator."));
|
||||
qDeleteAll(actionCopy);
|
||||
|
||||
m_filterMenu->addSeparator();
|
||||
|
@@ -95,7 +95,7 @@ private:
|
||||
Utils::FilterLineEdit *m_fileLineEdit;
|
||||
QTimer *m_showPopupTimer;
|
||||
QFutureWatcher<FilterEntry> *m_entriesWatcher;
|
||||
QMap<QString, QAction *> m_filterActionMap;
|
||||
QMap<Core::Id, QAction *> m_filterActionMap;
|
||||
bool m_updateRequested;
|
||||
bool m_acceptRequested;
|
||||
bool m_possibleToolTipRequest;
|
||||
|
@@ -44,12 +44,15 @@ using namespace Utils;
|
||||
OpenDocumentsFilter::OpenDocumentsFilter(EditorManager *editorManager) :
|
||||
m_editorManager(editorManager)
|
||||
{
|
||||
setId("Open documents");
|
||||
setDisplayName(tr("Open Documents"));
|
||||
setShortcutString(QString(QLatin1Char('o')));
|
||||
setIncludedByDefault(true);
|
||||
|
||||
connect(m_editorManager, SIGNAL(editorOpened(Core::IEditor*)),
|
||||
this, SLOT(refreshInternally()));
|
||||
connect(m_editorManager, SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
||||
this, SLOT(refreshInternally()));
|
||||
setShortcutString(QString(QLatin1Char('o')));
|
||||
setIncludedByDefault(true);
|
||||
}
|
||||
|
||||
QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry_)
|
||||
|
@@ -52,9 +52,6 @@ class OpenDocumentsFilter : public Locator::ILocatorFilter
|
||||
|
||||
public:
|
||||
explicit OpenDocumentsFilter(Core::EditorManager *editorManager);
|
||||
QString displayName() const { return tr("Open Documents"); }
|
||||
QString id() const { return QLatin1String("Open documents"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -43,6 +43,8 @@ using namespace Macros::Internal;
|
||||
MacroLocatorFilter::MacroLocatorFilter():
|
||||
m_icon(QPixmap(QLatin1String(":/macros/images/macro.png")))
|
||||
{
|
||||
setId("Macros");
|
||||
setDisplayName(tr("Macros"));
|
||||
setShortcutString(QLatin1String("rm"));
|
||||
}
|
||||
|
||||
|
@@ -48,10 +48,6 @@ public:
|
||||
MacroLocatorFilter();
|
||||
~MacroLocatorFilter();
|
||||
|
||||
QString displayName() const { return tr("Macros"); }
|
||||
QString id() const { return QLatin1String("Macros"); }
|
||||
Priority priority() const { return Medium; }
|
||||
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -42,10 +42,14 @@ using namespace ProjectExplorer::Internal;
|
||||
AllProjectsFilter::AllProjectsFilter(ProjectExplorerPlugin *pe)
|
||||
: m_projectExplorer(pe), m_filesUpToDate(false)
|
||||
{
|
||||
setId("Files in any project");
|
||||
setDisplayName(tr("Files in Any Project"));
|
||||
setShortcutString(QString(QLatin1Char('a')));
|
||||
setPriority(Low);
|
||||
setIncludedByDefault(true);
|
||||
|
||||
connect(m_projectExplorer, SIGNAL(fileListChanged()),
|
||||
this, SLOT(markFilesAsOutOfDate()));
|
||||
setShortcutString(QString(QLatin1Char('a')));
|
||||
setIncludedByDefault(true);
|
||||
}
|
||||
|
||||
void AllProjectsFilter::markFilesAsOutOfDate()
|
||||
|
@@ -47,9 +47,6 @@ class AllProjectsFilter : public Locator::BaseFileFilter
|
||||
|
||||
public:
|
||||
explicit AllProjectsFilter(ProjectExplorerPlugin *pe);
|
||||
QString displayName() const { return tr("Files in Any Project"); }
|
||||
QString id() const { return QLatin1String("Files in any project"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Low; }
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
||||
protected:
|
||||
|
@@ -41,12 +41,14 @@ using namespace ProjectExplorer::Internal;
|
||||
CurrentProjectFilter::CurrentProjectFilter(ProjectExplorerPlugin *pe)
|
||||
: BaseFileFilter(), m_projectExplorer(pe), m_project(0), m_filesUpToDate(false)
|
||||
{
|
||||
m_projectExplorer = pe;
|
||||
setId("Files in current project");
|
||||
setDisplayName(tr("Files in Current Project"));
|
||||
setPriority(Low);
|
||||
setShortcutString(QString(QLatin1Char('p')));
|
||||
setIncludedByDefault(false);
|
||||
|
||||
connect(m_projectExplorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
|
||||
this, SLOT(currentProjectChanged(ProjectExplorer::Project*)));
|
||||
setShortcutString(QString(QLatin1Char('p')));
|
||||
setIncludedByDefault(false);
|
||||
}
|
||||
|
||||
void CurrentProjectFilter::markFilesAsOutOfDate()
|
||||
|
@@ -47,9 +47,6 @@ class CurrentProjectFilter : public Locator::BaseFileFilter
|
||||
|
||||
public:
|
||||
CurrentProjectFilter(ProjectExplorerPlugin *pe);
|
||||
QString displayName() const { return tr("Files in Current Project"); }
|
||||
QString id() const { return QLatin1String("Files in current project"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::Low; }
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
||||
protected:
|
||||
@@ -60,7 +57,6 @@ private slots:
|
||||
void markFilesAsOutOfDate();
|
||||
|
||||
private:
|
||||
|
||||
ProjectExplorerPlugin *m_projectExplorer;
|
||||
Project *m_project;
|
||||
bool m_filesUpToDate;
|
||||
|
@@ -43,6 +43,8 @@ FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent)
|
||||
: Locator::ILocatorFilter(parent)
|
||||
, m_data(data)
|
||||
{
|
||||
setId("Functions");
|
||||
setDisplayName(tr("QML Methods and Functions"));
|
||||
setShortcutString(QString(QLatin1Char('m')));
|
||||
setIncludedByDefault(false);
|
||||
}
|
||||
|
@@ -40,13 +40,11 @@ class LocatorData;
|
||||
class FunctionFilter : public Locator::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FunctionFilter(LocatorData *data, QObject *parent = 0);
|
||||
~FunctionFilter();
|
||||
|
||||
QString displayName() const { return tr("QML Methods and Functions"); }
|
||||
QString id() const { return QLatin1String("Functions"); }
|
||||
Priority priority() const { return Medium; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &future);
|
||||
|
@@ -44,6 +44,9 @@ using namespace TextEditor::Internal;
|
||||
LineNumberFilter::LineNumberFilter(QObject *parent)
|
||||
: ILocatorFilter(parent)
|
||||
{
|
||||
setId("Line in current document");
|
||||
setDisplayName(tr("Line in Current Document"));
|
||||
setPriority(High);
|
||||
setShortcutString(QString(QLatin1Char('l')));
|
||||
setIncludedByDefault(true);
|
||||
}
|
||||
|
@@ -49,9 +49,6 @@ class LineNumberFilter : public Locator::ILocatorFilter
|
||||
public:
|
||||
explicit LineNumberFilter(QObject *parent = 0);
|
||||
|
||||
QString displayName() const { return tr("Line in Current Document"); }
|
||||
QString id() const { return QLatin1String("Line in current document"); }
|
||||
Locator::ILocatorFilter::Priority priority() const { return Locator::ILocatorFilter::High; }
|
||||
QList<Locator::FilterEntry> matchesFor(QFutureInterface<Locator::FilterEntry> &future, const QString &entry);
|
||||
void accept(Locator::FilterEntry selection) const;
|
||||
void refresh(QFutureInterface<void> &) {}
|
||||
|
Reference in New Issue
Block a user