From cd123422f95ca65544e01bc94cdd03bcbd27eb17 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 22 Jul 2026 16:28:10 +0200 Subject: [PATCH] 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. --- gitplusplus.cpp | 72 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/gitplusplus.cpp b/gitplusplus.cpp index b0ecd24..fab4594 100644 --- a/gitplusplus.cpp +++ b/gitplusplus.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -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();