Replace createWorkspace with proper dialog

Dialog has Source field (with Browse button, defaults to workspace source)
and Destination field (workspace name = branch name). OK/Cancel buttons.
This commit is contained in:
Levi Neely 2026-07-22 16:28:10 +02:00
parent fe4c618780
commit cd123422f9
1 changed files with 58 additions and 14 deletions

View File

@ -21,6 +21,7 @@
#include <QCheckBox>
#include <QClipboard>
#include <QComboBox>
#include <QDialog>
#include <QDir>
#include <QFile>
#include <QFileDialog>
@ -2453,13 +2454,64 @@ void GitPlusPlusView::refreshWorkspaces()
void GitPlusPlusView::createWorkspace()
{
// 1. Select source workspace directory
QString sourceDir = QFileDialog::getExistingDirectory(
m_toolView, QStringLiteral("Select source workspace (containing repos)"),
m_workspaceSourceDir.isEmpty() ? m_workspaceDir : m_workspaceSourceDir);
if (sourceDir.isEmpty()) return;
// --- Build dialog ---
QDialog dlg(m_toolView);
dlg.setWindowTitle(QStringLiteral("Create Workspace"));
dlg.setMinimumWidth(500);
// Verify it contains git repos
auto *layout = new QVBoxLayout(&dlg);
// Source row
auto *sourceLabel = new QLabel(QStringLiteral("Source:"), &dlg);
auto *sourceEdit = new QLineEdit(&dlg);
sourceEdit->setText(m_workspaceSourceDir.isEmpty() ? m_workspaceDir : m_workspaceSourceDir);
sourceEdit->setPlaceholderText(QStringLiteral("/path/to/source/workspace"));
auto *browseBtn = new QPushButton(QStringLiteral("Browse..."), &dlg);
connect(browseBtn, &QPushButton::clicked, &dlg, [&dlg, sourceEdit]() {
QString dir = QFileDialog::getExistingDirectory(&dlg, QStringLiteral("Select source workspace"), sourceEdit->text());
if (!dir.isEmpty())
sourceEdit->setText(dir);
});
auto *sourceRow = new QHBoxLayout;
sourceRow->addWidget(sourceLabel);
sourceRow->addWidget(sourceEdit, 1);
sourceRow->addWidget(browseBtn);
layout->addLayout(sourceRow);
// Destination row
auto *destLabel = new QLabel(QStringLiteral("Destination:"), &dlg);
auto *destEdit = new QLineEdit(&dlg);
destEdit->setPlaceholderText(QStringLiteral("workspace-name (also used as branch name)"));
auto *destRow = new QHBoxLayout;
destRow->addWidget(destLabel);
destRow->addWidget(destEdit, 1);
layout->addLayout(destRow);
// Buttons
auto *btnLayout = new QHBoxLayout;
btnLayout->addStretch();
auto *okBtn = new QPushButton(QStringLiteral("OK"), &dlg);
auto *cancelBtn = new QPushButton(QStringLiteral("Cancel"), &dlg);
okBtn->setDefault(true);
btnLayout->addWidget(okBtn);
btnLayout->addWidget(cancelBtn);
layout->addLayout(btnLayout);
connect(okBtn, &QPushButton::clicked, &dlg, &QDialog::accept);
connect(cancelBtn, &QPushButton::clicked, &dlg, &QDialog::reject);
if (dlg.exec() != QDialog::Accepted) return;
QString sourceDir = sourceEdit->text().trimmed();
QString name = destEdit->text().trimmed();
if (sourceDir.isEmpty() || name.isEmpty()) {
setMessage(QStringLiteral("Source and destination are required"), true);
return;
}
// Verify source contains git repos
QDir source(sourceDir);
QStringList sourceRepos;
const auto entries = source.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
@ -2472,14 +2524,6 @@ void GitPlusPlusView::createWorkspace()
return;
}
// 2. Get workspace name from user
bool ok;
QString name = QInputDialog::getText(m_toolView, QStringLiteral("Create Workspace"),
QStringLiteral("Workspace name (also used as branch name):"),
QLineEdit::Normal, {}, &ok);
if (!ok || name.trimmed().isEmpty()) return;
name = name.trimmed();
// 3. Create workspace directory (sibling of source)
QDir parentDir(sourceDir);
parentDir.cdUp();