# HG changeset patch # User Chris Cannam # Date 1308252905 -3600 # Node ID 69b2338c06e1cb808a678440bb7f2125659e6ecf # Parent 93cb9005bb6fd885443f1727325620d6c93f95e4 Add "Ignore this directory"; some fixes to ignore logic (though not yet enough) diff -r 93cb9005bb6f -r 69b2338c06e1 src/changeset.cpp --- a/src/changeset.cpp Thu Jun 16 16:46:35 2011 +0100 +++ b/src/changeset.cpp Thu Jun 16 20:35:05 2011 +0100 @@ -17,6 +17,7 @@ #include "changeset.h" #include "common.h" +#include "debug.h" #include @@ -53,6 +54,8 @@ description = ""; +// DEBUG << "comment is " << comment() << endl; + QString c = comment().trimmed(); c = c.replace(QRegExp("^\""), ""); c = c.replace(QRegExp("\"$"), ""); diff -r 93cb9005bb6f -r 69b2338c06e1 src/confirmcommentdialog.cpp --- a/src/confirmcommentdialog.cpp Thu Jun 16 16:46:35 2011 +0100 +++ b/src/confirmcommentdialog.cpp Thu Jun 16 20:35:05 2011 +0100 @@ -17,6 +17,7 @@ #include "confirmcommentdialog.h" #include "common.h" +#include "debug.h" #include #include @@ -67,7 +68,17 @@ QString ConfirmCommentDialog::getComment() const { - return m_textEdit->document()->toPlainText(); +/* + DEBUG << "ConfirmCommentDialog: as html is:" << endl; + DEBUG << m_textEdit->document()->toHtml() << endl; + DEBUG << "ConfirmCommentDialog: as plain text is:" << endl; + QString t = m_textEdit->document()->toPlainText(); + DEBUG << t << endl; + DEBUG << "Characters: " << endl; + for (int i = 0; i < t.length(); ++i) DEBUG << t[i].unicode(); + DEBUG << endl; + return t; +*/ } QString ConfirmCommentDialog::buildFilesText(QString intro, QStringList files) diff -r 93cb9005bb6f -r 69b2338c06e1 src/hgignoredialog.cpp --- a/src/hgignoredialog.cpp Thu Jun 16 16:46:35 2011 +0100 +++ b/src/hgignoredialog.cpp Thu Jun 16 20:35:05 2011 +0100 @@ -83,7 +83,9 @@ HgIgnoreDialog::IgnoreType HgIgnoreDialog::confirmIgnore(QWidget *parent, - QStringList files, QStringList suffixes) + QStringList files, + QStringList suffixes, + QString directory) { QString intro = "

"; intro += tr("Ignore files"); @@ -99,49 +101,54 @@ intro += "

