changeset 86:89f793fbedda

* More on "Open" logic; fix to StatParser, and start introducing it
author Chris Cannam
date Mon, 22 Nov 2010 20:17:14 +0000
parents 7ed57064f293
children a7904378ac6a
files hgexpwidget.cpp hgexpwidget.h mainwindow.cpp statparser.cpp statparser.h
diffstat 5 files changed, 67 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/hgexpwidget.cpp	Mon Nov 22 17:42:06 2010 +0000
+++ b/hgexpwidget.cpp	Mon Nov 22 20:17:14 2010 +0000
@@ -228,6 +228,8 @@
 
 void HgExpWidget::updateWorkFolderFileList(QString fileList)
 {
+    statParser = StatParser(fileList);
+
     workFolderFileList-> clear();
     workFolderFileList -> addItems(fileList.split("\n"));
 }
--- a/hgexpwidget.h	Mon Nov 22 17:42:06 2010 +0000
+++ b/hgexpwidget.h	Mon Nov 22 20:17:14 2010 +0000
@@ -20,6 +20,7 @@
 
 #include "changeset.h"
 #include "common.h"
+#include "statparser.h"
 
 #include <QMenu>
 #include <QListWidget>
@@ -28,6 +29,7 @@
 #include <QCheckBox>
 #include <QLabel>
 
+
 #define NUM_STAT_FILE_TYPES 7
 
 
@@ -90,6 +92,8 @@
 
     QVBoxLayout *headsLayout;
 
+    StatParser   statParser;
+
     QString     findRev(QString itemText, QString& smallRev);
     QStringList splitChangeSets(QString chgSetsStr);
     Changesets  parseChangeSets(QString changeSetsStr);
--- a/mainwindow.cpp	Mon Nov 22 17:42:06 2010 +0000
+++ b/mainwindow.cpp	Mon Nov 22 20:17:14 2010 +0000
@@ -711,51 +711,61 @@
 
 void MainWindow::open()
 {
-    MultiChoiceDialog *d = new MultiChoiceDialog
-        (tr("Open Repository"),
-         tr("<qt><big>What would you like to open?</big></qt>"),
-         this);
+    bool done = false;
 
-    d->addChoice("remote",
-                 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
-                 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
-                 MultiChoiceDialog::UrlToDirectoryArg);
+    while (!done) {
 
-    d->addChoice("local",
-                 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
-                 tr("Open an existing local Mercurial repository."),
-                 MultiChoiceDialog::DirectoryArg);
+        MultiChoiceDialog *d = new MultiChoiceDialog
+                               (tr("Open Repository"),
+                                tr("<qt><big>What would you like to open?</big></qt>"),
+                                this);
 
-    d->addChoice("init",
-                 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
-                 tr("Open a local folder, by creating a Mercurial repository in it."),
-                 MultiChoiceDialog::DirectoryArg);
-    
-    d->setCurrentChoice("local");
+        d->addChoice("remote",
+                     tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
+                     tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
+                     MultiChoiceDialog::UrlToDirectoryArg);
 
-    if (d->exec() == QDialog::Accepted) {
+        d->addChoice("local",
+                     tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
+                     tr("Open an existing local Mercurial repository."),
+                     MultiChoiceDialog::DirectoryArg);
 
-        QString choice = d->getCurrentChoice();
-        QString arg = d->getArgument().trimmed();
+        d->addChoice("init",
+                     tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
+                     tr("Open a local folder, by creating a Mercurial repository in it."),
+                     MultiChoiceDialog::DirectoryArg);
 
-        bool result = false;
-    
-        if (choice == "local") {
-            result = openLocal(arg);
-        } else if (choice == "remote") {
-            result = openRemote(arg, d->getAdditionalArgument().trimmed());
-        } else if (choice == "init") {
-            result = openInit(arg);
+        d->setCurrentChoice("local");
+
+        if (d->exec() == QDialog::Accepted) {
+
+            QString choice = d->getCurrentChoice();
+            QString arg = d->getArgument().trimmed();
+
+            bool result = false;
+
+            if (choice == "local") {
+                result = openLocal(arg);
+            } else if (choice == "remote") {
+                result = openRemote(arg, d->getAdditionalArgument().trimmed());
+            } else if (choice == "init") {
+                result = openInit(arg);
+            }
+
+            if (result) {
+                hgExp->clearLists();
+                enableDisableActions();
+                hgPaths();
+                done = true;            }
+
+        } else {
+
+            // cancelled
+            done = true;
         }
 
-        if (result) {
-            hgExp->clearLists();
-            enableDisableActions();
-            hgPaths();
-        }
+        delete d;
     }
-
-    delete d;
 }
 
 bool MainWindow::complainAboutFilePath(QString arg)
@@ -818,7 +828,7 @@
 {
     return (QMessageBox::question
             (this, tr("Path is inside a repository"),
-             tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>There is no repository here &mdash; but it is inside a repository, whose root folder is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
+             tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>This is not the root folder of a repository.<br>But it is inside a repository, whose root is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
              .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
              QMessageBox::Ok | QMessageBox::Cancel,
              QMessageBox::Ok)
@@ -876,6 +886,9 @@
             if (!askToOpenParentRepo(local, containing)) return false;
             local = containing;
         } else {
+            //!!! No -- this is likely to happen far more by accident
+            // than because the user actually wanted to init something.
+            // Don't ask, just politely reject.
             if (!askToInitExisting(local)) return false;
             return openInit(local);
         }
--- a/statparser.cpp	Mon Nov 22 17:42:06 2010 +0000
+++ b/statparser.cpp	Mon Nov 22 20:17:14 2010 +0000
@@ -1,5 +1,7 @@
 #include "statparser.h"
 
+#include "debug.h"
+
 #include <QMap>
 
 StatParser::StatParser(QString text)
@@ -15,11 +17,17 @@
 
     QStringList lines = text.split("\n", QString::SkipEmptyParts);
     foreach (QString line, lines) {
-        if (line.length() < 3 || line[2] != ' ') continue;
+        if (line.length() < 3 || line[1] != ' ') {
+            continue;
+        }
         QChar tag = line[0];
         QString file = line.right(line.length() - 2);
         if (buckets.contains(tag)) {
             buckets[tag]->push_back(file);
         }
     }
+
+    DEBUG << "StatParser: " << modified.size() << " modified, " << added.size()
+            << " added, " << removed.size() << " removed, " << missing.size()
+            << " missing, " << unknown.size() << " unknown" << endl;
 }
--- a/statparser.h	Mon Nov 22 17:42:06 2010 +0000
+++ b/statparser.h	Mon Nov 22 20:17:14 2010 +0000
@@ -18,13 +18,12 @@
 #ifndef STATPARSER_H
 #define STATPARSER_H
 
-#include <QObject>
 #include <QStringList>
 
-class StatParser : public QObject
+class StatParser
 {
-    Q_OBJECT
 public:
+    StatParser() { }
     StatParser(QString text);
 
     QStringList modified;