Commit 9e2f12c7 authored by Friedemann Kleint's avatar Friedemann Kleint

VCSBase: Add common functionality, make checkout use page lists.

Move GitClient::filterUntrackedFilesOfProject into submit editor.
Make checkout wizards use page lists for greater flexibility.
parent 8908c333
......@@ -59,19 +59,21 @@ QString CheckoutWizard::name() const
return tr("CVS Checkout");
}
QWizardPage *CheckoutWizard::createParameterPage(const QString &path)
QList<QWizardPage*> CheckoutWizard::createParameterPages(const QString &path)
{
CheckoutWizardPage *cwp = new CheckoutWizardPage;
cwp->setPath(path);
return cwp;
QList<QWizardPage*> rc;
rc.push_back(cwp);
return rc;
}
QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QWizardPage *parameterPage,
QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QList<QWizardPage*> &parameterPages,
QString *checkoutPath)
{
// Collect parameters for the checkout command.
// CVS does not allow for checking out into a different directory.
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPage);
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return QSharedPointer<VCSBase::AbstractCheckoutJob>())
const CVSSettings settings = CVSPlugin::cvsPluginInstance()->settings();
const QString binary = settings.cvsCommand;
......
......@@ -47,8 +47,8 @@ public:
protected:
// BaseCheckoutWizard
virtual QWizardPage *createParameterPage(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QWizardPage *parameterPage,
virtual QList<QWizardPage*> createParameterPages(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QList<QWizardPage*> &parameterPage,
QString *checkoutPath);
};
......
......@@ -60,18 +60,20 @@ QString CloneWizard::name() const
return tr("Git Repository Clone");
}
QWizardPage *CloneWizard::createParameterPage(const QString &path)
QList<QWizardPage*> CloneWizard::createParameterPages(const QString &path)
{
CloneWizardPage *cwp = new CloneWizardPage;
cwp->setPath(path);
return cwp;
QList<QWizardPage*> rc;
rc.push_back(cwp);
return rc;
}
QSharedPointer<VCSBase::AbstractCheckoutJob> CloneWizard::createJob(const QWizardPage *parameterPage,
QSharedPointer<VCSBase::AbstractCheckoutJob> CloneWizard::createJob(const QList<QWizardPage*> &parameterPages,
QString *checkoutPath)
{
// Collect parameters for the clone command.
const CloneWizardPage *cwp = qobject_cast<const CloneWizardPage *>(parameterPage);
const CloneWizardPage *cwp = qobject_cast<const CloneWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return QSharedPointer<VCSBase::AbstractCheckoutJob>())
const GitClient *client = GitPlugin::instance()->gitClient();
QStringList args = client->binary();
......
......@@ -47,8 +47,8 @@ public:
protected:
// BaseCheckoutWizard
virtual QWizardPage *createParameterPage(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QWizardPage *parameterPage,
virtual QList<QWizardPage*> createParameterPages(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QList<QWizardPage*> &parameterPages,
QString *checkoutPath);
};
......
......@@ -684,25 +684,6 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
return StatusChanged;
}
// Filter out untracked files that are not part of the project
static void filterUntrackedFilesOfProject(const QString &repoDir, QStringList *l)
{
if (l->empty())
return;
const QStringList nativeProjectFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true);
if (nativeProjectFiles.empty())
return;
const QDir repoDirectory(repoDir);
for (QStringList::iterator it = l->begin(); it != l->end(); ) {
const QString path = QDir::toNativeSeparators(repoDirectory.absoluteFilePath(*it));
if (nativeProjectFiles.contains(path)) {
++it;
} else {
it = l->erase(it);
}
}
}
bool GitClient::getCommitData(const QString &workingDirectory,
QString *commitTemplate,
CommitData *d,
......@@ -771,7 +752,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
return false;
}
// Filter out untracked files that are not part of the project
filterUntrackedFilesOfProject(repoDirectory, &d->untrackedFiles);
VCSBase::VCSBaseSubmitEditor::filterUntrackedFilesOfProject(repoDirectory, &d->untrackedFiles);
if (d->filesEmpty()) {
*errorMessage = msgNoChangedFiles();
return false;
......
......@@ -59,18 +59,20 @@ QString CheckoutWizard::name() const
return tr("Subversion Checkout");
}
QWizardPage *CheckoutWizard::createParameterPage(const QString &path)
QList<QWizardPage*> CheckoutWizard::createParameterPages(const QString &path)
{
CheckoutWizardPage *cwp = new CheckoutWizardPage;
cwp->setPath(path);
return cwp;
QList<QWizardPage*> rc;
rc.push_back(cwp);
return rc;
}
QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QWizardPage *parameterPage,
QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QList<QWizardPage*> &parameterPages,
QString *checkoutPath)
{
// Collect parameters for the checkout command.
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPage);
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return QSharedPointer<VCSBase::AbstractCheckoutJob>())
const SubversionSettings settings = SubversionPlugin::subversionPluginInstance()->settings();
const QString binary = settings.svnCommand;
......
......@@ -47,8 +47,8 @@ public:
protected:
// BaseCheckoutWizard
virtual QWizardPage *createParameterPage(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QWizardPage *parameterPage,
virtual QList<QWizardPage*> createParameterPages(const QString &path);
virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QList<QWizardPage*> &parameterPage,
QString *checkoutPath);
};
......
......@@ -43,17 +43,17 @@
namespace VCSBase {
struct BaseCheckoutWizardPrivate {
BaseCheckoutWizardPrivate() : dialog(0), parameterPage(0) {}
BaseCheckoutWizardPrivate() : dialog(0) {}
void clear();
Internal::CheckoutWizardDialog *dialog;
QWizardPage *parameterPage;
QList<QWizardPage *> parameterPages;
QString checkoutPath;
};
void BaseCheckoutWizardPrivate::clear()
{
parameterPage = 0;
parameterPages.clear();
dialog = 0;
checkoutPath.clear();
}
......@@ -87,8 +87,8 @@ QString BaseCheckoutWizard::trCategory() const
QStringList BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent)
{
// Create dialog and launch
d->parameterPage = createParameterPage(path);
Internal::CheckoutWizardDialog dialog(d->parameterPage, parent);
d->parameterPages = createParameterPages(path);
Internal::CheckoutWizardDialog dialog(d->parameterPages, parent);
d->dialog = &dialog;
connect(&dialog, SIGNAL(progressPageShown()), this, SLOT(slotProgressPageShown()));
dialog.setWindowTitle(name());
......@@ -142,7 +142,7 @@ QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessa
void BaseCheckoutWizard::slotProgressPageShown()
{
const QSharedPointer<AbstractCheckoutJob> job = createJob(d->parameterPage, &(d->checkoutPath));
const QSharedPointer<AbstractCheckoutJob> job = createJob(d->parameterPages, &(d->checkoutPath));
if (!job.isNull())
d->dialog->start(job);
}
......
......@@ -34,6 +34,7 @@
#include <coreplugin/dialogs/iwizard.h>
#include <QtCore/QSharedPointer>
#include <QtCore/QList>
QT_BEGIN_NAMESPACE
class QWizardPage;
......@@ -76,8 +77,8 @@ public:
static QString openProject(const QString &path, QString *errorMessage);
protected:
virtual QWizardPage *createParameterPage(const QString &path) = 0;
virtual QSharedPointer<AbstractCheckoutJob> createJob(const QWizardPage *parameterPage,
virtual QList<QWizardPage *> createParameterPages(const QString &path) = 0;
virtual QSharedPointer<AbstractCheckoutJob> createJob(const QList<QWizardPage *> &parameterPages,
QString *checkoutPath) = 0;
private slots:
......
......@@ -39,16 +39,17 @@
namespace VCSBase {
namespace Internal {
enum PageId { ParameterPageId, ProgressPageId };
CheckoutWizardDialog::CheckoutWizardDialog(QWizardPage *parameterPage,
CheckoutWizardDialog::CheckoutWizardDialog(const QList<QWizardPage *> &parameterPages,
QWidget *parent) :
QWizard(parent),
m_progressPage(new CheckoutProgressWizardPage)
m_progressPage(new CheckoutProgressWizardPage),
m_progressPageId(-1)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setPage(ParameterPageId, parameterPage);
setPage(ProgressPageId, m_progressPage);
foreach(QWizardPage *wp, parameterPages)
addPage(wp);
m_progressPageId = parameterPages.size();
setPage(m_progressPageId, m_progressPage);
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotPageChanged(int)));
connect(m_progressPage, SIGNAL(terminated(bool)), this, SLOT(slotTerminated(bool)));
Core::BaseFileWizard::setupWizard(this);
......@@ -56,7 +57,7 @@ CheckoutWizardDialog::CheckoutWizardDialog(QWizardPage *parameterPage,
void CheckoutWizardDialog::slotPageChanged(int id)
{
if (id == ProgressPageId)
if (id == m_progressPageId)
emit progressPageShown();
}
......@@ -74,15 +75,10 @@ void CheckoutWizardDialog::start(const QSharedPointer<AbstractCheckoutJob> &job)
button(QWizard::BackButton)->setEnabled(false);
}
const QWizardPage *CheckoutWizardDialog::parameterPage() const
{
return page(ParameterPageId);
}
void CheckoutWizardDialog::reject()
{
// First click kills, 2nd closes
if (currentId() == ProgressPageId && m_progressPage->isRunning()) {
if (currentId() == m_progressPageId && m_progressPage->isRunning()) {
m_progressPage->terminate();
} else {
QWizard::reject();
......
......@@ -31,6 +31,7 @@
#define CHECKOUTWIZARDDIALOG_H
#include <QtCore/QSharedPointer>
#include <QtCore/QList>
#include <QtGui/QWizard>
namespace VCSBase {
......@@ -46,11 +47,10 @@ class CheckoutProgressWizardPage;
class CheckoutWizardDialog : public QWizard {
Q_OBJECT
public:
CheckoutWizardDialog(QWizardPage *parameterPage,
CheckoutWizardDialog(const QList<QWizardPage *> &parameterPages,
QWidget *parent = 0);
void start(const QSharedPointer<AbstractCheckoutJob> &job);
const QWizardPage *parameterPage() const;
signals:
void progressPageShown();
......@@ -62,6 +62,7 @@ private slots:
private:
CheckoutProgressWizardPage *m_progressPage;
int m_progressPageId;
};
} // namespace Internal
......
......@@ -576,6 +576,7 @@ QIcon VCSBaseSubmitEditor::submitIcon()
return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
}
// Compile a list if files in the current projects. TODO: Recurse down qrc files?
QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QString *name)
{
using namespace ProjectExplorer;
......@@ -606,6 +607,26 @@ QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QStr
return files;
}
// Reduce a list of untracked files reported by a VCS down to the files
// that are actually part of the current project(s).
void VCSBaseSubmitEditor::filterUntrackedFilesOfProject(const QString &repositoryDirectory, QStringList *untrackedFiles)
{
if (untrackedFiles->empty())
return;
const QStringList nativeProjectFiles = VCSBase::VCSBaseSubmitEditor::currentProjectFiles(true);
if (nativeProjectFiles.empty())
return;
const QDir repoDir(repositoryDirectory);
for (QStringList::iterator it = untrackedFiles->begin(); it != untrackedFiles->end(); ) {
const QString path = QDir::toNativeSeparators(repoDir.absoluteFilePath(*it));
if (nativeProjectFiles.contains(path)) {
++it;
} else {
it = untrackedFiles->erase(it);
}
}
}
// Helper to raise an already open submit editor to prevent opening twice.
bool VCSBaseSubmitEditor::raiseSubmitEditor()
{
......
......@@ -162,6 +162,10 @@ public:
// be restricted to them
static QStringList currentProjectFiles(bool nativeSeparators, QString *name = 0);
// Reduce a list of untracked files reported by a VCS down to the files
// that are actually part of the current project(s).
static void filterUntrackedFilesOfProject(const QString &repositoryDirectory, QStringList *untrackedFiles);
virtual bool isTemporary() const { return true; }
// Helper to raise an already open submit editor to prevent opening twice.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment