Mercurial > hg > easyhg
diff src/mainwindow.cpp @ 476:7e8688784980
Use built-in edit window for editing .hgignore file (fixes #215)
author | Chris Cannam |
---|---|
date | Tue, 26 Jul 2011 15:21:45 +0100 |
parents | 101d113943c2 |
children | a582c6417004 |
line wrap: on
line diff
--- a/src/mainwindow.cpp Tue Jul 26 13:42:09 2011 +0100 +++ b/src/mainwindow.cpp Tue Jul 26 15:21:45 2011 +0100 @@ -33,6 +33,7 @@ #include <QRegExp> #include <QShortcut> #include <QUrl> +#include <QDialogButtonBox> #include <QTimer> #include "mainwindow.h" @@ -577,23 +578,50 @@ initHgIgnore(); QString hgIgnorePath = m_workFolderPath + "/.hgignore"; - QStringList params; - - params << hgIgnorePath; + + QFile f(hgIgnorePath); + if (!f.exists()) return; // shouldn't happen (after initHgIgnore called) + + if (!f.open(QFile::ReadOnly)) return; + QTextStream sin(&f); + QString all = sin.readAll(); + f.close(); + + QDialog d; + QGridLayout layout; + d.setLayout(&layout); + + int row = 0; + layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs? + + QTextEdit ed; + ed.setAcceptRichText(false); + ed.setLineWrapMode(QTextEdit::NoWrap); + layout.setRowStretch(row, 10); + layout.addWidget(&ed, row++, 0); - QString editor = getEditorBinaryName(); - - if (editor == "") { - QMessageBox::critical - (this, tr("Edit .hgignore"), - tr("Failed to locate a system text editor program!")); - return; + QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel); + connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()), + &d, SLOT(accept())); + connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()), + &d, SLOT(reject())); + layout.addWidget(&bb, row++, 0); + + ed.document()->setPlainText(all); + + d.resize(QSize(300, 400)); + + if (d.exec() == QDialog::Accepted) { + if (!f.open(QFile::WriteOnly | QFile::Truncate)) { + QMessageBox::critical(this, tr("Write failed"), + tr("Failed to open file %1 for writing") + .arg(f.fileName())); + return; + } + QTextStream sout(&f); + sout << ed.document()->toPlainText(); + f.close(); } - - HgAction action(ACT_HG_IGNORE, m_workFolderPath, params); - action.executable = editor; - - m_runner->requestAction(action); } static QString regexEscape(QString filename) @@ -767,13 +795,6 @@ return settings.value("mergebinary", "").toString(); } -QString MainWindow::getEditorBinaryName() -{ - QSettings settings; - settings.beginGroup("Locations"); - return settings.value("editorbinary", "").toString(); -} - void MainWindow::hgShowSummary() { QStringList params;