diff mainwindow.cpp @ 251:0689dada1419

Merge
author Chris Cannam
date Tue, 11 Jan 2011 20:19:19 +0000
parents 0fe81e1b26ce 123e06d5d9af
children 8730dd806cca
line wrap: on
line diff
--- a/mainwindow.cpp	Tue Jan 11 20:18:37 2011 +0000
+++ b/mainwindow.cpp	Tue Jan 11 20:19:19 2011 +0000
@@ -124,10 +124,6 @@
     cs->addDefaultName("default");
     cs->addDefaultName(getUserInfo());
 
-    if (workFolderPath == "") {
-        open();
-    }
-
     hgTest();
 }
 
@@ -495,6 +491,16 @@
     
     hgIgnorePath = workFolderPath;
     hgIgnorePath += "/.hgignore";
+
+    if (!QDir(workFolderPath).exists()) return;
+    QFile f(hgIgnorePath);
+    if (!f.exists()) {
+        f.open(QFile::WriteOnly);
+        QTextStream *ts = new QTextStream(&f);
+        *ts << "syntax: glob\n";
+        delete ts;
+        f.close();
+    }
     
     params << hgIgnorePath;
     
@@ -973,11 +979,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 +1087,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 +1304,9 @@
     }
 
     if (status == FolderUnknown) {
-        return complainAboutUnknownFolder(local);
+        if (!askAboutUnknownFolder(local)) {
+            return false;
+        }
     }
 
     if (status == FolderExists) {
@@ -1902,11 +1943,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:
@@ -2055,7 +2110,7 @@
         workFolderExist = false;
     }
 
-    if (!workFolderDir.exists(workFolderPath)) {
+    if (workFolderPath == "" || !workFolderDir.exists(workFolderPath)) {
         localRepoActionsEnabled = false;
         workFolderExist = false;
     } else {
@@ -2177,7 +2232,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) {