2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "quickopenplugin.h"
|
2009-03-18 16:43:01 +01:00
|
|
|
#include "quickopenconstants.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "quickopenfiltersfilter.h"
|
|
|
|
|
#include "quickopenmanager.h"
|
|
|
|
|
#include "quickopentoolwindow.h"
|
|
|
|
|
#include "opendocumentsfilter.h"
|
|
|
|
|
#include "filesystemfilter.h"
|
|
|
|
|
#include "directoryfilter.h"
|
|
|
|
|
#include "settingspage.h"
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtCore/QtPlugin>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QFuture>
|
|
|
|
|
#include <QtCore/QFutureWatcher>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/baseview.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-05-19 19:20:53 +02:00
|
|
|
#include <coreplugin/settingsdatabase.h>
|
2009-01-23 13:03:36 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2009-01-23 13:03:36 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <qtconcurrent/QtConcurrentTools>
|
|
|
|
|
|
2009-04-24 16:00:19 +02:00
|
|
|
/*!
|
|
|
|
|
\namespace QuickOpen
|
|
|
|
|
The QuickOpen namespace provides the hooks for Locator content.
|
|
|
|
|
*/
|
|
|
|
|
/*!
|
|
|
|
|
\namespace QuickOpen::Internal
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace QuickOpen;
|
|
|
|
|
using namespace QuickOpen::Internal;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
static bool filterLessThan(const IQuickOpenFilter *first, const IQuickOpenFilter *second)
|
|
|
|
|
{
|
|
|
|
|
return first->priority() < second->priority();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickOpenPlugin::QuickOpenPlugin()
|
|
|
|
|
{
|
|
|
|
|
m_refreshTimer.setSingleShot(false);
|
|
|
|
|
connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickOpenPlugin::~QuickOpenPlugin()
|
|
|
|
|
{
|
|
|
|
|
removeObject(m_openDocumentsFilter);
|
|
|
|
|
removeObject(m_fileSystemFilter);
|
|
|
|
|
removeObject(m_settingsPage);
|
|
|
|
|
delete m_openDocumentsFilter;
|
|
|
|
|
delete m_fileSystemFilter;
|
|
|
|
|
delete m_settingsPage;
|
2009-01-13 15:41:33 +01:00
|
|
|
qDeleteAll(m_customFilters);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QuickOpenPlugin::initialize(const QStringList &, QString *)
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2009-01-20 17:14:00 +01:00
|
|
|
m_settingsPage = new SettingsPage(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
addObject(m_settingsPage);
|
|
|
|
|
|
|
|
|
|
m_quickOpenToolWindow = new QuickOpenToolWindow(this);
|
|
|
|
|
m_quickOpenToolWindow->setEnabled(false);
|
2009-01-26 14:49:26 +01:00
|
|
|
Core::BaseView *view = new Core::BaseView;
|
2009-02-20 17:22:16 +01:00
|
|
|
view->setUniqueViewName("QuickOpen");
|
2009-01-26 14:49:26 +01:00
|
|
|
view->setWidget(m_quickOpenToolWindow);
|
|
|
|
|
view->setContext(QList<int>() << core->uniqueIDManager()
|
|
|
|
|
->uniqueIdentifier(QLatin1String("QuickOpenToolWindow")));
|
|
|
|
|
view->setDefaultPosition(Core::IView::First);
|
2008-12-02 12:01:29 +01:00
|
|
|
addAutoReleasedObject(view);
|
|
|
|
|
|
2009-02-20 17:22:16 +01:00
|
|
|
const QString actionId = QLatin1String("QtCreator.QuickOpen");
|
2008-12-02 12:01:29 +01:00
|
|
|
QAction *action = new QAction(m_quickOpenToolWindow->windowIcon(), m_quickOpenToolWindow->windowTitle(), this);
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd = core->actionManager()->registerAction(action, actionId, QList<int>() << Core::Constants::C_GLOBAL_ID);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence("Ctrl+K"));
|
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(openQuickOpen()));
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
Core::ActionContainer *mtools = core->actionManager()->actionContainer(Core::Constants::M_TOOLS);
|
2008-12-02 12:01:29 +01:00
|
|
|
mtools->addAction(cmd);
|
|
|
|
|
|
|
|
|
|
addObject(new QuickOpenManager(m_quickOpenToolWindow));
|
|
|
|
|
|
|
|
|
|
m_openDocumentsFilter = new OpenDocumentsFilter(core->editorManager());
|
|
|
|
|
addObject(m_openDocumentsFilter);
|
|
|
|
|
|
|
|
|
|
m_fileSystemFilter = new FileSystemFilter(core->editorManager(), m_quickOpenToolWindow);
|
|
|
|
|
addObject(m_fileSystemFilter);
|
|
|
|
|
|
|
|
|
|
addAutoReleasedObject(new QuickOpenFiltersFilter(this, m_quickOpenToolWindow));
|
|
|
|
|
|
|
|
|
|
connect(core, SIGNAL(coreOpened()), this, SLOT(startSettingsLoad()));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::openQuickOpen()
|
|
|
|
|
{
|
|
|
|
|
m_quickOpenToolWindow->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
m_filters = ExtensionSystem::PluginManager::instance()->getObjects<IQuickOpenFilter>();
|
|
|
|
|
qSort(m_filters.begin(), m_filters.end(), filterLessThan);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::startSettingsLoad()
|
|
|
|
|
{
|
|
|
|
|
m_loadWatcher.setFuture(QtConcurrent::run(this, &QuickOpenPlugin::loadSettings));
|
|
|
|
|
connect(&m_loadWatcher, SIGNAL(finished()), this, SLOT(settingsLoaded()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::loadSettings()
|
|
|
|
|
{
|
2009-05-19 19:20:53 +02:00
|
|
|
Core::SettingsDatabase *settings = Core::ICore::instance()->settingsDatabase();
|
|
|
|
|
settings->beginGroup("QuickOpen");
|
|
|
|
|
m_refreshTimer.setInterval(settings->value("RefreshInterval", 60).toInt() * 60000);
|
2009-01-13 15:41:33 +01:00
|
|
|
foreach (IQuickOpenFilter *filter, m_filters) {
|
2009-05-19 19:20:53 +02:00
|
|
|
if (settings->contains(filter->name())) {
|
|
|
|
|
const QByteArray state = settings->value(filter->name()).toByteArray();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!state.isEmpty())
|
|
|
|
|
filter->restoreState(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-05-19 19:20:53 +02:00
|
|
|
settings->beginGroup("CustomFilters");
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<IQuickOpenFilter *> customFilters;
|
2009-05-19 19:20:53 +02:00
|
|
|
foreach (const QString &key, settings->childKeys()) {
|
2009-01-20 15:31:33 +01:00
|
|
|
IQuickOpenFilter *filter = new DirectoryFilter;
|
2009-05-19 19:20:53 +02:00
|
|
|
filter->restoreState(settings->value(key).toByteArray());
|
2009-01-13 15:41:33 +01:00
|
|
|
m_filters.append(filter);
|
2008-12-02 12:01:29 +01:00
|
|
|
customFilters.append(filter);
|
|
|
|
|
}
|
2009-01-13 15:41:33 +01:00
|
|
|
setCustomFilters(customFilters);
|
2009-05-19 19:20:53 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
settings->endGroup();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::settingsLoaded()
|
|
|
|
|
{
|
|
|
|
|
m_quickOpenToolWindow->updateFilterList();
|
|
|
|
|
m_quickOpenToolWindow->setEnabled(true);
|
|
|
|
|
m_refreshTimer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::saveSettings()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2009-05-19 19:20:53 +02:00
|
|
|
if (core && core->settingsDatabase()) {
|
|
|
|
|
Core::SettingsDatabase *s = core->settingsDatabase();
|
2008-12-02 12:01:29 +01:00
|
|
|
s->beginGroup("QuickOpen");
|
2009-01-20 11:52:04 +01:00
|
|
|
s->setValue("Interval", m_refreshTimer.interval() / 60000);
|
2008-12-02 12:01:29 +01:00
|
|
|
s->remove("");
|
2009-01-13 15:41:33 +01:00
|
|
|
foreach (IQuickOpenFilter *filter, m_filters) {
|
2009-01-20 11:52:04 +01:00
|
|
|
if (!m_customFilters.contains(filter))
|
2008-12-02 12:01:29 +01:00
|
|
|
s->setValue(filter->name(), filter->saveState());
|
|
|
|
|
}
|
|
|
|
|
s->beginGroup("CustomFilters");
|
|
|
|
|
int i = 0;
|
2009-01-13 15:41:33 +01:00
|
|
|
foreach (IQuickOpenFilter *filter, m_customFilters) {
|
2008-12-02 12:01:29 +01:00
|
|
|
s->setValue(QString("directory%1").arg(i), filter->saveState());
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
s->endGroup();
|
|
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QList<IQuickOpenFilter*> QuickOpenPlugin::filter()
|
|
|
|
|
|
|
|
|
|
Return all filters, including the ones created by the user.
|
|
|
|
|
*/
|
2009-01-13 15:41:33 +01:00
|
|
|
QList<IQuickOpenFilter*> QuickOpenPlugin::filters()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
return m_filters;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QList<IQuickOpenFilter*> QuickOpenPlugin::customFilter()
|
|
|
|
|
|
|
|
|
|
This returns a subset of all the filters, that contains only the filters that
|
|
|
|
|
have been created by the user at some point (maybe in a previous session).
|
|
|
|
|
*/
|
2009-01-13 15:41:33 +01:00
|
|
|
QList<IQuickOpenFilter*> QuickOpenPlugin::customFilters()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
return m_customFilters;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void QuickOpenPlugin::setFilters(QList<IQuickOpenFilter*> f)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
m_filters = f;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_quickOpenToolWindow->updateFilterList();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void QuickOpenPlugin::setCustomFilters(QList<IQuickOpenFilter *> filters)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
m_customFilters = filters;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int QuickOpenPlugin::refreshInterval()
|
|
|
|
|
{
|
|
|
|
|
return m_refreshTimer.interval()/60000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::setRefreshInterval(int interval)
|
|
|
|
|
{
|
|
|
|
|
if (interval < 1) {
|
|
|
|
|
m_refreshTimer.stop();
|
|
|
|
|
m_refreshTimer.setInterval(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_refreshTimer.setInterval(interval*60000);
|
|
|
|
|
m_refreshTimer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QuickOpenPlugin::refresh(QList<IQuickOpenFilter*> filters)
|
|
|
|
|
{
|
|
|
|
|
if (filters.isEmpty())
|
2009-01-13 15:41:33 +01:00
|
|
|
filters = m_filters;
|
2008-12-02 12:01:29 +01:00
|
|
|
QFuture<void> task = QtConcurrent::run(&IQuickOpenFilter::refresh, filters);
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::FutureProgress *progress = Core::ICore::instance()
|
2009-03-18 16:43:01 +01:00
|
|
|
->progressManager()->addTask(task, tr("Indexing"), QuickOpen::Constants::TASK_INDEX, Core::ProgressManager::CloseOnSuccess);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(progress, SIGNAL(finished()), this, SLOT(saveSettings()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(QuickOpenPlugin)
|