comparison mainwindow.cpp @ 79:aaeabc920ca8

* Some work toward doing the Right Thing with each possible combination of existing/nonexisting directories in Open dialog
author Chris Cannam
date Mon, 22 Nov 2010 12:30:40 +0000
parents d575a8f76a53
children 8a4e26dc3182
comparison
equal deleted inserted replaced
78:07405f3a428b 79:aaeabc920ca8
734 734
735 if (d->exec() == QDialog::Accepted) { 735 if (d->exec() == QDialog::Accepted) {
736 736
737 QString choice = d->getCurrentChoice(); 737 QString choice = d->getCurrentChoice();
738 QString arg = d->getArgument().trimmed(); 738 QString arg = d->getArgument().trimmed();
739
740 bool result = false;
739 741
740 if (choice == "local") { 742 if (choice == "local") {
741 DEBUG << "open " << arg << endl; 743 result = openLocal(arg);
742 workFolderPath = arg;
743 remoteRepoPath = "";
744 } else if (choice == "remote") { 744 } else if (choice == "remote") {
745 DEBUG << "clone " << arg << " to " << d->getAdditionalArgument().trimmed() << endl; 745 result = openRemote(arg, d->getAdditionalArgument().trimmed());
746 //!!! check that work folder does not exist, append to it if it does
747 } else if (choice == "init") { 746 } else if (choice == "init") {
748 DEBUG << "init " << arg << endl; 747 result = openInit(arg);
749 //!!! 748 }
750 } 749
750 if (result) {
751 hgExp->clearLists();
752 enableDisableActions();
753 hgPaths();
754 }
755 }
756
757 delete d;
758 }
759
760 bool MainWindow::complainAboutFilePath(QString arg)
761 {
762 QMessageBox::critical
763 (this, tr("File chosen"),
764 tr("<qt><b>File chosen<b><br>The selected path (%1) is a file, not a folder as expected</qt>").arg(xmlEncode(arg)));
765 return false;
766 }
767
768 bool MainWindow::complainAboutUnknownFolder(QString arg)
769 {
770 QMessageBox::critical
771 (this, tr("Folder does not exist"),
772 tr("<qt><b>Folder does not exist<b><br>The selected path (%1) does not exist, and nor does its parent</qt>").arg(xmlEncode(arg)));
773 return false;
774 }
775
776 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
777 {
778 return (QMessageBox::question
779 (this, tr("Open containing repository?"),
780 tr("<qt><b>Open containing repository?</b><br>The selected path (%1) is located inside an existing repository (at %2).<br>Would you like to open that repository instead?</qt>")
781 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
782 QMessageBox::Ok | QMessageBox::Cancel,
783 QMessageBox::Ok)
784 == QMessageBox::Ok);
785 }
786
787 bool MainWindow::askToInitExisting(QString arg)
788 {
789 return (QMessageBox::question
790 (this, tr("Initialise repository?"),
791 tr("<qt><b>Initialise repository?</b><br>The selected folder (%1) does not contain a Mercurial repository. Would you like to initialise a repository here?</qt>")
792 .arg(xmlEncode(arg)),
793 QMessageBox::Ok | QMessageBox::Cancel,
794 QMessageBox::Ok)
795 == QMessageBox::Ok);
796 }
797
798 bool MainWindow::askToInitNew(QString arg)
799 {
800 return (QMessageBox::question
801 (this, tr("Initialise new repository?"),
802 tr("<qt><b>Initialise new repository?</b><br>The selected folder (%1) does not exist, but its parent does. Would you like to initialise a new empty repository in the selected folder?</qt>")
803 .arg(xmlEncode(arg)),
804 QMessageBox::Ok | QMessageBox::Cancel,
805 QMessageBox::Ok)
806 == QMessageBox::Ok);
807 }
808
809 bool MainWindow::openLocal(QString local)
810 {
811 DEBUG << "open " << local << endl;
812
813 FolderStatus status = getFolderStatus(local);
814 QString containing = getContainingRepoFolder(local);
815
816 switch (status) {
817
818 case FolderHasRepo:
819 // fine
820 break;
821
822 case FolderExists:
823 if (containing != "") {
824 if (!askToOpenParentRepo(local, containing)) return false;
825 } else {
826 if (!askToInitExisting(local)) return false;
827 return openInit(local);
828 }
829 break;
830
831 case FolderParentExists:
832 if (containing != "") {
833 if (!askToOpenParentRepo(local, containing)) return false;
834 } else {
835 if (!askToInitNew(local)) return false;
836 return openInit(local);
837 }
838 break;
839
840 case FolderUnknown:
841 return complainAboutUnknownFolder(local);
751 842
752 hgExp->clearLists(); 843 case FolderIsFile:
753 enableDisableActions(); 844 return complainAboutFilePath(local);
754 hgPaths(); 845 }
755 } 846
756 847 workFolderPath = local;
757 delete d; 848 remoteRepoPath = "";
849 return true;
850 }
851
852 bool MainWindow::openRemote(QString remote, QString local)
853 {
854 DEBUG << "clone " << remote << " to " << local << endl;
855 //!!! check that work folder does not exist, append to it if it does
856 return true;
857 }
858
859 bool MainWindow::openInit(QString arg)
860 {
861 return true;
758 } 862 }
759 863
760 void MainWindow::settings() 864 void MainWindow::settings()
761 { 865 {
762 /*!!! 866 /*!!!
994 { 1098 {
995 DEBUG << "MainWindow::commandFailed" << endl; 1099 DEBUG << "MainWindow::commandFailed" << endl;
996 runningAction = ACT_NONE; 1100 runningAction = ACT_NONE;
997 runner -> hideProgBar(); 1101 runner -> hideProgBar();
998 1102
999 //!!! N.B hg incoming returns failure even if successful, if there were no changes 1103 //!!! N.B hg incoming returns 1 even if successful, if there were no changes
1000 } 1104 }
1001 1105
1002 void MainWindow::commandCompleted() 1106 void MainWindow::commandCompleted()
1003 { 1107 {
1004 bool shouldHgStat = false; 1108 bool shouldHgStat = false;