Commit 9c8f4e30 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

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.
parent d2f07b96
......@@ -39,7 +39,8 @@ namespace Utils {
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.
* When invalid, the text color will turn red and a tooltip will
* 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
* "<Enter name here>". This results in state 'DisplayingInitialText', which
* is not valid, but is not marked red. */
class QWORKBENCH_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit {
* is not valid, but is not marked red.
*/
class QWORKBENCH_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit
{
Q_OBJECT
Q_DISABLE_COPY(BaseValidatingLineEdit)
Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
......@@ -97,4 +99,5 @@ private:
} // namespace Utils
} // namespace Core
#endif // BASEVALIDATINGLINEEDIT_H
......@@ -35,6 +35,10 @@
namespace Core {
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
{
Q_OBJECT
......@@ -47,6 +51,10 @@ public:
bool allowDirectories = false,
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;
void setAllowDirectories(bool v);
......
......@@ -30,10 +30,6 @@
#include "filewizardpage.h"
#include "ui_filewizardpage.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtGui/QMessageBox>
namespace Core {
namespace Utils {
......@@ -103,6 +99,16 @@ bool FileWizardPage::isComplete() const
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()
{
const bool newComplete = m_d->m_ui.pathChooser->isValid() && m_d->m_ui.nameLineEdit->isValid();
......
......@@ -39,10 +39,15 @@ namespace Utils {
struct FileWizardPagePrivate;
/* 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 {
/**
* Standard wizard page for a single file letting the user choose name
* and path. Sets the "FileNames" QWizard field.
*
* 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_DISABLE_COPY(FileWizardPage)
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
......@@ -56,7 +61,10 @@ public:
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);
signals:
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>196</width>
<height>68</height>
</rect>
</property>
<property name="windowTitle">
......@@ -16,52 +16,26 @@
<property name="title">
<string>Choose the location</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<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>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>201</height>
</size>
</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>
</spacer>
</widget>
</item>
<item row="1" column="1">
<widget class="Core::Utils::PathChooser" name="pathChooser" native="true"/>
</item>
</layout>
</widget>
......
......@@ -39,10 +39,10 @@ namespace Utils {
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
* QWizardPage. */
/**
* 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 QWizardPage.
*/
class QWORKBENCH_UTILS_EXPORT PathChooser : public QWidget
{
Q_DISABLE_COPY(PathChooser)
......@@ -74,12 +74,12 @@ public:
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();
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();
private:
......
......@@ -31,6 +31,7 @@
#include "genericprojectconstants.h"
#include "genericmakestep.h"
#include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
......@@ -112,12 +113,12 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_toolChain(0)
{
QFileInfo fileInfo(m_fileName);
const QString projectBaseName = fileInfo.baseName();
QDir dir = fileInfo.dir();
m_filesFileName = QFileInfo(dir, projectBaseName + QLatin1String(".files")).absoluteFilePath();
m_includesFileName = QFileInfo(dir, projectBaseName + QLatin1String(".includes")).absoluteFilePath();
m_configFileName = QFileInfo(dir, projectBaseName + QLatin1String(".config")).absoluteFilePath();
m_projectName = fileInfo.baseName();
m_filesFileName = QFileInfo(dir, m_projectName + QLatin1String(".files")).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_rootNode = new GenericProjectNode(this, m_file);
......
......@@ -36,7 +36,6 @@
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h>
#include <projectexplorer/toolchain.h>
#include <coreplugin/ifile.h>
QT_BEGIN_NAMESPACE
......
......@@ -30,12 +30,10 @@
#include "genericprojectnodes.h"
#include "genericproject.h"
#include <coreplugin/ifile.h>
#include <projectexplorer/projectexplorer.h>
#include <QDir>
#include <QFileInfo>
#include <QSettings>
#include <QtDebug>
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
......@@ -44,7 +42,9 @@ GenericProjectNode::GenericProjectNode(GenericProject *project, Core::IFile *pro
: ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absolutePath()),
m_project(project),
m_projectFile(projectFile)
{}
{
setFolderName(QFileInfo(projectFile->fileName()).baseName());
}
GenericProjectNode::~GenericProjectNode()
{ }
......
......@@ -30,11 +30,15 @@
#ifndef GENERICPROJECTNODE_H
#define GENERICPROJECTNODE_H
#include <coreplugin/ifile.h>
#include <projectexplorer/projectnodes.h>
#include <QStringList>
#include <QHash>
namespace Core {
class IFile;
}
namespace GenericProjectManager {
namespace Internal {
......
......@@ -4,16 +4,17 @@
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/filenamevalidatinglineedit.h>
#include <utils/filewizardpage.h>
#include <utils/pathchooser.h>
#include <QtCore/QDir>
#include <QtCore/QtDebug>
#include <QtGui/QWizard>
#include <QtGui/QDirModel>
#include <QtGui/QFormLayout>
#include <QtGui/QListView>
#include <QtGui/QTreeView>
#include <QtGui/QDirModel>
using namespace GenericProjectManager::Internal;
using namespace Core::Utils;
......@@ -94,14 +95,12 @@ GenericProjectWizardDialog::GenericProjectWizardDialog(QWidget *parent)
setWindowTitle(tr("Import Existing Project"));
// first page
QWizardPage *firstPage = new QWizardPage;
firstPage->setTitle(tr("Project"));
QFormLayout *layout = new QFormLayout(firstPage);
m_pathChooser = new PathChooser;
layout->addRow(tr("Source Directory:"), m_pathChooser);
m_firstPage = new FileWizardPage;
m_firstPage->setTitle(tr("Import Project"));
m_firstPage->setNameLabel(tr("Project name:"));
m_firstPage->setPathLabel(tr("Location:"));
m_firstPageId = addPage(firstPage);
addPage(m_firstPage);
#if 0
// second page
......@@ -146,7 +145,14 @@ GenericProjectWizardDialog::~GenericProjectWizardDialog()
{ }
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,
const QModelIndex &)
......@@ -182,12 +188,11 @@ bool GenericProjectWizardDialog::validateCurrentPage()
{
using namespace Core::Utils;
if (currentId() == m_firstPageId) {
return ! m_pathChooser->path().isEmpty();
} else if (currentId() == m_secondPageId) {
#if 0
if (currentId() == m_secondPageId) {
return true;
}
#endif
return QWizard::validateCurrentPage();
}
......@@ -271,7 +276,7 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w,
const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w);
const QString projectPath = wizard->path();
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 filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath();
const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath();
......
......@@ -2,23 +2,31 @@
#define GENERICPROJECTWIZARD_H
#include <coreplugin/basefilewizard.h>
#include <utils/pathchooser.h>
#include <QWizard>
#include <QtGui/QWizard>
QT_BEGIN_NAMESPACE
class QListView;
class QTreeView;
class QDir;
class QDirModel;
class QFileInfo;
class QListView;
class QModelIndex;
class QDir;
class QStringList;
class QFileInfo;
class QTreeView;
QT_END_NAMESPACE
namespace Core {
namespace Utils {
class FileWizardPage;
} // namespace Utils
} // namespace Core
namespace GenericProjectManager {
namespace Internal {
class GenericProjectWizardDialog: public QWizard
class GenericProjectWizardDialog : public QWizard
{
Q_OBJECT
......@@ -27,6 +35,7 @@ public:
virtual ~GenericProjectWizardDialog();
QString path() const;
QString projectName() const;
private Q_SLOTS:
void updateFilesView(const QModelIndex &current,
......@@ -37,10 +46,9 @@ protected:
virtual bool validateCurrentPage();
private:
int m_firstPageId;
int m_secondPageId;
Core::Utils::PathChooser *m_pathChooser;
Core::Utils::FileWizardPage *m_firstPage;
QTreeView *m_dirView;
QDirModel *m_dirModel;
......
......@@ -98,7 +98,8 @@ class Qt4PriFileNode;
class Qt4ProFileNode;
// Implements ProjectNode for qt4 pro files
class Qt4PriFileNode : public ProjectExplorer::ProjectNode {
class Qt4PriFileNode : public ProjectExplorer::ProjectNode
{
Q_OBJECT
Q_DISABLE_COPY(Qt4PriFileNode)
public:
......@@ -164,7 +165,8 @@ private:
};
// Implements ProjectNode for qt4 pro files
class Qt4ProFileNode : public Qt4PriFileNode {
class Qt4ProFileNode : public Qt4PriFileNode
{
Q_OBJECT
Q_DISABLE_COPY(Qt4ProFileNode)
public:
......@@ -208,7 +210,8 @@ private:
friend class Qt4NodeHierarchy;
};
class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher {
class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher
{
Q_OBJECT
Q_DISABLE_COPY(Qt4NodesWatcher)
public:
......
......@@ -78,8 +78,7 @@ class Qt4Manager;
class Qt4Project;
class Qt4RunStep;
class Qt4ProjectFile
: public Core::IFile
class Qt4ProjectFile : public Core::IFile
{
Q_OBJECT
......@@ -108,8 +107,7 @@ private:
QString m_filePath;
};
class Qt4Project
: public ProjectExplorer::Project
class Qt4Project : public ProjectExplorer::Project
{
Q_OBJECT
......
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