diff --git a/src/libs/utils/projectintropage.cpp b/src/libs/utils/projectintropage.cpp index da66bb644990badc2dde8d195844144f7f5473ff..e6ee2921bffcc6a85f551cde082cfd7b5edb2b71 100644 --- a/src/libs/utils/projectintropage.cpp +++ b/src/libs/utils/projectintropage.cpp @@ -208,4 +208,14 @@ void ProjectIntroPage::hideStatusLabel() displayStatusMessage(Hint, QString()); } +bool ProjectIntroPage::useAsDefaultPath() const +{ + return m_d->m_ui.projectsDirectoryCheckBox->isChecked(); +} + +void ProjectIntroPage::setUseAsDefaultPath(bool u) +{ + m_d->m_ui.projectsDirectoryCheckBox->setChecked(u); +} + } // namespace Utils diff --git a/src/libs/utils/projectintropage.h b/src/libs/utils/projectintropage.h index 9e127ee64658ae5b231940a0032d0db769fdce74..6fb53ec66d21ebd3b21677960f0c93576fc8c909 100644 --- a/src/libs/utils/projectintropage.h +++ b/src/libs/utils/projectintropage.h @@ -58,6 +58,7 @@ class QTCREATOR_UTILS_EXPORT ProjectIntroPage : public QWizardPage Q_PROPERTY(QString description READ description WRITE setPath DESIGNABLE true) Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true) Q_PROPERTY(QString name READ name WRITE setName DESIGNABLE true) + Q_PROPERTY(bool useAsDefaultPath READ useAsDefaultPath WRITE setUseAsDefaultPath DESIGNABLE true) public: explicit ProjectIntroPage(QWidget *parent = 0); virtual ~ProjectIntroPage(); @@ -65,11 +66,12 @@ public: QString name() const; QString path() const; QString description() const; + bool useAsDefaultPath() const; // Insert an additional control into the form layout for the target. void insertControl(int row, QWidget *label, QWidget *control); - virtual bool isComplete() const; + virtual bool isComplete() const; // Validate a project directory name entry field static bool validateProjectDirectory(const QString &name, QString *errorMessage); @@ -81,6 +83,7 @@ public slots: void setPath(const QString &path); void setName(const QString &name); void setDescription(const QString &description); + void setUseAsDefaultPath(bool u); private slots: void slotChanged(); diff --git a/src/libs/utils/projectintropage.ui b/src/libs/utils/projectintropage.ui index a37da218c3e0c764fc2c99c4bf0ef58643d0a330..b1efee76c8107970a7285a7198f17fb41e67f5e2 100644 --- a/src/libs/utils/projectintropage.ui +++ b/src/libs/utils/projectintropage.ui @@ -2,14 +2,6 @@ <ui version="4.0"> <class>Utils::ProjectIntroPage</class> <widget class="QWizardPage" name="Utils::ProjectIntroPage"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>208</width> - <height>143</height> - </rect> - </property> <property name="title"> <string>Introduction and project location</string> </property> @@ -41,53 +33,59 @@ </spacer> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QFrame" name="frame"> - <property name="frameShape"> - <enum>QFrame::StyledPanel</enum> - </property> - <property name="frameShadow"> - <enum>QFrame::Raised</enum> - </property> - <layout class="QFormLayout" name="formLayout"> - <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="Utils::ProjectNameValidatingLineEdit" name="nameLineEdit"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="pathLabel"> - <property name="text"> - <string>Create in:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="Utils::PathChooser" name="pathChooser" native="true"/> - </item> - </layout> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - </layout> + <widget class="QFrame" name="frame"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QFormLayout" name="formLayout"> + <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="Utils::ProjectNameValidatingLineEdit" name="nameLineEdit"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="pathLabel"> + <property name="text"> + <string>Create in:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="Utils::PathChooser" name="pathChooser"/> + </item> + <item row="1" column="0"> + <spacer name="directorySeparatorLabel"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>12</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QCheckBox" name="projectsDirectoryCheckBox"> + <property name="text"> + <string>Use as default project location</string> + </property> + </widget> + </item> + </layout> + </widget> </item> <item> <widget class="QLabel" name="stateLabel"> @@ -99,17 +97,17 @@ </layout> </widget> <customwidgets> + <customwidget> + <class>Utils::ProjectNameValidatingLineEdit</class> + <extends>QLineEdit</extends> + <header location="global">utils/projectnamevalidatinglineedit.h</header> + </customwidget> <customwidget> <class>Utils::PathChooser</class> <extends>QWidget</extends> - <header>pathchooser.h</header> + <header location="global">utils/pathchooser.h</header> <container>1</container> </customwidget> - <customwidget> - <class>Utils::ProjectNameValidatingLineEdit</class> - <extends>QLineEdit</extends> - <header>projectnamevalidatinglineedit.h</header> - </customwidget> </customwidgets> <resources/> <connections/> diff --git a/src/plugins/coreplugin/basefilewizard.cpp b/src/plugins/coreplugin/basefilewizard.cpp index 5c185a546c5b1e4ee8e4bd57aa9b7783d80f1fc4..9f9df40409b5588e8df7fb83c618cb236ac63569 100644 --- a/src/plugins/coreplugin/basefilewizard.cpp +++ b/src/plugins/coreplugin/basefilewizard.cpp @@ -37,6 +37,7 @@ #include <extensionsystem/pluginmanager.h> #include <utils/filewizarddialog.h> +#include <utils/qtcassert.h> #include <QtCore/QDir> #include <QtCore/QFile> @@ -423,6 +424,8 @@ QString BaseFileWizard::trCategory() const QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent) { + QTC_ASSERT(!path.isEmpty(), return QStringList()) + typedef QList<IFileWizardExtension*> ExtensionList; QString errorMessage; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index de6dde03251926b6dfbecdc6782110c479706051..3e13ca2e75bbce2d6cd003ad027455145b8bec8a 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1166,21 +1166,10 @@ bool EditorManager::openExternalEditor(const QString &fileName, const QString &e QStringList EditorManager::getOpenFileNames() const { - static QString dir = QDir::homePath(); if (m_d->fileFilters.isEmpty()) m_d->fileFilters = formatFileFilters(m_d->m_core, &m_d->selectedFilter); - - QString currentFile = ICore::instance()->fileManager()->currentFile(); - if (!currentFile.isEmpty()) { - const QFileInfo fi(currentFile); - dir = fi.absolutePath(); - } - - QStringList files = QFileDialog::getOpenFileNames(m_d->m_core->mainWindow(), tr("Open File"), - dir, m_d->fileFilters, &m_d->selectedFilter); - if (!files.isEmpty()) - dir = QFileInfo(files.at(0)).absolutePath(); - return files; + return ICore::instance()->fileManager()->getOpenFileNames(m_d->fileFilters, + QString(), &m_d->selectedFilter); } void EditorManager::ensureEditorManagerVisible() diff --git a/src/plugins/coreplugin/filemanager.cpp b/src/plugins/coreplugin/filemanager.cpp index 86cc0ffc0e0c0d60c742faa40a6cbbc52b344606..c7b6127cf1ab5dc4ed5878a79509ca64e0936039 100644 --- a/src/plugins/coreplugin/filemanager.cpp +++ b/src/plugins/coreplugin/filemanager.cpp @@ -39,6 +39,7 @@ #include "vcsmanager.h" #include <utils/qtcassert.h> +#include <utils/pathchooser.h> #include <QtCore/QDebug> #include <QtCore/QSettings> @@ -77,8 +78,12 @@ (see addToRecentFiles() and recentFiles()). */ -static const char *settingsGroup = "RecentFiles"; -static const char *filesKey = "Files"; +static const char settingsGroupC[] = "RecentFiles"; +static const char filesKeyC[] = "Files"; + +static const char directoryGroupC[] = "Directories"; +static const char projectDirectoryKeyC[] = "Projects"; +static const char useProjectDirectoryKeyC[] = "UseProjectsDirectory"; namespace Core { namespace Internal { @@ -104,12 +109,22 @@ struct FileManagerPrivate { QFileSystemWatcher *m_fileWatcher; QList<QPointer<IFile> > m_changedFiles; bool m_blockActivated; + QString m_lastVisitedDirectory; + QString m_projectsDirectory; + bool m_useProjectsDirectory; }; FileManagerPrivate::FileManagerPrivate(QObject *q, QMainWindow *mw) : m_mainWindow(mw), m_fileWatcher(new QFileSystemWatcher(q)), - m_blockActivated(false) + m_blockActivated(false), + m_lastVisitedDirectory(QDir::currentPath()), + m_projectsDirectory(Utils::PathChooser::homePath()), +#ifdef Q_OS_MAC // Creator is in bizarre places when launched via finder. + m_useProjectsDirectory(true) +#else + m_useProjectsDirectory(false) +#endif { } @@ -128,7 +143,7 @@ FileManager::FileManager(QMainWindow *mw) this, SLOT(syncWithEditor(Core::IContext*))); const QSettings *s = core->settings(); - d->m_recentFiles = s->value(QLatin1String(settingsGroup) + QLatin1Char('/') + QLatin1String(filesKey), QStringList()).toStringList(); + d->m_recentFiles = s->value(QLatin1String(settingsGroupC) + QLatin1Char('/') + QLatin1String(filesKeyC), QStringList()).toStringList(); for (QStringList::iterator it = d->m_recentFiles.begin(); it != d->m_recentFiles.end(); ) { if (QFileInfo(*it).isFile()) { ++it; @@ -136,6 +151,10 @@ FileManager::FileManager(QMainWindow *mw) it = d->m_recentFiles.erase(it); } } + const QString directoryGroup = QLatin1String(directoryGroupC) + QLatin1Char('/'); + d->m_projectsDirectory = s->value(directoryGroup + QLatin1String(projectDirectoryKeyC), QString()).toString(); + d->m_useProjectsDirectory = s->value(directoryGroup + QLatin1String(useProjectDirectoryKeyC), + d->m_useProjectsDirectory).toBool(); } FileManager::~FileManager() @@ -441,13 +460,14 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files, return notSaved; } -QString FileManager::getSaveFileNameWithExtension(const QString &title, const QString &path, +QString FileManager::getSaveFileNameWithExtension(const QString &title, const QString &pathIn, const QString &fileFilter, const QString &extension) { QString fileName; bool repeat; do { repeat = false; + const QString path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn; fileName = QFileDialog::getSaveFileName(d->m_mainWindow, title, path, fileFilter); if (!fileName.isEmpty() && !extension.isEmpty() && !fileName.endsWith(extension)) { fileName.append(extension); @@ -459,6 +479,8 @@ QString FileManager::getSaveFileNameWithExtension(const QString &title, const QS } } } while (repeat); + if (!fileName.isEmpty()) + setFileDialogLastVisitedDirectory(QFileInfo(fileName).absolutePath()); return fileName; } @@ -495,6 +517,27 @@ QString FileManager::getSaveAsFileName(IFile *file) return absoluteFilePath; } +/*! + \fn QString FileManager::getOpenFileNames(const QStringList &filters, QString *selectedFilter) const + + Asks the user for a set of file names to be opened. +*/ + +QStringList FileManager::getOpenFileNames(const QString &filters, + const QString pathIn, + QString *selectedFilter) +{ + const QString path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn; + const QStringList files = QFileDialog::getOpenFileNames(d->m_mainWindow, + tr("Open File"), + path, filters, + selectedFilter); + if (!files.isEmpty()) + setFileDialogLastVisitedDirectory(QFileInfo(files.front()).absolutePath()); + return files; +} + + void FileManager::changedFile(const QString &file) { const bool wasempty = d->m_changedFiles.isEmpty(); @@ -586,8 +629,12 @@ QStringList FileManager::recentFiles() const void FileManager::saveRecentFiles() { QSettings *s = Core::ICore::instance()->settings(); - s->beginGroup(QLatin1String(settingsGroup)); - s->setValue(QLatin1String(filesKey), d->m_recentFiles); + s->beginGroup(QLatin1String(settingsGroupC)); + s->setValue(QLatin1String(filesKeyC), d->m_recentFiles); + s->endGroup(); + s->beginGroup(QLatin1String(directoryGroupC)); + s->setValue(QLatin1String(projectDirectoryKeyC), d->m_projectsDirectory); + s->setValue(QLatin1String(useProjectDirectoryKeyC), d->m_useProjectsDirectory); s->endGroup(); } @@ -638,6 +685,99 @@ QList<IFile *> FileManager::managedFiles(const QString &fileName) const return result; } +/*! + + Returns the initial directory for a new file dialog. If there is + a current file, use that, else use last visited directory. + + \sa setFileDialogLastVisitedDirectory +*/ + +QString FileManager::fileDialogInitialDirectory() const +{ + if (!d->m_currentFile.isEmpty()) + return QFileInfo(d->m_currentFile).absolutePath(); + return d->m_lastVisitedDirectory; +} + +/*! + + Returns the directory for projects. Defaults to HOME. + + \sa setProjectsDirectory, setUseProjectsDirectory +*/ + +QString FileManager::projectsDirectory() const +{ + return d->m_projectsDirectory; +} + +/*! + + Set the directory for projects. + + \sa projectsDirectory, useProjectsDirectory +*/ + +void FileManager::setProjectsDirectory(const QString &dir) +{ + d->m_projectsDirectory = dir; +} + +/*! + + Returns whether the directory for projects is to be + used or the user wants the current directory. + + \sa setProjectsDirectory, setUseProjectsDirectory +*/ + +bool FileManager::useProjectsDirectory() const +{ + return d->m_useProjectsDirectory; +} + +/*! + + Sets whether the directory for projects is to be used. + + \sa projectsDirectory, useProjectsDirectory +*/ + +void FileManager::setUseProjectsDirectory(bool useProjectsDirectory) +{ + d->m_useProjectsDirectory = useProjectsDirectory; +} + +/*! + + Returns last visited directory of a file dialog. + + \sa setFileDialogLastVisitedDirectory, fileDialogInitialDirectory + +*/ + +QString FileManager::fileDialogLastVisitedDirectory() const +{ + return d->m_lastVisitedDirectory; +} + +/*! + + Set the last visited directory of a file dialog that will be remembered + for the next one. + + \sa fileDialogLastVisitedDirectory, fileDialogInitialDirectory + + */ + +void FileManager::setFileDialogLastVisitedDirectory(const QString &directory) +{ + d->m_lastVisitedDirectory = directory; +} + +// -------------- FileChangeBlocker + FileChangeBlocker::FileChangeBlocker(const QString &fileName) : m_reload(false) { diff --git a/src/plugins/coreplugin/filemanager.h b/src/plugins/coreplugin/filemanager.h index b3cf4b4c9b76fd2e67e41cde289431b349fe836d..1cc606425fb1bb44a152b5c6c3ac6589db8fff64 100644 --- a/src/plugins/coreplugin/filemanager.h +++ b/src/plugins/coreplugin/filemanager.h @@ -79,6 +79,10 @@ public: // helper methods static QString fixFileName(const QString &fileName); + QStringList getOpenFileNames(const QString &filters, + const QString path = QString(), + QString *selectedFilter = 0); + QString getSaveFileNameWithExtension(const QString &title, const QString &path, const QString &fileFilter, const QString &extension); QString getSaveAsFileName(IFile *file); @@ -90,6 +94,18 @@ public: const QString &alwaysSaveMessage = QString::null, bool *alwaysSave = 0); + + QString fileDialogLastVisitedDirectory() const; + void setFileDialogLastVisitedDirectory(const QString &); + + QString fileDialogInitialDirectory() const; + + bool useProjectsDirectory() const; + void setUseProjectsDirectory(bool); + + QString projectsDirectory() const; + void setProjectsDirectory(const QString &); + signals: void currentFileChanged(const QString &filePath); diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index f0727278ba2c24c2e9513fedf21e3e95acdf88b2..a00d29ac0a6a55eb1c6c211b265f575bd637dd28 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -866,12 +866,6 @@ QStringList MainWindow::showNewItemDialog(const QString &title, const QList<IWizard *> &wizards, const QString &defaultLocation) { - QString defaultDir = defaultLocation; - if (defaultDir.isEmpty() && !m_coreImpl->fileManager()->currentFile().isEmpty()) - defaultDir = QFileInfo(m_coreImpl->fileManager()->currentFile()).absolutePath(); - if (defaultDir.isEmpty()) - defaultDir = Utils::PathChooser::homePath(); - // Scan for wizards matching the filter and pick one. Don't show // dialog if there is only one. IWizard *wizard = 0; @@ -892,7 +886,25 @@ QStringList MainWindow::showNewItemDialog(const QString &title, if (!wizard) return QStringList(); - return wizard->runWizard(defaultDir, this); + + QString path = defaultLocation; + if (path.isEmpty()) { + const FileManager *fm = m_coreImpl->fileManager(); + switch (wizard->kind()) { + case IWizard::ProjectWizard: + // Project wizards: Check for projects directory or + // use last visited directory of file dialog. Never start + // at current. + path = fm->useProjectsDirectory() ? + fm->projectsDirectory() : + fm->fileDialogLastVisitedDirectory(); + break; + default: + path = fm->fileDialogInitialDirectory(); + break; + } + } + return wizard->runWizard(path, this); } bool MainWindow::showOptionsDialog(const QString &category, diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.cpp b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c648cfe2a803449d5a63f04e2a94f34a47072c99 --- /dev/null +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp @@ -0,0 +1,134 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (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 http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "baseprojectwizarddialog.h" + +#include <coreplugin/basefilewizard.h> +#include <coreplugin/icore.h> +#include <coreplugin/filemanager.h> +#include <utils/projectintropage.h> + +#include <QtCore/QDir> + +namespace ProjectExplorer { + +struct BaseProjectWizardDialogPrivate { + explicit BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id = -1); + + const int introId; + Utils::ProjectIntroPage *introPage; +}; + +BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) : + introId(id), + introPage(page) +{ +} + +BaseProjectWizardDialog::BaseProjectWizardDialog(QWidget *parent) : + QWizard(parent), + d(new BaseProjectWizardDialogPrivate(new Utils::ProjectIntroPage)) +{ + init(); +} + +BaseProjectWizardDialog::BaseProjectWizardDialog(Utils::ProjectIntroPage *introPage, + int introId, + QWidget *parent) : + QWizard(parent), + d(new BaseProjectWizardDialogPrivate(introPage, introId)) +{ + init(); +} + +void BaseProjectWizardDialog::init() +{ + Core::BaseFileWizard::setupWizard(this); + addPage(d->introPage); + connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted())); +} + +BaseProjectWizardDialog::~BaseProjectWizardDialog() +{ + delete d; +} + +QString BaseProjectWizardDialog::name() const +{ + return d->introPage->name(); +} + +QString BaseProjectWizardDialog::path() const +{ + return d->introPage->path(); +} + +void BaseProjectWizardDialog::setIntroDescription(const QString &des) +{ + d->introPage->setDescription(des); +} + +void BaseProjectWizardDialog::setPath(const QString &path) +{ + d->introPage->setPath(path); +} + +void BaseProjectWizardDialog::setName(const QString &name) +{ + d->introPage->setName(name); +} + +void BaseProjectWizardDialog::slotAccepted() +{ + if (d->introPage->useAsDefaultPath()) { + Core::FileManager *fm = Core::ICore::instance()->fileManager(); + fm->setProjectsDirectory(path()); + fm->setUseProjectsDirectory(true); + } +} + +Utils::ProjectIntroPage *BaseProjectWizardDialog::introPage() const +{ + return d->introPage; +} + +QString BaseProjectWizardDialog::projectName(const QString &path) +{ + const QDir pathDir(path); + const QString prefix = tr("untitled"); + for (unsigned i = 0; ; i++) { + QString name = prefix; + if (i) + name += QString::number(i); + if (!pathDir.exists(name)) + return name; + } + return prefix; +} +} // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.h b/src/plugins/projectexplorer/baseprojectwizarddialog.h new file mode 100644 index 0000000000000000000000000000000000000000..9f0eb94b17dd937d669bb7a7bfacb0cffa443ed8 --- /dev/null +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.h @@ -0,0 +1,87 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (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 http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef BASEPROJECTWIZARDDIALOG_H +#define BASEPROJECTWIZARDDIALOG_H + +#include "projectexplorer_export.h" + +#include <QtGui/QWizard> + +namespace Utils { + class ProjectIntroPage; +} + +namespace ProjectExplorer { + +struct BaseProjectWizardDialogPrivate; + +/* BaseProjectWizardDialog: Presents the introductory + * page and takes care of setting the directory as default + * should the user wish to do that. */ + +class PROJECTEXPLORER_EXPORT BaseProjectWizardDialog : public QWizard +{ + Q_OBJECT + +protected: + explicit BaseProjectWizardDialog(QWidget *parent = 0); + explicit BaseProjectWizardDialog(Utils::ProjectIntroPage *introPage, + int introId = -1, + QWidget *parent = 0); + +public: + virtual ~BaseProjectWizardDialog(); + + QString name() const; + QString path() const; + + // Generate a new project name (untitled<n>) in path. + static QString projectName(const QString &path); + +public slots: + void setIntroDescription(const QString &d); + void setPath(const QString &path); + void setName(const QString &name); + +protected: + Utils::ProjectIntroPage *introPage() const; + +private slots: + void slotAccepted(); + +private: + void init(); + + BaseProjectWizardDialogPrivate *d; +}; + +} // namespace ProjectExplorer + +#endif // BASEPROJECTWIZARDDIALOG_H diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index fbc3219b14fe3a825e1999ae1b20d5c7c8c669e0..326e7d9e1d27b494d41a819f933269035e0dc70e 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -66,7 +66,8 @@ HEADERS += projectexplorer.h \ projectexplorersettingspage.h \ projectwelcomepage.h \ projectwelcomepagewidget.h \ - qmakeparser.h + qmakeparser.h \ + baseprojectwizarddialog.h SOURCES += projectexplorer.cpp \ projectwindow.cpp \ buildmanager.cpp \ @@ -120,7 +121,8 @@ SOURCES += projectexplorer.cpp \ projectwelcomepage.cpp \ projectwelcomepagewidget.cpp \ corelistenercheckingforrunningbuild.cpp \ - qmakeparser.cpp + qmakeparser.cpp \ + baseprojectwizarddialog.cpp FORMS += processstep.ui \ editorsettingspropertiespage.ui \ runsettingspropertiespage.ui \ diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.cpp b/src/plugins/projectexplorer/projectexplorersettingspage.cpp index 3a4993a661c997c847467532c7ad4fce2249f14f..833a91a63908f7bf64acdfdba2d9bd46a3cce01f 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.cpp +++ b/src/plugins/projectexplorer/projectexplorersettingspage.cpp @@ -32,11 +32,16 @@ #include "projectexplorerconstants.h" #include "projectexplorer.h" +#include <coreplugin/icore.h> +#include <coreplugin/filemanager.h> + #include <QtGui/QLabel> namespace ProjectExplorer { namespace Internal { + enum { UseCurrentDirectory, UseProjectDirectory }; + ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) : QWidget(parent) { @@ -44,6 +49,10 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) : #ifndef Q_OS_WIN setJomVisible(false); #endif + m_ui.directoryButtonGroup->setId(m_ui.currentDirectoryRadioButton, UseCurrentDirectory); + m_ui.directoryButtonGroup->setId(m_ui.directoryRadioButton, UseProjectDirectory); + connect(m_ui.directoryButtonGroup, SIGNAL(buttonClicked(int)), + this, SLOT(slotDirectoryButtonGroupChanged())); } void ProjectExplorerSettingsWidget::setJomVisible(bool v) @@ -70,15 +79,46 @@ void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings & m_ui.jomCheckbox->setChecked(pes.useJom); } +QString ProjectExplorerSettingsWidget::projectsDirectory() const +{ + return m_ui.projectsDirectoryPathChooser->path(); +} + +void ProjectExplorerSettingsWidget::setProjectsDirectory(const QString &pd) +{ + m_ui.projectsDirectoryPathChooser->setPath(pd); +} + +bool ProjectExplorerSettingsWidget::useProjectsDirectory() +{ + return m_ui.directoryButtonGroup->checkedId() == UseProjectDirectory; +} + +void ProjectExplorerSettingsWidget::setUseProjectsDirectory(bool b) +{ + if (useProjectsDirectory() != b) { + (b ? m_ui.directoryRadioButton : m_ui.currentDirectoryRadioButton)->setChecked(true); + slotDirectoryButtonGroupChanged(); + } +} + +void ProjectExplorerSettingsWidget::slotDirectoryButtonGroupChanged() +{ + m_ui.projectsDirectoryPathChooser->setEnabled(useProjectsDirectory()); +} + QString ProjectExplorerSettingsWidget::searchKeywords() const { - return QLatin1String("jom"); + return QLatin1String("jom") + QLatin1Char(' ') + m_ui.directoryGroupBox->title(); } +// ------------------ ProjectExplorerSettingsPage ProjectExplorerSettingsPage::ProjectExplorerSettingsPage() { } + + QString ProjectExplorerSettingsPage::id() const { return QLatin1String(Constants::PROJECTEXPLORER_PAGE); @@ -86,7 +126,7 @@ QString ProjectExplorerSettingsPage::id() const QString ProjectExplorerSettingsPage::trName() const { - return tr("Build and Run"); + return tr("General"); } QString ProjectExplorerSettingsPage::category() const @@ -103,6 +143,9 @@ QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent) { m_widget = new ProjectExplorerSettingsWidget(parent); m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings()); + const Core::FileManager *fm = Core::ICore::instance()->fileManager(); + m_widget->setProjectsDirectory(fm->projectsDirectory()); + m_widget->setUseProjectsDirectory(fm->useProjectsDirectory()); if (m_searchKeywords.isEmpty()) m_searchKeywords = m_widget->searchKeywords(); return m_widget; @@ -110,8 +153,12 @@ QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent) void ProjectExplorerSettingsPage::apply() { - if (m_widget) + if (m_widget) { ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings()); + Core::FileManager *fm = Core::ICore::instance()->fileManager(); + fm->setProjectsDirectory(m_widget->projectsDirectory()); + fm->setUseProjectsDirectory(m_widget->useProjectsDirectory()); + } } void ProjectExplorerSettingsPage::finish() diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.h b/src/plugins/projectexplorer/projectexplorersettingspage.h index b70ae1eccd8585b0d479da4d8868ee6aea8a45c6..f2888f5c8e1edd1761ec56883539e44c05a018f9 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.h +++ b/src/plugins/projectexplorer/projectexplorersettingspage.h @@ -48,8 +48,16 @@ public: ProjectExplorerSettings settings() const; void setSettings(const ProjectExplorerSettings &s) const; + QString projectsDirectory() const; + void setProjectsDirectory(const QString &pd); + + bool useProjectsDirectory(); + void setUseProjectsDirectory(bool v); + QString searchKeywords() const; +private slots: + void slotDirectoryButtonGroupChanged(); private: void setJomVisible(bool); diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.ui b/src/plugins/projectexplorer/projectexplorersettingspage.ui index 2e912e52730c9ce36585b6310e617c1342ea63ee..385e48aa2e604033b6eddd609106e11fcc8bd948 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.ui +++ b/src/plugins/projectexplorer/projectexplorersettingspage.ui @@ -6,13 +6,54 @@ <rect> <x>0</x> <y>0</y> - <width>338</width> - <height>289</height> + <width>437</width> + <height>343</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QGroupBox" name="directoryGroupBox"> + <property name="title"> + <string>Projects Directory </string> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::ExpandingFieldsGrow</enum> + </property> + <item row="1" column="1"> + <widget class="Utils::PathChooser" name="projectsDirectoryPathChooser"/> + </item> + <item row="0" column="0" colspan="2"> + <widget class="QRadioButton" name="currentDirectoryRadioButton"> + <property name="text"> + <string>Current directory</string> + </property> + <attribute name="buttonGroup"> + <string>directoryButtonGroup</string> + </attribute> + </widget> + </item> + <item row="1" column="0"> + <widget class="QRadioButton" name="directoryRadioButton"> + <property name="text"> + <string>Directory</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <attribute name="buttonGroup"> + <string>directoryButtonGroup</string> + </attribute> + </widget> + </item> + </layout> + </widget> + </item> <item> <widget class="QGroupBox" name="buildAndRunGroupBox"> + <property name="title"> + <string>Build and Run</string> + </property> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QCheckBox" name="saveAllFilesCheckBox"> @@ -86,6 +127,16 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>Utils::PathChooser</class> + <extends>QWidget</extends> + <header location="global">utils/pathchooser.h</header> + </customwidget> + </customwidgets> <resources/> <connections/> + <buttongroups> + <buttongroup name="directoryButtonGroup"/> + </buttongroups> </ui> diff --git a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp index 94019f9c1f3926c1a8f9aea14adfb12bab1d0ae3..fe3f1fb1abf553b1a56338ba96ea7efd5f28badd 100644 --- a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp +++ b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.cpp @@ -29,149 +29,21 @@ #include "qmlnewprojectwizard.h" -#include <coreplugin/icore.h> -#include <coreplugin/mimedatabase.h> #include <projectexplorer/projectexplorer.h> -#include <utils/filenamevalidatinglineedit.h> -#include <utils/filewizardpage.h> -#include <utils/pathchooser.h> -#include <utils/projectintropage.h> - -#include <QtCore/QDir> -#include <QtCore/QtDebug> - -#include <QtGui/QDirModel> -#include <QtGui/QFormLayout> -#include <QtGui/QListView> -#include <QtGui/QTreeView> +#include <QtCore/QTextStream> using namespace QmlProjectManager::Internal; -using namespace Utils; - -namespace { - -class DirModel : public QDirModel -{ -public: - DirModel(QObject *parent) - : QDirModel(parent) - { setFilter(QDir::Dirs | QDir::NoDotAndDotDot); } - - virtual ~DirModel() - { } - -public: - virtual int columnCount(const QModelIndex &) const - { return 1; } - - virtual Qt::ItemFlags flags(const QModelIndex &index) const - { return QDirModel::flags(index) | Qt::ItemIsUserCheckable; } - - virtual QVariant data(const QModelIndex &index, int role) const - { - if (index.column() == 0 && role == Qt::CheckStateRole) { - if (m_selectedPaths.contains(index)) - return Qt::Checked; - - return Qt::Unchecked; - } - - return QDirModel::data(index, role); - } - - virtual bool setData(const QModelIndex &index, const QVariant &value, int role) - { - if (index.column() == 0 && role == Qt::CheckStateRole) { - if (value.toBool()) - m_selectedPaths.insert(index); - else - m_selectedPaths.remove(index); - - return true; - } - - return QDirModel::setData(index, value, role); - } - - void clearSelectedPaths() - { m_selectedPaths.clear(); } - - QSet<QString> selectedPaths() const - { - QSet<QString> paths; - - foreach (const QModelIndex &index, m_selectedPaths) - paths.insert(filePath(index)); - - return paths; - } - -private: - QSet<QModelIndex> m_selectedPaths; -}; - -} // end of anonymous namespace - ////////////////////////////////////////////////////////////////////////////// // QmlNewProjectWizardDialog ////////////////////////////////////////////////////////////////////////////// - -QmlNewProjectWizardDialog::QmlNewProjectWizardDialog(QWidget *parent) - : QWizard(parent) +QmlNewProjectWizardDialog::QmlNewProjectWizardDialog(QWidget *parent) : + ProjectExplorer::BaseProjectWizardDialog(parent) { setWindowTitle(tr("New QML Project")); - - m_introPage = new Utils::ProjectIntroPage(); - m_introPage->setDescription(tr("This wizard generates a QML application project.")); - - addPage(m_introPage); -} - -QmlNewProjectWizardDialog::~QmlNewProjectWizardDialog() -{ } - -QString QmlNewProjectWizardDialog::path() const -{ - return m_introPage->path(); -} - -void QmlNewProjectWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -QString QmlNewProjectWizardDialog::projectName() const -{ - return m_introPage->name(); -} - -void QmlNewProjectWizardDialog::updateFilesView(const QModelIndex ¤t, - const QModelIndex &) -{ - if (! current.isValid()) - m_filesView->setModel(0); - - else { - const QString selectedPath = m_dirModel->filePath(current); - - if (! m_filesView->model()) - m_filesView->setModel(m_filesModel); - - m_filesView->setRootIndex(m_filesModel->index(selectedPath)); - } -} - -void QmlNewProjectWizardDialog::initializePage(int id) -{ - Q_UNUSED(id) -} - -bool QmlNewProjectWizardDialog::validateCurrentPage() -{ - return QWizard::validateCurrentPage(); + setIntroDescription(tr("This wizard generates a QML application project.")); } QmlNewProjectWizard::QmlNewProjectWizard() @@ -197,9 +69,9 @@ QWizard *QmlNewProjectWizard::createWizardDialog(QWidget *parent, const WizardPageList &extensionPages) const { QmlNewProjectWizardDialog *wizard = new QmlNewProjectWizardDialog(parent); - setupWizard(wizard); wizard->setPath(defaultPath); + wizard->setName(QmlNewProjectWizardDialog::projectName(defaultPath)); foreach (QWizardPage *p, extensionPages) wizard->addPage(p); @@ -213,7 +85,7 @@ Core::GeneratedFiles QmlNewProjectWizard::generateFiles(const QWizard *w, Q_UNUSED(errorMessage) const QmlNewProjectWizardDialog *wizard = qobject_cast<const QmlNewProjectWizardDialog *>(w); - const QString projectName = wizard->projectName(); + const QString projectName = wizard->name(); const QString projectPath = wizard->path() + QLatin1Char('/') + projectName; const QString creatorFileName = Core::BaseFileWizard::buildFileName(projectPath, diff --git a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.h b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.h index 52acd2cf9da3a7de559e1f8e5c44695f960cf867..d418b313fd376d7df746d7579375d8dfc8bfe4b2 100644 --- a/src/plugins/qmlprojectmanager/qmlnewprojectwizard.h +++ b/src/plugins/qmlprojectmanager/qmlnewprojectwizard.h @@ -31,17 +31,7 @@ #define QMLNEWPROJECTWIZARD_H #include <coreplugin/basefilewizard.h> -#include <QtGui/QWizard> - -QT_BEGIN_NAMESPACE -class QDir; -class QDirModel; -class QFileInfo; -class QListView; -class QModelIndex; -class QStringList; -class QTreeView; -QT_END_NAMESPACE +#include <projectexplorer/baseprojectwizarddialog.h> namespace Utils { @@ -54,37 +44,11 @@ class ProjectIntroPage; namespace QmlProjectManager { namespace Internal { -class QmlNewProjectWizardDialog : public QWizard +class QmlNewProjectWizardDialog : public ProjectExplorer::BaseProjectWizardDialog { Q_OBJECT - public: - QmlNewProjectWizardDialog(QWidget *parent = 0); - virtual ~QmlNewProjectWizardDialog(); - - QString path() const; - void setPath(const QString &path); - - QString projectName() const; - -private Q_SLOTS: - void updateFilesView(const QModelIndex ¤t, - const QModelIndex &previous); - -protected: - virtual void initializePage(int id); - virtual bool validateCurrentPage(); - -private: - int m_secondPageId; - - Utils::ProjectIntroPage *m_introPage; - - QTreeView *m_dirView; - QDirModel *m_dirModel; - - QListView *m_filesView; - QDirModel *m_filesModel; + explicit QmlNewProjectWizardDialog(QWidget *parent = 0); }; class QmlNewProjectWizard : public Core::BaseFileWizard diff --git a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp index 8020bdfcf8c238ffb20e3ce4553b61c4b890ef36..075009ee0502bf6c99a13e7c33a25ab7153486f1 100644 --- a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp +++ b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp @@ -34,7 +34,6 @@ #include "filenamingparameters.h" #include <cpptools/cppmodelmanagerinterface.h> -#include <utils/pathchooser.h> namespace Qt4ProjectManager { namespace Internal { @@ -51,7 +50,8 @@ QWizard *CustomWidgetWizard::createWizardDialog(QWidget *parent, const WizardPageList &extensionPages) const { CustomWidgetWizardDialog *rc = new CustomWidgetWizardDialog(name(), icon(), extensionPages, parent); - rc->setPath(defaultPath.isEmpty() ? Utils::PathChooser::homePath() : defaultPath); + rc->setPath(defaultPath); + rc->setName(CustomWidgetWizardDialog::projectName(defaultPath)); rc->setFileNamingParameters(FileNamingParameters(headerSuffix(), sourceSuffix(), QtWizard::lowerCaseFiles())); return rc; } diff --git a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.cpp b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.cpp index b0f2c5a362d5899cf53f9acfc17a0e9c43b98017..171027bacbcd4d295da64b8644e8f2d569c322d0 100644 --- a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.cpp +++ b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.cpp @@ -32,8 +32,6 @@ #include "customwidgetpluginwizardpage.h" #include "customwidgetwizard.h" -#include <utils/projectintropage.h> - namespace Qt4ProjectManager { namespace Internal { @@ -43,20 +41,17 @@ CustomWidgetWizardDialog::CustomWidgetWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, QWidget *parent) : - QWizard(parent), - m_introPage(new Utils::ProjectIntroPage), + ProjectExplorer::BaseProjectWizardDialog(parent), m_widgetsPage(new CustomWidgetWidgetsWizardPage), m_pluginPage(new CustomWidgetPluginWizardPage) { setWindowIcon(icon); setWindowTitle(templateName); - Core::BaseFileWizard::setupWizard(this); - m_introPage->setDescription(tr("This wizard generates a Qt4 Designer Custom Widget " - "or a Qt4 Designer Custom Widget Collection project.")); + setIntroDescription(tr("This wizard generates a Qt4 Designer Custom Widget " + "or a Qt4 Designer Custom Widget Collection project.")); - setPage(IntroPageId, m_introPage); setPage(WidgetsPageId, m_widgetsPage); setPage(PluginPageId, m_pluginPage); @@ -65,21 +60,6 @@ CustomWidgetWizardDialog::CustomWidgetWizardDialog(const QString &templateName, connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int))); } -void CustomWidgetWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -QString CustomWidgetWizardDialog::path() const -{ - return m_introPage->path(); -} - -QString CustomWidgetWizardDialog::name() const -{ - return m_introPage->name(); -} - FileNamingParameters CustomWidgetWizardDialog::fileNamingParameters() const { return m_widgetsPage->fileNamingParameters(); diff --git a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.h b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.h index c4c3505770537611246d15aa2487944f63e23b63..d99e06f701d64298930f285f09330dcc5ef87060 100644 --- a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.h +++ b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizarddialog.h @@ -30,14 +30,9 @@ #ifndef CUSTOMWIDGETWIZARDDIALOG_H #define CUSTOMWIDGETWIZARDDIALOG_H -#include <QtCore/QSharedPointer> - -#include <QtGui/QWizard> -#include <QtGui/QWizardPage> +#include <projectexplorer/baseprojectwizarddialog.h> -namespace Utils { - class ProjectIntroPage; -} +#include <QtCore/QSharedPointer> namespace Qt4ProjectManager { namespace Internal { @@ -47,7 +42,7 @@ class CustomWidgetPluginWizardPage; struct PluginOptions; struct FileNamingParameters; -class CustomWidgetWizardDialog : public QWizard +class CustomWidgetWizardDialog : public ProjectExplorer::BaseProjectWizardDialog { Q_OBJECT public: @@ -58,20 +53,14 @@ public: QSharedPointer<PluginOptions> pluginOptions() const; - QString path() const; - QString name() const; FileNamingParameters fileNamingParameters() const; void setFileNamingParameters(const FileNamingParameters &fnp); -public slots: - void setPath(const QString &path); - private slots: void slotCurrentIdChanged (int id); private: - Utils::ProjectIntroPage *m_introPage; CustomWidgetWidgetsWizardPage *m_widgetsPage; CustomWidgetPluginWizardPage *m_pluginPage; }; diff --git a/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp b/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp index 438ac44152a13dd3635625c772715f01a7f82eb7..921b72840c17daa7e58f11989662b7e36e382cd7 100644 --- a/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp @@ -33,7 +33,6 @@ #include "qt4projectmanager.h" #include "qt4projectmanagerconstants.h" -#include <utils/pathchooser.h> #include <cpptools/cppmodelmanagerinterface.h> #include <QtCore/QDir> @@ -66,8 +65,10 @@ QWizard *ConsoleAppWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { - ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(name(), icon(), extensionPages, parent); - dialog->setPath(defaultPath.isEmpty() ? Utils::PathChooser::homePath() : defaultPath); + ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(name(), icon(), extensionPages, + showModulesPageForApplications(), parent); + dialog->setPath(defaultPath); + dialog->setName(ConsoleAppWizardDialog::projectName(defaultPath)); return dialog; } diff --git a/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.cpp index b3214e400af45b2ba1de2ab52a50c4b998d71c7d..445a34620adceaefea3efdd7ac08c2f684339cd3 100644 --- a/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.cpp @@ -29,10 +29,8 @@ #include "consoleappwizarddialog.h" #include "consoleappwizard.h" -#include "modulespage.h" #include <QtCore/QDebug> -#include <utils/projectintropage.h> namespace Qt4ProjectManager { namespace Internal { @@ -40,45 +38,32 @@ namespace Internal { ConsoleAppWizardDialog::ConsoleAppWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage, QWidget *parent) : - QWizard(parent), - m_introPage(new Utils::ProjectIntroPage), - m_modulesPage(new ModulesPage) + BaseQt4ProjectWizardDialog(showModulesPage, parent) { setWindowIcon(icon); setWindowTitle(templateName); - Core::BaseFileWizard::setupWizard(this); + setSelectedModules(QLatin1String("core")); - m_introPage->setDescription(tr("This wizard generates a Qt4 console application " + setIntroDescription(tr("This wizard generates a Qt4 console application " "project. The application derives from QCoreApplication and does not " "provide a GUI.")); - addPage(m_introPage); - - m_modulesPage->setModuleSelected(QLatin1String("core")); - addPage(m_modulesPage); + addModulesPage(); foreach (QWizardPage *p, extensionPages) addPage(p); } -void ConsoleAppWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -void ConsoleAppWizardDialog::setName(const QString &name) -{ - m_introPage->setName(name); -} - QtProjectParameters ConsoleAppWizardDialog::parameters() const { QtProjectParameters rc; rc.type = QtProjectParameters::ConsoleApp; - rc.name = m_introPage->name(); - rc.path = m_introPage->path(); - rc.selectedModules = m_modulesPage->selectedModules(); - rc.deselectedModules = m_modulesPage-> deselectedModules(); + rc.name = name(); + rc.path = path(); + + rc.selectedModules = selectedModules(); + rc.deselectedModules = deselectedModules(); return rc; } diff --git a/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.h b/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.h index 41aa2f3dfd2ceec306411ce0e3c379264af73305..0ae288392ded513e9dd5ffdb9d62931ee0d05b6e 100644 --- a/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.h +++ b/src/plugins/qt4projectmanager/wizards/consoleappwizarddialog.h @@ -30,37 +30,24 @@ #ifndef CONSOLEAPPWIZARDDIALOG_H #define CONSOLEAPPWIZARDDIALOG_H -#include <QtGui/QWizard> - -namespace Utils { - class ProjectIntroPage; -} +#include "qtwizard.h" namespace Qt4ProjectManager { namespace Internal { struct QtProjectParameters; -class ModulesPage; -class ConsoleAppWizardDialog : public QWizard +class ConsoleAppWizardDialog : public BaseQt4ProjectWizardDialog { Q_OBJECT - public: explicit ConsoleAppWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage = false, QWidget *parent = 0); QtProjectParameters parameters() const; - -public slots: - void setPath(const QString &path); - void setName(const QString &name); - -private: - Utils::ProjectIntroPage *m_introPage; - ModulesPage *m_modulesPage; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp index ad8e07aa33a23986f23fde8a42583fc7f6761124..465ece59c6c3f37a59b4228d14ddf45d9d94ad3c 100644 --- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp @@ -31,8 +31,6 @@ #include "emptyprojectwizarddialog.h" -#include <utils/pathchooser.h> - namespace Qt4ProjectManager { namespace Internal { @@ -48,7 +46,8 @@ QWizard *EmptyProjectWizard::createWizardDialog(QWidget *parent, const WizardPageList &extensionPages) const { EmptyProjectWizardDialog *dialog = new EmptyProjectWizardDialog(name(), icon(), extensionPages, parent); - dialog->setPath(defaultPath.isEmpty() ? Utils::PathChooser::homePath() : defaultPath); + dialog->setPath(defaultPath); + dialog->setName(EmptyProjectWizardDialog::projectName(defaultPath)); return dialog; } diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp index 4953ecf3bdd518e006c2f6f00006aea7851e3269..b32bb7bf035780171e3e4ca2b01eb52ecb9057e0 100644 --- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.cpp @@ -28,10 +28,7 @@ **************************************************************************/ #include "emptyprojectwizarddialog.h" - -#include "emptyprojectwizard.h" - -#include <utils/projectintropage.h> +#include "qtprojectparameters.h" namespace Qt4ProjectManager { namespace Internal { @@ -40,38 +37,24 @@ EmptyProjectWizardDialog::EmptyProjectWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, QWidget *parent) : - QWizard(parent), - m_introPage(new Utils::ProjectIntroPage) + ProjectExplorer::BaseProjectWizardDialog(parent) { setWindowIcon(icon); setWindowTitle(templateName); - Core::BaseFileWizard::setupWizard(this); - - m_introPage->setDescription(tr("This wizard generates an empty Qt4 project. " - "Add files to it later on by using the other wizards.")); - addPage(m_introPage); + setIntroDescription(tr("This wizard generates an empty Qt4 project. " + "Add files to it later on by using the other wizards.")); foreach (QWizardPage *p, extensionPages) addPage(p); } -void EmptyProjectWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -void EmptyProjectWizardDialog::setName(const QString &name) -{ - m_introPage->setName(name); -} - QtProjectParameters EmptyProjectWizardDialog::parameters() const { QtProjectParameters rc; rc.type = QtProjectParameters::EmptyProject; - rc.name = m_introPage->name(); - rc.path = m_introPage->path(); + rc.name = name(); + rc.path = path(); return rc; } diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h index adc9571eec7662bb73b04cdacbdc14e7a82f555e..065339590047257a9d943b6f6a0def7b266964b4 100644 --- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h +++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizarddialog.h @@ -30,21 +30,16 @@ #ifndef EMPTYPROJECTWIZARDDIALOG_H #define EMPTYPROJECTWIZARDDIALOG_H -#include <QtGui/QWizard> - -namespace Utils { - class ProjectIntroPage; -} +#include <projectexplorer/baseprojectwizarddialog.h> namespace Qt4ProjectManager { namespace Internal { struct QtProjectParameters; -class EmptyProjectWizardDialog : public QWizard +class EmptyProjectWizardDialog : public ProjectExplorer::BaseProjectWizardDialog { Q_OBJECT - public: explicit EmptyProjectWizardDialog(const QString &templateName, const QIcon &icon, @@ -52,13 +47,6 @@ public: QWidget *parent = 0); QtProjectParameters parameters() const; - -public slots: - void setPath(const QString &path); - void setName(const QString &name); - -private: - Utils::ProjectIntroPage *m_introPage; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp index 2c4a7d2c86cb4c9de3f97c4fff7f2505f178954e..f63442877e1a2c10e1a4e82817cb195bd81fd934 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp @@ -34,7 +34,6 @@ #include "filespage.h" #include "qt4projectmanagerconstants.h" -#include <utils/pathchooser.h> #include <projectexplorer/projectnodes.h> #include <cpptools/cppmodelmanagerinterface.h> #include <designer/cpp/formclasswizardparameters.h> @@ -83,8 +82,11 @@ QWizard *GuiAppWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { - GuiAppWizardDialog *dialog = new GuiAppWizardDialog(name(), icon(), extensionPages, parent); - dialog->setPath(defaultPath.isEmpty() ? Utils::PathChooser::homePath() : defaultPath); + GuiAppWizardDialog *dialog = new GuiAppWizardDialog(name(), icon(), extensionPages, + showModulesPageForApplications(), + parent); + dialog->setPath(defaultPath); + dialog->setName(GuiAppWizardDialog::projectName(defaultPath)); // Order! suffixes first to generate files correctly dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles()); dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix()); diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp index ab54738fc93ff8b10dc5f8e09c888fbb276a82c4..2c1769369aeea691c9d3b8218c34df3627d9e8a0 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.cpp @@ -28,17 +28,11 @@ **************************************************************************/ #include "guiappwizarddialog.h" -#include "consoleappwizard.h" -#include "modulespage.h" #include "filespage.h" #include "qtprojectparameters.h" -#include <utils/projectintropage.h> - #include <QtGui/QAbstractButton> -enum PageId { IntroPageId, ModulesPageId, FilesPageId }; - namespace Qt4ProjectManager { namespace Internal { @@ -50,32 +44,23 @@ GuiAppParameters::GuiAppParameters() GuiAppWizardDialog::GuiAppWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage, QWidget *parent) : - QWizard(parent), - m_introPage(new Utils::ProjectIntroPage), - m_modulesPage(new ModulesPage), + BaseQt4ProjectWizardDialog(showModulesPage, parent), m_filesPage(new FilesPage) { setWindowIcon(icon); setWindowTitle(templateName); - Core::BaseFileWizard::setupWizard(this); + setSelectedModules(QLatin1String("core gui"), true); - m_introPage->setDescription(tr("This wizard generates a Qt4 GUI application " + setIntroDescription(tr("This wizard generates a Qt4 GUI application " "project. The application derives by default from QApplication " "and includes an empty widget.")); - setPage(IntroPageId, m_introPage); - - const QString coreModule = QLatin1String("core"); - const QString guiModule = QLatin1String("gui"); - m_modulesPage->setModuleSelected(coreModule); - m_modulesPage->setModuleEnabled(coreModule, false); - m_modulesPage->setModuleSelected(guiModule); - m_modulesPage->setModuleEnabled(guiModule, false); - setPage(ModulesPageId, m_modulesPage); + addModulesPage(); m_filesPage->setFormInputCheckable(true); m_filesPage->setClassTypeComboVisible(false); - setPage(FilesPageId, m_filesPage); + addPage(m_filesPage); foreach (QWizardPage *p, extensionPages) addPage(p); @@ -98,25 +83,14 @@ void GuiAppWizardDialog::setLowerCaseFiles(bool l) m_filesPage->setLowerCaseFiles(l); } - -void GuiAppWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -void GuiAppWizardDialog::setName(const QString &name) -{ - m_introPage->setName(name); -} - QtProjectParameters GuiAppWizardDialog::projectParameters() const { QtProjectParameters rc; rc.type = QtProjectParameters::GuiApp; - rc.name = m_introPage->name(); - rc.path = m_introPage->path(); - rc.selectedModules = m_modulesPage->selectedModules(); - rc.deselectedModules = m_modulesPage-> deselectedModules(); + rc.name = name(); + rc.path = path(); + rc.selectedModules = selectedModules(); + rc.deselectedModules = deselectedModules(); return rc; } diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h index ee6d327cf5e168b674066c49f8c098be551b8099..204dcf26458f8e9a9bf87562fe5b5f6e74334407 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h +++ b/src/plugins/qt4projectmanager/wizards/guiappwizarddialog.h @@ -30,17 +30,12 @@ #ifndef GUIAPPWIZARDDIALOG_H #define GUIAPPWIZARDDIALOG_H -#include <QtGui/QWizard> - -namespace Utils { - class ProjectIntroPage; -} +#include "qtwizard.h" namespace Qt4ProjectManager { namespace Internal { struct QtProjectParameters; -class ModulesPage; class FilesPage; // Additional parameters required besides QtProjectParameters @@ -55,7 +50,7 @@ struct GuiAppParameters bool designerForm; }; -class GuiAppWizardDialog : public QWizard +class GuiAppWizardDialog : public BaseQt4ProjectWizardDialog { Q_OBJECT @@ -63,6 +58,7 @@ public: explicit GuiAppWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage = false, QWidget *parent = 0); void setBaseClasses(const QStringList &baseClasses); @@ -72,13 +68,7 @@ public: QtProjectParameters projectParameters() const; GuiAppParameters parameters() const; -public slots: - void setPath(const QString &path); - void setName(const QString &name); - private: - Utils::ProjectIntroPage *m_introPage; - ModulesPage *m_modulesPage; FilesPage *m_filesPage; }; diff --git a/src/plugins/qt4projectmanager/wizards/librarywizard.cpp b/src/plugins/qt4projectmanager/wizards/librarywizard.cpp index 9247d26b3cf91eb3c36841fdcf256ab80093984e..a8af318e774360affd47e6f9b4383d25406d2ae9 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/librarywizard.cpp @@ -33,7 +33,6 @@ #include "qt4projectmanagerconstants.h" #include <utils/codegeneration.h> -#include <utils/pathchooser.h> #include <cpptools/cppmodelmanagerinterface.h> #include <QtCore/QDir> @@ -58,9 +57,11 @@ QWizard *LibraryWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { - LibraryWizardDialog *dialog = new LibraryWizardDialog(name(), icon(), extensionPages, parent); + LibraryWizardDialog *dialog = new LibraryWizardDialog(name(), icon(), extensionPages, + showModulesPageForLibraries(), parent); dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles()); - dialog->setPath(defaultPath.isEmpty() ? Utils::PathChooser::homePath() : defaultPath); + dialog->setPath(defaultPath); + dialog->setName(LibraryWizardDialog::projectName(defaultPath)); dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix()); return dialog; } diff --git a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp index d378de0eaa0326ddfdbde4ccf0b52018eaa461b7..e445f628543e594d52d7cf94210512bf4a7a33a1 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp +++ b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp @@ -28,8 +28,6 @@ **************************************************************************/ #include "librarywizarddialog.h" - -#include "consoleappwizard.h" #include "filespage.h" #include "libraryparameters.h" #include "modulespage.h" @@ -128,6 +126,7 @@ LibraryIntroPage::LibraryIntroPage(QWidget *parent) : insertControl(0, new QLabel(LibraryWizardDialog::tr("Type")), m_typeCombo); } + QtProjectParameters::Type LibraryIntroPage::type() const { return static_cast<QtProjectParameters::Type>(m_typeCombo->itemData(m_typeCombo->currentIndex()).toInt()); @@ -147,25 +146,21 @@ int LibraryIntroPage::nextId() const LibraryWizardDialog::LibraryWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage, QWidget *parent) : - QWizard(parent), - m_introPage(new LibraryIntroPage), - m_modulesPage(new ModulesPage), + BaseQt4ProjectWizardDialog(showModulesPage, new LibraryIntroPage, IntroPageId, parent), m_filesPage(new FilesPage), m_pluginBaseClassesInitialized(false) { setWindowIcon(icon); setWindowTitle(templateName); - Core::BaseFileWizard::setupWizard(this); + setSelectedModules(QLatin1String("core")); // Note that QWizard::currentIdChanged() is emitted at strange times. // Use the intro page instead, set up initially - m_introPage->setDescription(tr("This wizard generates a C++ library project.")); - - setPage(IntroPageId, m_introPage); + setIntroDescription(tr("This wizard generates a C++ library project.")); - m_modulesPage->setModuleSelected(QLatin1String("core")); - setPage(ModulesPageId, m_modulesPage); + addModulesPage(ModulesPageId); m_filesPage->setNamespacesEnabled(true); m_filesPage->setFormFileInputVisible(false); @@ -188,22 +183,17 @@ void LibraryWizardDialog::setLowerCaseFiles(bool l) m_filesPage->setLowerCaseFiles(l); } -void LibraryWizardDialog::setPath(const QString &path) -{ - m_introPage->setPath(path); -} - -void LibraryWizardDialog::setName(const QString &name) +QtProjectParameters::Type LibraryWizardDialog::type() const { - m_introPage->setName(name); + return static_cast<const LibraryIntroPage*>(introPage())->type(); } QtProjectParameters LibraryWizardDialog::parameters() const { QtProjectParameters rc; - rc.type = m_introPage->type(); - rc.name = m_introPage->name(); - rc.path = m_introPage->path(); + rc.type = type(); + rc.name = name(); + rc.path = path(); if (rc.type == QtProjectParameters::Qt4Plugin) { // Plugin: Dependencies & Target directory if (const PluginBaseClasses *plb = findPluginBaseClass(m_filesPage->baseClassName())) { @@ -215,8 +205,8 @@ QtProjectParameters LibraryWizardDialog::parameters() const } } else { // Modules from modules page - rc.selectedModules = m_modulesPage->selectedModules(); - rc.deselectedModules = m_modulesPage-> deselectedModules(); + rc.selectedModules = selectedModules(); + rc.deselectedModules = deselectedModules(); } return rc; } @@ -228,7 +218,7 @@ void LibraryWizardDialog::slotCurrentIdChanged(int id) // Switching to files page: Set up base class accordingly (plugin) if (id != FilePageId) return; - switch (m_introPage->type()) { + switch (type()) { case QtProjectParameters::Qt4Plugin: if (!m_pluginBaseClassesInitialized) { if (debugLibWizard) @@ -246,9 +236,10 @@ void LibraryWizardDialog::slotCurrentIdChanged(int id) break; default: { // Urrm, figure out a good class name. Use project name this time - QString name = m_introPage->name(); - name[0] = name.at(0).toUpper(); - m_filesPage->setClassName(name); + QString className = name(); + if (!className.isEmpty()) + className[0] = className.at(0).toUpper(); + m_filesPage->setClassName(className); m_filesPage->setBaseClassInputVisible(false); } break; diff --git a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.h b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.h index c0ebb3a78de713b57dae5f0d229de4fe92b5dd50..6d81a281c0eea57b3dda2346a31cc530a25cc6be 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizarddialog.h +++ b/src/plugins/qt4projectmanager/wizards/librarywizarddialog.h @@ -30,19 +30,18 @@ #ifndef LIBRARYWIZARDDIALOG_H #define LIBRARYWIZARDDIALOG_H -#include <QtGui/QWizard> +#include "qtwizard.h" +#include "qtprojectparameters.h" namespace Qt4ProjectManager { namespace Internal { struct QtProjectParameters; -class ModulesPage; -class LibraryIntroPage; class FilesPage; struct LibraryParameters; // Library wizard dialog. -class LibraryWizardDialog : public QWizard +class LibraryWizardDialog : public BaseQt4ProjectWizardDialog { Q_OBJECT @@ -50,6 +49,7 @@ public: explicit LibraryWizardDialog(const QString &templateName, const QIcon &icon, const QList<QWizardPage*> &extensionPages, + bool showModulesPage, QWidget *parent = 0); void setSuffixes(const QString &header, const QString &source, const QString &form= QString()); @@ -58,16 +58,12 @@ public: QtProjectParameters parameters() const; LibraryParameters libraryParameters() const; -public slots: - void setPath(const QString &path); - void setName(const QString &name); - private slots: void slotCurrentIdChanged(int); private: - LibraryIntroPage *m_introPage; - ModulesPage *m_modulesPage; + QtProjectParameters::Type type() const; + FilesPage *m_filesPage; bool m_pluginBaseClassesInitialized; }; diff --git a/src/plugins/qt4projectmanager/wizards/qtwizard.cpp b/src/plugins/qt4projectmanager/wizards/qtwizard.cpp index 2394ae868d50758738f77b8a0893ed2bd0229adf..765cf9d5c5383f37f3b849dab19450ed6543a7dc 100644 --- a/src/plugins/qt4projectmanager/wizards/qtwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/qtwizard.cpp @@ -30,6 +30,7 @@ #include "qtwizard.h" #include "qt4project.h" #include "qt4projectmanagerconstants.h" +#include "modulespage.h" #include <coreplugin/icore.h> #include <projectexplorer/projectexplorer.h> @@ -113,8 +114,79 @@ bool QtWizard::lowerCaseFiles() return Core::ICore::instance()->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool(); } +bool QtWizard::showModulesPageForApplications() +{ + return false; +} + +bool QtWizard::showModulesPageForLibraries() +{ + return true; +} + +// ----------------- BaseQt4ProjectWizardDialog +BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage, QWidget *parent) : + ProjectExplorer::BaseProjectWizardDialog(parent), + m_modulesPage(0) +{ + init(showModulesPage); +} + +BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage, + Utils::ProjectIntroPage *introPage, + int introId, QWidget *parent) : + ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent), + m_modulesPage(0) +{ + init(showModulesPage); +} + +void BaseQt4ProjectWizardDialog::init(bool showModulesPage) +{ + if (showModulesPage) + m_modulesPage = new ModulesPage; +} +void BaseQt4ProjectWizardDialog::addModulesPage(int id) +{ + if (m_modulesPage) { + if (id >= 0) { + setPage(id, m_modulesPage); + } else { + addPage(m_modulesPage); + } + } +} + +QString BaseQt4ProjectWizardDialog::selectedModules() const +{ + return m_modulesPage ? m_modulesPage->selectedModules() : m_selectedModules; +} +void BaseQt4ProjectWizardDialog::setSelectedModules(const QString &modules, bool lock) +{ + if (m_modulesPage) { + foreach(const QString &module, modules.split(QLatin1Char(' '))) { + m_modulesPage->setModuleSelected(module, true); + m_modulesPage->setModuleEnabled(module, !lock); + } + } else { + m_selectedModules = modules; + } +} +QString BaseQt4ProjectWizardDialog::deselectedModules() const +{ + return m_modulesPage ? m_modulesPage->deselectedModules() : m_deselectedModules; +} +void BaseQt4ProjectWizardDialog::setDeselectedModules(const QString &modules) +{ + if (m_modulesPage) { + foreach(const QString &module, modules.split(QLatin1Char(' '))) + m_modulesPage->setModuleSelected(module, false); + } else { + m_deselectedModules = modules; + } +} diff --git a/src/plugins/qt4projectmanager/wizards/qtwizard.h b/src/plugins/qt4projectmanager/wizards/qtwizard.h index 715ba5cf512916f5f83ea1edc39435ccf4277819..1712446bc7866dfa923b5513d0976f35e515a94b 100644 --- a/src/plugins/qt4projectmanager/wizards/qtwizard.h +++ b/src/plugins/qt4projectmanager/wizards/qtwizard.h @@ -31,6 +31,7 @@ #define QTWIZARD_H #include "qtprojectparameters.h" +#include <projectexplorer/baseprojectwizarddialog.h> #include <coreplugin/basefilewizard.h> @@ -38,6 +39,8 @@ namespace Qt4ProjectManager { namespace Internal { +class ModulesPage; + /* Base class for wizard creating Qt projects using QtProjectParameters. * To implement a project wizard, overwrite: * - createWizardDialog() to create up the dialog @@ -64,10 +67,45 @@ protected: // Query CppTools settings for the class wizard settings static bool lowerCaseFiles(); +protected: + static bool showModulesPageForApplications(); + static bool showModulesPageForLibraries(); + private: bool postGenerateFiles(const Core::GeneratedFiles &l, QString *errorMessage); }; +/* BaseQt4ProjectWizardDialog: Additionally offers modules page + * and getter/setter for blank-delimited modules list, transparently + * handling the visibility of the modules page list. */ + +class BaseQt4ProjectWizardDialog : public ProjectExplorer::BaseProjectWizardDialog { + Q_OBJECT + +protected: + explicit BaseQt4ProjectWizardDialog(bool showModulesPage, QWidget *parent = 0); + explicit BaseQt4ProjectWizardDialog(bool showModulesPage, + Utils::ProjectIntroPage *introPage, + int introId = -1, + QWidget *parent = 0); + + void addModulesPage(int id = -1); + +public: + QString selectedModules() const; + void setSelectedModules(const QString &, bool lock = false); + + QString deselectedModules() const; + void setDeselectedModules(const QString &); + +private: + inline void init(bool showModulesPage); + + ModulesPage *m_modulesPage; + QString m_selectedModules; + QString m_deselectedModules; +}; + } // namespace Internal } // namespace Qt4ProjectManager