Commit 9bc042e0 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by hjk

WelcomePage: Add tooltip for sessions

The tooltip allows renaming, cloning and deleting and shows
included projects.

The following method was added to Session:

QStringList projectsForSessionName(const QString &session) const;

I moved the SessionNameInputDialog into the header to reuse it.

I added new roles to SessionModel (ProjectsPathRole, ProjectsDisplayRole).
The following slots were added to SessionModel to expose the backend
functionality:

void cloneSession(const QString &session);
void deleteSession(const QString &session);
void renameSession(const QString &session);

Change-Id: I0182a26dc63b4f051ea948756decd5413c832c60
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 7e380e9d
......@@ -64,22 +64,6 @@ Rectangle {
anchors.top: parent.top
anchors.topMargin: 0
RecentSessions {
id: recentSessions
x: 87
y: 144
width: 274
anchors.left: recentlyUsedSessions.left
anchors.right: recentlyUsedProjects.left
anchors.rightMargin: 40
anchors.top: recentlyUsedSessions.bottom
anchors.topMargin: 20
model: sessionList
}
Rectangle {
width: 1
height: line.height
......@@ -94,7 +78,7 @@ Rectangle {
x: 406
y: 144
width: 481
height: 416
height: 432
id: recentProjects
anchors.left: recentlyUsedProjects.left
......@@ -184,5 +168,21 @@ Rectangle {
source: "widgets/images/icons/createIcon.png"
}
}
RecentSessions {
id: recentSessions
x: 87
y: 144
width: 274
anchors.left: recentlyUsedSessions.left
anchors.right: recentlyUsedProjects.left
anchors.rightMargin: 40
anchors.top: recentlyUsedSessions.bottom
anchors.topMargin: 20
model: sessionList
}
}
}
......@@ -37,6 +37,7 @@ QtObject {
property alias standardCaption: standardCaptionText.font
property alias standstandardDescription: standardDescriptionText.font
property alias italicDescription: italicDescriptionText.font
property alias boldDescription: boldText.font
property list<Item> texts: [
......@@ -50,6 +51,16 @@ QtObject {
font.family: "Helvetica"
},
Text {
id: boldText
visible: false
font.pixelSize: 13
font.bold: true
font.family: "Helvetica"
},
Text {
id: standardCaptionText
......
......@@ -47,6 +47,7 @@ Text {
property bool active: false
property bool hovered: mouseArea.state === "hovered"
onActiveChanged: {
if (active)
mouseArea.state = ""
......
......@@ -35,6 +35,13 @@ import QtQuick 1.1
Row {
spacing: 4
property alias name: sessionText.text
property alias hovered: sessionText.hovered
signal clicked
id: root
Image {
source: "images/bullet.png"
anchors.verticalCenter: sessionText.verticalCenter
......@@ -42,6 +49,9 @@ Row {
LinkedText {
id: sessionText
onClicked: projectWelcomePage.requestSession(sessionName)
onClicked: {
projectWelcomePage.requestSession(sessionName);
root.clicked();
}
}
}
......@@ -36,9 +36,12 @@
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QFileInfo>
#include <QDir>
#include <projectexplorer/session.h>
#include <projectexplorer/projectexplorer.h>
#include <sessiondialog.h>
namespace ProjectExplorer {
namespace Internal {
......@@ -51,6 +54,8 @@ SessionModel::SessionModel(SessionManager *manager, QObject *parent)
roleNames[DefaultSessionRole] = "defaultSession";
roleNames[ActiveSessionRole] = "activeSession";
roleNames[LastSessionRole] = "lastSession";
roleNames[ProjectsPathRole] = "projectsPath";
roleNames[ProjectsDisplayRole] = "projectsName";
setRoleNames(roleNames);
connect(manager, SIGNAL(sessionLoaded(QString)), SLOT(resetSessions()));
}
......@@ -60,10 +65,28 @@ int SessionModel::rowCount(const QModelIndex &) const
return m_manager->sessions().count();
}
QStringList pathsToBaseNames(const QStringList &paths)
{
QStringList stringList;
foreach (const QString &path, paths)
stringList.append(QFileInfo(path).completeBaseName());
return stringList;
}
QStringList pathsWithTildeHomePath(const QStringList &paths)
{
QStringList stringList;
foreach (const QString &path, paths)
stringList.append(Utils::withTildeHomePath(QDir::toNativeSeparators(path)));
return stringList;
}
QVariant SessionModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole || role == DefaultSessionRole ||
role == LastSessionRole || role == ActiveSessionRole) {
role == LastSessionRole || role == ActiveSessionRole || role == ProjectsPathRole || role == ProjectsDisplayRole) {
QString sessionName = m_manager->sessions().at(index.row());
if (role == Qt::DisplayRole)
return sessionName;
......@@ -73,6 +96,10 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const
return m_manager->lastSession() == sessionName;
else if (role == ActiveSessionRole)
return m_manager->activeSession() == sessionName;
else if (role == ProjectsPathRole)
return pathsWithTildeHomePath(m_manager->projectsForSessionName(sessionName));
else if (role == ProjectsDisplayRole)
return pathsToBaseNames(m_manager->projectsForSessionName(sessionName));
}
return QVariant();
}
......@@ -87,6 +114,49 @@ void SessionModel::resetSessions()
reset();
}
void SessionModel::cloneSession(const QString &session)
{
SessionNameInputDialog newSessionInputDialog(m_manager->sessions(), 0);
newSessionInputDialog.setWindowTitle(tr("New session name"));
newSessionInputDialog.setValue(session + QLatin1String(" (2)"));
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
m_manager->cloneSession(session, newSession);
reset();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
}
}
}
void SessionModel::deleteSession(const QString &session)
{
m_manager->deleteSession(session);
reset();
}
void SessionModel::renameSession(const QString &session)
{
SessionNameInputDialog newSessionInputDialog(m_manager->sessions(), 0);
newSessionInputDialog.setWindowTitle(tr("New session name"));
newSessionInputDialog.setValue(session);
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
m_manager->renameSession(session, newSession);
reset();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
}
}
}
ProjectModel::ProjectModel(ProjectExplorerPlugin *plugin, QObject *parent)
: QAbstractListModel(parent), m_plugin(plugin)
......
......@@ -54,7 +54,7 @@ class SessionModel : public QAbstractListModel
{
Q_OBJECT
public:
enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole };
enum { DefaultSessionRole = Qt::UserRole+1, LastSessionRole, ActiveSessionRole, ProjectsPathRole, ProjectsDisplayRole };
SessionModel(SessionManager* manager, QObject* parent = 0);
int rowCount(const QModelIndex &parent) const;
......@@ -64,6 +64,9 @@ public:
public slots:
void resetSessions();
void cloneSession(const QString &session);
void deleteSession(const QString &session);
void renameSession(const QString &session);
private:
SessionManager *m_manager;
......
......@@ -914,3 +914,16 @@ void SessionManager::sessionLoadingProgress()
m_future.setProgressValue(m_future.progressValue() + 1);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
QStringList ProjectExplorer::SessionManager::projectsForSessionName(const QString &session) const
{
const QString fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (QFileInfo(fileName).exists()) {
if (!reader.load(fileName)) {
qWarning() << "Could not restore session" << fileName;
return QStringList();
}
}
return reader.restoreValue(QLatin1String("ProjectList")).toStringList();
}
......@@ -120,6 +120,7 @@ public:
Node *nodeForFile(const QString &fileName, Project *project = 0) const;
Project *projectForFile(const QString &fileName) const;
QStringList projectsForSessionName(const QString &session) const;
void reportProjectLoadingProgress();
signals:
......
......@@ -85,26 +85,6 @@ void SessionValidator::fixup(QString &input) const
input = copy;
}
class SessionNameInputDialog : public QDialog
{
Q_OBJECT
public:
SessionNameInputDialog(const QStringList &sessions, QWidget *parent = 0);
void setValue(const QString &value);
QString value() const;
bool isSwitchToRequested() const;
private slots:
void clicked(QAbstractButton *button);
private:
QLineEdit *m_newSessionLineEdit;
QPushButton *m_switchToButton;
bool m_usedSwitchTo;
};
SessionNameInputDialog::SessionNameInputDialog(const QStringList &sessions, QWidget *parent)
: QDialog(parent), m_usedSwitchTo(false)
{
......@@ -299,5 +279,3 @@ void SessionDialog::switchToSession()
} // namespace Internal
} // namespace ProjectExplorer
#include "sessiondialog.moc"
......@@ -38,6 +38,11 @@
#include "ui_sessiondialog.h"
QT_BEGIN_NAMESPACE
class QLineEdit;
class QPushButton;
QT_END_NAMESPACE
namespace ProjectExplorer {
class SessionManager;
......@@ -69,6 +74,25 @@ private:
SessionManager *m_sessionManager;
};
class SessionNameInputDialog : public QDialog
{
Q_OBJECT
public:
SessionNameInputDialog(const QStringList &sessions, QWidget *parent = 0);
void setValue(const QString &value);
QString value() const;
bool isSwitchToRequested() const;
private slots:
void clicked(QAbstractButton *button);
private:
QLineEdit *m_newSessionLineEdit;
QPushButton *m_switchToButton;
bool m_usedSwitchTo;
};
} // namespace Internal
} // namespace ProjectExplorer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment