ProjectExplorer: Use LayoutBuilder for session management

Change-Id: I18de9933c52b147c7c2bd1f75852531e787937d8
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-08-01 12:46:43 +02:00
parent 100f51ff50
commit a356ccd0ad
7 changed files with 114 additions and 228 deletions

View File

@@ -160,7 +160,7 @@ add_qtc_plugin(ProjectExplorer
sanitizerparser.cpp sanitizerparser.h sanitizerparser.cpp sanitizerparser.h
selectablefilesmodel.cpp selectablefilesmodel.h selectablefilesmodel.cpp selectablefilesmodel.h
session.cpp session.h session.cpp session.h
sessiondialog.cpp sessiondialog.h sessiondialog.ui sessiondialog.cpp sessiondialog.h
sessionmodel.cpp sessionmodel.h sessionmodel.cpp sessionmodel.h
sessionview.cpp sessionview.h sessionview.cpp sessionview.h
showineditortaskhandler.cpp showineditortaskhandler.h showineditortaskhandler.cpp showineditortaskhandler.h

View File

@@ -129,8 +129,10 @@
#include <coreplugin/navigationwidget.h> #include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h> #include <coreplugin/outputpane.h>
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h> #include <extensionsystem/pluginspec.h>
#include <texteditor/findinfiles.h> #include <texteditor/findinfiles.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
@@ -159,6 +161,7 @@
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QPair> #include <QPair>
#include <QPushButton>
#include <QSettings> #include <QSettings>
#include <QThreadPool> #include <QThreadPool>
#include <QTimer> #include <QTimer>

View File

@@ -136,7 +136,7 @@ Project {
"session.cpp", "session.h", "session.cpp", "session.h",
"sessionmodel.cpp", "sessionmodel.h", "sessionmodel.cpp", "sessionmodel.h",
"sessionview.cpp", "sessionview.h", "sessionview.cpp", "sessionview.h",
"sessiondialog.cpp", "sessiondialog.h", "sessiondialog.ui", "sessiondialog.cpp", "sessiondialog.h",
"showineditortaskhandler.cpp", "showineditortaskhandler.h", "showineditortaskhandler.cpp", "showineditortaskhandler.h",
"showoutputtaskhandler.cpp", "showoutputtaskhandler.h", "showoutputtaskhandler.cpp", "showoutputtaskhandler.h",
"simpleprojectwizard.cpp", "simpleprojectwizard.h", "simpleprojectwizard.cpp", "simpleprojectwizard.h",

View File

@@ -24,18 +24,22 @@
****************************************************************************/ ****************************************************************************/
#include "sessiondialog.h" #include "sessiondialog.h"
#include "session.h" #include "session.h"
#include "sessionview.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/layoutbuilder.h>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QFrame>
#include <QInputDialog> #include <QInputDialog>
#include <QLabel>
#include <QPushButton>
#include <QValidator> #include <QValidator>
using namespace ProjectExplorer; namespace ProjectExplorer::Internal {
using namespace ProjectExplorer::Internal;
namespace ProjectExplorer {
namespace Internal {
class SessionValidator : public QValidator class SessionValidator : public QValidator
{ {
@@ -83,12 +87,9 @@ void SessionValidator::fixup(QString &input) const
SessionNameInputDialog::SessionNameInputDialog(QWidget *parent) SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
auto hlayout = new QVBoxLayout(this);
auto label = new QLabel(tr("Enter the name of the session:"), this);
hlayout->addWidget(label);
m_newSessionLineEdit = new QLineEdit(this); m_newSessionLineEdit = new QLineEdit(this);
m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions())); m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions()));
hlayout->addWidget(m_newSessionLineEdit);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
m_okButton = buttons->button(QDialogButtonBox::Ok); m_okButton = buttons->button(QDialogButtonBox::Ok);
m_switchToButton = new QPushButton; m_switchToButton = new QPushButton;
@@ -96,10 +97,16 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
connect(m_switchToButton, &QPushButton::clicked, this, [this] { connect(m_switchToButton, &QPushButton::clicked, this, [this] {
m_usedSwitchTo = true; m_usedSwitchTo = true;
}); });
using namespace Utils::Layouting;
Column {
tr("Enter the name of the session:"),
m_newSessionLineEdit,
buttons,
}.attachTo(this);
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
hlayout->addWidget(buttons);
setLayout(hlayout);
} }
void SessionNameInputDialog::setActionText(const QString &actionText, const QString &openActionText) void SessionNameInputDialog::setActionText(const QString &actionText, const QString &openActionText)
@@ -125,58 +132,106 @@ bool SessionNameInputDialog::isSwitchToRequested() const
SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent) SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent)
{ {
m_ui.setupUi(this); resize(550, 400);
m_ui.sessionView->setActivationMode(Utils::DoubleClickActivation); setWindowTitle(tr("Session Manager"));
connect(m_ui.btCreateNew, &QAbstractButton::clicked,
m_ui.sessionView, &SessionView::createNewSession);
connect(m_ui.btClone, &QAbstractButton::clicked,
m_ui.sessionView, &SessionView::cloneCurrentSession);
connect(m_ui.btDelete, &QAbstractButton::clicked,
m_ui.sessionView, &SessionView::deleteSelectedSessions);
connect(m_ui.btSwitch, &QAbstractButton::clicked,
m_ui.sessionView, &SessionView::switchToCurrentSession);
connect(m_ui.btRename, &QAbstractButton::clicked,
m_ui.sessionView, &SessionView::renameCurrentSession);
connect(m_ui.sessionView, &SessionView::sessionActivated,
m_ui.sessionView, &SessionView::switchToCurrentSession);
connect(m_ui.sessionView, &SessionView::sessionsSelected, auto sessionView = new SessionView(this);
this, &SessionDialog::updateActions); sessionView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(m_ui.sessionView, &SessionView::sessionSwitched, sessionView->setActivationMode(Utils::DoubleClickActivation);
this, &QDialog::reject);
m_ui.whatsASessionLabel->setOpenExternalLinks(true); auto createNewButton = new QPushButton(tr("&New"));
m_renameButton = new QPushButton(tr("&Rename"));
m_cloneButton = new QPushButton(tr("C&lone"));
m_deleteButton = new QPushButton(tr("&Delete"));
m_switchButton = new QPushButton(tr("&Switch To"));
m_autoLoadCheckBox = new QCheckBox(tr("Restore last session on startup"));
auto line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
auto buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Close);
m_switchButton->setDefault(true);
// FIXME: Simplify translator's work.
auto whatsASessionLabel = new QLabel(
tr("<a href=\"qthelp://org.qt-project.qtcreator/doc/creator-project-managing-sessions.html\">"
"What is a Session?</a>"));
whatsASessionLabel->setOpenExternalLinks(true);
using namespace Utils::Layouting;
Column {
Row {
sessionView,
Column {
createNewButton,
m_renameButton,
m_cloneButton,
m_deleteButton,
m_switchButton,
st
}
},
m_autoLoadCheckBox,
line,
Row { whatsASessionLabel, buttonBox },
}.attachTo(this);
connect(createNewButton, &QAbstractButton::clicked,
sessionView, &SessionView::createNewSession);
connect(m_cloneButton, &QAbstractButton::clicked,
sessionView, &SessionView::cloneCurrentSession);
connect(m_deleteButton, &QAbstractButton::clicked,
sessionView, &SessionView::deleteSelectedSessions);
connect(m_switchButton, &QAbstractButton::clicked,
sessionView, &SessionView::switchToCurrentSession);
connect(m_renameButton, &QAbstractButton::clicked,
sessionView, &SessionView::renameCurrentSession);
connect(sessionView, &SessionView::sessionActivated,
sessionView, &SessionView::switchToCurrentSession);
connect(sessionView, &SessionView::sessionsSelected,
this, &SessionDialog::updateActions);
connect(sessionView, &SessionView::sessionSwitched,
this, &QDialog::reject);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
} }
void SessionDialog::setAutoLoadSession(bool check) void SessionDialog::setAutoLoadSession(bool check)
{ {
m_ui.autoLoadCheckBox->setChecked(check); m_autoLoadCheckBox->setChecked(check);
} }
bool SessionDialog::autoLoadSession() const bool SessionDialog::autoLoadSession() const
{ {
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked; return m_autoLoadCheckBox->checkState() == Qt::Checked;
} }
void SessionDialog::updateActions(const QStringList &sessions) void SessionDialog::updateActions(const QStringList &sessions)
{ {
if (sessions.isEmpty()) { if (sessions.isEmpty()) {
m_ui.btDelete->setEnabled(false); m_deleteButton->setEnabled(false);
m_ui.btRename->setEnabled(false); m_renameButton->setEnabled(false);
m_ui.btClone->setEnabled(false); m_cloneButton->setEnabled(false);
m_ui.btSwitch->setEnabled(false); m_switchButton->setEnabled(false);
return; return;
} }
const bool defaultIsSelected = sessions.contains("default"); const bool defaultIsSelected = sessions.contains("default");
const bool activeIsSelected = Utils::anyOf(sessions, [](const QString &session) { const bool activeIsSelected = Utils::anyOf(sessions, [](const QString &session) {
return session == SessionManager::activeSession(); return session == SessionManager::activeSession();
}); });
m_ui.btDelete->setEnabled(!defaultIsSelected && !activeIsSelected); m_deleteButton->setEnabled(!defaultIsSelected && !activeIsSelected);
m_ui.btRename->setEnabled(sessions.size() == 1 && !defaultIsSelected); m_renameButton->setEnabled(sessions.size() == 1 && !defaultIsSelected);
m_ui.btClone->setEnabled(sessions.size() == 1); m_cloneButton->setEnabled(sessions.size() == 1);
m_ui.btSwitch->setEnabled(sessions.size() == 1); m_switchButton->setEnabled(sessions.size() == 1);
} }
} // namespace Internal } // ProjectExplorer::Internal
} // namespace ProjectExplorer

