diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index a71ca7c8b008d477be1fad35bf59eeeb38e61d61..e07c4106d4be4fec3e384d9cfa97bbfd6414c5e6 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -105,6 +105,7 @@ public: CMakeStep *cmakeStep() const; QStringList targets() const; + private: void parseCMakeLists(const QDir &directory); QString findCbpFile(const QDir &); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index 966c0144355d73273e7d03b0db7d9ce527e3f7dc..fb19dbdbf9b897afce50db1241eb059caea7328b 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -39,16 +39,25 @@ #include <coreplugin/icore.h> #include <coreplugin/uniqueidmanager.h> #include <projectexplorer/projectexplorerconstants.h> +#include <projectexplorer/environment.h> +#include <QtCore/QSettings> +#include <QFormLayout> using namespace CMakeProjectManager::Internal; -CMakeManager::CMakeManager() +CMakeManager::CMakeManager(CMakeSettingsPage *cmakeSettingsPage) + : m_settingsPage(cmakeSettingsPage) { Core::ICore *core = Core::ICore::instance(); m_projectContext = core->uniqueIDManager()->uniqueIdentifier(CMakeProjectManager::Constants::PROJECTCONTEXT); m_projectLanguage = core->uniqueIDManager()->uniqueIdentifier(ProjectExplorer::Constants::LANG_CXX); } +CMakeSettingsPage::~CMakeSettingsPage() +{ + +} + int CMakeManager::projectContext() const { return m_projectContext; @@ -62,6 +71,14 @@ int CMakeManager::projectLanguage() const ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName) { // TODO check wheter this project is already opened + // Check that we have a cmake executable first + // Look at the settings first + QString cmakeExecutable = m_settingsPage->cmakeExecutable(); + if (cmakeExecutable.isNull()) + m_settingsPage->askUserForCMakeExecutable(); + cmakeExecutable = m_settingsPage->cmakeExecutable(); + if (cmakeExecutable.isNull()) + return 0; return new CMakeProject(this, fileName); } @@ -69,3 +86,89 @@ QString CMakeManager::mimeType() const { return Constants::CMAKEMIMETYPE; } + +///// +// CMakeSettingsPage +//// + +CMakeSettingsPage::CMakeSettingsPage() +{ + Core::ICore *core = Core::ICore::instance(); + QSettings * settings = core->settings(); + settings->beginGroup("CMakeSettings"); + m_cmakeExecutable = settings->value("cmakeExecutable").toString(); + settings->endGroup(); +} + +QString CMakeSettingsPage::findCmakeExecutable() const +{ + ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment(); + return env.searchInPath("cmake"); +} + + +QString CMakeSettingsPage::name() const +{ + return "CMake"; +} + +QString CMakeSettingsPage::category() const +{ + return "CMake"; +} + +QString CMakeSettingsPage::trCategory() const +{ + return tr("CMake"); +} + +QWidget *CMakeSettingsPage::createPage(QWidget *parent) +{ + QWidget *w = new QWidget(parent); + QFormLayout *fl = new QFormLayout(w); + m_pathchooser = new Core::Utils::PathChooser(w); + m_pathchooser->setExpectedKind(Core::Utils::PathChooser::Command); + fl->addRow("CMake executable", m_pathchooser); + m_pathchooser->setPath(cmakeExecutable()); + return w; +} + +void CMakeSettingsPage::saveSettings() const +{ + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("CMakeSettings"); + settings->setValue("cmakeExecutable", m_cmakeExecutable); + settings->endGroup(); +} + +void CMakeSettingsPage::apply() +{ + m_cmakeExecutable = m_pathchooser->path(); + saveSettings(); +} + +void CMakeSettingsPage::finish() +{ + +} + +QString CMakeSettingsPage::cmakeExecutable() const +{ + if (m_cmakeExecutable.isEmpty()) { + m_cmakeExecutable = findCmakeExecutable(); + if (!m_cmakeExecutable.isEmpty()) { + saveSettings(); + } + } + return m_cmakeExecutable; +} + +void CMakeSettingsPage::askUserForCMakeExecutable() +{ + // TODO implement + // That is ideally add a label to the settings page, which says something + // to the effect: please configure the cmake executable + // and show the settings page + // ensure that we rehide the label in the finish() function + // But to test that i need an environment without cmake, e.g. windows +} diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index 34d97f1cc7c9f2f21920aecd33eb284c0849c133..f0481c51498aef6974234d5e725adfce45a12ba8 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -34,16 +34,20 @@ #ifndef CMAKEPROJECTMANAGER_H #define CMAKEPROJECTMANAGER_H +#include <coreplugin/dialogs/ioptionspage.h> #include <projectexplorer/iprojectmanager.h> +#include <utils/pathchooser.h> namespace CMakeProjectManager { namespace Internal { +class CMakeSettingsPage; + class CMakeManager : public ProjectExplorer::IProjectManager { Q_OBJECT public: - CMakeManager(); + CMakeManager(CMakeSettingsPage *cmakeSettingsPage); virtual int projectContext() const; virtual int projectLanguage() const; @@ -55,6 +59,30 @@ public: private: int m_projectContext; int m_projectLanguage; + CMakeSettingsPage *m_settingsPage; +}; + +class CMakeSettingsPage : public Core::IOptionsPage +{ + Q_OBJECT +public: + CMakeSettingsPage(); + virtual ~CMakeSettingsPage(); + virtual QString name() const; + virtual QString category() const; + virtual QString trCategory() const; + + virtual QWidget *createPage(QWidget *parent); + virtual void apply(); + virtual void finish(); + + QString cmakeExecutable() const; + void askUserForCMakeExecutable(); +private: + void saveSettings() const; + QString findCmakeExecutable() const; + mutable QString m_cmakeExecutable; + Core::Utils::PathChooser *m_pathchooser; }; } // namespace Internal diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro index 74f69fea4abb6116609bb704cc399e52259369b2..688d16b0a97f946f55d42793848e8cac9b2cc196 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro @@ -18,3 +18,4 @@ SOURCES = cmakeproject.cpp \ makestep.cpp \ cmakerunconfiguration.cpp RESOURCES += cmakeproject.qrc +FORMS += cmakesettingspage.ui diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index 29ad08ec5f1501ee5ec58c5a62f1fb72673a4f68..4c16e0d997bd819beb90b59e1b33abec1d411a29 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -59,7 +59,9 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString * Core::ICore *core = Core::ICore::instance(); if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":cmakeproject/CMakeProject.mimetypes.xml"), errorMessage)) return false; - addAutoReleasedObject(new CMakeManager()); + CMakeSettingsPage *cmp = new CMakeSettingsPage(); + addAutoReleasedObject(cmp); + addAutoReleasedObject(new CMakeManager(cmp)); addAutoReleasedObject(new CMakeBuildStepFactory()); addAutoReleasedObject(new MakeBuildStepFactory()); addAutoReleasedObject(new CMakeRunConfigurationFactory()); diff --git a/src/plugins/projectexplorer/environment.cpp b/src/plugins/projectexplorer/environment.cpp index 7a767d75b2e1692f0dfd563bf6f2328e01383f68..38f35af97274f44fb78fe8af4105558417e3ad4c 100644 --- a/src/plugins/projectexplorer/environment.cpp +++ b/src/plugins/projectexplorer/environment.cpp @@ -183,10 +183,6 @@ void Environment::clear() m_values.clear(); } -// currently it returns the string that was passed in, except -// under windows and if the executable does not end in .exe -// then it returns executable appended with .exe -// that is clearly wrong QString Environment::searchInPath(QString executable) { // qDebug()<<"looking for "<<executable<< "in PATH: "<<m_values.value("PATH");