# HG changeset patch # User Chris Cannam # Date 1292884662 0 # Node ID ef5feb0d648fe0f1fedb236a01d43ac7d0539658 # Parent 702ca6dafcbe8150a0c7e386c00ac98274bef6d8 * Give all of the substantial confirmation dialogs meaningful labels for their OK buttons diff -r 702ca6dafcbe -r ef5feb0d648f confirmcommentdialog.cpp --- a/confirmcommentdialog.cpp Mon Dec 20 21:33:42 2010 +0000 +++ b/confirmcommentdialog.cpp Mon Dec 20 22:37:42 2010 +0000 @@ -28,7 +28,8 @@ ConfirmCommentDialog::ConfirmCommentDialog(QWidget *parent, QString title, QString introText, - QString initialComment) : + QString initialComment, + QString okButtonText) : QDialog(parent) { setWindowTitle(title); @@ -50,6 +51,7 @@ layout->addWidget(bbox, 2, 0); m_ok = bbox->button(QDialogButtonBox::Ok); m_ok->setEnabled(initialComment != ""); + m_ok->setText(okButtonText); connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); @@ -77,11 +79,46 @@ return text; } +bool ConfirmCommentDialog::confirm(QWidget *parent, + QString title, + QString text, + QString okButtonText) +{ + QMessageBox box(QMessageBox::Question, + title, + text, + QMessageBox::Cancel, + parent); + + QPushButton *ok = box.addButton(QMessageBox::Ok); + ok->setText(okButtonText); + if (box.exec() == -1) return QMessageBox::Cancel; + return box.standardButton(box.clickedButton()); +} + +bool ConfirmCommentDialog::confirmDangerous(QWidget *parent, + QString title, + QString text, + QString okButtonText) +{ + QMessageBox box(QMessageBox::Warning, + title, + text, + QMessageBox::Cancel, + parent); + + QPushButton *ok = box.addButton(QMessageBox::Ok); + ok->setText(okButtonText); + if (box.exec() == -1) return QMessageBox::Cancel; + return box.standardButton(box.clickedButton()); +} + bool ConfirmCommentDialog::confirmFilesAction(QWidget *parent, QString title, QString introText, QString introTextWithCount, - QStringList files) + QStringList files, + QString okButtonText) { QString text; if (files.size() <= 10) { @@ -89,19 +126,15 @@ } else { text = "" + introTextWithCount + ""; } - return (QMessageBox::information(parent, - title, - text, - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Ok) - == QMessageBox::Ok); + return confirm(parent, title, text, okButtonText); } bool ConfirmCommentDialog::confirmDangerousFilesAction(QWidget *parent, QString title, QString introText, QString introTextWithCount, - QStringList files) + QStringList files, + QString okButtonText) { QString text; if (files.size() <= 10) { @@ -109,12 +142,7 @@ } else { text = "" + introTextWithCount + ""; } - return (QMessageBox::warning(parent, - title, - text, - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel) - == QMessageBox::Ok); + return confirmDangerous(parent, title, text, okButtonText); } bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, @@ -122,10 +150,12 @@ QString introText, QString introTextWithCount, QStringList files, - QString &comment) + QString &comment, + QString okButtonText) { return confirmAndComment(parent, title, introText, - introTextWithCount, files, comment, false); + introTextWithCount, files, comment, false, + okButtonText); } bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, @@ -133,10 +163,12 @@ QString introText, QString introTextWithCount, QStringList files, - QString &comment) + QString &comment, + QString okButtonText) { return confirmAndComment(parent, title, introText, - introTextWithCount, files, comment, true); + introTextWithCount, files, comment, true, + okButtonText); } bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, @@ -145,7 +177,8 @@ QString introTextWithCount, QStringList files, QString &comment, - bool longComment) + bool longComment, + QString okButtonText) { QString text; if (files.size() <= 10) { @@ -154,44 +187,56 @@ text = "" + introTextWithCount; } text += tr("

