Commit 563c542a authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Add option to restore last session at startup

 * Add an option to the session manager to restore the last
   session on startup of creator.
 * Align close button on session manager dialog with the other
   buttons.
 * Clean up handling of session restoration in the ProjectExplorer:
   Move all the relevant code into determineSessionToRestoreAtStartup,
   since most was there already.

Task-number: QTCREATORBUG-2324
parent b85597da
......@@ -260,9 +260,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
d->m_session = new SessionManager(this);
if (arguments.contains("-lastsession"))
d->m_sessionToRestoreAtStartup = d->m_session->lastSession();
connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project *)),
this, SIGNAL(fileListChanged()));
connect(d->m_session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project *)),
......@@ -799,6 +796,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
d->m_projectExplorerSettings.cleanOldAppOutput = s->value("ProjectExplorer/Settings/CleanOldAppOutput", false).toBool();
d->m_projectExplorerSettings.wrapAppOutput = s->value("ProjectExplorer/Settings/WrapAppOutput", true).toBool();
d->m_projectExplorerSettings.useJom = s->value("ProjectExplorer/Settings/UseJom", true).toBool();
d->m_projectExplorerSettings.autorestoreLastSession = s->value("ProjectExplorer/Settings/AutoRestoreLastSession", false).toBool();
d->m_projectExplorerSettings.environmentId = QUuid(s->value("ProjectExplorer/Settings/EnvironmentId").toString());
if (d->m_projectExplorerSettings.environmentId.isNull())
d->m_projectExplorerSettings.environmentId = QUuid::createUuid();
......@@ -994,7 +992,9 @@ void ProjectExplorerPlugin::showSessionManager()
d->m_session->save();
}
SessionDialog sessionDialog(d->m_session);
sessionDialog.setAutoLoadSession(d->m_projectExplorerSettings.autorestoreLastSession);
sessionDialog.exec();
d->m_projectExplorerSettings.autorestoreLastSession = sessionDialog.autoLoadSession();
updateActions();
......@@ -1053,6 +1053,7 @@ void ProjectExplorerPlugin::savePersistentSettings()
s->setValue("ProjectExplorer/Settings/CleanOldAppOutput", d->m_projectExplorerSettings.cleanOldAppOutput);
s->setValue("ProjectExplorer/Settings/WrapAppOutput", d->m_projectExplorerSettings.wrapAppOutput);
s->setValue("ProjectExplorer/Settings/UseJom", d->m_projectExplorerSettings.useJom);
s->setValue("ProjectExplorer/Settings/AutoRestoreLastSession", d->m_projectExplorerSettings.autorestoreLastSession);
s->setValue("ProjectExplorer/Settings/EnvironmentId", d->m_projectExplorerSettings.environmentId.toString());
}
}
......@@ -1187,15 +1188,20 @@ void ProjectExplorerPlugin::currentModeChanged(Core::IMode *mode, Core::IMode *o
void ProjectExplorerPlugin::determineSessionToRestoreAtStartup()
{
QStringList sessions = d->m_session->sessions();
// We have command line arguments, try to find a session in them
QStringList arguments = ExtensionSystem::PluginManager::instance()->arguments();
// Default to no session loading
foreach (const QString &arg, arguments) {
if (sessions.contains(arg)) {
// Session argument
d->m_sessionToRestoreAtStartup = arg;
break;
if (arguments.contains("-lastsession")
|| d->m_projectExplorerSettings.autorestoreLastSession) {
d->m_sessionToRestoreAtStartup = d->m_session->lastSession();
} else {
QStringList sessions = d->m_session->sessions();
// We have command line arguments, try to find a session in them
// Default to no session loading
foreach (const QString &arg, arguments) {
if (sessions.contains(arg)) {
// Session argument
d->m_sessionToRestoreAtStartup = arg;
break;
}
}
}
......
......@@ -37,9 +37,12 @@ namespace Internal {
struct ProjectExplorerSettings
{
ProjectExplorerSettings() : buildBeforeDeploy(true), deployBeforeRun(true),
saveBeforeBuild(false), showCompilerOutput(false),
cleanOldAppOutput(false), wrapAppOutput(true), useJom(true) {}
ProjectExplorerSettings() :
buildBeforeDeploy(true), deployBeforeRun(true),
saveBeforeBuild(false), showCompilerOutput(false),
cleanOldAppOutput(false), wrapAppOutput(true), useJom(true),
autorestoreLastSession(false)
{ }
bool buildBeforeDeploy;
bool deployBeforeRun;
......@@ -48,6 +51,8 @@ struct ProjectExplorerSettings
bool cleanOldAppOutput;
bool wrapAppOutput;
bool useJom;
bool autorestoreLastSession; // This option is set in the Session Manager!
// Add a UUid which is used to identify the development environment.
// This is used to warn the user when he is trying to open a .user file that was created
// somewhere else (which might lead to unexpected results).
......@@ -62,7 +67,8 @@ inline bool operator==(const ProjectExplorerSettings &p1, const ProjectExplorerS
&& p1.showCompilerOutput == p2.showCompilerOutput
&& p1.cleanOldAppOutput == p2.cleanOldAppOutput
&& p1.wrapAppOutput == p2.wrapAppOutput
&& p1.useJom == p2.useJom;
&& p1.useJom == p2.useJom
&& p1.autorestoreLastSession == p2.autorestoreLastSession;
}
......
......@@ -149,6 +149,17 @@ SessionDialog::SessionDialog(SessionManager *sessionManager)
markItems();
}
void SessionDialog::setAutoLoadSession(bool check)
{
m_ui.autoLoadCheckBox->setChecked(check ? Qt::Checked : Qt::Unchecked);
}
bool SessionDialog::autoLoadSession() const
{
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
}
void SessionDialog::addItems(bool setDefaultSession)
{
QStringList sessions = m_sessionManager->sessions();
......
......@@ -47,6 +47,9 @@ class SessionDialog : public QDialog
public:
SessionDialog(SessionManager *sessionManager);
void setAutoLoadSession(bool);
bool autoLoadSession() const;
private slots:
void createNew();
void clone();
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>260</height>
<width>373</width>
<height>282</height>
</rect>
</property>
<property name="windowTitle">
......@@ -17,8 +17,14 @@
<item row="0" column="0">
<widget class="QListWidget" name="sessionList"/>
</item>
<item row="0" column="1">
<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">
......@@ -65,21 +71,31 @@
<property name="sizeHint" stdset="0">
<size>
<width>85</width>
<height>13</height>
<height>48</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<item row="1" column="0">
<widget class="QCheckBox" name="autoLoadCheckBox">
<property name="toolTip">
<string>Automatically restore the last session when Qt Creator is started.</string>
</property>
<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="2" column="0" rowspan="2">
<item row="3" column="0">
<widget class="QLabel" name="whatsASessionLabel">
<property name="text">
<string>&lt;a href=&quot;qthelp://com.nokia.qtcreator/doc/creator-project-managing-sessions.html&quot;&gt;What is a Session?&lt;/a&gt;</string>
......@@ -88,9 +104,21 @@
</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>
......
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