changeset 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 45e6b35afc70
children 123e06d5d9af
files mainwindow.cpp mainwindow.h
diffstat 2 files changed, 60 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mainwindow.cpp	Tue Jan 11 13:52:54 2011 +0000
+++ b/mainwindow.cpp	Tue Jan 11 13:56:48 2011 +0000
@@ -124,10 +124,6 @@
     cs->addDefaultName("default");
     cs->addDefaultName(getUserInfo());
 
-    if (workFolderPath == "") {
-        open();
-    }
-
     hgTest();
 }
 
@@ -973,11 +969,22 @@
                      tr("Open a local folder, by creating a Mercurial repository in it."),
                      MultiChoiceDialog::DirectoryArg);
 
-        d->setCurrentChoice("local");
+        QSettings settings;
+        settings.beginGroup("General");
+        QString lastChoice = settings.value("lastopentype", "local").toString();
+        if (lastChoice != "local" &&
+            lastChoice != "remote" &&
+            lastChoice != "init") {
+            lastChoice = "local";
+        }
+
+        d->setCurrentChoice(lastChoice);
 
         if (d->exec() == QDialog::Accepted) {
 
             QString choice = d->getCurrentChoice();
+            settings.setValue("lastopentype", choice);
+
             QString arg = d->getArgument().trimmed();
 
             bool result = false;
@@ -1070,6 +1077,28 @@
     return false;
 }
 
+bool MainWindow::askAboutUnknownFolder(QString arg)
+{    
+    bool result = (QMessageBox::question
+                   (this, tr("Path does not exist"),
+                    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)),
+                    QMessageBox::Ok | QMessageBox::Cancel,
+                    QMessageBox::Cancel)
+                   == QMessageBox::Ok);
+    if (result) {
+        QDir dir(arg);
+        dir.cdUp();
+        if (!dir.mkpath(dir.absolutePath())) {
+            QMessageBox::critical
+                (this, tr("Failed to create folder"),
+                 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()));
+            return false;
+        }
+        return true;
+    }
+    return false;
+}
+
 bool MainWindow::complainAboutUnknownFolder(QString arg)
 {    
     QMessageBox::critical
@@ -1265,7 +1294,9 @@
     }
 
     if (status == FolderUnknown) {
-        return complainAboutUnknownFolder(local);
+        if (!askAboutUnknownFolder(local)) {
+            return false;
+        }
     }
 
     if (status == FolderExists) {
@@ -1900,11 +1931,25 @@
     switch (action) {
 
     case ACT_TEST_HG:
-        hgTestExtension();
+    {
+        QSettings settings;
+        settings.beginGroup("General");
+        if (settings.value("useextension", true).toBool()) {
+            hgTestExtension();
+        } else if (workFolderPath == "") {
+            open();
+        } else {
+            hgQueryPaths();
+        }
         break;
+    }
         
     case ACT_TEST_HG_EXT:
-        hgQueryPaths();
+        if (workFolderPath == "") {
+            open();
+        } else{
+            hgQueryPaths();
+        }
         break;
         
     case ACT_QUERY_PATHS:
@@ -2053,7 +2098,7 @@
         workFolderExist = false;
     }
 
-    if (!workFolderDir.exists(workFolderPath)) {
+    if (workFolderPath == "" || !workFolderDir.exists(workFolderPath)) {
         localRepoActionsEnabled = false;
         workFolderExist = false;
     } else {
@@ -2175,7 +2220,11 @@
     }
 
     if (stateUnknown) {
-        hgTabs->setState(tr("(Examining repository)"));
+        if (workFolderPath == "") {
+            hgTabs->setState(tr("No repository open"));
+        } else {
+            hgTabs->setState(tr("(Examining repository)"));
+        }
     } else if (emptyRepo) {
         hgTabs->setState(tr("Nothing committed to this repository yet"));
     } else if (noWorkingCopy) {
--- a/mainwindow.h	Tue Jan 11 13:52:54 2011 +0000
+++ b/mainwindow.h	Tue Jan 11 13:56:48 2011 +0000
@@ -144,6 +144,7 @@
     bool complainAboutCloneToFile(QString);
     QString complainAboutCloneToExistingFolder(QString local, QString remote); // returns new location, or empty string for cancel
 
+    bool askAboutUnknownFolder(QString);
     bool askToInitExisting(QString);
     bool askToInitNew(QString);
     bool askToOpenParentRepo(QString, QString);