Internal
Public Access
Merge Profiles and Session windows into a single window
ProfilesWindow and SessionWindow were two independent top-level windows, coordinated through a QPointer and manual show/create-or-reuse logic, with duplicated Help menus and a path where Quit didn't actually quit if a SessionWindow happened to be open. ProfilesWindow is now an embedded QWidget shown as a permanent, unclosable "Profiles" tab inside SessionWindow's tab widget; SessionWindow is the app's sole top-level window. Double-clicking a profile opens a session tab in the same window instead of finding-or-creating a second one, and closing all session tabs falls back to the Profiles tab rather than closing the app. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+39
-7
@@ -1,6 +1,7 @@
|
||||
#include "session_window.h"
|
||||
|
||||
#include "about_dialog.h"
|
||||
#include "profiles_window.h"
|
||||
#include <QApplication>
|
||||
#include "session_tab.h"
|
||||
|
||||
@@ -38,12 +39,12 @@ QStringList terminalThemeNames()
|
||||
}
|
||||
}
|
||||
|
||||
SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
||||
: QMainWindow(parent), m_tabs(new QTabWidget(this))
|
||||
SessionWindow::SessionWindow(QWidget* parent)
|
||||
: QMainWindow(parent), m_tabs(new QTabWidget(this)), m_profilesWidget(nullptr)
|
||||
{
|
||||
loadUiPreferences();
|
||||
|
||||
setWindowTitle(QStringLiteral("OrbitHub Session - %1").arg(profile.name));
|
||||
setWindowTitle(QStringLiteral("OrbitHub"));
|
||||
resize(1080, 760);
|
||||
setWindowIcon(QApplication::windowIcon());
|
||||
|
||||
@@ -58,8 +59,8 @@ SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
||||
}
|
||||
m_tabs->removeTab(index);
|
||||
delete tab;
|
||||
if (m_tabs->count() == 0) {
|
||||
close();
|
||||
if (sessionTabCount() == 0) {
|
||||
setWindowTitle(QStringLiteral("OrbitHub"));
|
||||
}
|
||||
});
|
||||
m_tabs->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@@ -164,6 +165,22 @@ SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
||||
}
|
||||
});
|
||||
|
||||
QMenu* fileMenu = menuBar()->addMenu(QStringLiteral("File"));
|
||||
QAction* newProfileAction = fileMenu->addAction(QStringLiteral("New Profile"));
|
||||
QAction* newFolderAction = fileMenu->addAction(QStringLiteral("New Folder"));
|
||||
fileMenu->addSeparator();
|
||||
QAction* quitAction = fileMenu->addAction(QStringLiteral("Quit"));
|
||||
|
||||
connect(newProfileAction,
|
||||
&QAction::triggered,
|
||||
this,
|
||||
[this]() { m_profilesWidget->createProfileInCurrentContext(); });
|
||||
connect(newFolderAction,
|
||||
&QAction::triggered,
|
||||
this,
|
||||
[this]() { m_profilesWidget->createFolderInCurrentContext(); });
|
||||
connect(quitAction, &QAction::triggered, this, []() { qApp->quit(); });
|
||||
|
||||
QMenu* helpMenu = menuBar()->addMenu(QStringLiteral("Help"));
|
||||
QAction* aboutAction = helpMenu->addAction(QStringLiteral("About OrbitHub"));
|
||||
connect(aboutAction,
|
||||
@@ -175,7 +192,15 @@ SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
||||
});
|
||||
|
||||
setCentralWidget(m_tabs);
|
||||
addSessionTab(profile);
|
||||
|
||||
m_profilesWidget = new ProfilesWindow(this);
|
||||
const int profilesIndex = m_tabs->addTab(m_profilesWidget, QStringLiteral("Profiles"));
|
||||
m_tabs->tabBar()->setTabButton(profilesIndex, QTabBar::LeftSide, nullptr);
|
||||
m_tabs->tabBar()->setTabButton(profilesIndex, QTabBar::RightSide, nullptr);
|
||||
connect(m_profilesWidget,
|
||||
&ProfilesWindow::connectRequested,
|
||||
this,
|
||||
&SessionWindow::addSessionTab);
|
||||
}
|
||||
|
||||
void SessionWindow::openProfile(const Profile& profile)
|
||||
@@ -188,8 +213,10 @@ void SessionWindow::addSessionTab(const Profile& profile)
|
||||
auto* tab = new SessionTab(profile, m_preferences, this);
|
||||
const int index = m_tabs->addTab(tab, tab->tabTitle());
|
||||
m_tabs->setCurrentIndex(index);
|
||||
if (m_tabs->count() > 1) {
|
||||
if (sessionTabCount() > 1) {
|
||||
setWindowTitle(QStringLiteral("OrbitHub Sessions"));
|
||||
} else {
|
||||
setWindowTitle(QStringLiteral("OrbitHub Session - %1").arg(profile.name));
|
||||
}
|
||||
m_tabs->tabBar()->setTabTextColor(
|
||||
index, tabColorForState(SessionState::Disconnected, m_tabs->palette()));
|
||||
@@ -248,6 +275,11 @@ void SessionWindow::updateTabTitle(SessionTab* tab, const QString& title)
|
||||
}
|
||||
}
|
||||
|
||||
int SessionWindow::sessionTabCount() const
|
||||
{
|
||||
return m_tabs->count() - 1;
|
||||
}
|
||||
|
||||
void SessionWindow::loadUiPreferences()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
Reference in New Issue
Block a user