Mercurial > hg > easyhg
comparison mainwindow.cpp @ 179:a51980a00dac
* Tidier lookup for diff, merge, editor binaries
author | Chris Cannam |
---|---|
date | Fri, 17 Dec 2010 08:48:01 +0000 |
parents | 1a3af8617ea4 |
children | bf366e0b9050 |
comparison
equal
deleted
inserted
replaced
178:1a3af8617ea4 | 179:a51980a00dac |
---|---|
85 | 85 |
86 if (firstStart) { | 86 if (firstStart) { |
87 startupDialog(); | 87 startupDialog(); |
88 } | 88 } |
89 | 89 |
90 findDiffBinaryName(); | 90 (void)findDiffBinaryName(); |
91 findMergeBinaryName(); | 91 (void)findMergeBinaryName(); |
92 (void)findEditorBinaryName(); | |
92 | 93 |
93 ColourSet *cs = ColourSet::instance(); | 94 ColourSet *cs = ColourSet::instance(); |
94 cs->clearDefaultNames(); | 95 cs->clearDefaultNames(); |
95 cs->addDefaultName(""); | 96 cs->addDefaultName(""); |
96 cs->addDefaultName("default"); | 97 cs->addDefaultName("default"); |
379 | 380 |
380 hgIgnorePath = workFolderPath; | 381 hgIgnorePath = workFolderPath; |
381 hgIgnorePath += "/.hgignore"; | 382 hgIgnorePath += "/.hgignore"; |
382 | 383 |
383 params << hgIgnorePath; | 384 params << hgIgnorePath; |
384 | 385 |
386 QString editor = findEditorBinaryName(); | |
387 | |
388 if (editor == "") { | |
389 DEBUG << "Failed to find a text editor" << endl; | |
390 //!!! visible error! | |
391 return; | |
392 } | |
393 | |
394 HgAction action(ACT_HG_IGNORE, workFolderPath, params); | |
395 action.executable = editor; | |
396 | |
397 runner->requestAction(action); | |
398 } | |
399 | |
400 QString MainWindow::findDiffBinaryName() | |
401 { | |
402 QSettings settings; | |
403 settings.beginGroup("Locations"); | |
404 QString diff = settings.value("extdiffbinary", "").toString(); | |
405 if (diff == "") { | |
406 QStringList bases; | |
407 bases << "opendiff" << "kompare" << "kdiff3" << "meld"; | |
408 bool found = false; | |
409 foreach (QString base, bases) { | |
410 diff = findInPath(base, m_myDirPath, true); | |
411 if (diff != base && diff != base + ".exe") { | |
412 found = true; | |
413 break; | |
414 } | |
415 } | |
416 if (found) { | |
417 settings.setValue("extdiffbinary", diff); | |
418 } else { | |
419 diff = ""; | |
420 } | |
421 } | |
422 return diff; | |
423 } | |
424 | |
425 QString MainWindow::findMergeBinaryName() | |
426 { | |
427 QSettings settings; | |
428 settings.beginGroup("Locations"); | |
429 QString merge = settings.value("mergebinary", "").toString(); | |
430 if (merge == "") { | |
431 QStringList bases; | |
432 bases << "fmdiff3" << "meld" << "diffuse" << "kdiff3"; | |
433 bool found = false; | |
434 foreach (QString base, bases) { | |
435 merge = findInPath(base, m_myDirPath, true); | |
436 if (merge != base) { | |
437 found = true; | |
438 break; | |
439 } | |
440 } | |
441 if (found) { | |
442 settings.setValue("mergebinary", merge); | |
443 } else { | |
444 merge = ""; | |
445 } | |
446 } | |
447 return merge; | |
448 } | |
449 | |
450 QString MainWindow::findEditorBinaryName() | |
451 { | |
385 QSettings settings; | 452 QSettings settings; |
386 settings.beginGroup("Locations"); | 453 settings.beginGroup("Locations"); |
387 QString editor = settings.value("editorbinary", "").toString(); | 454 QString editor = settings.value("editorbinary", "").toString(); |
388 if (editor == "") { | 455 if (editor == "") { |
389 QStringList bases; | 456 QStringList bases; |
410 settings.setValue("editorbinary", editor); | 477 settings.setValue("editorbinary", editor); |
411 } else { | 478 } else { |
412 editor = ""; | 479 editor = ""; |
413 } | 480 } |
414 } | 481 } |
415 | 482 return editor; |
416 if (editor == "") { | |
417 DEBUG << "Failed to find a text editor" << endl; | |
418 //!!! visible error! | |
419 return; | |
420 } | |
421 | |
422 HgAction action(ACT_HG_IGNORE, workFolderPath, params); | |
423 action.executable = editor; | |
424 | |
425 runner->requestAction(action); | |
426 } | |
427 | |
428 void MainWindow::findDiffBinaryName() | |
429 { | |
430 QSettings settings; | |
431 settings.beginGroup("Locations"); | |
432 QString diff = settings.value("extdiffbinary", "").toString(); | |
433 if (diff == "") { | |
434 QStringList bases; | |
435 bases << "opendiff" << "kompare" << "kdiff3" << "meld"; | |
436 bool found = false; | |
437 foreach (QString base, bases) { | |
438 diff = findInPath(base, m_myDirPath, true); | |
439 if (diff != base && diff != base + ".exe") { | |
440 found = true; | |
441 break; | |
442 } | |
443 } | |
444 if (found) { | |
445 settings.setValue("extdiffbinary", diff); | |
446 } else { | |
447 diff = ""; | |
448 } | |
449 } | |
450 diffBinaryName = diff; | |
451 } | |
452 | |
453 void MainWindow::findMergeBinaryName() | |
454 { | |
455 QSettings settings; | |
456 settings.beginGroup("Locations"); | |
457 QString merge = settings.value("mergebinary", "").toString(); | |
458 if (merge == "") { | |
459 QStringList bases; | |
460 bases << "fmdiff3" << "meld" << "diffuse" << "kdiff3"; | |
461 bool found = false; | |
462 foreach (QString base, bases) { | |
463 merge = findInPath(base, m_myDirPath, true); | |
464 if (merge != base) { | |
465 found = true; | |
466 break; | |
467 } | |
468 } | |
469 if (found) { | |
470 settings.setValue("mergebinary", merge); | |
471 } else { | |
472 merge = ""; | |
473 } | |
474 } | |
475 mergeBinaryName = merge; | |
476 } | 483 } |
477 | 484 |
478 void MainWindow::hgShowSummary() | 485 void MainWindow::hgShowSummary() |
479 { | 486 { |
480 QStringList params; | 487 QStringList params; |
484 runner->requestAction(HgAction(ACT_DIFF_SUMMARY, workFolderPath, params)); | 491 runner->requestAction(HgAction(ACT_DIFF_SUMMARY, workFolderPath, params)); |
485 } | 492 } |
486 | 493 |
487 void MainWindow::hgFolderDiff() | 494 void MainWindow::hgFolderDiff() |
488 { | 495 { |
489 if (diffBinaryName == "") return; | 496 QString diff = findDiffBinaryName(); |
497 if (diff == "") return; | |
490 | 498 |
491 QStringList params; | 499 QStringList params; |
492 | 500 |
493 // Diff parent against working folder (folder diff) | 501 // Diff parent against working folder (folder diff) |
494 | 502 |
495 params << "--config" << "extensions.extdiff=" << "extdiff"; | 503 params << "--config" << "extensions.extdiff=" << "extdiff"; |
496 params << "--program" << diffBinaryName; | 504 params << "--program" << diff; |
497 | 505 |
498 params << hgTabs->getSelectedCommittableFiles(); // may be none: whole dir | 506 params << hgTabs->getSelectedCommittableFiles(); // may be none: whole dir |
499 | 507 |
500 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params)); | 508 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params)); |
501 } | 509 } |
502 | 510 |
503 | 511 |
504 void MainWindow::hgDiffToCurrent(QString id) | 512 void MainWindow::hgDiffToCurrent(QString id) |
505 { | 513 { |
506 if (diffBinaryName == "") return; | 514 QString diff = findDiffBinaryName(); |
515 if (diff == "") return; | |
507 | 516 |
508 QStringList params; | 517 QStringList params; |
509 | 518 |
510 // Diff given revision against working folder | 519 // Diff given revision against working folder |
511 | 520 |
512 params << "--config" << "extensions.extdiff=" << "extdiff"; | 521 params << "--config" << "extensions.extdiff=" << "extdiff"; |
513 params << "--program" << diffBinaryName; | 522 params << "--program" << diff; |
514 params << "--rev" << Changeset::hashOf(id); | 523 params << "--rev" << Changeset::hashOf(id); |
515 | 524 |
516 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params)); | 525 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params)); |
517 } | 526 } |
518 | 527 |
519 | 528 |
520 void MainWindow::hgDiffToParent(QString child, QString parent) | 529 void MainWindow::hgDiffToParent(QString child, QString parent) |
521 { | 530 { |
522 if (diffBinaryName == "") return; | 531 QString diff = findDiffBinaryName(); |
532 if (diff == "") return; | |
523 | 533 |
524 QStringList params; | 534 QStringList params; |
525 | 535 |
526 // Diff given revision against working folder | 536 // Diff given revision against working folder |
527 | 537 |
528 params << "--config" << "extensions.extdiff=" << "extdiff"; | 538 params << "--config" << "extensions.extdiff=" << "extdiff"; |
529 params << "--program" << diffBinaryName; | 539 params << "--program" << diff; |
530 params << "--rev" << Changeset::hashOf(parent) | 540 params << "--rev" << Changeset::hashOf(parent) |
531 << "--rev" << Changeset::hashOf(child); | 541 << "--rev" << Changeset::hashOf(child); |
532 | 542 |
533 runner->requestAction(HgAction(ACT_CHGSETDIFF, workFolderPath, params)); | 543 runner->requestAction(HgAction(ACT_CHGSETDIFF, workFolderPath, params)); |
534 } | 544 } |
620 { | 630 { |
621 QStringList params; | 631 QStringList params; |
622 | 632 |
623 params << "resolve"; | 633 params << "resolve"; |
624 | 634 |
625 if (mergeBinaryName != "") { | 635 QString merge = findMergeBinaryName(); |
626 params << "--tool" << mergeBinaryName; | 636 if (merge != "") { |
637 params << "--tool" << merge; | |
627 } | 638 } |
628 | 639 |
629 QStringList files = hgTabs->getSelectedUnresolvedFiles(); | 640 QStringList files = hgTabs->getSelectedUnresolvedFiles(); |
630 if (files.empty()) { | 641 if (files.empty()) { |
631 params << "--all"; | 642 params << "--all"; |
648 | 659 |
649 QStringList params; | 660 QStringList params; |
650 | 661 |
651 params << "merge"; | 662 params << "merge"; |
652 | 663 |
653 if (mergeBinaryName != "") { | 664 QString merge = findMergeBinaryName(); |
654 params << "--tool" << mergeBinaryName; | 665 if (merge != "") { |
666 params << "--tool" << merge; | |
655 } | 667 } |
656 | 668 |
657 if (currentParents.size() == 1) { | 669 if (currentParents.size() == 1) { |
658 mergeTargetRevision = currentParents[0]->id(); | 670 mergeTargetRevision = currentParents[0]->id(); |
659 } | 671 } |
669 QStringList params; | 681 QStringList params; |
670 | 682 |
671 params << "merge"; | 683 params << "merge"; |
672 params << "--rev" << Changeset::hashOf(id); | 684 params << "--rev" << Changeset::hashOf(id); |
673 | 685 |
674 if (mergeBinaryName != "") { | 686 QString merge = findMergeBinaryName(); |
675 params << "--tool" << mergeBinaryName; | 687 if (merge != "") { |
688 params << "--tool" << merge; | |
676 } | 689 } |
677 | 690 |
678 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params)); | 691 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params)); |
679 | 692 |
680 mergeCommitComment = ""; | 693 mergeCommitComment = ""; |
1730 | 1743 |
1731 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); | 1744 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); |
1732 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); | 1745 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); |
1733 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); | 1746 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled); |
1734 | 1747 |
1735 bool haveDiff = (diffBinaryName != ""); | 1748 bool haveDiff = false; |
1749 QSettings settings; | |
1750 settings.beginGroup("Locations"); | |
1751 if (settings.value("extdiffbinary", "").toString() != "") { | |
1752 haveDiff = true; | |
1753 } | |
1754 settings.endGroup(); | |
1736 | 1755 |
1737 hgRefreshAct -> setEnabled(localRepoActionsEnabled); | 1756 hgRefreshAct -> setEnabled(localRepoActionsEnabled); |
1738 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff); | 1757 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff); |
1739 hgRevertAct -> setEnabled(localRepoActionsEnabled); | 1758 hgRevertAct -> setEnabled(localRepoActionsEnabled); |
1740 hgAddAct -> setEnabled(localRepoActionsEnabled); | 1759 hgAddAct -> setEnabled(localRepoActionsEnabled); |