forked from qt-creator/qt-creator
Modify behaviour of sessions on the welcomescreen and tweak the session manager
- List sessions by recent use instead of alphabetically - Tweak the session manager. It is now a persistent dialog with only a close button - Implement session renaming in the session manager - Cleanups Task-Number: QTCREATORBUG-1168
This commit is contained in:
@@ -74,21 +74,20 @@ void SessionValidator::fixup(QString &input) const
|
||||
input = copy;
|
||||
}
|
||||
|
||||
class NewSessionInputDialog : public QDialog
|
||||
class SessionNameInputDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NewSessionInputDialog(QStringList sessions);
|
||||
QString value();
|
||||
SessionNameInputDialog(const QStringList& sessions);
|
||||
QString value() const;
|
||||
private:
|
||||
QLineEdit *m_newSessionLineEdit;
|
||||
};
|
||||
|
||||
NewSessionInputDialog::NewSessionInputDialog(QStringList sessions)
|
||||
SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions)
|
||||
{
|
||||
setWindowTitle(tr("New session name"));
|
||||
QVBoxLayout *hlayout = new QVBoxLayout(this);
|
||||
QLabel *label = new QLabel(tr("Enter the name of the new session:"), this);
|
||||
QLabel *label = new QLabel(tr("Enter the name of the session:"), this);
|
||||
hlayout->addWidget(label);
|
||||
m_newSessionLineEdit = new QLineEdit(this);
|
||||
m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions));
|
||||
@@ -100,57 +99,83 @@ NewSessionInputDialog::NewSessionInputDialog(QStringList sessions)
|
||||
setLayout(hlayout);
|
||||
}
|
||||
|
||||
QString NewSessionInputDialog::value()
|
||||
QString SessionNameInputDialog::value() const
|
||||
{
|
||||
return m_newSessionLineEdit->text();
|
||||
}
|
||||
|
||||
SessionDialog::SessionDialog(SessionManager *sessionManager, const QString &lastSession, bool startup)
|
||||
: m_sessionManager(sessionManager), m_startup(startup)
|
||||
SessionDialog::SessionDialog(SessionManager *sessionManager)
|
||||
: m_sessionManager(sessionManager)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
QPushButton *switchButton = m_ui.buttonBox->addButton(tr("Switch to session"),
|
||||
QDialogButtonBox::AcceptRole);
|
||||
connect(switchButton, SIGNAL(clicked()),
|
||||
this, SLOT(switchToSession()));
|
||||
|
||||
connect(m_ui.btCreateNew, SIGNAL(clicked()),
|
||||
this, SLOT(createNew()));
|
||||
|
||||
connect(m_ui.btClone, SIGNAL(clicked()),
|
||||
this, SLOT(clone()));
|
||||
connect(m_ui.btDelete, SIGNAL(clicked()),
|
||||
this, SLOT(remove()));
|
||||
|
||||
connect(m_ui.sessionList, SIGNAL(itemDoubleClicked ( QListWidgetItem *)),
|
||||
this, SLOT(accept()));
|
||||
connect(m_ui.btSwitch, SIGNAL(clicked()), this, SLOT(switchToSession()));
|
||||
connect(m_ui.btRename, SIGNAL(clicked()), this, SLOT(rename()));
|
||||
|
||||
connect(m_ui.sessionList, SIGNAL(itemDoubleClicked (QListWidgetItem *)),
|
||||
this, SLOT(switchToSession()));
|
||||
|
||||
connect(m_ui.sessionList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
||||
this, SLOT(updateActions()));
|
||||
|
||||
m_ui.whatsASessionLabel->setOpenExternalLinks(true);
|
||||
QStringList sessions = sessionManager->sessions();
|
||||
addItems(true);
|
||||
markItems();
|
||||
}
|
||||
|
||||
void SessionDialog::addItems(bool setDefaultSession)
|
||||
{
|
||||
QStringList sessions = m_sessionManager->sessions();
|
||||
foreach (const QString &session, sessions) {
|
||||
m_ui.sessionList->addItem(session);
|
||||
if (session == lastSession)
|
||||
if (setDefaultSession && session == m_sessionManager->activeSession())
|
||||
m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1);
|
||||
}
|
||||
}
|
||||
void SessionDialog::markItems()
|
||||
{
|
||||
for(int i = 0; i < m_ui.sessionList->count(); ++i) {
|
||||
QListWidgetItem *item = m_ui.sessionList->item(i);
|
||||
QFont f = item->font();
|
||||
QString session = item->data(Qt::DisplayRole).toString();
|
||||
if (m_sessionManager->isDefaultSession(session))
|
||||
f.setItalic(true);
|
||||
else
|
||||
f.setItalic(false);
|
||||
if (m_sessionManager->activeSession() == session && !m_sessionManager->isDefaultVirgin())
|
||||
f.setBold(true);
|
||||
else
|
||||
f.setBold(false);
|
||||
item->setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
void SessionDialog::updateActions()
|
||||
{
|
||||
bool enableDelete = false;
|
||||
bool isDefault = false;
|
||||
bool isActive = false;
|
||||
|
||||
if (m_ui.sessionList->currentItem())
|
||||
enableDelete = (m_ui.sessionList->currentItem()->text() != m_sessionManager->activeSession()
|
||||
&& (m_ui.sessionList->currentItem()->text() != QLatin1String("default")));
|
||||
m_ui.btDelete->setEnabled(enableDelete);
|
||||
if (m_ui.sessionList->currentItem()) {
|
||||
isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default"));
|
||||
isActive = (m_ui.sessionList->currentItem()->text() == m_sessionManager->activeSession());
|
||||
}
|
||||
|
||||
m_ui.btDelete->setDisabled(isActive || isDefault);
|
||||
m_ui.btRename->setDisabled(isDefault);
|
||||
}
|
||||
|
||||
void SessionDialog::createNew()
|
||||
{
|
||||
NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions());
|
||||
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions());
|
||||
newSessionInputDialog.setWindowTitle(tr("New session name"));
|
||||
|
||||
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
||||
QString newSession = newSessionInputDialog.value();
|
||||
if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession))
|
||||
@@ -166,7 +191,8 @@ void SessionDialog::createNew()
|
||||
|
||||
void SessionDialog::clone()
|
||||
{
|
||||
NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions());
|
||||
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions());
|
||||
newSessionInputDialog.setWindowTitle(tr("New session name"));
|
||||
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
||||
QString newSession = newSessionInputDialog.value();
|
||||
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
|
||||
@@ -182,16 +208,32 @@ void SessionDialog::remove()
|
||||
{
|
||||
m_sessionManager->deleteSession(m_ui.sessionList->currentItem()->text());
|
||||
m_ui.sessionList->clear();
|
||||
m_ui.sessionList->addItems(m_sessionManager->sessions());
|
||||
addItems(false);
|
||||
markItems();
|
||||
}
|
||||
|
||||
|
||||
void SessionDialog::rename()
|
||||
{
|
||||
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions());
|
||||
newSessionInputDialog.setWindowTitle(tr("Rename session"));
|
||||
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
||||
m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
|
||||
m_ui.sessionList->clear();
|
||||
addItems(false);
|
||||
markItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SessionDialog::switchToSession()
|
||||
{
|
||||
if (m_ui.sessionList->currentItem()) {
|
||||
QString session = m_ui.sessionList->currentItem()->text();
|
||||
m_sessionManager->loadSession(session);
|
||||
markItems();
|
||||
}
|
||||
accept();
|
||||
updateActions();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user