comparison mainwindow.cpp @ 248:011312e59e44

Startup fixes: * Check that Hg works before open-or-stat, and only open-or-stat if tests successful * Make multichoicedialog for open always reopen with the same choice as last time (vital when an open action is aborted and user has to enter details again) * Offer to create full path to target dir for clone if parent doesn't exist
author Chris Cannam
date Tue, 11 Jan 2011 13:56:48 +0000
parents 8fd71f570884
children 123e06d5d9af
comparison
equal deleted inserted replaced
247:45e6b35afc70 248:011312e59e44
121 ColourSet *cs = ColourSet::instance(); 121 ColourSet *cs = ColourSet::instance();
122 cs->clearDefaultNames(); 122 cs->clearDefaultNames();
123 cs->addDefaultName(""); 123 cs->addDefaultName("");
124 cs->addDefaultName("default"); 124 cs->addDefaultName("default");
125 cs->addDefaultName(getUserInfo()); 125 cs->addDefaultName(getUserInfo());
126
127 if (workFolderPath == "") {
128 open();
129 }
130 126
131 hgTest(); 127 hgTest();
132 } 128 }
133 129
134 130
971 d->addChoice("init", 967 d->addChoice("init",
972 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"), 968 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
973 tr("Open a local folder, by creating a Mercurial repository in it."), 969 tr("Open a local folder, by creating a Mercurial repository in it."),
974 MultiChoiceDialog::DirectoryArg); 970 MultiChoiceDialog::DirectoryArg);
975 971
976 d->setCurrentChoice("local"); 972 QSettings settings;
973 settings.beginGroup("General");
974 QString lastChoice = settings.value("lastopentype", "local").toString();
975 if (lastChoice != "local" &&
976 lastChoice != "remote" &&
977 lastChoice != "init") {
978 lastChoice = "local";
979 }
980
981 d->setCurrentChoice(lastChoice);
977 982
978 if (d->exec() == QDialog::Accepted) { 983 if (d->exec() == QDialog::Accepted) {
979 984
980 QString choice = d->getCurrentChoice(); 985 QString choice = d->getCurrentChoice();
986 settings.setValue("lastopentype", choice);
987
981 QString arg = d->getArgument().trimmed(); 988 QString arg = d->getArgument().trimmed();
982 989
983 bool result = false; 990 bool result = false;
984 991
985 if (choice == "local") { 992 if (choice == "local") {
1065 bool MainWindow::complainAboutFilePath(QString arg) 1072 bool MainWindow::complainAboutFilePath(QString arg)
1066 { 1073 {
1067 QMessageBox::critical 1074 QMessageBox::critical
1068 (this, tr("File chosen"), 1075 (this, tr("File chosen"),
1069 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))); 1076 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)));
1077 return false;
1078 }
1079
1080 bool MainWindow::askAboutUnknownFolder(QString arg)
1081 {
1082 bool result = (QMessageBox::question
1083 (this, tr("Path does not exist"),
1084 tr("<qt><b>Path does not exist: create it?</b><br><br>You asked to open a remote repository by cloning it to \"%1\". This folder does not exist, and neither does its parent.<br><br>Would you like to create the parent folder as well?</qt>").arg(xmlEncode(arg)),
1085 QMessageBox::Ok | QMessageBox::Cancel,
1086 QMessageBox::Cancel)
1087 == QMessageBox::Ok);
1088 if (result) {
1089 QDir dir(arg);
1090 dir.cdUp();
1091 if (!dir.mkpath(dir.absolutePath())) {
1092 QMessageBox::critical
1093 (this, tr("Failed to create folder"),
1094 tr("<qt><b>Failed to create folder</b><br><br>Sorry, the path for the parent folder \"%1\" could not be created.</qt>").arg(dir.absolutePath()));
1095 return false;
1096 }
1097 return true;
1098 }
1070 return false; 1099 return false;
1071 } 1100 }
1072 1101
1073 bool MainWindow::complainAboutUnknownFolder(QString arg) 1102 bool MainWindow::complainAboutUnknownFolder(QString arg)
1074 { 1103 {
1263 if (status == FolderIsFile) { 1292 if (status == FolderIsFile) {
1264 return complainAboutCloneToFile(local); 1293 return complainAboutCloneToFile(local);
1265 } 1294 }
1266 1295
1267 if (status == FolderUnknown) { 1296 if (status == FolderUnknown) {
1268 return complainAboutUnknownFolder(local); 1297 if (!askAboutUnknownFolder(local)) {
1298 return false;
1299 }
1269 } 1300 }
1270 1301
1271 if (status == FolderExists) { 1302 if (status == FolderExists) {
1272 local = complainAboutCloneToExistingFolder(local, remote); 1303 local = complainAboutCloneToExistingFolder(local, remote);
1273 if (local == "") return false; 1304 if (local == "") return false;
1898 bool noMore = false; 1929 bool noMore = false;
1899 1930
1900 switch (action) { 1931 switch (action) {
1901 1932
1902 case ACT_TEST_HG: 1933 case ACT_TEST_HG:
1903 hgTestExtension(); 1934 {
1904 break; 1935 QSettings settings;
1936 settings.beginGroup("General");
1937 if (settings.value("useextension", true).toBool()) {
1938 hgTestExtension();
1939 } else if (workFolderPath == "") {
1940 open();
1941 } else {
1942 hgQueryPaths();
1943 }
1944 break;
1945 }
1905 1946
1906 case ACT_TEST_HG_EXT: 1947 case ACT_TEST_HG_EXT:
1907 hgQueryPaths(); 1948 if (workFolderPath == "") {
1949 open();
1950 } else{
1951 hgQueryPaths();
1952 }
1908 break; 1953 break;
1909 1954
1910 case ACT_QUERY_PATHS: 1955 case ACT_QUERY_PATHS:
1911 hgQueryBranch(); 1956 hgQueryBranch();
1912 break; 1957 break;
2051 if (workFolderPath.isEmpty()) { 2096 if (workFolderPath.isEmpty()) {
2052 localRepoActionsEnabled = false; 2097 localRepoActionsEnabled = false;
2053 workFolderExist = false; 2098 workFolderExist = false;
2054 } 2099 }
2055 2100
2056 if (!workFolderDir.exists(workFolderPath)) { 2101 if (workFolderPath == "" || !workFolderDir.exists(workFolderPath)) {
2057 localRepoActionsEnabled = false; 2102 localRepoActionsEnabled = false;
2058 workFolderExist = false; 2103 workFolderExist = false;
2059 } else { 2104 } else {
2060 workFolderExist = true; 2105 workFolderExist = true;
2061 } 2106 }
2173 } else { 2218 } else {
2174 branchText = tr("branch \"%1\"").arg(currentBranch); 2219 branchText = tr("branch \"%1\"").arg(currentBranch);
2175 } 2220 }
2176 2221
2177 if (stateUnknown) { 2222 if (stateUnknown) {
2178 hgTabs->setState(tr("(Examining repository)")); 2223 if (workFolderPath == "") {
2224 hgTabs->setState(tr("No repository open"));
2225 } else {
2226 hgTabs->setState(tr("(Examining repository)"));
2227 }
2179 } else if (emptyRepo) { 2228 } else if (emptyRepo) {
2180 hgTabs->setState(tr("Nothing committed to this repository yet")); 2229 hgTabs->setState(tr("Nothing committed to this repository yet"));
2181 } else if (noWorkingCopy) { 2230 } else if (noWorkingCopy) {
2182 hgTabs->setState(tr("No working copy yet: consider updating")); 2231 hgTabs->setState(tr("No working copy yet: consider updating"));
2183 } else if (canMerge) { 2232 } else if (canMerge) {