# # # patch "res/forms/dialogs/update_workspace.ui" # from [9ab8858e2d6e2c098d641974eda6d029a19c3b4b] # to [8c6d14f5ee14124e1caa636298854c929b83d92b] # # patch "src/view/dialogs/UpdateWorkspace.cpp" # from [fc8e3ff3f490dffea8fd906bfdc4f014756906f7] # to [bf20d99b24daa876fe1b29fae832ff8abb4e5773] # # patch "src/view/dialogs/UpdateWorkspace.h" # from [d51f6698c1e9b13c89b660fff1dd0944e5095365] # to [9be3dd2b3cab3b6769fadf35865e81bd065f4f53] # # patch "src/view/dialogs/WorkspaceDialogManager.cpp" # from [ed9e9897de007f9b6e34d1dbae8e15562ff0b441] # to [8d4a25eb22d5cb20bf3f3856388360b71c7cf339] # # patch "src/view/dialogs/WorkspaceDialogManager.h" # from [b990af551a2bf1a0276f1fb386cd99c9c536ba48] # to [0b4324f9c0a09e5a8cba428bf4a59859b7066f74] # # patch "src/view/mainwindows/WorkspaceWindow.cpp" # from [f9c8af974e5585beff33b6f55b69e2fd9bd1f10e] # to [42cf7d056cc700fb255b8ff7575a343886857e35] # # patch "src/view/mainwindows/WorkspaceWindow.h" # from [f20d3515c093e43af587667d01ff49a8a3154c2f] # to [b611ad3e5d0a89657582a0bc2c718d93c7e528ab] # ============================================================ --- res/forms/dialogs/update_workspace.ui 9ab8858e2d6e2c098d641974eda6d029a19c3b4b +++ res/forms/dialogs/update_workspace.ui 8c6d14f5ee14124e1caa636298854c929b83d92b @@ -1,261 +1,250 @@ - + + UpdateWorkspace - - + + 0 0 - 475 - 265 + 414 + 399 - - - 5 - 0 + + 0 0 - - - 0 - 265 - - - - - 16777215 - 265 - - - + Update workspace - - :/icons/guitone.png + + + :/icons/guitone.png:/icons/guitone.png - - - 9 + + + QLayout::SetFixedSize - - 6 - - - - 0 + + + Update the current workspace to - - 6 - - - - - Update the current workspace to - - - - 9 + + + + + + + the latest revision (branch: %1) + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + the head of branch + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + + + 0 - - 6 - - - - 0 + + + the tag - - 6 + + + + + + Qt::Horizontal - - - - the latest revision (branch: %1) - - - true - - - - - - - 0 - - - 6 - - - - - the head of branch - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 40 - 20 - - - - - - - - - 3 - 0 - 0 - 0 - - - - - 200 - 0 - - - - - - - - - - 0 - - - 6 - - - - - the tag - - - - - - - Qt::Horizontal - - - QSizePolicy::MinimumExpanding - - - - 40 - 20 - - - - - - - - - 3 - 0 - 0 - 0 - - - - - 200 - 0 - - - - - - - - - - 0 - - - 3 - - - - - an individual revision (selectors allowed) - - - - - - - 0 - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - - - select revision - - - - - - - - + + + 40 + 20 + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok - - - - + + + + + + + an individual revision (selectors allowed) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + select revision + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Update progress + + + + + + + 10 + + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + true + + + + + + - + + @@ -264,11 +253,11 @@ UpdateWorkspace accept() - + 237 235 - + 237 130 @@ -280,11 +269,11 @@ UpdateWorkspace reject() - + 237 235 - + 237 130 ============================================================ --- src/view/dialogs/UpdateWorkspace.cpp fc8e3ff3f490dffea8fd906bfdc4f014756906f7 +++ src/view/dialogs/UpdateWorkspace.cpp bf20d99b24daa876fe1b29fae832ff8abb4e5773 @@ -22,6 +22,7 @@ #include "Settings.h" #include +#include UpdateWorkspace::UpdateWorkspace(QWidget * parent, const WorkspacePath & ws) : Dialog(parent), workspacePath(ws) @@ -29,18 +30,12 @@ UpdateWorkspace::UpdateWorkspace(QWidget setupUi(this); Dialog::init(); - updateToLatest->setText( - updateToLatest->text().arg(MonotoneUtil::getBranchName(workspacePath)) - ); - DatabaseFile db = MonotoneUtil::getDatabaseFile(workspacePath); branchesModel = new Branches(this, db, false); - branchesModel->readBranches(); branchList->setModel(branchesModel); tagsModel = new Tags(this, db); - tagsModel->readTags(QString()); tagList->setModel(tagsModel); selectorCompleter = new QCompleter( @@ -70,6 +65,23 @@ UpdateWorkspace::UpdateWorkspace(QWidget selectedRevision, SIGNAL(textChanged(const QString &)), this, SLOT(selectSelectorOption()) ); + + mtnProcess = new MonotoneProcess(workspacePath); + + connect( + mtnProcess, SIGNAL(output(const QString &)), + this, SLOT(processOutput(const QString &)) + ); + + connect( + mtnProcess, SIGNAL(error(const QString &)), + this, SLOT(processError(const QString &)) + ); + + connect( + mtnProcess, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(processFinished(int, QProcess::ExitStatus)) + ); } UpdateWorkspace::~UpdateWorkspace() @@ -77,8 +89,24 @@ UpdateWorkspace::~UpdateWorkspace() delete branchesModel; delete tagsModel; delete selectorCompleter; + delete mtnProcess; } +void UpdateWorkspace::init() +{ + tagsModel->readTags(QString()); + branchesModel->readBranches(); + + updateToLatest->setText( + tr("the latest revision (branch: %1)") + .arg(MonotoneUtil::getBranchName(workspacePath)) + ); + + updateSelection->setEnabled(true); + buttonBox->setEnabled(true); + updateProgress->hide(); +} + void UpdateWorkspace::accept() { QString selector; @@ -114,8 +142,8 @@ void UpdateWorkspace::accept() tr("No tag selected"), tr("Please select a tag from the list of tags (if any are available)."), QMessageBox::Ok - ); - return; + ); + return; } selector = "t:" + selection; } @@ -128,10 +156,11 @@ void UpdateWorkspace::accept() QMessageBox::warning( this, tr("No selector given"), - tr("Please enter a monotone selector or choose a revision by clicking on 'select revision'."), + tr("Please enter a monotone selector or choose a revision " + "by clicking on 'select revision'."), QMessageBox::Ok - ); - return; + ); + return; } selector = selection; Settings::addItemToList("RecentUpdateSelectors", selection, 10); @@ -149,8 +178,8 @@ void UpdateWorkspace::accept() tr("No revisions matched"), tr("Your selection didn't match any revisions or was invalid."), QMessageBox::Ok - ); - return; + ); + return; } if (revList.size() > 1) @@ -167,10 +196,81 @@ void UpdateWorkspace::accept() } selectedRevisionId = revList.at(0); - D(QString("Selected %1 as update revision").arg(selectedRevisionId)); - done(0); + QString baseRevisionId = + MonotoneUtil::getBaseWorkspaceRevision(workspacePath); + + QStringList commonAncestors = MonotoneUtil::getCommonAncestors( + MonotoneUtil::getDatabaseFile(workspacePath), + QStringList() << selectedRevisionId << baseRevisionId + ); + + if (commonAncestors.size() == 0) + { + QMessageBox::StandardButton btn = QMessageBox::question( + this, + tr("No common ancestors found"), + tr("The selected revision shares no common ancestor with the " + "current revision of the workspace. Do you really want to " + "continue?"), + QMessageBox::Yes | QMessageBox::No + ); + + if (btn == QMessageBox::No) return; + } + + updateSelection->setEnabled(false); + buttonBox->setEnabled(false); + output->clear(); + updateProgress->show(); + + emit beforeWorkspaceUpdate(); + + QStringList params; + params << "update" + << "-r" << selectedRevisionId + << "--move-conflicting-paths"; + mtnProcess->start(params); } +void UpdateWorkspace::processOutput(const QString & out) +{ + QListWidgetItem * item = new QListWidgetItem(out, output); + output->addItem(item); + output->scrollToItem(item); +} + +void UpdateWorkspace::processError(const QString & error) +{ + QListWidgetItem * item = new QListWidgetItem( + tr("Update failed: %1").arg(error), + output + ); + item->setForeground(QBrush(QColor("red"))); + output->addItem(item); + output->scrollToItem(item); + + updateSelection->setEnabled(true); + buttonBox->setEnabled(true); +} + +void UpdateWorkspace::processFinished(int exitCode, QProcess::ExitStatus exitStatus) +{ + Q_UNUSED(exitStatus); + if (exitCode == 0) + { + QListWidgetItem * item = new QListWidgetItem(tr("Update successfully completed"), output); + item->setForeground(QBrush(QColor("green"))); + output->addItem(item); + output->scrollToItem(item); + + emit workspaceUpdated(selectedRevisionId); + // give the user some time to read the successful message + QTimer::singleShot(2500, this, SLOT(close())); + return; + } + processError(tr("monotone exited with code %1").arg(exitCode)); +} + void UpdateWorkspace::slotSelectRevision() { emit selectRevisionFromSelector(QString()); @@ -196,3 +296,13 @@ void UpdateWorkspace::selectSelectorOpti updateToRevision->setChecked(true); } +void UpdateWorkspace::closeEvent(QCloseEvent * event) +{ + if (mtnProcess->state() == QProcess::Running) + { + event->ignore(); + return; + } + event->accept(); +} + ============================================================ --- src/view/dialogs/UpdateWorkspace.h d51f6698c1e9b13c89b660fff1dd0944e5095365 +++ src/view/dialogs/UpdateWorkspace.h 9be3dd2b3cab3b6769fadf35865e81bd065f4f53 @@ -24,6 +24,7 @@ #include "Select.h" #include "Branches.h" #include "Tags.h" +#include "MonotoneProcess.h" #include @@ -33,20 +34,27 @@ public: public: UpdateWorkspace(QWidget *, const WorkspacePath &); ~UpdateWorkspace(); - inline QString getSelectedRevision() const { return selectedRevisionId; } + void init(); + public slots: void setSelectedRevision(const QString &); signals: + void beforeWorkspaceUpdate(); + void workspaceUpdated(const QString &); void selectRevisionFromSelector(const QString &); +protected: + virtual void closeEvent(QCloseEvent *); + private: - Branches * branchesModel; - Tags * tagsModel; - QCompleter * selectorCompleter; - QString selectedRevisionId; - WorkspacePath workspacePath; + Branches * branchesModel; + Tags * tagsModel; + QCompleter * selectorCompleter; + MonotoneProcess * mtnProcess; + WorkspacePath workspacePath; + QString selectedRevisionId; private slots: void slotSelectRevision(); @@ -54,6 +62,9 @@ private slots: void selectBranchOption(); void selectTagOption(); void selectSelectorOption(); + void processOutput(const QString &); + void processError(const QString &); + void processFinished(int, QProcess::ExitStatus); }; #endif ============================================================ --- src/view/dialogs/WorkspaceDialogManager.cpp ed9e9897de007f9b6e34d1dbae8e15562ff0b441 +++ src/view/dialogs/WorkspaceDialogManager.cpp 8d4a25eb22d5cb20bf3f3856388360b71c7cf339 @@ -138,6 +138,16 @@ void WorkspaceDialogManager::showUpdateW this, SLOT(showSelectRevision(const QString &)) ); + connect( + updateWorkspace, SIGNAL(beforeWorkspaceUpdate()), + this, SIGNAL(beforeWorkspaceUpdate()) + ); + + connect( + updateWorkspace, SIGNAL(workspaceUpdated(const QString &)), + this, SIGNAL(workspaceUpdated(const QString &)) + ); + if (selectRevision) { connect( @@ -147,6 +157,7 @@ void WorkspaceDialogManager::showUpdateW } } + updateWorkspace->init(); showDialog(updateWorkspace); } ============================================================ --- src/view/dialogs/WorkspaceDialogManager.h b990af551a2bf1a0276f1fb386cd99c9c536ba48 +++ src/view/dialogs/WorkspaceDialogManager.h 0b4324f9c0a09e5a8cba428bf4a59859b7066f74 @@ -40,6 +40,8 @@ signals: //! delegated signals signals: void revisionCommitted(const QString &); + void beforeWorkspaceUpdate(); + void workspaceUpdated(const QString &); public slots: void showCommitRevision(); ============================================================ --- src/view/mainwindows/WorkspaceWindow.cpp f9c8af974e5585beff33b6f55b69e2fd9bd1f10e +++ src/view/mainwindows/WorkspaceWindow.cpp 42cf7d056cc700fb255b8ff7575a343886857e35 @@ -242,6 +242,11 @@ void WorkspaceWindow::setup() ); connect( + dialogManager, SIGNAL(beforeWorkspaceUpdate()), + invWatcher, SLOT(clearAllWatches()) + ); + + connect( invModel, SIGNAL(invalidWorkspaceFormat()), this, SLOT(invalidWorkspaceFormat()) ); @@ -311,6 +316,11 @@ void WorkspaceWindow::setup() nodeInfo, SIGNAL(showSelectRevision(const QString &)), dialogManager, SLOT(showSelectRevision(const QString &)) ); + + connect( + dialogManager, SIGNAL(workspaceUpdated(const QString &)), + this, SLOT(workspaceUpdated(const QString &)) + ); } void WorkspaceWindow::load(const QString & path) @@ -392,3 +402,8 @@ void WorkspaceWindow::invalidWorkspaceFo close(); } +void WorkspaceWindow::workspaceUpdated(const QString & rev) +{ + invModel->refresh(); +} + ============================================================ --- src/view/mainwindows/WorkspaceWindow.h f20d3515c093e43af587667d01ff49a8a3154c2f +++ src/view/mainwindows/WorkspaceWindow.h b611ad3e5d0a89657582a0bc2c718d93c7e528ab @@ -70,6 +70,7 @@ private slots: private slots: void maybeReadNodeInfo(const QModelIndexList &); + void workspaceUpdated(const QString &); void invalidWorkspaceFormat(); void openFile(const QString &); };