View File

@@ -25,18 +25,16 @@
#pragma once #pragma once
#include "ui_sessiondialog.h"
#include <QString> #include <QString>
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCheckBox;
class QLineEdit; class QLineEdit;
class QPushButton; class QPushButton;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace ProjectExplorer { namespace ProjectExplorer::Internal {
namespace Internal {
class SessionDialog : public QDialog class SessionDialog : public QDialog
{ {
@@ -51,7 +49,11 @@ public:
private: private:
void updateActions(const QStringList &sessions); void updateActions(const QStringList &sessions);
Ui::SessionDialog m_ui; QPushButton *m_renameButton;
QPushButton *m_cloneButton;
QPushButton *m_deleteButton;
QPushButton *m_switchButton;
QCheckBox *m_autoLoadCheckBox;
}; };
class SessionNameInputDialog : public QDialog class SessionNameInputDialog : public QDialog
@@ -73,5 +75,4 @@ private:
bool m_usedSwitchTo = false; bool m_usedSwitchTo = false;
}; };
} // namespace Internal } // ProjectExplorer::Internal
} // namespace ProjectExplorer

View File

@@ -1,172 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectExplorer::Internal::SessionDialog</class>
<widget class="QDialog" name="ProjectExplorer::Internal::SessionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Session Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="SessionView" name="sessionView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btCreateNew">
<property name="text">
<string>&amp;New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btRename">
<property name="text">
<string>&amp;Rename</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btClone">
<property name="text">
<string>C&amp;lone</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btDelete">
<property name="text">
<string>&amp;Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btSwitch">
<property name="text">
<string>&amp;Switch To</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>85</width>
<height>48</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="autoLoadCheckBox">
<property name="text">
<string>Restore last session on startup</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="whatsASessionLabel">
<property name="text">
<string>&lt;a href=&quot;qthelp://org.qt-project.qtcreator/doc/creator-project-managing-sessions.html&quot;&gt;What is a Session?&lt;/a&gt;</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SessionView</class>
<extends>QTreeView</extends>
<header>projectexplorer/sessionview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ProjectExplorer::Internal::SessionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>191</x>
<y>244</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>237</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ProjectExplorer::Internal::SessionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>246</x>
<y>237</y>
</hint>
<hint type="destinationlabel">
<x>78</x>
<y>216</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -31,10 +31,10 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
namespace ProjectExplorer { namespace ProjectExplorer::Internal {
namespace Internal {
class SessionView : public Utils::TreeView { class SessionView : public Utils::TreeView
{
Q_OBJECT Q_OBJECT
public: public:
@@ -66,5 +66,4 @@ private:
SessionModel m_sessionModel; SessionModel m_sessionModel;
}; };
} // namespace Internal } // ProjectExplorer::Internal
} // namespace ProjectExplorer