Allow specifying the name of a new generic project

The name is used as the base for files like [project].creator,
[project].files, etc. and is displayed in the Projects mode and the
Projects tree.
This commit is contained in:
Thorbjørn Lindeijer
2009-03-19 16:33:44 +01:00
parent d2f07b967d
commit 9c8f4e30a7
14 changed files with 124 additions and 107 deletions

View File

@@ -39,7 +39,8 @@ namespace Utils {
struct BaseValidatingLineEditPrivate; struct BaseValidatingLineEditPrivate;
/* Base class for validating line edits that performs validation in a virtual /**
* Base class for validating line edits that performs validation in a virtual
* validate() function to be implemented in derived classes. * validate() function to be implemented in derived classes.
* When invalid, the text color will turn red and a tooltip will * When invalid, the text color will turn red and a tooltip will
* contain the error message. This approach is less intrusive than a * contain the error message. This approach is less intrusive than a
@@ -47,9 +48,10 @@ struct BaseValidatingLineEditPrivate;
* *
* The widget has a concept of an "initialText" which can be something like * The widget has a concept of an "initialText" which can be something like
* "<Enter name here>". This results in state 'DisplayingInitialText', which * "<Enter name here>". This results in state 'DisplayingInitialText', which
* is not valid, but is not marked red. */ * is not valid, but is not marked red.
*/
class QWORKBENCH_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit { class QWORKBENCH_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(BaseValidatingLineEdit) Q_DISABLE_COPY(BaseValidatingLineEdit)
Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true) Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
@@ -97,4 +99,5 @@ private:
} // namespace Utils } // namespace Utils
} // namespace Core } // namespace Core
#endif // BASEVALIDATINGLINEEDIT_H #endif // BASEVALIDATINGLINEEDIT_H

View File