"; - if (suffixes.size() > 0) { + QString textTheseFiles; + QString textTheseNames; + if (files.size() > 1) { + textTheseFiles = tr("Ignore these files only"); + textTheseNames = tr("Ignore files with these names, in any folder"); + } else { + textTheseFiles = tr("Ignore this file only"); + textTheseNames = tr("Ignore files with the same name as this, in any folder"); + } - QStringList options; - options << tr("Ignore these files only"); - options << tr("Ignore files with these names in any subdirectory"); + QString textThisFolder; + QString textTheseSuffixes; - if (suffixes.size() > 1) { - options << tr("Ignore all files with these extensions:\n%1") - .arg(suffixes.join(", ")); - } else { - options << tr("Ignore all files with the extension \"%1\"") - .arg(suffixes[0]); - } + QStringList options; + options << textTheseFiles; + options << textTheseNames; - HgIgnoreDialog d(parent, tr("Ignore files"), - intro, tr("

Please choose whether to:

"), - options, tr("Ignore")); + if (directory != "") { + textThisFolder = tr("Ignore the whole folder \"%1\"") + .arg(directory); + options << textThisFolder; + } - if (d.exec() == QDialog::Accepted) { - QString option = d.getOption(); - DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; - if (option == options[0]) return IgnoreGivenFilesOnly; - else if (option == options[1]) return IgnoreAllFilesOfGivenNames; - else return IgnoreAllFilesOfGivenSuffixes; - } - - } else { + if (suffixes.size() > 1) { - QStringList options; - options << tr("Ignore these files only"); - options << tr("Ignore files with these names in any subdirectory"); + textTheseSuffixes = tr("Ignore all files with these extensions:\n%1") + .arg(suffixes.join(", ")); + options << textTheseSuffixes; - HgIgnoreDialog d(parent, tr("Ignore files"), - intro, tr("

Please choose whether to:

"), - options, tr("Ignore")); + } else if (suffixes.size() > 0) { - if (d.exec() == QDialog::Accepted) { - QString option = d.getOption(); - DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; - if (option == options[0]) return IgnoreGivenFilesOnly; - else return IgnoreAllFilesOfGivenNames; - } - } + textTheseSuffixes = tr("Ignore all files with the extension \"%1\"") + .arg(suffixes[0]); + options << textTheseSuffixes; + } + + HgIgnoreDialog d(parent, tr("Ignore files"), + intro, tr("

Please choose whether to:

"), + options, tr("Ignore")); + + if (d.exec() == QDialog::Accepted) { + QString option = d.getOption(); + DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl; + if (option == textTheseFiles) return IgnoreGivenFilesOnly; + else if (option == textTheseNames) return IgnoreAllFilesOfGivenNames; + else if (option == textTheseSuffixes) return IgnoreAllFilesOfGivenSuffixes; + else if (option == textThisFolder) return IgnoreWholeDirectory; + } return IgnoreNothing; } diff -r 93cb9005bb6f -r 69b2338c06e1 src/hgignoredialog.h --- a/src/hgignoredialog.h Thu Jun 16 16:46:35 2011 +0100 +++ b/src/hgignoredialog.h Thu Jun 16 20:35:05 2011 +0100 @@ -29,11 +29,14 @@ IgnoreNothing, IgnoreGivenFilesOnly, IgnoreAllFilesOfGivenNames, - IgnoreAllFilesOfGivenSuffixes + IgnoreAllFilesOfGivenSuffixes, + IgnoreWholeDirectory }; static IgnoreType confirmIgnore(QWidget *parent, - QStringList files, QStringList suffixes); + QStringList files, + QStringList suffixes, + QString directory); private slots: void optionToggled(bool); diff -r 93cb9005bb6f -r 69b2338c06e1 src/mainwindow.cpp --- a/src/mainwindow.cpp Thu Jun 16 16:46:35 2011 +0100 +++ b/src/mainwindow.cpp Thu Jun 16 20:35:05 2011 +0100 @@ -617,9 +617,20 @@ if (s != "") suffixes.insert(s); } + QString directory; + bool dirCount = 0; + foreach (QString file, files) { + QString d = QFileInfo(file).path(); + if (d != directory) { + ++dirCount; + directory = d; + } + } + if (dirCount != 1) directory = ""; + HgIgnoreDialog::IgnoreType itype = HgIgnoreDialog::confirmIgnore - (this, files, QStringList::fromSet(suffixes)); + (this, files, QStringList::fromSet(suffixes), directory); DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl; @@ -674,17 +685,28 @@ // anywhere -- anchor the path to / to make it specific to // this file only //!!! check this! + //!!! ... no, it doesn't work. does this mean we need regex syntax? foreach (QString f, files) { out << "/" + f << endl; } - } else { + } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) { foreach (QString f, files) { - out << f << endl; + out << QFileInfo(f).fileName() << endl; } + } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) { + out << directory + "/" << endl; } + f.close(); + + //!!! report, and offer to edit .hgignore now + + // (tell the user at least what lines have been added to the + // hgignore file and how to edit it) + // (also, if the hgignore is not tracked, suggest that they add + // it) hgRefresh(); }