changeset 419:69b2338c06e1 ignore

Add "Ignore this directory"; some fixes to ignore logic (though not yet enough)
author Chris Cannam
date Thu, 16 Jun 2011 20:35:05 +0100
parents 93cb9005bb6f
children 50920723dd16
files src/changeset.cpp src/confirmcommentdialog.cpp src/hgignoredialog.cpp src/hgignoredialog.h src/mainwindow.cpp
diffstat 5 files changed, 89 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- 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 <QVariant>
 
@@ -53,6 +54,8 @@
 
     description = "<qt><table border=0>";
 
+//    DEBUG << "comment is " << comment() << endl;
+
     QString c = comment().trimmed();
     c = c.replace(QRegExp("^\""), "");
     c = c.replace(QRegExp("\"$"), "");
--- 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 <QMessageBox>
 #include <QInputDialog>
@@ -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)
--- 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 = "<qt><h3>";
     intro += tr("Ignore files");
@@ -99,49 +101,54 @@
 
     intro += "</p></qt>";
 
-    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("<p>Please choose whether to:</p>"),
-			 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("<p>Please choose whether to:</p>"),
-			 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("<p>Please choose whether to:</p>"),
+                     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;
 }
--- 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);
--- 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();
 }