aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/projectexplorer/projectexplorer.pro2
-rw-r--r--src/plugins/projectexplorer/projectexplorer.qbs1
-rw-r--r--src/plugins/projectexplorer/projectwelcomepage.cpp133
-rw-r--r--src/plugins/projectexplorer/projectwelcomepage.h23
-rw-r--r--src/plugins/projectexplorer/sessionmodel.cpp159
-rw-r--r--src/plugins/projectexplorer/sessionmodel.h56
6 files changed, 224 insertions, 150 deletions
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 4600996991..526c1fca5c 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -144,6 +144,7 @@ HEADERS += projectexplorer.h \
propertiespanel.h \
panelswidget.h \
projectwelcomepage.h \
+ sessionmodel.h \
projectpanelfactory.h \
projecttree.h \
expanddata.h \
@@ -283,6 +284,7 @@ SOURCES += projectexplorer.cpp \
propertiespanel.cpp \
panelswidget.cpp \
projectwelcomepage.cpp \
+ sessionmodel.cpp \
projectpanelfactory.cpp \
projecttree.cpp \
expanddata.cpp \
diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs
index 3b24451dec..0650a70d7d 100644
--- a/src/plugins/projectexplorer/projectexplorer.qbs
+++ b/src/plugins/projectexplorer/projectexplorer.qbs
@@ -136,6 +136,7 @@ Project {
"runsettingspropertiespage.cpp", "runsettingspropertiespage.h",
"selectablefilesmodel.cpp", "selectablefilesmodel.h",
"session.cpp", "session.h",
+ "sessionmodel.cpp", "sessionmodel.h",
"sessiondialog.cpp", "sessiondialog.h", "sessiondialog.ui",
"settingsaccessor.cpp", "settingsaccessor.h",
"showineditortaskhandler.cpp", "showineditortaskhandler.h",
diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp
index 93084124da..c0479c6978 100644
--- a/src/plugins/projectexplorer/projectwelcomepage.cpp
+++ b/src/plugins/projectexplorer/projectwelcomepage.cpp
@@ -24,145 +24,22 @@
****************************************************************************/
#include "projectwelcomepage.h"
-
-#include <QQmlContext>
-#include <QQmlEngine>
-#include <QFileInfo>
-#include <QDir>
+#include "sessionmodel.h"
+#include "projectexplorer.h"
#include <coreplugin/icore.h>
#include <coreplugin/iwizardfactory.h>
-#include <projectexplorer/session.h>
-#include <projectexplorer/projectexplorer.h>
-#include <projectexplorer/sessiondialog.h>
#include <utils/fileutils.h>
#include <utils/stringutils.h>
#include <utils/algorithm.h>
+#include <QQmlContext>
+#include <QQmlEngine>
+
namespace ProjectExplorer {
namespace Internal {
-SessionModel::SessionModel(QObject *parent)
- : QAbstractListModel(parent)
-{
- connect(SessionManager::instance(), &SessionManager::sessionLoaded,
- this, &SessionModel::resetSessions);
-}
-
-int SessionModel::rowCount(const QModelIndex &) const
-{
- return SessionManager::sessions().count();
-}
-
-QStringList pathsToBaseNames(const QStringList &paths)
-{
- return Utils::transform(paths, [](const QString &path) {
- return QFileInfo(path).completeBaseName();
- });
-}
-
-
-
-QStringList pathsWithTildeHomePath(const QStringList &paths)
-{
- return Utils::transform(paths, [](const QString &path) {
- return Utils::withTildeHomePath(QDir::toNativeSeparators(path));
- });
-}
-
-QVariant SessionModel::data(const QModelIndex &index, int role) const
-{
- if (role == Qt::DisplayRole || role == DefaultSessionRole ||
- role == LastSessionRole || role == ActiveSessionRole || role == ProjectsPathRole || role == ProjectsDisplayRole) {
- QString sessionName = SessionManager::sessions().at(index.row());
- if (role == Qt::DisplayRole)
- return sessionName;
- else if (role == DefaultSessionRole)
- return SessionManager::isDefaultSession(sessionName);
- else if (role == LastSessionRole)
- return SessionManager::lastSession() == sessionName;
- else if (role == ActiveSessionRole)
- return SessionManager::activeSession() == sessionName;
- else if (role == ProjectsPathRole)
- return pathsWithTildeHomePath(SessionManager::projectsForSessionName(sessionName));
- else if (role == ProjectsDisplayRole)
- return pathsToBaseNames(SessionManager::projectsForSessionName(sessionName));
- }
- return QVariant();
-}
-
-QHash<int, QByteArray> SessionModel::roleNames() const
-{
- static QHash<int, QByteArray> extraRoles{
- {Qt::DisplayRole, "sessionName"},
- {DefaultSessionRole, "defaultSession"},
- {ActiveSessionRole, "activeSession"},
- {LastSessionRole, "lastSession"},
- {ProjectsPathRole, "projectsPath"},
- {ProjectsDisplayRole, "projectsName"}
- };
- return QAbstractListModel::roleNames().unite(extraRoles);
-}
-
-bool SessionModel::isDefaultVirgin() const
-{
- return SessionManager::isDefaultVirgin();
-}
-
-void SessionModel::resetSessions()
-{
- beginResetModel();
- endResetModel();
-}
-
-void SessionModel::cloneSession(const QString &session)
-{
- SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr);
- newSessionInputDialog.setWindowTitle(tr("New session name"));
- newSessionInputDialog.setValue(session + QLatin1String(" (2)"));
-
- if (newSessionInputDialog.exec() == QDialog::Accepted) {
- QString newSession = newSessionInputDialog.value();
- if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
- return;
- beginResetModel();
- SessionManager::cloneSession(session, newSession);
- endResetModel();
-
- if (newSessionInputDialog.isSwitchToRequested())
- SessionManager::loadSession(newSession);
- }
-}
-
-void SessionModel::deleteSession(const QString &session)
-{
- if (!SessionManager::confirmSessionDelete(session))
- return;
- beginResetModel();
- SessionManager::deleteSession(session);
- endResetModel();
-}
-
-void SessionModel::renameSession(const QString &session)
-{
- SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr);
- newSessionInputDialog.setWindowTitle(tr("New session name"));
- newSessionInputDialog.setValue(session);
-
- if (newSessionInputDialog.exec() == QDialog::Accepted) {
- QString newSession = newSessionInputDialog.value();
- if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
- return;
- beginResetModel();
- SessionManager::renameSession(session, newSession);
- endResetModel();
-
- if (newSessionInputDialog.isSwitchToRequested())
- SessionManager::loadSession(newSession);
- }
-}
-
ProjectModel::ProjectModel(QObject *parent)
: QAbstractListModel(parent)
{
diff --git a/src/plugins/projectexplorer/projectwelcomepage.h b/src/plugins/projectexplorer/projectwelcomepage.h
index 2d56e4c103..56ff469a70 100644
--- a/src/plugins/projectexplorer/projectwelcomepage.h
+++ b/src/plugins/projectexplorer/projectwelcomepage.h
@@ -36,28 +36,7 @@ QT_END_NAMESPACE
namespace ProjectExplorer {
namespace Internal {
-class SessionModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
- enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole, ProjectsPathRole, ProjectsDisplayRole };
-
- explicit SessionModel(QObject *parent = nullptr);
-
- int rowCount(const QModelIndex &parent) const override;
- QVariant data(const QModelIndex &index, int role) const override;
- QHash<int, QByteArray> roleNames() const override;
-
- Q_SCRIPTABLE bool isDefaultVirgin() const;
-
-public slots:
- void resetSessions();
- void cloneSession(const QString &session);
- void deleteSession(const QString &session);
- void renameSession(const QString &session);
-};
-
+class SessionModel;
class ProjectModel : public QAbstractListModel
{
diff --git a/src/plugins/projectexplorer/sessionmodel.cpp b/src/plugins/projectexplorer/sessionmodel.cpp
new file mode 100644
index 0000000000..608a8e649e
--- /dev/null
+++ b/src/plugins/projectexplorer/sessionmodel.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "sessionmodel.h"
+#include "session.h"
+
+#include "sessiondialog.h"
+
+#include <utils/algorithm.h>
+#include <utils/fileutils.h>
+#include <utils/stringutils.h>
+
+#include <QFileInfo>
+#include <QDir>
+
+namespace ProjectExplorer {
+namespace Internal {
+
+SessionModel::SessionModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+ connect(SessionManager::instance(), &SessionManager::sessionLoaded,
+ this, &SessionModel::resetSessions);
+}
+
+int SessionModel::rowCount(const QModelIndex &) const
+{
+ return SessionManager::sessions().count();
+}
+
+QStringList pathsToBaseNames(const QStringList &paths)
+{
+ return Utils::transform(paths, [](const QString &path) {
+ return QFileInfo(path).completeBaseName();
+ });
+}
+
+QStringList pathsWithTildeHomePath(const QStringList &paths)
+{
+ return Utils::transform(paths, [](const QString &path) {
+ return Utils::withTildeHomePath(QDir::toNativeSeparators(path));
+ });
+}
+
+QVariant SessionModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole || role == DefaultSessionRole ||
+ role == LastSessionRole || role == ActiveSessionRole || role == ProjectsPathRole || role == ProjectsDisplayRole) {
+ QString sessionName = SessionManager::sessions().at(index.row());
+ if (role == Qt::DisplayRole)
+ return sessionName;
+ else if (role == DefaultSessionRole)
+ return SessionManager::isDefaultSession(sessionName);
+ else if (role == LastSessionRole)
+ return SessionManager::lastSession() == sessionName;
+ else if (role == ActiveSessionRole)
+ return SessionManager::activeSession() == sessionName;
+ else if (role == ProjectsPathRole)
+ return pathsWithTildeHomePath(SessionManager::projectsForSessionName(sessionName));
+ else if (role == ProjectsDisplayRole)
+ return pathsToBaseNames(SessionManager::projectsForSessionName(sessionName));
+ }
+ return QVariant();
+}
+
+QHash<int, QByteArray> SessionModel::roleNames() const
+{
+ static QHash<int, QByteArray> extraRoles{
+ {Qt::DisplayRole, "sessionName"},
+ {DefaultSessionRole, "defaultSession"},
+ {ActiveSessionRole, "activeSession"},
+ {LastSessionRole, "lastSession"},
+ {ProjectsPathRole, "projectsPath"},
+ {ProjectsDisplayRole, "projectsName"}
+ };
+ return QAbstractListModel::roleNames().unite(extraRoles);
+}
+
+bool SessionModel::isDefaultVirgin() const
+{
+ return SessionManager::isDefaultVirgin();
+}
+
+void SessionModel::resetSessions()
+{
+ beginResetModel();
+ endResetModel();
+}
+
+void SessionModel::cloneSession(const QString &session)
+{
+ SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr);
+ newSessionInputDialog.setWindowTitle(tr("New Session Name"));
+ newSessionInputDialog.setValue(session + QLatin1String(" (2)"));
+
+ if (newSessionInputDialog.exec() == QDialog::Accepted) {
+ QString newSession = newSessionInputDialog.value();
+ if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
+ return;
+ beginResetModel();
+ SessionManager::cloneSession(session, newSession);
+ endResetModel();
+
+ if (newSessionInputDialog.isSwitchToRequested())
+ SessionManager::loadSession(newSession);
+ }
+}
+
+void SessionModel::deleteSession(const QString &session)
+{
+ if (!SessionManager::confirmSessionDelete(session))
+ return;
+ beginResetModel();
+ SessionManager::deleteSession(session);
+ endResetModel();
+}
+
+void SessionModel::renameSession(const QString &session)
+{
+ SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), nullptr);
+ newSessionInputDialog.setWindowTitle(tr("New Session Name"));
+ newSessionInputDialog.setValue(session);
+
+ if (newSessionInputDialog.exec() == QDialog::Accepted) {
+ QString newSession = newSessionInputDialog.value();
+ if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
+ return;
+ beginResetModel();
+ SessionManager::renameSession(session, newSession);
+ endResetModel();
+
+ if (newSessionInputDialog.isSwitchToRequested())
+ SessionManager::loadSession(newSession);
+ }
+}
+} // namespace Internal
+} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/sessionmodel.h b/src/plugins/projectexplorer/sessionmodel.h
new file mode 100644
index 0000000000..9534077f5a
--- /dev/null
+++ b/src/plugins/projectexplorer/sessionmodel.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QAbstractListModel>
+
+namespace ProjectExplorer {
+namespace Internal {
+
+class SessionModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole, ProjectsPathRole, ProjectsDisplayRole };
+
+ explicit SessionModel(QObject *parent = nullptr);
+
+ int rowCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ QHash<int, QByteArray> roleNames() const override;
+
+ Q_SCRIPTABLE bool isDefaultVirgin() const;
+
+public slots:
+ void resetSessions();
+ void cloneSession(const QString &session);
+ void deleteSession(const QString &session);
+ void renameSession(const QString &session);
+};
+
+} // namespace Internal
+} // namespace ProjectExplorer