# HG changeset patch # User Chris Cannam # Date 1290457034 0 # Node ID 89f793fbedda1ec8c4f95f7a62c5d452592afad1 # Parent 7ed57064f29397258a476315fdb20c9d0babf135 * More on "Open" logic; fix to StatParser, and start introducing it diff -r 7ed57064f293 -r 89f793fbedda hgexpwidget.cpp --- 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")); } diff -r 7ed57064f293 -r 89f793fbedda hgexpwidget.h --- 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 #include @@ -28,6 +29,7 @@ #include #include + #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); diff -r 7ed57064f293 -r 89f793fbedda mainwindow.cpp --- 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("What would you like to open?"), - this); + bool done = false; - d->addChoice("remote", - tr("

Remote repository
"), - tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."), - MultiChoiceDialog::UrlToDirectoryArg); + while (!done) { - d->addChoice("local", - tr("

Local repository
"), - tr("Open an existing local Mercurial repository."), - MultiChoiceDialog::DirectoryArg); + MultiChoiceDialog *d = new MultiChoiceDialog + (tr("Open Repository"), + tr("What would you like to open?"), + this); - d->addChoice("init", - tr("

File folder
"), - tr("Open a local folder, by creating a Mercurial repository in it."), - MultiChoiceDialog::DirectoryArg); - - d->setCurrentChoice("local"); + d->addChoice("remote", + tr("

Remote repository
"), + 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("

Local repository
"), + tr("Open an existing local Mercurial repository."), + MultiChoiceDialog::DirectoryArg); - QString choice = d->getCurrentChoice(); - QString arg = d->getArgument().trimmed(); + d->addChoice("init", + tr("

File folder
"), + 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("Open the repository that contains this path?

You asked to open \"%1\".
There is no repository here — but it is inside a repository, whose root folder is at \"%2\".

Would you like to open that repository instead?
") + tr("Open the repository that contains this path?

You asked to open \"%1\".
This is not the root folder of a repository.
But it is inside a repository, whose root is at \"%2\".

Would you like to open that repository instead?
") .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); } diff -r 7ed57064f293 -r 89f793fbedda statparser.cpp --- 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 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; } diff -r 7ed57064f293 -r 89f793fbedda statparser.h --- 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 #include -class StatParser : public QObject +class StatParser { - Q_OBJECT public: + StatParser() { } StatParser(QString text); QStringList modified;