Mercurial > hg > easyhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
475:dec4695f64e0 | 476:7e8688784980 |
---|---|
31 #include <QInputDialog> | 31 #include <QInputDialog> |
32 #include <QWidgetAction> | 32 #include <QWidgetAction> |
33 #include <QRegExp> | 33 #include <QRegExp> |
34 #include <QShortcut> | 34 #include <QShortcut> |
35 #include <QUrl> | 35 #include <QUrl> |
36 #include <QDialogButtonBox> | |
36 #include <QTimer> | 37 #include <QTimer> |
37 | 38 |
38 #include "mainwindow.h" | 39 #include "mainwindow.h" |
39 #include "multichoicedialog.h" | 40 #include "multichoicedialog.h" |
40 #include "startupdialog.h" | 41 #include "startupdialog.h" |
575 if (!QDir(m_workFolderPath).exists()) return; | 576 if (!QDir(m_workFolderPath).exists()) return; |
576 | 577 |
577 initHgIgnore(); | 578 initHgIgnore(); |
578 | 579 |
579 QString hgIgnorePath = m_workFolderPath + "/.hgignore"; | 580 QString hgIgnorePath = m_workFolderPath + "/.hgignore"; |
580 QStringList params; | 581 |
581 | 582 QFile f(hgIgnorePath); |
582 params << hgIgnorePath; | 583 if (!f.exists()) return; // shouldn't happen (after initHgIgnore called) |
584 | |
585 if (!f.open(QFile::ReadOnly)) return; | |
586 QTextStream sin(&f); | |
587 QString all = sin.readAll(); | |
588 f.close(); | |
589 | |
590 QDialog d; | |
591 QGridLayout layout; | |
592 d.setLayout(&layout); | |
593 | |
594 int row = 0; | |
595 layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs? | |
596 | |
597 QTextEdit ed; | |
598 ed.setAcceptRichText(false); | |
599 ed.setLineWrapMode(QTextEdit::NoWrap); | |
600 layout.setRowStretch(row, 10); | |
601 layout.addWidget(&ed, row++, 0); | |
583 | 602 |
584 QString editor = getEditorBinaryName(); | 603 QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel); |
585 | 604 connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()), |
586 if (editor == "") { | 605 &d, SLOT(accept())); |
587 QMessageBox::critical | 606 connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()), |
588 (this, tr("Edit .hgignore"), | 607 &d, SLOT(reject())); |
589 tr("Failed to locate a system text editor program!")); | 608 layout.addWidget(&bb, row++, 0); |
590 return; | 609 |
591 } | 610 ed.document()->setPlainText(all); |
592 | 611 |
593 HgAction action(ACT_HG_IGNORE, m_workFolderPath, params); | 612 d.resize(QSize(300, 400)); |
594 action.executable = editor; | 613 |
595 | 614 if (d.exec() == QDialog::Accepted) { |
596 m_runner->requestAction(action); | 615 if (!f.open(QFile::WriteOnly | QFile::Truncate)) { |
616 QMessageBox::critical(this, tr("Write failed"), | |
617 tr("Failed to open file %1 for writing") | |
618 .arg(f.fileName())); | |
619 return; | |
620 } | |
621 QTextStream sout(&f); | |
622 sout << ed.document()->toPlainText(); | |
623 f.close(); | |
624 } | |
597 } | 625 } |
598 | 626 |
599 static QString regexEscape(QString filename) | 627 static QString regexEscape(QString filename) |
600 { | 628 { |
601 return filename | 629 return filename |
763 QString MainWindow::getMergeBinaryName() | 791 QString MainWindow::getMergeBinaryName() |
764 { | 792 { |
765 QSettings settings; | 793 QSettings settings; |
766 settings.beginGroup("Locations"); | 794 settings.beginGroup("Locations"); |
767 return settings.value("mergebinary", "").toString(); | 795 return settings.value("mergebinary", "").toString(); |
768 } | |
769 | |
770 QString MainWindow::getEditorBinaryName() | |
771 { | |
772 QSettings settings; | |
773 settings.beginGroup("Locations"); | |
774 return settings.value("editorbinary", "").toString(); | |
775 } | 796 } |
776 | 797 |
777 void MainWindow::hgShowSummary() | 798 void MainWindow::hgShowSummary() |
778 { | 799 { |
779 QStringList params; | 800 QStringList params; |