diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -74,7 +74,8 @@ settings/editstyledialog.cpp settings/projectpreferences.cpp settings/environmentwidget.cpp - settings/environmentgroupmodel.cpp + settings/environmentprofilemodel.cpp + settings/environmentprofilelistmodel.cpp settings/environmentpreferences.cpp settings/languagepreferences.cpp settings/bgpreferences.cpp diff --git a/shell/settings/environmentgroupmodel.h b/shell/settings/environmentgroupmodel.h deleted file mode 100644 --- a/shell/settings/environmentgroupmodel.h +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of KDevelop -Copyright 2007 Andreas Pakulat - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ - -#ifndef KDEVPLATFORM_ENVIRONMENTGROUPMODEL_H -#define KDEVPLATFORM_ENVIRONMENTGROUPMODEL_H - -#include -#include -#include "util/environmentgrouplist.h" - -class QVariant; -class QModelIndex; - -namespace KDevelop -{ - - -class EnvironmentGroupModel : public QAbstractTableModel, public EnvironmentGroupList -{ - Q_OBJECT -public: - enum Role { - VariableRole = Qt::UserRole + 1, - ValueRole - }; - - enum Column { - VariableColumn, - ValueColumn - }; - - EnvironmentGroupModel(); - int rowCount( const QModelIndex &parent = QModelIndex() ) const override; - int columnCount( const QModelIndex &parent = QModelIndex() ) const override; - Qt::ItemFlags flags( const QModelIndex& idx ) const override; - QVariant data( const QModelIndex& idx, int role = Qt::DisplayRole) const override; - QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - bool setData( const QModelIndex& idx, const QVariant&, int role = Qt::EditRole) override; - void setCurrentGroup( const QString& group ); - bool cloneCurrentGroup( const QString& newGroup ); - - /** - * Load a set of environment variables from a string. - * - * @p plainText In the form "FOO=1\nBAR=2" - */ - void loadEnvironmentFromString(const QString& plainText); - - void loadFromConfig( KConfig* ); - void saveToConfig( KConfig* ); - QModelIndex addVariable( const QString& var, const QString& value ); - void removeVariable(const QString& variable); - void removeVariables(const QStringList& variables); - void removeGroup( const QString& grp ); - void changeDefaultGroup( const QString& grp ); - -private: - QStringList m_varsByIndex; - QString m_currentGroup; -}; - -} - -#endif diff --git a/shell/settings/environmentgroupmodel.cpp b/shell/settings/environmentgroupmodel.cpp deleted file mode 100644 --- a/shell/settings/environmentgroupmodel.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* This file is part of KDevelop -Copyright 2007 Andreas Pakulat - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public License -along with this library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. -*/ - -#include "environmentgroupmodel.h" - -#include -#include -#include - -#include - -namespace KDevelop -{ - -EnvironmentGroupModel::EnvironmentGroupModel() - : QAbstractTableModel() -{ -} - -int EnvironmentGroupModel::rowCount( const QModelIndex& parent ) const -{ - if( parent.isValid() ) - return 0; - if( !m_currentGroup.isEmpty() ) - return m_varsByIndex.count(); - return 0; -} - -int EnvironmentGroupModel::columnCount( const QModelIndex& parent ) const -{ - if( parent.isValid() ) - return 0; - return 2; -} - -Qt::ItemFlags EnvironmentGroupModel::flags( const QModelIndex& idx ) const -{ - if( !idx.isValid() || m_currentGroup.isEmpty() ) - { - return Qt::NoItemFlags ; - } - return ( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); -} - -QVariant EnvironmentGroupModel::data( const QModelIndex& idx, int role ) const -{ - if( !idx.isValid() - || m_currentGroup.isEmpty() - || idx.row() < 0 || idx.row() >= rowCount() - || idx.column() < 0 || idx.column() >= columnCount(QModelIndex()) ) - { - return QVariant(); - } - - const QString variable = m_varsByIndex[idx.row()]; - if (role == VariableRole) { - return variable; - } else if (role == ValueRole) { - return variables( m_currentGroup ).value(variable); - } else if (role == Qt::DisplayRole || role == Qt::EditRole) { - if(idx.column() == VariableColumn) { - return variable; - } else { - return variables( m_currentGroup ).value(variable); - } - } - return QVariant(); -} - -QVariant EnvironmentGroupModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if( section < 0 || section >= columnCount(QModelIndex()) || m_currentGroup.isEmpty() - || orientation != Qt::Horizontal || role != Qt::DisplayRole ) - { - return QVariant(); - } - if( section == VariableColumn ) - { - return i18n( "Variable" ); - } else - { - return i18n( "Value" ); - } -} - -bool EnvironmentGroupModel::setData( const QModelIndex& idx, const QVariant& data, int role ) -{ - if( !idx.isValid() || m_currentGroup.isEmpty() - || idx.row() < 0 || idx.row() >= rowCount() - || idx.column() < 0 || idx.column() >= columnCount(QModelIndex()) ) - { - return false; - } - - if (role == Qt::EditRole) { - if (idx.column() == VariableColumn) { - const QString oldVariable = m_varsByIndex[idx.row()]; - const QString value = variables(m_currentGroup).take(oldVariable); - const QString newVariable = data.toString(); - variables(m_currentGroup).insert(newVariable, value); - m_varsByIndex[idx.row()] = newVariable; - } else { - variables(m_currentGroup).insert(m_varsByIndex[idx.row()], data.toString()); - } - emit dataChanged(idx, idx); - } - return true; -} - -QModelIndex EnvironmentGroupModel::addVariable( const QString& var, const QString& value ) -{ - const int pos = m_varsByIndex.indexOf(var); - if (pos != -1) { - return index(pos, 0, QModelIndex()); // No duplicates - } - - const int insertPos = rowCount(); - beginInsertRows( QModelIndex(), insertPos, insertPos ); - m_varsByIndex << var; - variables( m_currentGroup ).insert( var, value ); - endInsertRows(); - return index(insertPos, 0, QModelIndex()); -} - -void EnvironmentGroupModel::removeGroup( const QString& grp ) -{ - if( groups().contains( grp ) ) - { - EnvironmentGroupList::removeGroup( grp ); - setCurrentGroup(defaultGroup()); - } -} - -void EnvironmentGroupModel::removeVariables(const QStringList& variables) -{ - foreach (const QString& variable, variables) { - removeVariable(variable); - } -} - -void EnvironmentGroupModel::removeVariable(const QString& variable) -{ - if (m_currentGroup.isEmpty()) - return; - - const int pos = m_varsByIndex.indexOf(variable); - if (pos == -1) - return; - - beginRemoveRows(QModelIndex(), pos, pos); - m_varsByIndex.removeAt(pos); - variables(m_currentGroup).remove(variable); - endRemoveRows(); -} - -void EnvironmentGroupModel::setCurrentGroup( const QString& group ) -{ - if( group.isEmpty() ) - return; - - beginResetModel(); - m_currentGroup = group; - m_varsByIndex.clear(); - - foreach( const QString &var, variables( m_currentGroup ).keys() ) - { - m_varsByIndex << var; - } - endResetModel(); -} - -bool EnvironmentGroupModel::cloneCurrentGroup( const QString& newGroup ) -{ - if( newGroup.isEmpty() || groups().contains( newGroup ) ) { - return false; - } - - beginResetModel(); - foreach( const QString &key, m_varsByIndex ) { - variables( newGroup ).insert( key, variables( m_currentGroup ).value( key ) ); - } - m_currentGroup = newGroup; - endResetModel(); - return true; -} - -void EnvironmentGroupModel::changeDefaultGroup( const QString& grp ) -{ - if( !grp.isEmpty() ) - setDefaultGroup( grp ); -} - -void EnvironmentGroupModel::loadEnvironmentFromString(const QString& plainText) -{ - beginResetModel(); - - m_varsByIndex.clear(); - variables(m_currentGroup).clear(); - - const QStringList lines = plainText.split(QLatin1Char('\n'), QString::SkipEmptyParts); - foreach (const auto& line, lines) { - const QString var = line.section('=', 0, 0); - const QString value = line.section('=', 1, -1).trimmed(); - if (!var.isEmpty()) { - m_varsByIndex << var; - variables(m_currentGroup).insert(var, value); - } - } - - endResetModel(); -} - -void EnvironmentGroupModel::loadFromConfig( KConfig* cfg ) -{ - loadSettings( cfg ); - setCurrentGroup(defaultGroup()); -} - - -void EnvironmentGroupModel::saveToConfig( KConfig* cfg ) -{ - saveSettings( cfg ); -} - -} - diff --git a/shell/settings/environmentpreferences.h b/shell/settings/environmentpreferences.h --- a/shell/settings/environmentpreferences.h +++ b/shell/settings/environmentpreferences.h @@ -29,7 +29,7 @@ { Q_OBJECT public: - explicit EnvironmentPreferences(const QString& activeGroup = QString(), QWidget* parent = nullptr); + explicit EnvironmentPreferences(const QString& preselectedProfileName = {}, QWidget* parent = nullptr); ~EnvironmentPreferences() override; QString name() const override; diff --git a/shell/settings/environmentpreferences.cpp b/shell/settings/environmentpreferences.cpp --- a/shell/settings/environmentpreferences.cpp +++ b/shell/settings/environmentpreferences.cpp @@ -35,10 +35,10 @@ public: EnvironmentWidget *preferencesDialog; KConfigSkeleton* skel; - QString activeGroup; + QString preselectedProfileName; }; -EnvironmentPreferences::EnvironmentPreferences(const QString& activeGroup, QWidget* parent) +EnvironmentPreferences::EnvironmentPreferences(const QString& preselectedProfileName, QWidget* parent) : ConfigPage(nullptr, nullptr, parent), d(new EnvironmentPreferencesPrivate) { QVBoxLayout * l = new QVBoxLayout( this ); @@ -52,7 +52,7 @@ d->skel = new KConfigSkeleton(KSharedConfig::openConfig()); setConfigSkeleton(d->skel); - d->activeGroup = activeGroup; + d->preselectedProfileName = preselectedProfileName; } EnvironmentPreferences::~EnvironmentPreferences( ) @@ -69,7 +69,9 @@ void EnvironmentPreferences::reset() { d->preferencesDialog->loadSettings(d->skel->config()); - d->preferencesDialog->setActiveGroup(d->activeGroup); + if (!d->preselectedProfileName.isEmpty()) { + d->preferencesDialog->selectProfile(d->preselectedProfileName); + } ConfigPage::reset(); } diff --git a/shell/settings/environmentprofilelistmodel.h b/shell/settings/environmentprofilelistmodel.h new file mode 100644 --- /dev/null +++ b/shell/settings/environmentprofilelistmodel.h @@ -0,0 +1,67 @@ +/* This file is part of KDevelop +Copyright 2007 Andreas Pakulat +Copyright 2017 Friedrich W. H. Kossebau + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef KDEVPLATFORM_ENVIRONMENTPROFILELISTMODEL_H +#define KDEVPLATFORM_ENVIRONMENTPROFILELISTMODEL_H + +#include +#include "util/environmentgrouplist.h" + +class QStringList; + +namespace KDevelop +{ + +// Subclassing EnvironmentGroupList instead of having as a member, to have access to protected API +class EnvironmentProfileListModel : public QAbstractItemModel, protected EnvironmentGroupList +{ + Q_OBJECT + +public: + explicit EnvironmentProfileListModel(QObject* parent = nullptr); + + int rowCount(const QModelIndex& parent = {}) const override; + int columnCount(const QModelIndex& parent = {}) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override; + QModelIndex parent(const QModelIndex& index) const override; + + int profileIndex(const QString& profileName) const; + int defaultProfileIndex() const; + QString profileName(int profileIndex) const; + bool hasProfile(const QString& profileName) const; + QMap& variables(const QString& profileName); + + int addProfile(const QString& newProfileName); + int cloneProfile(const QString& newProfileName, const QString& sourceProfileName); + void removeProfile(int profileIndex); + void setDefaultProfile(int profileIndex); + + void loadFromConfig(KConfig* config); + void saveToConfig(KConfig* config); + +Q_SIGNALS: + void profileAboutToBeRemoved(const QString& profileName); + void defaultProfileChanged(int defaultProfileIndex); +}; + +} + +#endif diff --git a/shell/settings/environmentprofilelistmodel.cpp b/shell/settings/environmentprofilelistmodel.cpp new file mode 100644 --- /dev/null +++ b/shell/settings/environmentprofilelistmodel.cpp @@ -0,0 +1,213 @@ +/* This file is part of KDevelop +Copyright 2007 Andreas Pakulat +Copyright 2017 Friedrich W. H. Kossebau + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include "environmentprofilelistmodel.h" + +#include + +using namespace KDevelop; + +EnvironmentProfileListModel::EnvironmentProfileListModel(QObject* parent) + : QAbstractItemModel(parent) +{ +} + +int EnvironmentProfileListModel::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) { + return 0; + } + + return groups().count(); +} + +int EnvironmentProfileListModel::columnCount(const QModelIndex& parent) const +{ + if (parent.isValid()) { + return 0; + } + + return 1; +} + +QVariant EnvironmentProfileListModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid() || + index.row() < 0 || index.row() >= rowCount() || + index.column() != 0) { + return {}; + } + + if (role == Qt::DisplayRole) { + auto profileName = groups().at(index.row()); + if (profileName == defaultGroup()) { + profileName = i18n("%1 (default profile)", profileName); + } + return profileName; + } + + return {}; +} + +QModelIndex EnvironmentProfileListModel::index(int row, int column, const QModelIndex& parent) const +{ + if (parent.isValid()) { + return {}; + } + return createIndex(row, column); +} + +QModelIndex EnvironmentProfileListModel::parent(const QModelIndex& index) const +{ + Q_UNUSED(index); + return {}; +} + +int EnvironmentProfileListModel::defaultProfileIndex() const +{ + return groups().indexOf(defaultGroup()); +} + +QString EnvironmentProfileListModel::profileName(int profileIndex) const +{ + return groups().value(profileIndex); +} + +int EnvironmentProfileListModel::profileIndex(const QString& profileName) const +{ + return groups().indexOf(profileName); +} + +bool EnvironmentProfileListModel::hasProfile(const QString& profileName) const +{ + return groups().contains(profileName); +} + +QMap& EnvironmentProfileListModel::variables(const QString& profileName) +{ + return EnvironmentGroupList::variables(profileName); +} + +int EnvironmentProfileListModel::addProfile(const QString& newProfileName) +{ + const auto profileNames = groups(); + if (newProfileName.isEmpty() || + profileNames.contains(newProfileName)) { + return -1; + } + + // estimate insert position by comparison as used by QMap for the keys + int insertPos = 0; + while (insertPos < profileNames.size() && + profileNames.at(insertPos) < newProfileName) { + ++insertPos; + } + beginInsertRows(QModelIndex(), insertPos, insertPos); + + // trigger creation of new profile + variables(newProfileName); + + endInsertRows(); + return insertPos; +} + +void EnvironmentProfileListModel::removeProfile(int profileIndex) +{ + const auto profileNames = groups(); + if (profileIndex < 0 || profileIndex >= profileNames.size()) { + return; + } + const auto profileName = profileNames.at(profileIndex); + if (defaultGroup() == profileName) { + return; + } + + emit profileAboutToBeRemoved(profileName); + + beginRemoveRows(QModelIndex(), profileIndex, profileIndex); + + EnvironmentGroupList::removeGroup(profileName); + + endRemoveRows(); +} + +int EnvironmentProfileListModel::cloneProfile(const QString& newProfileName, const QString& sourceProfileName) +{ + const auto profileNames = groups(); + if (newProfileName.isEmpty() || + profileNames.contains(newProfileName) || + !profileNames.contains(sourceProfileName)) { + return -1; + } + + // estimate insert position by comparison as used by QMap for the keys + int insertPos = 0; + while (insertPos < profileNames.size() && + profileNames.at(insertPos) < newProfileName) { + ++insertPos; + } + + beginInsertRows(QModelIndex(), insertPos, insertPos); + + variables(newProfileName) = variables(sourceProfileName); + + endInsertRows(); + + return insertPos; +} + +void EnvironmentProfileListModel::setDefaultProfile(int profileIndex) +{ + const auto profileNames = groups(); + const auto oldDefaultProfileName = defaultGroup(); + const int oldDefaultProfileIndex = profileNames.indexOf(oldDefaultProfileName); + + if (profileIndex < 0 || profileIndex >= profileNames.size() || + oldDefaultProfileIndex == profileIndex) { + return; + } + + const auto oldIndex = index(oldDefaultProfileIndex, 0); + + const auto profileName = profileNames.at(profileIndex); + setDefaultGroup(profileName); + + const int newDefaultProfileIndex = profileNames.indexOf(profileName); + const auto newIndex = index(newDefaultProfileIndex, 0); + + emit dataChanged(oldIndex, oldIndex); + emit dataChanged(newIndex, newIndex); + emit defaultProfileChanged(newDefaultProfileIndex); +} + +void EnvironmentProfileListModel::loadFromConfig(KConfig* config) +{ + beginResetModel(); + + loadSettings(config); + + endResetModel(); +} + + +void EnvironmentProfileListModel::saveToConfig(KConfig* config) +{ + saveSettings(config); +} diff --git a/shell/settings/environmentprofilemodel.h b/shell/settings/environmentprofilemodel.h new file mode 100644 --- /dev/null +++ b/shell/settings/environmentprofilemodel.h @@ -0,0 +1,79 @@ +/* This file is part of KDevelop +Copyright 2007 Andreas Pakulat +Copyright 2017 Friedrich W. H. Kossebau + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#ifndef KDEVPLATFORM_ENVIRONMENTPROFILEMODEL_H +#define KDEVPLATFORM_ENVIRONMENTPROFILEMODEL_H + +#include +#include +#include "util/environmentgrouplist.h" + +namespace KDevelop +{ +class EnvironmentProfileListModel; + +class EnvironmentProfileModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + enum Role { + VariableRole = Qt::UserRole + 1, + ValueRole + }; + + enum Column { + VariableColumn = 0, + ValueColumn = 1 + }; + + EnvironmentProfileModel(EnvironmentProfileListModel* profileListModel, QObject* parent = nullptr); + + int rowCount(const QModelIndex& parent = {}) const override; + int columnCount(const QModelIndex& parent = {}) const override; + Qt::ItemFlags flags(const QModelIndex& index) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + bool setData(const QModelIndex& index, const QVariant&, int role = Qt::EditRole) override; + + void setCurrentProfile(const QString& profileName); + + void addVariable(const QString& variableName, const QString& value); + /** + * Load a set of environment variables from a plaintext string. + * + * @p plainText In the form "FOO=1\nBAR=2" + */ + void setVariablesFromString(const QString& plainText); + void removeVariable(const QString& variableName); + void removeVariables(const QStringList& variableNames); + +private: + void onProfileAboutToBeRemoved(const QString& profileName); + +private: + QStringList m_varsByIndex; + QString m_currentProfileName; + EnvironmentProfileListModel* m_profileListModel; +}; + +} + +#endif diff --git a/shell/settings/environmentprofilemodel.cpp b/shell/settings/environmentprofilemodel.cpp new file mode 100644 --- /dev/null +++ b/shell/settings/environmentprofilemodel.cpp @@ -0,0 +1,237 @@ +/* This file is part of KDevelop +Copyright 2007 Andreas Pakulat +Copyright 2017 Friedrich W. H. Kossebau + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public License +along with this library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. +*/ + +#include "environmentprofilemodel.h" + +#include "environmentprofilelistmodel.h" + +#include + +#include +#include + +using namespace KDevelop; + +EnvironmentProfileModel::EnvironmentProfileModel(EnvironmentProfileListModel* profileListModel, + QObject* parent) + : QAbstractTableModel(parent) + , m_profileListModel(profileListModel) +{ + connect(m_profileListModel, &EnvironmentProfileListModel::profileAboutToBeRemoved, + this, &EnvironmentProfileModel::onProfileAboutToBeRemoved); +} + +int EnvironmentProfileModel::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) { + return 0; + } + + return m_varsByIndex.count(); +} + +int EnvironmentProfileModel::columnCount(const QModelIndex& parent) const +{ + if (parent.isValid()) { + return 0; + } + + return 2; +} + +Qt::ItemFlags EnvironmentProfileModel::flags(const QModelIndex& index) const +{ + if (!index.isValid()) { + return Qt::NoItemFlags; + } + + return (Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); +} + +QVariant EnvironmentProfileModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid() || + index.row() < 0 || index.row() >= rowCount() || + index.column() < 0 || index.column() >= columnCount(QModelIndex()) || + m_currentProfileName.isEmpty()) { + return {}; + } + + const auto variable = m_varsByIndex[index.row()]; + if (role == VariableRole) { + return variable; + } + if (role == ValueRole) { + const auto& variables = m_profileListModel->variables(m_currentProfileName); + return variables.value(variable); + } + if (role == Qt::DisplayRole || role == Qt::EditRole) { + if (index.column() == VariableColumn) { + return variable; + } + const auto& variables = m_profileListModel->variables(m_currentProfileName); + return variables.value(variable); + } + return {}; +} + +QVariant EnvironmentProfileModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (section < 0 || section >= columnCount(QModelIndex()) || + orientation != Qt::Horizontal || + role != Qt::DisplayRole) { + return {}; + } + + if (section == VariableColumn) { + return i18n("Variable"); + } + return i18n("Value"); +} + +bool EnvironmentProfileModel::setData(const QModelIndex& index, const QVariant& data, int role) +{ + if (!index.isValid() || + index.row() < 0 || index.row() >= rowCount() || + index.column() < 0 || index.column() >= columnCount(QModelIndex()) || + m_currentProfileName.isEmpty()) { + return false; + } + + if (role == Qt::EditRole) { + auto& variables = m_profileListModel->variables(m_currentProfileName); + if (index.column() == VariableColumn) { + const QString oldVariable = m_varsByIndex[index.row()]; + const QString value = variables.take(oldVariable); + const QString newVariable = data.toString(); + variables.insert(newVariable, value); + m_varsByIndex[index.row()] = newVariable; + } else { + variables.insert(m_varsByIndex[index.row()], data.toString()); + } + emit dataChanged(index, index); + } + return true; +} + +void EnvironmentProfileModel::addVariable(const QString& variableName, const QString& value) +{ + if (m_currentProfileName.isEmpty()) { + return; + } + + const int pos = m_varsByIndex.indexOf(variableName); + if (pos != -1) { + return; // No duplicates, first value + } + + auto& variables = m_profileListModel->variables(m_currentProfileName); + + const int insertPos = rowCount(); + beginInsertRows(QModelIndex(), insertPos, insertPos); + m_varsByIndex << variableName; + variables.insert(variableName, value); + endInsertRows(); +} + +void EnvironmentProfileModel::removeVariables(const QStringList& variableNames) +{ + for (const auto& variableName : variableNames) { + removeVariable(variableName); + } +} + +void EnvironmentProfileModel::removeVariable(const QString& variableName) +{ + if (m_currentProfileName.isEmpty()) { + return; + } + + const int pos = m_varsByIndex.indexOf(variableName); + if (pos == -1) { + return; + } + + auto& variables = m_profileListModel->variables(m_currentProfileName); + + beginRemoveRows(QModelIndex(), pos, pos); + m_varsByIndex.removeAt(pos); + variables.remove(variableName); + endRemoveRows(); +} + +void EnvironmentProfileModel::setCurrentProfile(const QString& profileName) +{ + if (profileName == m_currentProfileName) { + return; + } + + beginResetModel(); + m_currentProfileName = profileName; + m_varsByIndex.clear(); + + if (!m_currentProfileName.isEmpty()) { + const auto& variables = m_profileListModel->variables(m_currentProfileName); + + const auto endIt = variables.constEnd(); + for (auto it = variables.constBegin(); it != endIt; ++it) { + m_varsByIndex << it.key(); + } + } + endResetModel(); +} + +void EnvironmentProfileModel::setVariablesFromString(const QString& plainText) +{ + if (m_currentProfileName.isEmpty()) { + return; + } + + beginResetModel(); + + auto& variables = m_profileListModel->variables(m_currentProfileName); + variables.clear(); + m_varsByIndex.clear(); + + const auto lines = plainText.split(QLatin1Char('\n'), QString::SkipEmptyParts); + for (const auto& line : lines) { + const int pos = line.indexOf(QLatin1Char('=')); + // has a = and at least 1 char + if (pos < 0) { + continue; + } + const QString variableName = line.left(pos).trimmed(); + if (variableName.isEmpty()) { + continue; + } + const QString value = line.mid(pos+1).trimmed(); + m_varsByIndex << variableName; + variables.insert(variableName, value); + } + + endResetModel(); +} + +void EnvironmentProfileModel::onProfileAboutToBeRemoved(const QString& profileName) +{ + if (m_currentProfileName == profileName) { + setCurrentProfile(QString()); + } +} diff --git a/shell/settings/environmentwidget.h b/shell/settings/environmentwidget.h --- a/shell/settings/environmentwidget.h +++ b/shell/settings/environmentwidget.h @@ -31,7 +31,8 @@ namespace KDevelop { -class EnvironmentGroupModel; +class EnvironmentProfileListModel; +class EnvironmentProfileModel; /** @@ -50,27 +51,29 @@ void loadSettings( KConfig* config ); void saveSettings( KConfig* config ); void defaults( KConfig* config ); - void setActiveGroup( const QString& group ); + void selectProfile(const QString& profileName); Q_SIGNALS: void changed(); -private Q_SLOTS: - void handleVariableInserted(int column, const QVariant& value); - void deleteButtonClicked(); +private: + QString askNewProfileName(const QString& defaultName); + void removeSelectedVariables(); void batchModeEditButtonClicked(); - void addGroupClicked(); - void cloneGroupClicked(); - void removeGroupClicked(); - void activeGroupChanged( int ); - void enableDeleteButton(); - void setAsDefault(); - void enableButtons( const QString& ); + void addProfile(); + void cloneSelectedProfile(); + void removeSelectedProfile(); + void setSelectedProfileAsDefault(); + void onDefaultProfileChanged(int defaultProfileIndex); + void onSelectedProfileChanged(int selectedProfileIndex); + void onVariableInserted(int column, const QVariant& value); + void updateDeleteVariableButton(); private: Ui::EnvironmentWidget ui; - EnvironmentGroupModel* groupModel; - QSortFilterProxyModel* proxyModel; + EnvironmentProfileListModel* const m_environmentProfileListModel; + EnvironmentProfileModel* const m_environmentProfileModel; + QSortFilterProxyModel* const m_proxyModel; }; diff --git a/shell/settings/environmentwidget.cpp b/shell/settings/environmentwidget.cpp --- a/shell/settings/environmentwidget.cpp +++ b/shell/settings/environmentwidget.cpp @@ -2,6 +2,7 @@ Copyright 2006 Adam Treat Copyright 2007 Dukju Ahn Copyright 2008 Andreas Pakuat +Copyright 2017 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -27,125 +28,215 @@ #include #include #include +#include #include +#include +#include #include -#include "environmentgroupmodel.h" +#include "environmentprofilelistmodel.h" +#include "environmentprofilemodel.h" #include "placeholderitemproxymodel.h" #include "../debug.h" -namespace KDevelop +using namespace KDevelop; + + +class ProfileNameValidator : public QValidator { + Q_OBJECT -EnvironmentWidget::EnvironmentWidget( QWidget *parent ) - : QWidget( parent ), groupModel( new EnvironmentGroupModel() ), proxyModel( new QSortFilterProxyModel() ) +public: + explicit ProfileNameValidator(EnvironmentProfileListModel* environmentProfileListModel, QObject* parent = nullptr); + QValidator::State validate(QString& input, int& pos) const override; + +private: + const EnvironmentProfileListModel* const m_environmentProfileListModel; +}; + +ProfileNameValidator::ProfileNameValidator(EnvironmentProfileListModel* environmentProfileListModel, + QObject* parent) + : QValidator(parent) + , m_environmentProfileListModel(environmentProfileListModel) +{ +} + +QValidator::State ProfileNameValidator::validate(QString& input, int& pos) const { + Q_UNUSED(pos); + + if (input.isEmpty()) { + return QValidator::Intermediate; + } + if (m_environmentProfileListModel->hasProfile(input)) { + return QValidator::Intermediate; + } + return QValidator::Acceptable; +} + + +EnvironmentWidget::EnvironmentWidget( QWidget *parent ) + : QWidget(parent) + , m_environmentProfileListModel(new EnvironmentProfileListModel(this)) + , m_environmentProfileModel(new EnvironmentProfileModel(m_environmentProfileListModel, this)) + , m_proxyModel(new QSortFilterProxyModel(this)) +{ // setup ui ui.setupUi( this ); - ui.variableTable->verticalHeader()->hide(); - proxyModel->setSourceModel( groupModel ); + ui.profileSelect->setModel(m_environmentProfileListModel); + m_proxyModel->setSourceModel(m_environmentProfileModel); PlaceholderItemProxyModel* topProxyModel = new PlaceholderItemProxyModel(this); - topProxyModel->setSourceModel(proxyModel); - topProxyModel->setColumnHint(0, i18n("Enter variable ...")); - connect(topProxyModel, &PlaceholderItemProxyModel::dataInserted, this, &EnvironmentWidget::handleVariableInserted); + topProxyModel->setSourceModel(m_proxyModel); + topProxyModel->setColumnHint(0, i18n("Enter variable...")); + connect(topProxyModel, &PlaceholderItemProxyModel::dataInserted, this, &EnvironmentWidget::onVariableInserted); ui.variableTable->setModel( topProxyModel ); ui.variableTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::ResizeToContents ); ui.variableTable->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch ); - ui.addgrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); - ui.clonegrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("edit-clone"))); - ui.removegrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); - ui.deleteButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); - ui.deleteButton->setShortcut(Qt::Key_Delete); - ui.batchModeEditButton->setIcon(QIcon::fromTheme(QStringLiteral("format-list-unordered"))); - - connect( ui.deleteButton, &QPushButton::clicked, - this, &EnvironmentWidget::deleteButtonClicked ); - connect( ui.batchModeEditButton, &QPushButton::clicked, - this, &EnvironmentWidget::batchModeEditButtonClicked ); - - connect( ui.clonegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::cloneGroupClicked ); - connect( ui.addgrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::addGroupClicked ); - connect( ui.addgrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); - connect( ui.removegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::removeGroupClicked ); - connect( ui.removegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); - connect( ui.setAsDefaultBtn, &QPushButton::clicked, this, &EnvironmentWidget::setAsDefault ); - connect( ui.setAsDefaultBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); - connect( ui.activeCombo, static_cast(&KComboBox::currentIndexChanged), - this, &EnvironmentWidget::activeGroupChanged ); - connect( ui.activeCombo, &KComboBox::editTextChanged, this, &EnvironmentWidget::enableButtons); - connect( groupModel, &EnvironmentGroupModel::dataChanged, this, &EnvironmentWidget::changed ); - connect( groupModel, &EnvironmentGroupModel::rowsRemoved, this, &EnvironmentWidget::changed ); - connect( groupModel, &EnvironmentGroupModel::rowsInserted, this, &EnvironmentWidget::changed ); - connect( groupModel, &EnvironmentGroupModel::rowsRemoved, this, &EnvironmentWidget::enableDeleteButton ); - connect( groupModel, &EnvironmentGroupModel::rowsInserted, this, &EnvironmentWidget::enableDeleteButton ); - connect( groupModel, &EnvironmentGroupModel::modelReset, this, &EnvironmentWidget::enableDeleteButton ); + ui.removeVariableButton->setShortcut(Qt::Key_Delete); + + connect(ui.removeVariableButton, &QPushButton::clicked, + this, &EnvironmentWidget::removeSelectedVariables); + connect(ui.batchModeEditButton, &QPushButton::clicked, + this, &EnvironmentWidget::batchModeEditButtonClicked); + + connect(ui.cloneProfileButton, &QPushButton::clicked, this, &EnvironmentWidget::cloneSelectedProfile); + connect(ui.addProfileButton, &QPushButton::clicked, this, &EnvironmentWidget::addProfile); + connect(ui.removeProfileButton, &QPushButton::clicked, this, &EnvironmentWidget::removeSelectedProfile); + connect(ui.setAsDefaultProfileButton, &QPushButton::clicked, this, &EnvironmentWidget::setSelectedProfileAsDefault); + connect(ui.profileSelect, static_cast(&KComboBox::currentIndexChanged), + this, &EnvironmentWidget::onSelectedProfileChanged); + + connect(m_environmentProfileListModel, &EnvironmentProfileListModel::defaultProfileChanged, + this, &EnvironmentWidget::onDefaultProfileChanged); + connect(m_environmentProfileListModel, &EnvironmentProfileListModel::rowsInserted, + this, &EnvironmentWidget::changed); + connect(m_environmentProfileListModel, &EnvironmentProfileListModel::rowsRemoved, + this, &EnvironmentWidget::changed); + connect(m_environmentProfileListModel, &EnvironmentProfileListModel::defaultProfileChanged, + this, &EnvironmentWidget::changed); + + connect(ui.variableTable->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &EnvironmentWidget::updateDeleteVariableButton); + connect(m_environmentProfileModel, &EnvironmentProfileModel::rowsInserted, + this, &EnvironmentWidget::updateDeleteVariableButton); + connect(m_environmentProfileModel, &EnvironmentProfileModel::rowsRemoved, + this, &EnvironmentWidget::updateDeleteVariableButton); + connect(m_environmentProfileModel, &EnvironmentProfileModel::modelReset, + this, &EnvironmentWidget::updateDeleteVariableButton); + connect(m_environmentProfileModel, &EnvironmentProfileModel::dataChanged, + this, &EnvironmentWidget::changed); + connect(m_environmentProfileModel, &EnvironmentProfileModel::rowsInserted, + this, &EnvironmentWidget::changed); + connect(m_environmentProfileModel, &EnvironmentProfileModel::rowsRemoved, + this, &EnvironmentWidget::changed); } -void EnvironmentWidget::setActiveGroup( const QString& group ) +void EnvironmentWidget::selectProfile(const QString& profileName) { - ui.activeCombo->setCurrentItem(group); + const int profileIndex = m_environmentProfileListModel->profileIndex(profileName); + if (profileIndex < 0) { + return; + } + ui.profileSelect->setCurrentIndex(profileIndex); } -void EnvironmentWidget::enableDeleteButton() +void EnvironmentWidget::updateDeleteVariableButton() { - ui.deleteButton->setEnabled( groupModel->rowCount() > 0 ); + const auto selectedRows = ui.variableTable->selectionModel()->selectedRows(); + ui.removeVariableButton->setEnabled(!selectedRows.isEmpty()); } -void EnvironmentWidget::setAsDefault() +void EnvironmentWidget::setSelectedProfileAsDefault() { - groupModel->changeDefaultGroup( ui.activeCombo->currentText() ); - enableButtons( ui.activeCombo->currentText() ); - emit changed(); + const int selectedIndex = ui.profileSelect->currentIndex(); + m_environmentProfileListModel->setDefaultProfile(selectedIndex); } void EnvironmentWidget::loadSettings( KConfig* config ) { - qCDebug(SHELL) << "Loading groups from config"; - groupModel->loadFromConfig( config ); - - ui.activeCombo->clear(); + qCDebug(SHELL) << "Loading profiles from config"; + m_environmentProfileListModel->loadFromConfig(config); - QStringList groupList = groupModel->groups(); - qCDebug(SHELL) << "Grouplist:" << groupList << "default group:" << groupModel->defaultGroup(); - ui.activeCombo->addItems( groupList ); - int idx = ui.activeCombo->findText( groupModel->defaultGroup() ); - ui.activeCombo->setCurrentIndex( idx ); + const int defaultProfileIndex = m_environmentProfileListModel->defaultProfileIndex(); + ui.profileSelect->setCurrentIndex(defaultProfileIndex); } void EnvironmentWidget::saveSettings( KConfig* config ) { - groupModel->saveToConfig( config ); + m_environmentProfileListModel->saveToConfig(config); } void EnvironmentWidget::defaults( KConfig* config ) { loadSettings( config ); } -void EnvironmentWidget::deleteButtonClicked() +QString EnvironmentWidget::askNewProfileName(const QString& defaultName) +{ + QDialog dialog(this); + dialog.setWindowTitle(i18n("Enter Name of New Environment Profile")); + + QVBoxLayout *layout = new QVBoxLayout(&dialog); + + auto editLayout = new QHBoxLayout; + + auto label = new QLabel(i18n("Name:")); + editLayout->addWidget(label); + auto edit = new QLineEdit; + editLayout->addWidget(edit); + layout->addLayout(editLayout); + + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + auto okButton = buttonBox->button(QDialogButtonBox::Ok); + okButton->setEnabled(false); + okButton->setDefault(true); + dialog.connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + dialog.connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + layout->addWidget(buttonBox); + + auto validator = new ProfileNameValidator(m_environmentProfileListModel, &dialog); + connect(edit, &QLineEdit::textChanged, validator, [validator, okButton](const QString& text) { + int pos; + QString t(text); + const bool isValidProfileName = (validator->validate(t, pos) == QValidator::Acceptable); + okButton->setEnabled(isValidProfileName); + }); + + edit->setText(defaultName); + edit->selectAll(); + + if (dialog.exec() != QDialog::Accepted) { + return {}; + } + + return edit->text(); +} + +void EnvironmentWidget::removeSelectedVariables() { - QModelIndexList selected = ui.variableTable->selectionModel()->selectedRows(); - if( selected.isEmpty() ) + const auto selectedRows = ui.variableTable->selectionModel()->selectedRows(); + if (selectedRows.isEmpty()) { return; + } QStringList variables; - foreach( const QModelIndex &idx, selected ) - { - const QString variable = idx.data(EnvironmentGroupModel::VariableRole).toString(); + for (const auto& idx : selectedRows) { + const QString variable = idx.data(EnvironmentProfileModel::VariableRole).toString(); variables << variable; } - groupModel->removeVariables(variables); + m_environmentProfileModel->removeVariables(variables); } -void EnvironmentWidget::handleVariableInserted(int /*column*/, const QVariant& value) +void EnvironmentWidget::onVariableInserted(int column, const QVariant& value) { - groupModel->addVariable(value.toString(), QString()); + Q_UNUSED(column); + m_environmentProfileModel->addVariable(value.toString(), QString()); } void EnvironmentWidget::batchModeEditButtonClicked() @@ -158,9 +249,9 @@ QTextEdit *edit = new QTextEdit; edit->setPlaceholderText(QStringLiteral("VARIABLE1=VALUE1\nVARIABLE2=VALUE2")); QString text; - for (int i = 0; i < proxyModel->rowCount(); ++i) { - const auto variable = proxyModel->index(i, EnvironmentGroupModel::VariableColumn).data().toString(); - const auto value = proxyModel->index(i, EnvironmentGroupModel::ValueColumn).data().toString(); + for (int i = 0; i < m_proxyModel->rowCount(); ++i) { + const auto variable = m_proxyModel->index(i, EnvironmentProfileModel::VariableColumn).data().toString(); + const auto value = m_proxyModel->index(i, EnvironmentProfileModel::ValueColumn).data().toString(); text.append(QStringLiteral("%1=%2\n").arg(variable, value)); } edit->setText(text); @@ -180,65 +271,70 @@ return; } - groupModel->loadEnvironmentFromString(edit->toPlainText()); + m_environmentProfileModel->setVariablesFromString(edit->toPlainText()); } -void EnvironmentWidget::addGroupClicked() +void EnvironmentWidget::addProfile() { - QString curText = ui.activeCombo->currentText(); - if( groupModel->groups().contains( curText ) ) - { - return; // same group name cannot be added twice. - } - ui.activeCombo->addItem( curText ); - ui.activeCombo->setCurrentItem( curText ); -} - -void EnvironmentWidget::cloneGroupClicked() -{ - QString newGroup = ui.activeCombo->currentText(); - if( !groupModel->cloneCurrentGroup( newGroup ) ) { - const KLocalizedString newGroupTemplate = - ki18nc("a copy of the existing environment was created", "%1 (Cloned %2)").subs(newGroup); - for (int id = 1; ; ++id) { - newGroup = newGroupTemplate.subs(id).toString(); - if (groupModel->cloneCurrentGroup(newGroup)) { - break; - } - } + const auto profileName = askNewProfileName(QString()); + if (profileName.isEmpty()) { + return; } - ui.activeCombo->addItem( newGroup ); - ui.activeCombo->setCurrentItem( newGroup ); + + const int profileIndex = m_environmentProfileListModel->addProfile(profileName); + + ui.profileSelect->setCurrentIndex(profileIndex); + ui.variableTable->setFocus(Qt::OtherFocusReason); } -void EnvironmentWidget::removeGroupClicked() +void EnvironmentWidget::cloneSelectedProfile() { - int idx = ui.activeCombo->currentIndex(); - if( idx < 0 || ui.activeCombo->count() == 1 ) - { + const int currentIndex = ui.profileSelect->currentIndex(); + const auto currentProfileName = m_environmentProfileListModel->profileName(currentIndex); + // pass original name as starting name, as the user might want to enter a variant of it + const auto profileName = askNewProfileName(currentProfileName); + if (profileName.isEmpty()) { return; } - QString curText = ui.activeCombo->currentText(); - groupModel->removeGroup( curText ); - ui.activeCombo->removeItem( idx ); - ui.activeCombo->setCurrentItem( groupModel->defaultGroup() ); + const int profileIndex = m_environmentProfileListModel->cloneProfile(profileName, currentProfileName); + + ui.profileSelect->setCurrentIndex(profileIndex); + ui.variableTable->setFocus(Qt::OtherFocusReason); } -void EnvironmentWidget::activeGroupChanged( int /*idx*/ ) +void EnvironmentWidget::removeSelectedProfile() { - groupModel->setCurrentGroup( ui.activeCombo->currentText() ); - enableButtons( ui.activeCombo->currentText() ); + if (ui.profileSelect->count() <= 1) { + return; + } + + const int selectedProfileIndex = ui.profileSelect->currentIndex(); + + m_environmentProfileListModel->removeProfile(selectedProfileIndex); + + const int defaultProfileIndex = m_environmentProfileListModel->defaultProfileIndex(); + ui.profileSelect->setCurrentIndex(defaultProfileIndex); } -void EnvironmentWidget::enableButtons( const QString& txt ) +void EnvironmentWidget::onDefaultProfileChanged(int defaultProfileIndex) { - ui.addgrpBtn->setEnabled( !groupModel->groups().contains( txt ) ); - ui.removegrpBtn->setEnabled( ( groupModel->groups().contains( txt ) && groupModel->defaultGroup() != txt ) ); - ui.setAsDefaultBtn->setEnabled( ( groupModel->groups().contains( txt ) && groupModel->defaultGroup() != txt ) ); + const int selectedProfileIndex = ui.profileSelect->currentIndex(); + const bool isDefaultProfile = (defaultProfileIndex == selectedProfileIndex); + + ui.removeProfileButton->setEnabled(ui.profileSelect->count() > 1 && !isDefaultProfile); + ui.setAsDefaultProfileButton->setEnabled(!isDefaultProfile); } +void EnvironmentWidget::onSelectedProfileChanged(int selectedProfileIndex) +{ + const auto selectedProfileName = m_environmentProfileListModel->profileName(selectedProfileIndex); + m_environmentProfileModel->setCurrentProfile(selectedProfileName); + + const bool isDefaultProfile = (m_environmentProfileListModel->defaultProfileIndex() == selectedProfileIndex); + ui.removeProfileButton->setEnabled(ui.profileSelect->count() > 1 && !isDefaultProfile); + ui.setAsDefaultProfileButton->setEnabled(!isDefaultProfile); } -#include "moc_environmentwidget.cpp" +#include "environmentwidget.moc" diff --git a/shell/settings/environmentwidget.ui b/shell/settings/environmentwidget.ui --- a/shell/settings/environmentwidget.ui +++ b/shell/settings/environmentwidget.ui @@ -19,48 +19,57 @@ - Environment group: + Environment profile: - + 1 0 - - true - - - - Add Group + + + Add profile... + + + - - - Clone Group + + + Clone profile... + + + - - - Remove Group + + + Remove profile + + + - - - Set As Default Group + + + Set as default + + + @@ -86,12 +95,15 @@ false + + false + - + 0 @@ -101,6 +113,9 @@ Remove variable + + + @@ -114,6 +129,9 @@ Batch Edit Mode + + +