Mercurial > hg > easyhg
comparison mainwindow.cpp @ 210:c5fceb3fe5b4
* OS/X: Add script to run external diff; add space around tab widget; textual fixes
* Bail out of easyhg.py in uisetup rather than at extension load time if we can't load PyQt4 -- that way we find out about it in easyhg
* Ensure editing the default path works even if hgrc doesn't yet exist; ensure path and branch are reset (to empty and default) if their respective files are absent
author | Chris Cannam |
---|---|
date | Wed, 05 Jan 2011 14:31:07 +0000 |
parents | 583faa8dadb6 |
children | 290a95b5ceae |
comparison
equal
deleted
inserted
replaced
209:0b040abb2aa3 | 210:c5fceb3fe5b4 |
---|---|
74 workFolderPath = ""; | 74 workFolderPath = ""; |
75 | 75 |
76 readSettings(); | 76 readSettings(); |
77 | 77 |
78 justMerged = false; | 78 justMerged = false; |
79 hgTabs = new HgTabWidget((QWidget *) this, remoteRepoPath, workFolderPath); | 79 |
80 QWidget *central = new QWidget(this); | |
81 setCentralWidget(central); | |
82 | |
83 hgTabs = new HgTabWidget(central, remoteRepoPath, workFolderPath); | |
80 connectTabsSignals(); | 84 connectTabsSignals(); |
81 setCentralWidget(hgTabs); | 85 |
86 // Instead of setting the tab widget as our central widget | |
87 // directly, put it in a layout, so that we can have some space | |
88 // around it on the Mac where it looks very strange without | |
89 | |
90 QGridLayout *cl = new QGridLayout(central); | |
91 cl->addWidget(hgTabs, 0, 0); | |
92 | |
93 #ifndef Q_OS_MAC | |
94 cl->setMargin(0); | |
95 #endif | |
82 | 96 |
83 connect(hgTabs, SIGNAL(selectionChanged()), | 97 connect(hgTabs, SIGNAL(selectionChanged()), |
84 this, SLOT(enableDisableActions())); | 98 this, SLOT(enableDisableActions())); |
85 connect(hgTabs, SIGNAL(showAllChanged(bool)), | 99 connect(hgTabs, SIGNAL(showAllChanged(bool)), |
86 this, SLOT(showAllChanged(bool))); | 100 this, SLOT(showAllChanged(bool))); |
223 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params)); | 237 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params)); |
224 } | 238 } |
225 | 239 |
226 void MainWindow::hgQueryPaths() | 240 void MainWindow::hgQueryPaths() |
227 { | 241 { |
228 // Quickest is to just read the file -- but fall back on hg | 242 // Quickest is to just read the file |
229 // command if we get confused | |
230 | 243 |
231 QFileInfo hgrc(workFolderPath + "/.hg/hgrc"); | 244 QFileInfo hgrc(workFolderPath + "/.hg/hgrc"); |
232 | 245 |
246 QString path; | |
247 | |
233 if (hgrc.exists()) { | 248 if (hgrc.exists()) { |
234 | |
235 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat); | 249 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat); |
236 s.beginGroup("paths"); | 250 s.beginGroup("paths"); |
237 remoteRepoPath = s.value("default").toString(); | 251 path = s.value("default").toString(); |
238 | 252 } |
239 // We have to do this here, because commandCompleted won't be called | 253 |
240 MultiChoiceDialog::addRecentArgument("local", workFolderPath); | 254 remoteRepoPath = path; |
241 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); | 255 |
242 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath); | 256 // We have to do this here, because commandCompleted won't be called |
243 | 257 MultiChoiceDialog::addRecentArgument("local", workFolderPath); |
244 hgQueryBranch(); | 258 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); |
245 return; | 259 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath); |
246 } | 260 |
261 hgQueryBranch(); | |
262 return; | |
263 | |
264 /* The classic method! | |
247 | 265 |
248 QStringList params; | 266 QStringList params; |
249 params << "paths"; | 267 params << "paths"; |
250 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params)); | 268 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params)); |
269 */ | |
251 } | 270 } |
252 | 271 |
253 void MainWindow::hgQueryBranch() | 272 void MainWindow::hgQueryBranch() |
254 { | 273 { |
255 // Quickest is to just read the file -- but fall back on hg | 274 // Quickest is to just read the file |
256 // command if we get confused | |
257 | 275 |
258 QFile hgbr(workFolderPath + "/.hg/branch"); | 276 QFile hgbr(workFolderPath + "/.hg/branch"); |
259 | 277 |
278 QString br = "default"; | |
279 | |
260 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) { | 280 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) { |
261 | |
262 QByteArray ba = hgbr.readLine(); | 281 QByteArray ba = hgbr.readLine(); |
263 currentBranch = QString::fromUtf8(ba).trimmed(); | 282 br = QString::fromUtf8(ba).trimmed(); |
264 | 283 } |
265 // We have to do this here, because commandCompleted won't be called | 284 |
266 hgStat(); | 285 currentBranch = br; |
267 return; | 286 |
268 } | 287 // We have to do this here, because commandCompleted won't be called |
288 hgStat(); | |
289 return; | |
290 | |
291 /* The classic method! | |
269 | 292 |
270 QStringList params; | 293 QStringList params; |
271 params << "branch"; | 294 params << "branch"; |
272 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params)); | 295 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params)); |
296 */ | |
273 } | 297 } |
274 | 298 |
275 void MainWindow::hgQueryHeads() | 299 void MainWindow::hgQueryHeads() |
276 { | 300 { |
277 QStringList params; | 301 QStringList params; |
479 QSettings settings; | 503 QSettings settings; |
480 settings.beginGroup("Locations"); | 504 settings.beginGroup("Locations"); |
481 QString diff = settings.value("extdiffbinary", "").toString(); | 505 QString diff = settings.value("extdiffbinary", "").toString(); |
482 if (diff == "") { | 506 if (diff == "") { |
483 QStringList bases; | 507 QStringList bases; |
484 bases << "opendiff" << "kompare" << "kdiff3" << "meld"; | 508 bases << "easyhg-extdiff-osx.sh" << "kompare" << "kdiff3" << "meld"; |
485 bool found = false; | 509 bool found = false; |
486 foreach (QString base, bases) { | 510 foreach (QString base, bases) { |
487 diff = findInPath(base, m_myDirPath, true); | 511 diff = findInPath(base, m_myDirPath, true); |
488 if (diff != base && diff != base + ".exe") { | 512 if (diff != base && diff != base + ".exe") { |
489 found = true; | 513 found = true; |
1022 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"), | 1046 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"), |
1023 tr("Provide a new URL to use for push and pull actions from the current local repository."), | 1047 tr("Provide a new URL to use for push and pull actions from the current local repository."), |
1024 MultiChoiceDialog::UrlArg); | 1048 MultiChoiceDialog::UrlArg); |
1025 | 1049 |
1026 if (d->exec() == QDialog::Accepted) { | 1050 if (d->exec() == QDialog::Accepted) { |
1027 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat); | 1051 |
1028 s.beginGroup("paths"); | 1052 // New block to ensure QSettings is deleted before |
1029 s.setValue("default", d->getArgument()); | 1053 // hgQueryPaths called. NB use of absoluteFilePath instead of |
1054 // canonicalFilePath, which would fail if the file did not yet | |
1055 // exist | |
1056 | |
1057 { | |
1058 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat); | |
1059 s.beginGroup("paths"); | |
1060 s.setValue("default", d->getArgument()); | |
1061 } | |
1062 | |
1030 stateUnknown = true; | 1063 stateUnknown = true; |
1031 hgQueryPaths(); | 1064 hgQueryPaths(); |
1032 } | 1065 } |
1033 | 1066 |
1034 delete d; | 1067 delete d; |
1484 | 1517 |
1485 void MainWindow::commandFailed(HgAction action, QString output) | 1518 void MainWindow::commandFailed(HgAction action, QString output) |
1486 { | 1519 { |
1487 DEBUG << "MainWindow::commandFailed" << endl; | 1520 DEBUG << "MainWindow::commandFailed" << endl; |
1488 | 1521 |
1522 QString setstr; | |
1523 #ifdef Q_OS_MAC | |
1524 setstr = tr("Preferences"); | |
1525 #else | |
1526 setstr = tr("Settings"); | |
1527 #endif | |
1528 | |
1489 // Some commands we just have to ignore bad return values from: | 1529 // Some commands we just have to ignore bad return values from: |
1490 | 1530 |
1491 switch(action.action) { | 1531 switch(action.action) { |
1492 case ACT_NONE: | 1532 case ACT_NONE: |
1493 // uh huh | 1533 // uh huh |
1494 return; | 1534 return; |
1495 case ACT_TEST_HG: | 1535 case ACT_TEST_HG: |
1496 QMessageBox::warning | 1536 QMessageBox::warning |
1497 (this, tr("Failed to run Mercurial"), | 1537 (this, tr("Failed to run Mercurial"), |
1498 format3(tr("Failed to run Mercurial"), | 1538 format3(tr("Failed to run Mercurial"), |
1499 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in Settings.<br><br>%1").arg(output == "" ? QString("") : tr("The test command said:")), | 1539 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in %1.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")), |
1500 output)); | 1540 output)); |
1501 settings(); | 1541 settings(); |
1502 return; | 1542 return; |
1503 case ACT_TEST_HG_EXT: | 1543 case ACT_TEST_HG_EXT: |
1504 QMessageBox::warning | 1544 QMessageBox::warning |
1505 (this, tr("Failed to run Mercurial"), | 1545 (this, tr("Failed to run Mercurial"), |
1506 format3(tr("Failed to run Mercurial with extension enabled"), | 1546 format3(tr("Failed to run Mercurial with extension enabled"), |
1507 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem with EasyMercurial.<br><br>You may be able to continue working if you switch off “Use EasyHg Mercurial Extension” in Settings. Note that remote repositories that require authentication may not work if you do this.<br><br>%1").arg(output == "" ? QString("") : tr("The test command said:")), | 1547 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem with EasyMercurial.<br><br>You may be able to continue working if you switch off “Use EasyHg Mercurial Extension” in %1. Note that remote repositories that require authentication may not work if you do this.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")), |
1508 output)); | 1548 output)); |
1509 settings(); | 1549 settings(); |
1510 return; | 1550 return; |
1511 case ACT_INCOMING: | 1551 case ACT_INCOMING: |
1512 // returns non-zero code if the check was successful but there | 1552 // returns non-zero code if the check was successful but there |
1582 LogList ll = lp.parse(); | 1622 LogList ll = lp.parse(); |
1583 DEBUG << ll.size() << " results" << endl; | 1623 DEBUG << ll.size() << " results" << endl; |
1584 if (!ll.empty()) { | 1624 if (!ll.empty()) { |
1585 remoteRepoPath = lp.parse()[0]["default"].trimmed(); | 1625 remoteRepoPath = lp.parse()[0]["default"].trimmed(); |
1586 DEBUG << "Set remote path to " << remoteRepoPath << endl; | 1626 DEBUG << "Set remote path to " << remoteRepoPath << endl; |
1627 } else { | |
1628 remoteRepoPath = ""; | |
1587 } | 1629 } |
1588 MultiChoiceDialog::addRecentArgument("local", workFolderPath); | 1630 MultiChoiceDialog::addRecentArgument("local", workFolderPath); |
1589 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); | 1631 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); |
1590 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath); | 1632 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath); |
1591 break; | 1633 break; |