comparison mainwindow.cpp @ 86:89f793fbedda

* More on "Open" logic; fix to StatParser, and start introducing it
author Chris Cannam
date Mon, 22 Nov 2010 20:17:14 +0000
parents 8a4e26dc3182
children b43355c2473a
comparison
equal deleted inserted replaced
85:7ed57064f293 86:89f793fbedda
709 } 709 }
710 710
711 711
712 void MainWindow::open() 712 void MainWindow::open()
713 { 713 {
714 MultiChoiceDialog *d = new MultiChoiceDialog 714 bool done = false;
715 (tr("Open Repository"), 715
716 tr("<qt><big>What would you like to open?</big></qt>"), 716 while (!done) {
717 this); 717
718 718 MultiChoiceDialog *d = new MultiChoiceDialog
719 d->addChoice("remote", 719 (tr("Open Repository"),
720 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"), 720 tr("<qt><big>What would you like to open?</big></qt>"),
721 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."), 721 this);
722 MultiChoiceDialog::UrlToDirectoryArg); 722
723 723 d->addChoice("remote",
724 d->addChoice("local", 724 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
725 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"), 725 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
726 tr("Open an existing local Mercurial repository."), 726 MultiChoiceDialog::UrlToDirectoryArg);
727 MultiChoiceDialog::DirectoryArg); 727
728 728 d->addChoice("local",
729 d->addChoice("init", 729 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
730 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"), 730 tr("Open an existing local Mercurial repository."),
731 tr("Open a local folder, by creating a Mercurial repository in it."), 731 MultiChoiceDialog::DirectoryArg);
732 MultiChoiceDialog::DirectoryArg); 732
733 733 d->addChoice("init",
734 d->setCurrentChoice("local"); 734 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
735 735 tr("Open a local folder, by creating a Mercurial repository in it."),
736 if (d->exec() == QDialog::Accepted) { 736 MultiChoiceDialog::DirectoryArg);
737 737
738 QString choice = d->getCurrentChoice(); 738 d->setCurrentChoice("local");
739 QString arg = d->getArgument().trimmed(); 739
740 740 if (d->exec() == QDialog::Accepted) {
741 bool result = false; 741
742 742 QString choice = d->getCurrentChoice();
743 if (choice == "local") { 743 QString arg = d->getArgument().trimmed();
744 result = openLocal(arg); 744
745 } else if (choice == "remote") { 745 bool result = false;
746 result = openRemote(arg, d->getAdditionalArgument().trimmed()); 746
747 } else if (choice == "init") { 747 if (choice == "local") {
748 result = openInit(arg); 748 result = openLocal(arg);
749 } 749 } else if (choice == "remote") {
750 750 result = openRemote(arg, d->getAdditionalArgument().trimmed());
751 if (result) { 751 } else if (choice == "init") {
752 hgExp->clearLists(); 752 result = openInit(arg);
753 enableDisableActions(); 753 }
754 hgPaths(); 754
755 } 755 if (result) {
756 } 756 hgExp->clearLists();
757 757 enableDisableActions();
758 delete d; 758 hgPaths();
759 done = true; }
760
761 } else {
762
763 // cancelled
764 done = true;
765 }
766
767 delete d;
768 }
759 } 769 }
760 770
761 bool MainWindow::complainAboutFilePath(QString arg) 771 bool MainWindow::complainAboutFilePath(QString arg)
762 { 772 {
763 QMessageBox::critical 773 QMessageBox::critical
816 826
817 bool MainWindow::askToOpenParentRepo(QString arg, QString parent) 827 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
818 { 828 {
819 return (QMessageBox::question 829 return (QMessageBox::question
820 (this, tr("Path is inside a repository"), 830 (this, tr("Path is inside a repository"),
821 tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>There is no repository here &mdash; but it is inside a repository, whose root folder is at \"%2\". <br><br>Would you like to open that repository instead?</qt>") 831 tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>This is not the root folder of a repository.<br>But it is inside a repository, whose root is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
822 .arg(xmlEncode(arg)).arg(xmlEncode(parent)), 832 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
823 QMessageBox::Ok | QMessageBox::Cancel, 833 QMessageBox::Ok | QMessageBox::Cancel,
824 QMessageBox::Ok) 834 QMessageBox::Ok)
825 == QMessageBox::Ok); 835 == QMessageBox::Ok);
826 } 836 }
874 case FolderExists: 884 case FolderExists:
875 if (containing != "") { 885 if (containing != "") {
876 if (!askToOpenParentRepo(local, containing)) return false; 886 if (!askToOpenParentRepo(local, containing)) return false;
877 local = containing; 887 local = containing;
878 } else { 888 } else {
889 //!!! No -- this is likely to happen far more by accident
890 // than because the user actually wanted to init something.
891 // Don't ask, just politely reject.
879 if (!askToInitExisting(local)) return false; 892 if (!askToInitExisting(local)) return false;
880 return openInit(local); 893 return openInit(local);
881 } 894 }
882 break; 895 break;
883 896