Mercurial > hg > easyhg
comparison mainwindow.cpp @ 84:8a4e26dc3182
* Make all of the "Open" options do something sensible
author | Chris Cannam |
---|---|
date | Mon, 22 Nov 2010 17:27:59 +0000 |
parents | aaeabc920ca8 |
children | 89f793fbedda |
comparison
equal
deleted
inserted
replaced
83:af7cf6f7282c | 84:8a4e26dc3182 |
---|---|
601 if (runningAction == ACT_NONE) | 601 if (runningAction == ACT_NONE) |
602 { | 602 { |
603 QStringList params; | 603 QStringList params; |
604 | 604 |
605 params << "init"; | 605 params << "init"; |
606 params << workFolderPath; | |
606 | 607 |
607 runner -> startHgCommand(workFolderPath, params); | 608 runner -> startHgCommand(workFolderPath, params); |
608 runningAction = ACT_INIT; | 609 runningAction = ACT_INIT; |
609 } | 610 } |
610 } | 611 } |
759 | 760 |
760 bool MainWindow::complainAboutFilePath(QString arg) | 761 bool MainWindow::complainAboutFilePath(QString arg) |
761 { | 762 { |
762 QMessageBox::critical | 763 QMessageBox::critical |
763 (this, tr("File chosen"), | 764 (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 tr("<qt><b>Folder required</b><br><br>You asked to open \"%1\".<br>This is a file; to open a repository, you need to choose a folder.</qt>").arg(xmlEncode(arg))); |
765 return false; | 766 return false; |
766 } | 767 } |
767 | 768 |
768 bool MainWindow::complainAboutUnknownFolder(QString arg) | 769 bool MainWindow::complainAboutUnknownFolder(QString arg) |
769 { | 770 { |
770 QMessageBox::critical | 771 QMessageBox::critical |
771 (this, tr("Folder does not exist"), | 772 (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 tr("<qt><b>Folder does not exist</b><br><br>You asked to open \"%1\".<br>This folder does not exist, and it cannot be created because its parent does not exist either.</qt>").arg(xmlEncode(arg))); |
773 return false; | 774 return false; |
774 } | 775 } |
775 | 776 |
777 bool MainWindow::complainAboutInitInRepo(QString arg) | |
778 { | |
779 QMessageBox::critical | |
780 (this, tr("Path is in existing repository"), | |
781 tr("<qt><b>Path is in an existing repository</b><br><br>You asked to initialise a repository at \"%1\".<br>This path is already inside an existing repository.</qt>").arg(xmlEncode(arg))); | |
782 return false; | |
783 } | |
784 | |
785 bool MainWindow::complainAboutInitFile(QString arg) | |
786 { | |
787 QMessageBox::critical | |
788 (this, tr("Path is a file"), | |
789 tr("<qt><b>Path is a file</b><br><br>You asked to initialise a repository at \"%1\".<br>This is an existing file; it is only possible to initialise in folders.</qt>").arg(xmlEncode(arg))); | |
790 return false; | |
791 } | |
792 | |
793 bool MainWindow::complainAboutCloneToExisting(QString arg) | |
794 { | |
795 QMessageBox::critical | |
796 (this, tr("Path is in existing repository"), | |
797 tr("<qt><b>Local path is in an existing repository</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is already inside an existing repository.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg))); | |
798 return false; | |
799 } | |
800 | |
801 bool MainWindow::complainAboutCloneToFile(QString arg) | |
802 { | |
803 QMessageBox::critical | |
804 (this, tr("Path is a file"), | |
805 tr("<qt><b>Local path is a file</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is an existing file.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg))); | |
806 return false; | |
807 } | |
808 | |
809 bool MainWindow::complainAboutCloneToExistingFolder(QString arg) | |
810 { | |
811 QMessageBox::critical | |
812 (this, tr("Folder exists"), | |
813 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This is the path of an existing folder.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg))); | |
814 return false; | |
815 } | |
816 | |
776 bool MainWindow::askToOpenParentRepo(QString arg, QString parent) | 817 bool MainWindow::askToOpenParentRepo(QString arg, QString parent) |
777 { | 818 { |
778 return (QMessageBox::question | 819 return (QMessageBox::question |
779 (this, tr("Open containing repository?"), | 820 (this, tr("Path is inside a 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>") | 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 — but it is inside a repository, whose root folder is at \"%2\". <br><br>Would you like to open that repository instead?</qt>") |
781 .arg(xmlEncode(arg)).arg(xmlEncode(parent)), | 822 .arg(xmlEncode(arg)).arg(xmlEncode(parent)), |
782 QMessageBox::Ok | QMessageBox::Cancel, | 823 QMessageBox::Ok | QMessageBox::Cancel, |
783 QMessageBox::Ok) | 824 QMessageBox::Ok) |
784 == QMessageBox::Ok); | 825 == QMessageBox::Ok); |
785 } | 826 } |
786 | 827 |
787 bool MainWindow::askToInitExisting(QString arg) | 828 bool MainWindow::askToInitExisting(QString arg) |
788 { | 829 { |
789 return (QMessageBox::question | 830 return (QMessageBox::question |
790 (this, tr("Initialise repository?"), | 831 (this, tr("Folder has no 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>") | 832 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder does not contain a Mercurial repository.<br><br>Would you like to initialise a repository here?</qt>") |
792 .arg(xmlEncode(arg)), | 833 .arg(xmlEncode(arg)), |
793 QMessageBox::Ok | QMessageBox::Cancel, | 834 QMessageBox::Ok | QMessageBox::Cancel, |
794 QMessageBox::Ok) | 835 QMessageBox::Ok) |
795 == QMessageBox::Ok); | 836 == QMessageBox::Ok); |
796 } | 837 } |
797 | 838 |
798 bool MainWindow::askToInitNew(QString arg) | 839 bool MainWindow::askToInitNew(QString arg) |
799 { | 840 { |
800 return (QMessageBox::question | 841 return (QMessageBox::question |
801 (this, tr("Initialise new repository?"), | 842 (this, tr("Folder does not exist"), |
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>") | 843 tr("<qt><b>Initialise a new repository?</b><br><br>You asked to open \"%1\".<br>This folder does not yet exist.<br><br>Would you like to create the folder and initialise a new empty repository in it?</qt>") |
803 .arg(xmlEncode(arg)), | 844 .arg(xmlEncode(arg)), |
804 QMessageBox::Ok | QMessageBox::Cancel, | 845 QMessageBox::Ok | QMessageBox::Cancel, |
805 QMessageBox::Ok) | 846 QMessageBox::Ok) |
806 == QMessageBox::Ok); | 847 == QMessageBox::Ok); |
807 } | 848 } |
808 | 849 |
850 bool MainWindow::askToOpenInsteadOfInit(QString arg) | |
851 { | |
852 return (QMessageBox::question | |
853 (this, tr("Repository exists"), | |
854 tr("<qt><b>Open existing repository?</b><br><br>You asked to initialise a new repository at \"%1\".<br>This folder already contains a repository. Would you like to open it?</qt>") | |
855 .arg(xmlEncode(arg)), | |
856 QMessageBox::Ok | QMessageBox::Cancel, | |
857 QMessageBox::Ok) | |
858 == QMessageBox::Ok); | |
859 } | |
860 | |
809 bool MainWindow::openLocal(QString local) | 861 bool MainWindow::openLocal(QString local) |
810 { | 862 { |
811 DEBUG << "open " << local << endl; | 863 DEBUG << "open " << local << endl; |
812 | 864 |
813 FolderStatus status = getFolderStatus(local); | 865 FolderStatus status = getFolderStatus(local); |
820 break; | 872 break; |
821 | 873 |
822 case FolderExists: | 874 case FolderExists: |
823 if (containing != "") { | 875 if (containing != "") { |
824 if (!askToOpenParentRepo(local, containing)) return false; | 876 if (!askToOpenParentRepo(local, containing)) return false; |
877 local = containing; | |
825 } else { | 878 } else { |
826 if (!askToInitExisting(local)) return false; | 879 if (!askToInitExisting(local)) return false; |
827 return openInit(local); | 880 return openInit(local); |
828 } | 881 } |
829 break; | 882 break; |
830 | 883 |
831 case FolderParentExists: | 884 case FolderParentExists: |
832 if (containing != "") { | 885 if (containing != "") { |
833 if (!askToOpenParentRepo(local, containing)) return false; | 886 if (!askToOpenParentRepo(local, containing)) return false; |
887 local = containing; | |
834 } else { | 888 } else { |
835 if (!askToInitNew(local)) return false; | 889 if (!askToInitNew(local)) return false; |
836 return openInit(local); | 890 return openInit(local); |
837 } | 891 } |
838 break; | 892 break; |
839 | 893 |
840 case FolderUnknown: | 894 case FolderUnknown: |
841 return complainAboutUnknownFolder(local); | 895 if (containing != "") { |
896 if (!askToOpenParentRepo(local, containing)) return false; | |
897 local = containing; | |
898 } else { | |
899 return complainAboutUnknownFolder(local); | |
900 } | |
901 break; | |
842 | 902 |
843 case FolderIsFile: | 903 case FolderIsFile: |
844 return complainAboutFilePath(local); | 904 return complainAboutFilePath(local); |
845 } | 905 } |
846 | 906 |
850 } | 910 } |
851 | 911 |
852 bool MainWindow::openRemote(QString remote, QString local) | 912 bool MainWindow::openRemote(QString remote, QString local) |
853 { | 913 { |
854 DEBUG << "clone " << remote << " to " << local << endl; | 914 DEBUG << "clone " << remote << " to " << local << endl; |
855 //!!! check that work folder does not exist, append to it if it does | 915 |
916 FolderStatus status = getFolderStatus(local); | |
917 QString containing = getContainingRepoFolder(local); | |
918 | |
919 DEBUG << "status = " << status << ", containing = " << containing << endl; | |
920 | |
921 if (status == FolderHasRepo || containing != "") { | |
922 return complainAboutCloneToExisting(local); | |
923 } | |
924 | |
925 if (status == FolderIsFile) { | |
926 return complainAboutCloneToFile(local); | |
927 } | |
928 | |
929 if (status == FolderUnknown) { | |
930 return complainAboutUnknownFolder(local); | |
931 } | |
932 | |
933 if (status == FolderExists) { | |
934 //!!! we can do better than this surely? | |
935 return complainAboutCloneToExistingFolder(local); | |
936 } | |
937 | |
938 workFolderPath = local; | |
939 remoteRepoPath = remote; | |
940 hgCloneFromRemote(); | |
941 | |
856 return true; | 942 return true; |
857 } | 943 } |
858 | 944 |
859 bool MainWindow::openInit(QString arg) | 945 bool MainWindow::openInit(QString local) |
860 { | 946 { |
947 DEBUG << "openInit " << local << endl; | |
948 | |
949 FolderStatus status = getFolderStatus(local); | |
950 QString containing = getContainingRepoFolder(local); | |
951 | |
952 DEBUG << "status = " << status << ", containing = " << containing << endl; | |
953 | |
954 if (status == FolderHasRepo) { | |
955 if (!askToOpenInsteadOfInit(local)) return false; | |
956 } | |
957 | |
958 if (containing != "") { | |
959 return complainAboutInitInRepo(local); | |
960 } | |
961 | |
962 if (status == FolderIsFile) { | |
963 return complainAboutInitFile(local); | |
964 } | |
965 | |
966 if (status == FolderUnknown) { | |
967 return complainAboutUnknownFolder(local); | |
968 } | |
969 | |
970 workFolderPath = local; | |
971 remoteRepoPath = ""; | |
972 hgInit(); | |
861 return true; | 973 return true; |
862 } | 974 } |
863 | 975 |
864 void MainWindow::settings() | 976 void MainWindow::settings() |
865 { | 977 { |
1123 //Successful running. | 1235 //Successful running. |
1124 switch(runningAction) | 1236 switch(runningAction) |
1125 { | 1237 { |
1126 case ACT_PATHS: | 1238 case ACT_PATHS: |
1127 { | 1239 { |
1128 QString sout = runner->getStdOut(); | 1240 QString sout = runner->getOutput(); |
1129 DEBUG << "stdout is " << sout << endl; | 1241 DEBUG << "stdout is " << sout << endl; |
1130 LogParser lp(sout, "="); | 1242 LogParser lp(sout, "="); |
1131 LogList ll = lp.parse(); | 1243 LogList ll = lp.parse(); |
1132 DEBUG << ll.size() << " results" << endl; | 1244 DEBUG << ll.size() << " results" << endl; |
1133 if (!ll.empty()) { | 1245 if (!ll.empty()) { |
1139 enableDisableActions(); | 1251 enableDisableActions(); |
1140 break; | 1252 break; |
1141 } | 1253 } |
1142 | 1254 |
1143 case ACT_STAT: | 1255 case ACT_STAT: |
1144 hgExp -> updateWorkFolderFileList(runner -> getStdOut()); | 1256 hgExp -> updateWorkFolderFileList(runner -> getOutput()); |
1145 break; | 1257 break; |
1146 | 1258 |
1147 case ACT_INCOMING: | 1259 case ACT_INCOMING: |
1148 case ACT_ANNOTATE: | 1260 case ACT_ANNOTATE: |
1149 case ACT_RESOLVE_LIST: | 1261 case ACT_RESOLVE_LIST: |
1150 case ACT_RESOLVE_MARK: | 1262 case ACT_RESOLVE_MARK: |
1151 presentLongStdoutToUser(runner -> getStdOut()); | 1263 presentLongStdoutToUser(runner -> getOutput()); |
1152 shouldHgStat = true; | 1264 shouldHgStat = true; |
1153 break; | 1265 break; |
1154 | 1266 |
1155 case ACT_PULL: | 1267 case ACT_PULL: |
1156 QMessageBox::information(this, "Pull", runner -> getStdOut()); | 1268 QMessageBox::information(this, "Pull", runner -> getOutput()); |
1157 shouldHgStat = true; | 1269 shouldHgStat = true; |
1158 break; | 1270 break; |
1159 | 1271 |
1160 case ACT_PUSH: | 1272 case ACT_PUSH: |
1161 QMessageBox::information(this, "Push", runner -> getStdOut()); | 1273 QMessageBox::information(this, "Push", runner -> getOutput()); |
1162 shouldHgStat = true; | 1274 shouldHgStat = true; |
1163 break; | 1275 break; |
1164 | 1276 |
1165 case ACT_INIT: | 1277 case ACT_INIT: |
1166 MultiChoiceDialog::addRecentArgument("init", workFolderPath); | 1278 MultiChoiceDialog::addRecentArgument("init", workFolderPath); |
1171 | 1283 |
1172 case ACT_CLONEFROMREMOTE: | 1284 case ACT_CLONEFROMREMOTE: |
1173 MultiChoiceDialog::addRecentArgument("local", workFolderPath); | 1285 MultiChoiceDialog::addRecentArgument("local", workFolderPath); |
1174 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); | 1286 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); |
1175 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true); | 1287 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true); |
1176 QMessageBox::information(this, "Clone", runner -> getStdOut()); | 1288 QMessageBox::information(this, "Clone", runner -> getOutput()); |
1177 enableDisableActions(); | 1289 enableDisableActions(); |
1178 shouldHgStat = true; | 1290 shouldHgStat = true; |
1179 break; | 1291 break; |
1180 | 1292 |
1181 case ACT_LOG: | 1293 case ACT_LOG: |
1182 { | 1294 { |
1183 hgExp -> updateLocalRepoHgLogList(runner -> getStdOut()); | 1295 hgExp -> updateLocalRepoHgLogList(runner -> getOutput()); |
1184 } | 1296 } |
1185 break; | 1297 break; |
1186 | 1298 |
1187 case ACT_PARENTS: | 1299 case ACT_PARENTS: |
1188 { | 1300 { |
1189 hgExp -> updateLocalRepoParentsList(runner -> getStdOut()); | 1301 hgExp -> updateLocalRepoParentsList(runner -> getOutput()); |
1190 } | 1302 } |
1191 break; | 1303 break; |
1192 | 1304 |
1193 case ACT_HEADS: | 1305 case ACT_HEADS: |
1194 { | 1306 { |
1195 QString stdOut = runner -> getStdOut(); | 1307 QString stdOut = runner -> getOutput(); |
1196 hgExp -> updateLocalRepoHeadsList(stdOut); | 1308 hgExp -> updateLocalRepoHeadsList(stdOut); |
1197 } | 1309 } |
1198 break; | 1310 break; |
1199 | 1311 |
1200 case ACT_REMOVE: | 1312 case ACT_REMOVE: |
1209 case ACT_HG_IGNORE: | 1321 case ACT_HG_IGNORE: |
1210 shouldHgStat = true; | 1322 shouldHgStat = true; |
1211 break; | 1323 break; |
1212 | 1324 |
1213 case ACT_UPDATE: | 1325 case ACT_UPDATE: |
1214 QMessageBox::information(this, tr("Update"), runner -> getStdOut()); | 1326 QMessageBox::information(this, tr("Update"), runner -> getOutput()); |
1215 shouldHgStat = true; | 1327 shouldHgStat = true; |
1216 break; | 1328 break; |
1217 | 1329 |
1218 case ACT_MERGE: | 1330 case ACT_MERGE: |
1219 QMessageBox::information(this, tr("Merge"), runner -> getStdOut()); | 1331 QMessageBox::information(this, tr("Merge"), runner -> getOutput()); |
1220 shouldHgStat = true; | 1332 shouldHgStat = true; |
1221 justMerged = true; | 1333 justMerged = true; |
1222 break; | 1334 break; |
1223 | 1335 |
1224 case ACT_RETRY_MERGE: | 1336 case ACT_RETRY_MERGE: |