Please enter your comment:"); - return confirmAndComment(parent, title, text, comment, longComment); + return confirmAndComment(parent, title, text, comment, longComment, + okButtonText); } bool ConfirmCommentDialog::confirmAndGetShortComment(QWidget *parent, QString title, QString introText, - QString &comment) + QString &comment, + QString okButtonText) { - return confirmAndComment(parent, title, introText, comment, false); + return confirmAndComment(parent, title, introText, comment, false, + okButtonText); } bool ConfirmCommentDialog::confirmAndGetLongComment(QWidget *parent, QString title, QString introText, - QString &comment) + QString &comment, + QString okButtonText) { - return confirmAndComment(parent, title, introText, comment, true); + return confirmAndComment(parent, title, introText, comment, true, + okButtonText); } bool ConfirmCommentDialog::confirmAndComment(QWidget *parent, QString title, QString introText, QString &comment, - bool longComment) + bool longComment, + QString okButtonText) { bool ok = false; if (!longComment) { - comment = QInputDialog::getText(parent, title, introText, - QLineEdit::Normal, comment, &ok); + QInputDialog d(parent); + d.setWindowTitle(title); + d.setLabelText(introText); + d.setTextValue(comment); + d.setOkButtonText(okButtonText); + d.setTextEchoMode(QLineEdit::Normal); + if (d.exec() == QDialog::Accepted) { + comment = d.textValue(); + ok = true; + } } else { - ConfirmCommentDialog *d = new ConfirmCommentDialog(parent, - title, - introText, - comment); - if (d->exec() == QDialog::Accepted) { - comment = d->getComment(); + ConfirmCommentDialog d(parent, title, introText, comment, okButtonText); + if (d.exec() == QDialog::Accepted) { + comment = d.getComment(); ok = true; } } + return ok; } diff -r 702ca6dafcbe -r ef5feb0d648f confirmcommentdialog.h --- a/confirmcommentdialog.h Mon Dec 20 21:33:42 2010 +0000 +++ b/confirmcommentdialog.h Mon Dec 20 22:37:42 2010 +0000 @@ -30,41 +30,57 @@ Q_OBJECT public: + static bool confirm(QWidget *parent, + QString title, + QString text, + QString okButtonText); + + static bool confirmDangerous(QWidget *parent, + QString title, + QString text, + QString okButtonText); + static bool confirmFilesAction(QWidget *parent, QString title, QString introText, QString introTextWithCount, - QStringList files); + QStringList files, + QString okButtonText); static bool confirmDangerousFilesAction(QWidget *parent, QString title, QString introText, QString introTextWithCount, - QStringList files); + QStringList files, + QString okButtonText); static bool confirmAndGetShortComment(QWidget *parent, QString title, QString introText, QString introTextWithCount, QStringList files, - QString &comment); + QString &comment, + QString okButtonText); static bool confirmAndGetLongComment(QWidget *parent, QString title, QString introText, QString introTextWithCount, QStringList files, - QString &comment); + QString &comment, + QString okButtonText); static bool confirmAndGetShortComment(QWidget *parent, QString title, QString introText, - QString &comment); + QString &comment, + QString okButtonText); static bool confirmAndGetLongComment(QWidget *parent, QString title, QString introText, - QString &comment); + QString &comment, + QString okButtonText); private slots: void commentChanged(); @@ -73,7 +89,8 @@ ConfirmCommentDialog(QWidget *parent, QString title, QString introText, - QString initialComment); + QString initialComment, + QString okButtonText); static bool confirmAndComment(QWidget *parent, QString title, @@ -81,13 +98,15 @@ QString introTextWithCount, QStringList files, QString &comment, - bool longComment); + bool longComment, + QString okButtonText); static bool confirmAndComment(QWidget *parent, QString title, QString introText, QString &comment, - bool longComment); + bool longComment, + QString okButtonText); static QString buildFilesText(QString intro, QStringList files); diff -r 702ca6dafcbe -r ef5feb0d648f mainwindow.cpp --- a/mainwindow.cpp Mon Dec 20 21:33:42 2010 +0000 +++ b/mainwindow.cpp Mon Dec 20 22:37:42 2010 +0000 @@ -330,7 +330,8 @@ tr("

%1

%2").arg(cf) .arg(tr("You are about to commit %n file(s).", "", reportFiles.size())), reportFiles, - comment)) { + comment, + tr("Commit"))) { if (!justMerged && !files.empty()) { // User wants to commit selected file(s) (and this is not @@ -374,7 +375,8 @@ (this, tr("Tag"), tr("Enter tag:"), - tag)) { + tag, + tr("Add Tag"))) { if (!tag.isEmpty()) {//!!! do something better if it is empty params << "tag" << "--user" << getUserInfo(); @@ -594,7 +596,8 @@ .arg(tr("You are about to revert the following files to their previous committed state.

This will throw away any changes that you have made to these files but have not committed:")), tr("

%1

%2").arg(rf) .arg(tr("You are about to revert %n file(s).

This will throw away any changes that you have made to these files but have not committed.", "", files.size())), - files)) { + files, + tr("Revert"))) { lastRevertedFiles = files; @@ -762,26 +765,9 @@ runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params)); } -static QMessageBox::StandardButton confirm(QWidget *parent, - QString title, - QString text, - QString okButtonText) -{ - QMessageBox box(QMessageBox::Question, - title, - text, - QMessageBox::Cancel, - parent); - - QPushButton *ok = box.addButton(QMessageBox::Ok); - ok->setText(okButtonText); - if (box.exec() == -1) return QMessageBox::Cancel; - return box.standardButton(box.clickedButton()); -} - void MainWindow::hgPull() { - if (confirm + if (ConfirmCommentDialog::confirm (this, tr("Confirm pull"), format3(tr("Confirm pull from remote repository"), tr("You are about to pull changes from the following remote repository:"), @@ -796,7 +782,7 @@ void MainWindow::hgPush() { - if (confirm + if (ConfirmCommentDialog::confirm (this, tr("Confirm push"), format3(tr("Confirm push to remote repository"), tr("You are about to push your changes to the following remote repository:"),