annotate src/hgignoredialog.cpp @ 418:93cb9005bb6f ignore

Minor adjustments to glob syntaxes
author Chris Cannam
date Thu, 16 Jun 2011 16:46:35 +0100
parents 4593555915cf
children 69b2338c06e1
rev   line source
Chris@414 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@414 2
Chris@414 3 /*
Chris@414 4 EasyMercurial
Chris@414 5
Chris@414 6 Based on hgExplorer by Jari Korhonen
Chris@414 7 Copyright (c) 2010 Jari Korhonen
Chris@414 8 Copyright (c) 2011 Chris Cannam
Chris@414 9 Copyright (c) 2011 Queen Mary, University of London
Chris@414 10
Chris@414 11 This program is free software; you can redistribute it and/or
Chris@414 12 modify it under the terms of the GNU General Public License as
Chris@414 13 published by the Free Software Foundation; either version 2 of the
Chris@414 14 License, or (at your option) any later version. See the file
Chris@414 15 COPYING included with this distribution for more information.
Chris@414 16 */
Chris@414 17
Chris@414 18 #include "hgignoredialog.h"
Chris@414 19 #include "common.h"
Chris@414 20 #include "debug.h"
Chris@414 21
Chris@415 22 #include <QGridLayout>
Chris@415 23 #include <QRadioButton>
Chris@415 24 #include <QLabel>
Chris@415 25 #include <QDialogButtonBox>
Chris@415 26 #include <QPushButton>
Chris@415 27
Chris@415 28 HgIgnoreDialog::HgIgnoreDialog(QWidget *parent,
Chris@415 29 QString title,
Chris@415 30 QString introText,
Chris@415 31 QString question,
Chris@415 32 QStringList options,
Chris@415 33 QString okButtonText) :
Chris@415 34 QDialog(parent)
Chris@415 35 {
Chris@415 36 setWindowTitle(title);
Chris@415 37
Chris@415 38 QGridLayout *layout = new QGridLayout;
Chris@415 39 setLayout(layout);
Chris@415 40
Chris@415 41 int row = 0;
Chris@415 42
Chris@415 43 QLabel *label = new QLabel(QString("%1%2").arg(introText).arg(question));
Chris@415 44 label->setWordWrap(true);
Chris@415 45 layout->addWidget(label, row++, 0, 1, 2);
Chris@415 46
Chris@415 47 if (!options.empty()) {
Chris@415 48 layout->addWidget(new QLabel(" "), row, 0);
Chris@415 49 layout->setColumnStretch(1, 10);
Chris@415 50 bool first = true;
Chris@415 51 foreach (QString option, options) {
Chris@415 52 QRadioButton *b = new QRadioButton(option);
Chris@415 53 layout->addWidget(b, row++, 1);
Chris@416 54 if (first) {
Chris@416 55 m_option = option;
Chris@416 56 b->setChecked(true);
Chris@416 57 first = false;
Chris@416 58 }
Chris@416 59 connect(b, SIGNAL(toggled(bool)), this, SLOT(optionToggled(bool)));
Chris@415 60 }
Chris@415 61 }
Chris@415 62
Chris@415 63 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@415 64 QDialogButtonBox::Cancel);
Chris@415 65 layout->addWidget(bbox, row++, 0, 1, 2);
Chris@415 66 bbox->button(QDialogButtonBox::Ok)->setDefault(true);
Chris@415 67 bbox->button(QDialogButtonBox::Ok)->setText(okButtonText);
Chris@415 68 bbox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
Chris@415 69
Chris@415 70 connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
Chris@415 71 connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
Chris@415 72 }
Chris@415 73
Chris@416 74 void
Chris@416 75 HgIgnoreDialog::optionToggled(bool checked)
Chris@416 76 {
Chris@416 77 QObject *s = sender();
Chris@416 78 QRadioButton *rb = qobject_cast<QRadioButton *>(s);
Chris@416 79 if (rb && checked) {
Chris@416 80 m_option = rb->text();
Chris@416 81 }
Chris@416 82 }
Chris@416 83
Chris@414 84 HgIgnoreDialog::IgnoreType
Chris@415 85 HgIgnoreDialog::confirmIgnore(QWidget *parent,
Chris@415 86 QStringList files, QStringList suffixes)
Chris@414 87 {
Chris@415 88 QString intro = "<qt><h3>";
Chris@415 89 intro += tr("Ignore files");
Chris@415 90 intro += "</h3><p>";
Chris@414 91
Chris@414 92 if (files.size() < 10) {
Chris@415 93 intro += tr("You have asked to ignore the following files:</p><p>");
Chris@415 94 intro += "<code>&nbsp;&nbsp;&nbsp;"
Chris@415 95 + files.join("<br>&nbsp;&nbsp;&nbsp;") + "</code>";
Chris@414 96 } else {
Chris@415 97 intro += tr("You have asked to ignore %n file(s).", "", files.size());
Chris@414 98 }
Chris@414 99
Chris@415 100 intro += "</p></qt>";
Chris@415 101
Chris@414 102 if (suffixes.size() > 0) {
Chris@414 103
Chris@415 104 QStringList options;
Chris@415 105 options << tr("Ignore these files only");
Chris@415 106 options << tr("Ignore files with these names in any subdirectory");
Chris@414 107
Chris@415 108 if (suffixes.size() > 1) {
Chris@415 109 options << tr("Ignore all files with these extensions:\n%1")
Chris@415 110 .arg(suffixes.join(", "));
Chris@415 111 } else {
Chris@415 112 options << tr("Ignore all files with the extension \"%1\"")
Chris@415 113 .arg(suffixes[0]);
Chris@415 114 }
Chris@414 115
Chris@415 116 HgIgnoreDialog d(parent, tr("Ignore files"),
Chris@415 117 intro, tr("<p>Please choose whether to:</p>"),
Chris@415 118 options, tr("Ignore"));
Chris@415 119
Chris@415 120 if (d.exec() == QDialog::Accepted) {
Chris@416 121 QString option = d.getOption();
Chris@416 122 DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl;
Chris@416 123 if (option == options[0]) return IgnoreGivenFilesOnly;
Chris@416 124 else if (option == options[1]) return IgnoreAllFilesOfGivenNames;
Chris@416 125 else return IgnoreAllFilesOfGivenSuffixes;
Chris@415 126 }
Chris@414 127
Chris@415 128 } else {
Chris@415 129
Chris@415 130 QStringList options;
Chris@415 131 options << tr("Ignore these files only");
Chris@415 132 options << tr("Ignore files with these names in any subdirectory");
Chris@415 133
Chris@415 134 HgIgnoreDialog d(parent, tr("Ignore files"),
Chris@415 135 intro, tr("<p>Please choose whether to:</p>"),
Chris@415 136 options, tr("Ignore"));
Chris@415 137
Chris@415 138 if (d.exec() == QDialog::Accepted) {
Chris@416 139 QString option = d.getOption();
Chris@416 140 DEBUG << "HgIgnoreDialog::confirmIgnore: option = " << option << endl;
Chris@416 141 if (option == options[0]) return IgnoreGivenFilesOnly;
Chris@416 142 else return IgnoreAllFilesOfGivenNames;
Chris@415 143 }
Chris@415 144 }
Chris@414 145
Chris@414 146 return IgnoreNothing;
Chris@414 147 }
Chris@414 148