comparison mainwindow.cpp @ 162:910c2c5d1873

* Better handling of empty repositories; some tidying & textual fixes
author Chris Cannam
date Fri, 03 Dec 2010 14:43:32 +0000
parents e411bb42d934
children 5c262ac73948
comparison
equal deleted inserted replaced
161:5b2046f67a56 162:910c2c5d1873
289 289
290 if (!files.empty()) { 290 if (!files.empty()) {
291 params << "remove" << "--after" << "--force" << "--" << files; 291 params << "remove" << "--after" << "--force" << "--" << files;
292 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params)); 292 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params));
293 } 293 }
294
295 /*!!!
296 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
297
298 if (!currentFile.isEmpty())
299 {
300 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?",
301 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel))
302 {
303 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
304
305 runner -> startHgCommand(workFolderPath, params);
306 runningAction = ACT_REMOVE;
307 }
308 }
309 */
310 } 294 }
311 295
312 void MainWindow::hgCommit() 296 void MainWindow::hgCommit()
313 { 297 {
314 QStringList params; 298 QStringList params;
437 diff = ""; 421 diff = "";
438 } 422 }
439 } 423 }
440 diffBinaryName = diff; 424 diffBinaryName = diff;
441 } 425 }
442
443 void MainWindow::hgFileDiff()
444 {
445 QStringList params;
446 /*!!!
447 QString currentFile = hgTabs -> getCurrentFileListLine();
448
449 if (!currentFile.isEmpty())
450 {
451 //Diff parent file against working folder file
452 params << "kdiff3" << "--" << currentFile.mid(2);
453 runner -> startHgCommand(workFolderPath, params);
454 runningAction = ACT_FILEDIFF;
455 }
456 */
457 }
458
459 426
460 void MainWindow::hgFolderDiff() 427 void MainWindow::hgFolderDiff()
461 { 428 {
462 if (diffBinaryName == "") return; 429 if (diffBinaryName == "") return;
463 430
1193 case ACT_INCOMING: 1160 case ACT_INCOMING:
1194 // returns non-zero code if the check was successful but there 1161 // returns non-zero code if the check was successful but there
1195 // are no changes pending 1162 // are no changes pending
1196 if (output.trimmed() == "") showIncoming(""); 1163 if (output.trimmed() == "") showIncoming("");
1197 return; 1164 return;
1165 case ACT_QUERY_HEADS:
1166 // fails if repo is empty; we don't care (if there's a genuine
1167 // problem, something else will fail too). Need to do this,
1168 // otherwise empty repo state will not be reflected properly
1169 // (since heads/log procedure never completes for empty repo)
1170 enableDisableActions();
1171 return;
1198 case ACT_FOLDERDIFF: 1172 case ACT_FOLDERDIFF:
1199 case ACT_FILEDIFF:
1200 case ACT_CHGSETDIFF: 1173 case ACT_CHGSETDIFF:
1201 // external program, unlikely to be anything useful in stderr 1174 // external program, unlikely to be anything useful in stderr
1202 // and some return with failure codes when something as basic 1175 // and some return with failure codes when something as basic
1203 // as the user closing the window via the wm happens 1176 // as the user closing the window via the wm happens
1204 return; 1177 return;
1362 case ACT_REVERT: 1335 case ACT_REVERT:
1363 hgTabs->clearSelections(); 1336 hgTabs->clearSelections();
1364 shouldHgStat = true; 1337 shouldHgStat = true;
1365 break; 1338 break;
1366 1339
1367 case ACT_FILEDIFF:
1368 case ACT_FOLDERDIFF: 1340 case ACT_FOLDERDIFF:
1369 case ACT_CHGSETDIFF: 1341 case ACT_CHGSETDIFF:
1370 case ACT_SERVE: 1342 case ACT_SERVE:
1371 case ACT_TAG: 1343 case ACT_TAG:
1372 case ACT_HG_IGNORE: 1344 case ACT_HG_IGNORE:
1373 shouldHgStat = true; 1345 shouldHgStat = true;
1374 break; 1346 break;
1375 1347
1376 case ACT_UPDATE: 1348 case ACT_UPDATE:
1377 QMessageBox::information(this, tr("Update"), output); 1349 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
1378 shouldHgStat = true; 1350 shouldHgStat = true;
1379 break; 1351 break;
1380 1352
1381 case ACT_MERGE: 1353 case ACT_MERGE:
1382 QMessageBox::information(this, tr("Merge"), output); 1354 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Merge successful</h3><p>%1</p>").arg(xmlEncode(output)));
1383 shouldHgStat = true; 1355 shouldHgStat = true;
1384 justMerged = true; 1356 justMerged = true;
1385 break; 1357 break;
1386 1358
1387 case ACT_RETRY_MERGE: 1359 case ACT_RETRY_MERGE:
1469 1441
1470 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh())); 1442 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
1471 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove())); 1443 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
1472 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd())); 1444 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
1473 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit())); 1445 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
1474 connect(hgFileDiffAct, SIGNAL(triggered()), this, SLOT(hgFileDiff()));
1475 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff())); 1446 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
1476 // connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff())); 1447 // connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff()));
1477 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate())); 1448 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
1478 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert())); 1449 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
1479 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge())); 1450 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
1582 */ 1553 */
1583 bool haveDiff = (diffBinaryName != ""); 1554 bool haveDiff = (diffBinaryName != "");
1584 1555
1585 hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true)); 1556 hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true));
1586 hgRefreshAct -> setEnabled(localRepoActionsEnabled); 1557 hgRefreshAct -> setEnabled(localRepoActionsEnabled);
1587 hgFileDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
1588 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff); 1558 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
1589 hgRevertAct -> setEnabled(localRepoActionsEnabled); 1559 hgRevertAct -> setEnabled(localRepoActionsEnabled);
1590 hgAddAct -> setEnabled(localRepoActionsEnabled); 1560 hgAddAct -> setEnabled(localRepoActionsEnabled);
1591 hgRemoveAct -> setEnabled(localRepoActionsEnabled); 1561 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
1592 hgUpdateAct -> setEnabled(localRepoActionsEnabled); 1562 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
1622 // * the parent is not one of the current heads 1592 // * the parent is not one of the current heads
1623 1593
1624 bool canMerge = false; 1594 bool canMerge = false;
1625 bool canUpdate = false; 1595 bool canUpdate = false;
1626 bool haveMerge = false; 1596 bool haveMerge = false;
1597 bool emptyRepo = false;
1627 int currentBranchHeads = 0; 1598 int currentBranchHeads = 0;
1628 1599
1629 if (currentParents.size() == 1) { 1600 if (currentParents.size() == 1) {
1630 bool parentIsHead = false; 1601 bool parentIsHead = false;
1631 Changeset *parent = currentParents[0]; 1602 Changeset *parent = currentParents[0];
1647 DEBUG << " head ids "<<endl; 1618 DEBUG << " head ids "<<endl;
1648 foreach (Changeset *h, currentHeads) { 1619 foreach (Changeset *h, currentHeads) {
1649 DEBUG << "head id = " << h->id() << endl; 1620 DEBUG << "head id = " << h->id() << endl;
1650 } 1621 }
1651 } 1622 }
1623 } else if (currentParents.size() == 0) {
1624 emptyRepo = true;
1652 } else { 1625 } else {
1653 haveMerge = true; 1626 haveMerge = true;
1654 } 1627 }
1655 1628
1656 hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge); 1629 hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge);
1665 branchText = tr("branch \"%1\"").arg(currentBranch); 1638 branchText = tr("branch \"%1\"").arg(currentBranch);
1666 } 1639 }
1667 1640
1668 //!!! Want "merge failed" report 1641 //!!! Want "merge failed" report
1669 1642
1670 if (canMerge) { 1643 if (emptyRepo) {
1644 hgTabs->setState(tr("Nothing committed to this repository yet"));
1645 } else if (canMerge) {
1671 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText)); 1646 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
1672 } else if (haveMerge) { 1647 } else if (haveMerge) {
1673 hgTabs->setState(tr("Have merged but not yet committed on %1").arg(branchText)); 1648 hgTabs->setState(tr("Have merged but not yet committed on %1").arg(branchText));
1674 } else if (canUpdate) { 1649 } else if (canUpdate) {
1675 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText)); 1650 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
1714 1689
1715 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this); 1690 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
1716 hgPushAct->setStatusTip(tr("Push local changesets to remote repository")); 1691 hgPushAct->setStatusTip(tr("Push local changesets to remote repository"));
1717 1692
1718 //Workfolder actions 1693 //Workfolder actions
1719 hgFileDiffAct = new QAction(QIcon(":/images/diff.png"), tr("Diff"), this);
1720 hgFileDiffAct->setStatusTip(tr("Filediff: View differences between selected working folder file and local repository file"));
1721
1722 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this); 1694 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
1723 hgFolderDiffAct->setStatusTip(tr("Folderdiff: View all differences between working folder files and local repository files")); 1695 hgFolderDiffAct->setStatusTip(tr("Folderdiff: View all differences between working folder files and local repository files"));
1724 1696
1725 hgChgSetDiffAct = new QAction(QIcon(":/images/chgsetdiff.png"), tr("View changesetdiff"), this); 1697 hgChgSetDiffAct = new QAction(QIcon(":/images/chgsetdiff.png"), tr("View changesetdiff"), this);
1726 hgChgSetDiffAct->setStatusTip(tr("Change set diff: View differences between all files of 2 repository changesets")); 1698 hgChgSetDiffAct->setStatusTip(tr("Change set diff: View differences between all files of 2 repository changesets"));
1833 repoToolBar -> setMovable(false); 1805 repoToolBar -> setMovable(false);
1834 1806
1835 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE)); 1807 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
1836 addToolBar(Qt::LeftToolBarArea, workFolderToolBar); 1808 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
1837 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE)); 1809 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
1838 // workFolderToolBar->addSeparator();
1839 // workFolderToolBar->addAction(hgFileDiffAct);
1840 workFolderToolBar->addAction(hgFolderDiffAct); 1810 workFolderToolBar->addAction(hgFolderDiffAct);
1841 workFolderToolBar->addSeparator(); 1811 workFolderToolBar->addSeparator();
1842 workFolderToolBar->addAction(hgRevertAct); 1812 workFolderToolBar->addAction(hgRevertAct);
1843 workFolderToolBar->addAction(hgUpdateAct); 1813 workFolderToolBar->addAction(hgUpdateAct);
1844 workFolderToolBar->addAction(hgCommitAct); 1814 workFolderToolBar->addAction(hgCommitAct);