forked from qt-creator/qt-creator
Move wizard list generating helper methods to IWizard.
They don't have anything to do specifically with file wizards.
This commit is contained in:
@@ -578,26 +578,6 @@ BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &l
|
|||||||
return yes ? OverwriteOk : OverwriteCanceled;
|
return yes ? OverwriteOk : OverwriteCanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IWizard*> BaseFileWizard::allWizards()
|
|
||||||
{
|
|
||||||
return ExtensionSystem::PluginManager::instance()->getObjects<IWizard>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Utility to find all registered wizards of a certain kind
|
|
||||||
|
|
||||||
class WizardKindPredicate {
|
|
||||||
public:
|
|
||||||
WizardKindPredicate(IWizard::Kind kind) : m_kind(kind) {}
|
|
||||||
bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
|
|
||||||
private:
|
|
||||||
const IWizard::Kind m_kind;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<IWizard*> BaseFileWizard::findWizardsOfKind(Kind kind)
|
|
||||||
{
|
|
||||||
return findWizards(WizardKindPredicate(kind));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString BaseFileWizard::buildFileName(const QString &path,
|
QString BaseFileWizard::buildFileName(const QString &path,
|
||||||
const QString &baseName,
|
const QString &baseName,
|
||||||
const QString &extension)
|
const QString &extension)
|
||||||
|
|||||||
@@ -151,11 +151,6 @@ public:
|
|||||||
|
|
||||||
virtual QStringList runWizard(const QString &path, QWidget *parent);
|
virtual QStringList runWizard(const QString &path, QWidget *parent);
|
||||||
|
|
||||||
// Utility to find all registered wizards
|
|
||||||
static QList<IWizard*> allWizards();
|
|
||||||
// Utility to find all registered wizards of a certain kind
|
|
||||||
static QList<IWizard*> findWizardsOfKind(Kind kind);
|
|
||||||
|
|
||||||
// Build a file name, adding the extension unless baseName already has one
|
// Build a file name, adding the extension unless baseName already has one
|
||||||
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
|
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
|
||||||
|
|
||||||
@@ -222,20 +217,6 @@ protected:
|
|||||||
QString *errorMessage) const = 0;
|
QString *errorMessage) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A utility to find all wizards supporting a view mode and matching a predicate */
|
|
||||||
template <class Predicate>
|
|
||||||
QList<IWizard*> findWizards(Predicate predicate)
|
|
||||||
{
|
|
||||||
// Filter all wizards
|
|
||||||
const QList<IWizard*> allWizards = BaseFileWizard::allWizards();
|
|
||||||
QList<IWizard*> rc;
|
|
||||||
const QList<IWizard*>::const_iterator cend = allWizards.constEnd();
|
|
||||||
for (QList<IWizard*>::const_iterator it = allWizards.constBegin(); it != cend; ++it)
|
|
||||||
if (predicate(*(*it)))
|
|
||||||
rc.push_back(*it);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
#endif // BASEFILEWIZARD_H
|
#endif // BASEFILEWIZARD_H
|
||||||
|
|||||||
@@ -1,5 +1,36 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** Commercial Usage
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** 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 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.
|
||||||
|
**
|
||||||
|
** If you are unsure which license is appropriate for your use, please
|
||||||
|
** contact the sales department at qt-sales@nokia.com.
|
||||||
|
**
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
#include "iwizard.h"
|
#include "iwizard.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Core::IWizard
|
\class Core::IWizard
|
||||||
\mainclass
|
\mainclass
|
||||||
@@ -95,3 +126,40 @@
|
|||||||
default path.
|
default path.
|
||||||
Returns a list of files (absolute paths) that have been created, if any.
|
Returns a list of files (absolute paths) that have been created, if any.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
|
/* A utility to find all wizards supporting a view mode and matching a predicate */
|
||||||
|
template <class Predicate>
|
||||||
|
QList<IWizard*> findWizards(Predicate predicate)
|
||||||
|
{
|
||||||
|
// Filter all wizards
|
||||||
|
const QList<IWizard*> allWizards = IWizard::allWizards();
|
||||||
|
QList<IWizard*> rc;
|
||||||
|
const QList<IWizard*>::const_iterator cend = allWizards.constEnd();
|
||||||
|
for (QList<IWizard*>::const_iterator it = allWizards.constBegin(); it != cend; ++it)
|
||||||
|
if (predicate(*(*it)))
|
||||||
|
rc.push_back(*it);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<IWizard*> IWizard::allWizards()
|
||||||
|
{
|
||||||
|
return ExtensionSystem::PluginManager::instance()->getObjects<IWizard>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility to find all registered wizards of a certain kind
|
||||||
|
|
||||||
|
class WizardKindPredicate {
|
||||||
|
public:
|
||||||
|
WizardKindPredicate(IWizard::Kind kind) : m_kind(kind) {}
|
||||||
|
bool operator()(const IWizard &w) const { return w.kind() == m_kind; }
|
||||||
|
private:
|
||||||
|
const IWizard::Kind m_kind;
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<IWizard*> IWizard::wizardsOfKind(Kind kind)
|
||||||
|
{
|
||||||
|
return findWizards(WizardKindPredicate(kind));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public:
|
|||||||
virtual QString trCategory() const = 0;
|
virtual QString trCategory() const = 0;
|
||||||
|
|
||||||
virtual QStringList runWizard(const QString &path, QWidget *parent) = 0;
|
virtual QStringList runWizard(const QString &path, QWidget *parent) = 0;
|
||||||
|
|
||||||
|
// Utility to find all registered wizards
|
||||||
|
static QList<IWizard*> allWizards();
|
||||||
|
// Utility to find all registered wizards of a certain kind
|
||||||
|
static QList<IWizard*> wizardsOfKind(Kind kind);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -760,7 +760,7 @@ void MainWindow::registerDefaultActions()
|
|||||||
|
|
||||||
void MainWindow::newFile()
|
void MainWindow::newFile()
|
||||||
{
|
{
|
||||||
showNewItemDialog(tr("New", "Title of dialog"),BaseFileWizard::allWizards());
|
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openFile()
|
void MainWindow::openFile()
|
||||||
|
|||||||
@@ -797,7 +797,7 @@ void ProjectExplorerPlugin::newProject()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Core::ICore::instance()->showNewItemDialog(tr("New Project", "Title of dialog"),
|
Core::ICore::instance()->showNewItemDialog(tr("New Project", "Title of dialog"),
|
||||||
Core::BaseFileWizard::findWizardsOfKind(Core::IWizard::ProjectWizard),
|
Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
|
||||||
defaultLocation);
|
defaultLocation);
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
@@ -1641,8 +1641,8 @@ void ProjectExplorerPlugin::addNewFile()
|
|||||||
return;
|
return;
|
||||||
const QString location = QFileInfo(m_currentNode->path()).dir().absolutePath();
|
const QString location = QFileInfo(m_currentNode->path()).dir().absolutePath();
|
||||||
Core::ICore::instance()->showNewItemDialog(tr("New File", "Title of dialog"),
|
Core::ICore::instance()->showNewItemDialog(tr("New File", "Title of dialog"),
|
||||||
Core::BaseFileWizard::findWizardsOfKind(Core::IWizard::FileWizard)
|
Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard)
|
||||||
+ Core::BaseFileWizard::findWizardsOfKind(Core::IWizard::ClassWizard),
|
+ Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard),
|
||||||
location);
|
location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user