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:
parent
fe4c618780
commit
cd123422f9
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QDialog>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
@ -2453,13 +2454,64 @@ void GitPlusPlusView::refreshWorkspaces()
|
||||||
|
|
||||||
void GitPlusPlusView::createWorkspace()
|
void GitPlusPlusView::createWorkspace()
|
||||||
{
|
{
|
||||||
// 1. Select source workspace directory
|
// --- Build dialog ---
|
||||||
QString sourceDir = QFileDialog::getExistingDirectory(
|
QDialog dlg(m_toolView);
|
||||||
m_toolView, QStringLiteral("Select source workspace (containing repos)"),
|
dlg.setWindowTitle(QStringLiteral("Create Workspace"));
|
||||||
m_workspaceSourceDir.isEmpty() ? m_workspaceDir : m_workspaceSourceDir);
|
dlg.setMinimumWidth(500);
|
||||||
if (sourceDir.isEmpty()) return;
|
|
||||||
|
|
||||||
// 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);
|
QDir source(sourceDir);
|
||||||
QStringList sourceRepos;
|
QStringList sourceRepos;
|
||||||
const auto entries = source.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
const auto entries = source.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||||
|
|
@ -2472,14 +2524,6 @@ void GitPlusPlusView::createWorkspace()
|
||||||
return;
|
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)
|
// 3. Create workspace directory (sibling of source)
|
||||||
QDir parentDir(sourceDir);
|
QDir parentDir(sourceDir);
|
||||||
parentDir.cdUp();
|
parentDir.cdUp();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue