comparison src/mainwindow.cpp @ 489:86cdaa346e59

Merge
author Chris Cannam
date Wed, 17 Aug 2011 22:13:51 +0100
parents 2f59333952ce 896b7903e8f2
children 1d90cd7a1c5f
comparison
equal deleted inserted replaced
488:2f59333952ce 489:86cdaa346e59
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"
108 109
109 cl->addWidget(m_hgTabs, row++, 0); 110 cl->addWidget(m_hgTabs, row++, 0);
110 111
111 connect(m_hgTabs, SIGNAL(selectionChanged()), 112 connect(m_hgTabs, SIGNAL(selectionChanged()),
112 this, SLOT(enableDisableActions())); 113 this, SLOT(enableDisableActions()));
113 connect(m_hgTabs, SIGNAL(showAllChanged(bool)), 114 connect(m_hgTabs, SIGNAL(showAllChanged()),
114 this, SLOT(showAllChanged(bool))); 115 this, SLOT(showAllChanged()));
115 116
116 setUnifiedTitleAndToolBarOnMac(true); 117 setUnifiedTitleAndToolBarOnMac(true);
117 connectActions(); 118 connectActions();
118 clearState(); 119 clearState();
119 enableDisableActions(); 120 enableDisableActions();
203 void MainWindow::clearSelections() 204 void MainWindow::clearSelections()
204 { 205 {
205 m_hgTabs->clearSelections(); 206 m_hgTabs->clearSelections();
206 } 207 }
207 208
208 void MainWindow::showAllChanged(bool s) 209 void MainWindow::showAllChanged()
209 { 210 {
210 m_showAllFiles = s;
211 hgQueryPaths(); 211 hgQueryPaths();
212 } 212 }
213 213
214 void MainWindow::hgRefresh() 214 void MainWindow::hgRefresh()
215 { 215 {
254 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params)); 254 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
255 } 255 }
256 256
257 void MainWindow::hgQueryPaths() 257 void MainWindow::hgQueryPaths()
258 { 258 {
259 m_showAllFiles = m_hgTabs->shouldShowAll();
260
259 // Quickest is to just read the file 261 // Quickest is to just read the file
260 262
261 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc"); 263 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
262 264
263 QString path; 265 QString path;
454 456
455 if (ConfirmCommentDialog::confirmAndGetLongComment 457 if (ConfirmCommentDialog::confirmAndGetLongComment
456 (this, 458 (this,
457 cf, 459 cf,
458 tr("<h3>%1</h3><p>%2%3").arg(cf) 460 tr("<h3>%1</h3><p>%2%3").arg(cf)
459 .arg(tr("You are about to commit the following files to %1:").arg(branchText)) 461 .arg(tr("You are about to commit changes to the following files in %1:").arg(branchText))
460 .arg(subsetNote), 462 .arg(subsetNote),
461 tr("<h3>%1</h3><p>%2%3").arg(cf) 463 tr("<h3>%1</h3><p>%2%3").arg(cf)
462 .arg(tr("You are about to commit %n file(s) to %1.", "", reportFiles.size()).arg(branchText)) 464 .arg(tr("You are about to commit changes to %n file(s) in %1.", "", reportFiles.size()).arg(branchText))
463 .arg(subsetNote), 465 .arg(subsetNote),
464 reportFiles, 466 reportFiles,
465 comment, 467 comment,
466 tr("Co&mmit"))) { 468 tr("Co&mmit"))) {
467 469
575 if (!QDir(m_workFolderPath).exists()) return; 577 if (!QDir(m_workFolderPath).exists()) return;
576 578
577 initHgIgnore(); 579 initHgIgnore();
578 580
579 QString hgIgnorePath = m_workFolderPath + "/.hgignore"; 581 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
580 QStringList params; 582
581 583 QFile f(hgIgnorePath);
582 params << hgIgnorePath; 584 if (!f.exists()) return; // shouldn't happen (after initHgIgnore called)
585
586 if (!f.open(QFile::ReadOnly)) return;
587 QTextStream sin(&f);
588 QString all = sin.readAll();
589 f.close();
590
591 QDialog d;
592 QGridLayout layout;
593 d.setLayout(&layout);
594
595 int row = 0;
596 layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs?
597
598 QTextEdit ed;
599 ed.setAcceptRichText(false);
600 ed.setLineWrapMode(QTextEdit::NoWrap);
601 layout.setRowStretch(row, 10);
602 layout.addWidget(&ed, row++, 0);
583 603
584 QString editor = getEditorBinaryName(); 604 QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
585 605 connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()),
586 if (editor == "") { 606 &d, SLOT(accept()));
587 QMessageBox::critical 607 connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
588 (this, tr("Edit .hgignore"), 608 &d, SLOT(reject()));
589 tr("Failed to locate a system text editor program!")); 609 layout.addWidget(&bb, row++, 0);
590 return; 610
591 } 611 ed.document()->setPlainText(all);
592 612
593 HgAction action(ACT_HG_IGNORE, m_workFolderPath, params); 613 d.resize(QSize(300, 400));
594 action.executable = editor; 614
595 615 if (d.exec() == QDialog::Accepted) {
596 m_runner->requestAction(action); 616 if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
617 QMessageBox::critical(this, tr("Write failed"),
618 tr("Failed to open file %1 for writing")
619 .arg(f.fileName()));
620 return;
621 }
622 QTextStream sout(&f);
623 sout << ed.document()->toPlainText();
624 f.close();
625 }
597 } 626 }
598 627
599 static QString regexEscape(QString filename) 628 static QString regexEscape(QString filename)
600 { 629 {
601 return filename 630 return filename
763 QString MainWindow::getMergeBinaryName() 792 QString MainWindow::getMergeBinaryName()
764 { 793 {
765 QSettings settings; 794 QSettings settings;
766 settings.beginGroup("Locations"); 795 settings.beginGroup("Locations");
767 return settings.value("mergebinary", "").toString(); 796 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 } 797 }
776 798
777 void MainWindow::hgShowSummary() 799 void MainWindow::hgShowSummary()
778 { 800 {
779 QStringList params; 801 QStringList params;
1311 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"), 1333 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
1312 tr("Open a local folder, by creating a Mercurial repository in it."), 1334 tr("Open a local folder, by creating a Mercurial repository in it."),
1313 MultiChoiceDialog::DirectoryArg); 1335 MultiChoiceDialog::DirectoryArg);
1314 1336
1315 QSettings settings; 1337 QSettings settings;
1316 settings.beginGroup("General"); 1338 settings.beginGroup("");
1317 QString lastChoice = settings.value("lastopentype", "remote").toString(); 1339 QString lastChoice = settings.value("lastopentype", "remote").toString();
1318 if (lastChoice != "local" && 1340 if (lastChoice != "local" &&
1319 lastChoice != "remote" && 1341 lastChoice != "remote" &&
1320 lastChoice != "init") { 1342 lastChoice != "init") {
1321 lastChoice = "remote"; 1343 lastChoice = "remote";
2040 case ACT_TEST_HG: 2062 case ACT_TEST_HG:
2041 MoreInformationDialog::warning 2063 MoreInformationDialog::warning
2042 (this, 2064 (this,
2043 tr("Failed to run Mercurial"), 2065 tr("Failed to run Mercurial"),
2044 tr("Failed to run Mercurial"), 2066 tr("Failed to run Mercurial"),
2045 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in %1.").arg(setstr), 2067 tr("The Mercurial program either could not be found or failed to run.<br><br>Check that the Mercurial program path is correct in %1.").arg(setstr),
2046 output); 2068 output);
2047 settings(SettingsDialog::PathsTab); 2069 settings(SettingsDialog::PathsTab);
2048 return; 2070 return;
2049 case ACT_TEST_HG_EXT: 2071 case ACT_TEST_HG_EXT:
2050 MoreInformationDialog::warning 2072 MoreInformationDialog::warning
2143 2165
2144 MoreInformationDialog::warning 2166 MoreInformationDialog::warning
2145 (this, 2167 (this,
2146 tr("Command failed"), 2168 tr("Command failed"),
2147 tr("Command failed"), 2169 tr("Command failed"),
2148 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output."), 2170 (output == "" ?
2171 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") :
2172 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output.")),
2149 output); 2173 output);
2150 } 2174 }
2151 2175
2152 void MainWindow::commandCompleted(HgAction completedAction, QString output) 2176 void MainWindow::commandCompleted(HgAction completedAction, QString output)
2153 { 2177 {
2420 switch (action) { 2444 switch (action) {
2421 2445
2422 case ACT_TEST_HG: 2446 case ACT_TEST_HG:
2423 { 2447 {
2424 QSettings settings; 2448 QSettings settings;
2425 settings.beginGroup("General");
2426 if (settings.value("useextension", true).toBool()) { 2449 if (settings.value("useextension", true).toBool()) {
2427 hgTestExtension(); 2450 hgTestExtension();
2428 } else if (m_workFolderPath == "") { 2451 } else if (m_workFolderPath == "") {
2429 open(); 2452 open();
2430 } else { 2453 } else {