@@ -35,6 +35,10 @@
namespace Core { namespace Core {
namespace Utils { namespace Utils {
/**
* A control that let's the user choose a file name, based on a QLineEdit. Has
* some validation logic for embedding into QWizardPage.
*/
class QWORKBENCH_UTILS_EXPORT FileNameValidatingLineEdit : public BaseValidatingLineEdit class QWORKBENCH_UTILS_EXPORT FileNameValidatingLineEdit : public BaseValidatingLineEdit
{ {
Q_OBJECT Q_OBJECT
@@ -47,6 +51,10 @@ public:
bool allowDirectories = false, bool allowDirectories = false,
QString *errorMessage = 0); QString *errorMessage = 0);
/**
* Sets whether entering directories is allowed. This will enable the user
* to enter slashes in the filename. Default is off.
*/
bool allowDirectories() const; bool allowDirectories() const;
void setAllowDirectories(bool v); void setAllowDirectories(bool v);

View File

@@ -30,10 +30,6 @@
#include "filewizardpage.h" #include "filewizardpage.h"
#include "ui_filewizardpage.h" #include "ui_filewizardpage.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtGui/QMessageBox>
namespace Core { namespace Core {
namespace Utils { namespace Utils {
@@ -103,6 +99,16 @@ bool FileWizardPage::isComplete() const
return m_d->m_complete; return m_d->m_complete;
} }
void FileWizardPage::setNameLabel(const QString &label)
{
m_d->m_ui.nameLabel->setText(label);
}
void FileWizardPage::setPathLabel(const QString &label)
{
m_d->m_ui.pathLabel->setText(label);
}
void FileWizardPage::slotValidChanged() void FileWizardPage::slotValidChanged()
{ {
const bool newComplete = m_d->m_ui.pathChooser->isValid() && m_d->m_ui.nameLineEdit->isValid(); const bool newComplete = m_d->m_ui.pathChooser->isValid() && m_d->m_ui.nameLineEdit->isValid();

View File

@@ -39,10 +39,15 @@ namespace Utils {
struct FileWizardPagePrivate; struct FileWizardPagePrivate;
/* Standard wizard page for a single file letting the user choose name /**
* and path. Sets the "FileNames" QWizard field. */ * Standard wizard page for a single file letting the user choose name
* and path. Sets the "FileNames" QWizard field.
class QWORKBENCH_UTILS_EXPORT FileWizardPage : public QWizardPage { *
* The name and path labels can be changed. By default they are simply "Name:"
* and "Path:".
*/
class QWORKBENCH_UTILS_EXPORT FileWizardPage : public QWizardPage
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(FileWizardPage) Q_DISABLE_COPY(FileWizardPage)
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true) Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
@@ -56,7 +61,10 @@ public:
virtual bool isComplete() const; virtual bool isComplete() const;
// Validate a base name entry field (potentially containing extension) void setNameLabel(const QString &label);
void setPathLabel(const QString &label);
// Validate a base name entry field (potentially containing extension)
static bool validateBaseName(const QString &name, QString *errorMessage = 0); static bool validateBaseName(const QString &name, QString *errorMessage = 0);
signals: signals:

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>196</width>
<height>300</height> <height>68</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -16,52 +16,26 @@
<property name="title"> <property name="title">
<string>Choose the location</string> <string>Choose the location</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QFormLayout" name="formLayout">
<item> <item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"> <widget class="QLabel" name="nameLabel">
<item> <property name="text">
<widget class="QWidget" name="widget" native="true"> <string>Name:</string>
<layout class="QFormLayout" name="formLayout"> </property>
<property name="fieldGrowthPolicy"> </widget>
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Core::Utils::FileNameValidatingLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="pathLabel">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Core::Utils::PathChooser" name="pathChooser" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</item> </item>
<item> <item row="0" column="1">
<spacer name="verticalSpacer"> <widget class="Core::Utils::FileNameValidatingLineEdit" name="nameLineEdit"/>
<property name="orientation"> </item>
<enum>Qt::Vertical</enum> <item row="1" column="0">
<widget class="QLabel" name="pathLabel">
<property name="text">
<string>Path:</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size> </item>
<width>20</width> <item row="1" column="1">
<height>201</height> <widget class="Core::Utils::PathChooser" name="pathChooser" native="true"/>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@@ -39,10 +39,10 @@ namespace Utils {
struct PathChooserPrivate; struct PathChooserPrivate;
/* A Control that let's the user choose a path, consisting of a QLineEdit and /**
* a "Browse" button. Has some validation logic for embedding into * A control that let's the user choose a path, consisting of a QLineEdit and
* QWizardPage. */ * a "Browse" button. Has some validation logic for embedding into QWizardPage.
*/
class QWORKBENCH_UTILS_EXPORT PathChooser : public QWidget class QWORKBENCH_UTILS_EXPORT PathChooser : public QWidget
{ {
Q_DISABLE_COPY(PathChooser) Q_DISABLE_COPY(PathChooser)
@@ -74,12 +74,12 @@ public:
QString path() const; QString path() const;
// Returns the suggested label title when used in a form layout /** Returns the suggested label title when used in a form layout. */
static QString label(); static QString label();
virtual bool validatePath(const QString &path, QString *errorMessage = 0); virtual bool validatePath(const QString &path, QString *errorMessage = 0);
// Return the home directory, which needs some fixing under Windows. /** Return the home directory, which needs some fixing under Windows. */
static QString homePath(); static QString homePath();
private: private:

View File

@@ -31,6 +31,7 @@
#include "genericprojectconstants.h" #include "genericprojectconstants.h"
#include "genericmakestep.h" #include "genericmakestep.h"
#include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/cppmodelmanagerinterface.h> #include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
@@ -112,12 +113,12 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_toolChain(0) m_toolChain(0)
{ {
QFileInfo fileInfo(m_fileName); QFileInfo fileInfo(m_fileName);
const QString projectBaseName = fileInfo.baseName();
QDir dir = fileInfo.dir(); QDir dir = fileInfo.dir();
m_filesFileName = QFileInfo(dir, projectBaseName + QLatin1String(".files")).absoluteFilePath(); m_projectName = fileInfo.baseName();
m_includesFileName = QFileInfo(dir, projectBaseName + QLatin1String(".includes")).absoluteFilePath(); m_filesFileName = QFileInfo(dir, m_projectName + QLatin1String(".files")).absoluteFilePath();
m_configFileName = QFileInfo(dir, projectBaseName + QLatin1String(".config")).absoluteFilePath(); m_includesFileName = QFileInfo(dir, m_projectName + QLatin1String(".includes")).absoluteFilePath();
m_configFileName = QFileInfo(dir, m_projectName + QLatin1String(".config")).absoluteFilePath();
m_file = new GenericProjectFile(this, fileName); m_file = new GenericProjectFile(this, fileName);
m_rootNode = new GenericProjectNode(this, m_file); m_rootNode = new GenericProjectNode(this, m_file);

View File

@@ -36,7 +36,6 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h> #include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h> #include <projectexplorer/buildstep.h>
#include <projectexplorer/toolchain.h>
#include <coreplugin/ifile.h> #include <coreplugin/ifile.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE

View File

@@ -30,12 +30,10 @@
#include "genericprojectnodes.h" #include "genericprojectnodes.h"
#include "genericproject.h" #include "genericproject.h"
#include <coreplugin/ifile.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QSettings>
#include <QtDebug>
using namespace GenericProjectManager; using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal; using namespace GenericProjectManager::Internal;
@@ -44,7 +42,9 @@ GenericProjectNode::GenericProjectNode(GenericProject *project, Core::IFile *pro
: ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absolutePath()), : ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absolutePath()),
m_project(project), m_project(project),
m_projectFile(projectFile) m_projectFile(projectFile)
{} {
setFolderName(QFileInfo(projectFile->fileName()).baseName());
}
GenericProjectNode::~GenericProjectNode() GenericProjectNode::~GenericProjectNode()
{ } { }

View File

@@ -30,11 +30,15 @@
#ifndef GENERICPROJECTNODE_H #ifndef GENERICPROJECTNODE_H
#define GENERICPROJECTNODE_H #define GENERICPROJECTNODE_H
#include <coreplugin/ifile.h>
#include <projectexplorer/projectnodes.h> #include <projectexplorer/projectnodes.h>
#include <QStringList> #include <QStringList>
#include <QHash> #include <QHash>
namespace Core {
class IFile;
}
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {

View File

@@ -4,16 +4,17 @@
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <utils/filenamevalidatinglineedit.h>
#include <utils/filewizardpage.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QtDebug> #include <QtCore/QtDebug>
#include <QtGui/QWizard> #include <QtGui/QDirModel>
#include <QtGui/QFormLayout> #include <QtGui/QFormLayout>
#include <QtGui/QListView> #include <QtGui/QListView>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include <QtGui/QDirModel>
using namespace GenericProjectManager::Internal; using namespace GenericProjectManager::Internal;
using namespace Core::Utils; using namespace Core::Utils;
@@ -94,14 +95,12 @@ GenericProjectWizardDialog::GenericProjectWizardDialog(QWidget *parent)
setWindowTitle(tr("Import Existing Project")); setWindowTitle(tr("Import Existing Project"));
// first page // first page
QWizardPage *firstPage = new QWizardPage; m_firstPage = new FileWizardPage;
firstPage->setTitle(tr("Project")); m_firstPage->setTitle(tr("Import Project"));
m_firstPage->setNameLabel(tr("Project name:"));
m_firstPage->setPathLabel(tr("Location:"));
QFormLayout *layout = new QFormLayout(firstPage); addPage(m_firstPage);
m_pathChooser = new PathChooser;
layout->addRow(tr("Source Directory:"), m_pathChooser);
m_firstPageId = addPage(firstPage);
#if 0 #if 0
// second page // second page
@@ -146,7 +145,14 @@ GenericProjectWizardDialog::~GenericProjectWizardDialog()
{ } { }
QString GenericProjectWizardDialog::path() const QString GenericProjectWizardDialog::path() const
{ return m_pathChooser->path(); } {
return m_firstPage->path();
}
QString GenericProjectWizardDialog::projectName() const
{
return m_firstPage->name();
}
void GenericProjectWizardDialog::updateFilesView(const QModelIndex &current, void GenericProjectWizardDialog::updateFilesView(const QModelIndex &current,
const QModelIndex &) const QModelIndex &)
@@ -182,12 +188,11 @@ bool GenericProjectWizardDialog::validateCurrentPage()
{ {
using namespace Core::Utils; using namespace Core::Utils;
if (currentId() == m_firstPageId) { #if 0
return ! m_pathChooser->path().isEmpty(); if (currentId() == m_secondPageId) {
} else if (currentId() == m_secondPageId) {
return true; return true;
} }
#endif
return QWizard::validateCurrentPage(); return QWizard::validateCurrentPage();
} }
@@ -271,7 +276,7 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w); const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w);
const QString projectPath = wizard->path(); const QString projectPath = wizard->path();
const QDir dir(projectPath); const QDir dir(projectPath);
const QString projectName = QFileInfo(projectPath).baseName(); const QString projectName = wizard->projectName();
const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath(); const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath();
const QString filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath(); const QString filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath();
const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath(); const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath();

View File

@@ -2,23 +2,31 @@
#define GENERICPROJECTWIZARD_H #define GENERICPROJECTWIZARD_H
#include <coreplugin/basefilewizard.h> #include <coreplugin/basefilewizard.h>
#include <utils/pathchooser.h>
#include <QWizard> #include <QtGui/QWizard>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QListView;
class QTreeView;
class QDirModel;
class QModelIndex;
class QDir; class QDir;
class QStringList; class QDirModel;
class QFileInfo; class QFileInfo;
class QListView;
class QModelIndex;
class QStringList;
class QTreeView;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core {
namespace Utils {
class FileWizardPage;
} // namespace Utils
} // namespace Core
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
class GenericProjectWizardDialog: public QWizard class GenericProjectWizardDialog : public QWizard
{ {
Q_OBJECT Q_OBJECT
@@ -27,6 +35,7 @@ public:
virtual ~GenericProjectWizardDialog(); virtual ~GenericProjectWizardDialog();
QString path() const; QString path() const;
QString projectName() const;
private Q_SLOTS: private Q_SLOTS:
void updateFilesView(const QModelIndex &current, void updateFilesView(const QModelIndex &current,
@@ -37,10 +46,9 @@ protected:
virtual bool validateCurrentPage(); virtual bool validateCurrentPage();
private: private:
int m_firstPageId;
int m_secondPageId; int m_secondPageId;
Core::Utils::PathChooser *m_pathChooser; Core::Utils::FileWizardPage *m_firstPage;
QTreeView *m_dirView; QTreeView *m_dirView;
QDirModel *m_dirModel; QDirModel *m_dirModel;

View File

@@ -98,7 +98,8 @@ class Qt4PriFileNode;
class Qt4ProFileNode; class Qt4ProFileNode;
// Implements ProjectNode for qt4 pro files // Implements ProjectNode for qt4 pro files
class Qt4PriFileNode : public ProjectExplorer::ProjectNode { class Qt4PriFileNode : public ProjectExplorer::ProjectNode
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Qt4PriFileNode) Q_DISABLE_COPY(Qt4PriFileNode)
public: public:
@@ -164,7 +165,8 @@ private:
}; };
// Implements ProjectNode for qt4 pro files // Implements ProjectNode for qt4 pro files
class Qt4ProFileNode : public Qt4PriFileNode { class Qt4ProFileNode : public Qt4PriFileNode
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Qt4ProFileNode) Q_DISABLE_COPY(Qt4ProFileNode)
public: public:
@@ -208,7 +210,8 @@ private:
friend class Qt4NodeHierarchy; friend class Qt4NodeHierarchy;
}; };
class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher { class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher
{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Qt4NodesWatcher) Q_DISABLE_COPY(Qt4NodesWatcher)
public: public:

View File

@@ -78,8 +78,7 @@ class Qt4Manager;
class Qt4Project; class Qt4Project;
class Qt4RunStep; class Qt4RunStep;
class Qt4ProjectFile class Qt4ProjectFile : public Core::IFile
: public Core::IFile
{ {
Q_OBJECT Q_OBJECT
@@ -108,8 +107,7 @@ private:
QString m_filePath; QString m_filePath;
}; };
class Qt4Project class Qt4Project : public ProjectExplorer::Project
: public ProjectExplorer::Project
{ {
Q_OBJECT Q_OBJECT