annotate src/mainwindow.cpp @ 519:000f13faa089

Bookmarks are now displayed -- but exactly like tags, so far, there's no differentiation yet
author Chris Cannam
date Tue, 08 Nov 2011 16:42:09 +0000
parents 5c846f3c9244
children a17c06f773cd
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
jtkorhonen@0 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@98 6 Based on hgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
Chris@50 17
jtkorhonen@0 18 #include <QStringList>
jtkorhonen@0 19 #include <QDir>
jtkorhonen@24 20 #include <QNetworkInterface>
jtkorhonen@17 21 #include <QHostAddress>
jtkorhonen@17 22 #include <QHostInfo>
jtkorhonen@34 23 #include <QDesktopServices>
Chris@50 24 #include <QStatusBar>
Chris@50 25 #include <QMessageBox>
Chris@50 26 #include <QMenuBar>
Chris@50 27 #include <QApplication>
Chris@50 28 #include <QToolBar>
Chris@61 29 #include <QToolButton>
Chris@50 30 #include <QSettings>
Chris@90 31 #include <QInputDialog>
Chris@359 32 #include <QWidgetAction>
Chris@125 33 #include <QRegExp>
Chris@199 34 #include <QShortcut>
Chris@237 35 #include <QUrl>
Chris@476 36 #include <QDialogButtonBox>
Chris@238 37 #include <QTimer>
Chris@494 38 #include <QTextBrowser>
jtkorhonen@0 39
Chris@53 40 #include "mainwindow.h"
Chris@69 41 #include "multichoicedialog.h"
Chris@64 42 #include "startupdialog.h"
Chris@53 43 #include "colourset.h"
Chris@62 44 #include "debug.h"
Chris@74 45 #include "logparser.h"
Chris@103 46 #include "confirmcommentdialog.h"
Chris@125 47 #include "incomingdialog.h"
Chris@175 48 #include "settingsdialog.h"
Chris@275 49 #include "moreinformationdialog.h"
Chris@331 50 #include "annotatedialog.h"
Chris@229 51 #include "version.h"
Chris@287 52 #include "workstatuswidget.h"
Chris@414 53 #include "hgignoredialog.h"
Chris@491 54 #include "versiontester.h"
Chris@53 55
jtkorhonen@0 56
Chris@172 57 MainWindow::MainWindow(QString myDirPath) :
Chris@238 58 m_myDirPath(myDirPath),
Chris@498 59 m_helpDialog(0),
Chris@238 60 m_fsWatcherGeneralTimer(0),
Chris@241 61 m_fsWatcherRestoreTimer(0),
Chris@498 62 m_fsWatcherSuspended(false)
jtkorhonen@0 63 {
Chris@197 64 setWindowIcon(QIcon(":images/easyhg-icon.png"));
Chris@197 65
jtkorhonen@0 66 QString wndTitle;
jtkorhonen@0 67
Chris@284 68 m_showAllFiles = false;
Chris@273 69
Chris@284 70 m_fsWatcher = 0;
Chris@284 71 m_commitsSincePush = 0;
Chris@284 72 m_shouldHgStat = true;
Chris@90 73
jtkorhonen@0 74 createActions();
jtkorhonen@0 75 createMenus();
jtkorhonen@0 76 createToolBars();
jtkorhonen@0 77 createStatusBar();
jtkorhonen@0 78
Chris@284 79 m_runner = new HgRunner(m_myDirPath, this);
Chris@284 80 connect(m_runner, SIGNAL(commandStarting(HgAction)),
Chris@241 81 this, SLOT(commandStarting(HgAction)));
Chris@284 82 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)),
Chris@109 83 this, SLOT(commandCompleted(HgAction, QString)));
Chris@284 84 connect(m_runner, SIGNAL(commandFailed(HgAction, QString)),
Chris@109 85 this, SLOT(commandFailed(HgAction, QString)));
Chris@284 86 statusBar()->addPermanentWidget(m_runner);
jtkorhonen@0 87
Chris@61 88 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 89
Chris@284 90 m_remoteRepoPath = "";
Chris@284 91 m_workFolderPath = "";
jtkorhonen@0 92
jtkorhonen@0 93 readSettings();
jtkorhonen@0 94
Chris@284 95 m_justMerged = false;
Chris@210 96
Chris@210 97 QWidget *central = new QWidget(this);
Chris@210 98 setCentralWidget(central);
Chris@210 99
Chris@210 100 QGridLayout *cl = new QGridLayout(central);
Chris@287 101 int row = 0;
Chris@210 102
Chris@210 103 #ifndef Q_OS_MAC
Chris@210 104 cl->setMargin(0);
Chris@210 105 #endif
jtkorhonen@0 106
Chris@287 107 m_workStatus = new WorkStatusWidget(this);
Chris@287 108 cl->addWidget(m_workStatus, row++, 0);
Chris@287 109
Chris@287 110 m_hgTabs = new HgTabWidget(central, m_workFolderPath);
Chris@287 111 connectTabsSignals();
Chris@287 112
Chris@287 113 cl->addWidget(m_hgTabs, row++, 0);
Chris@287 114
Chris@284 115 connect(m_hgTabs, SIGNAL(selectionChanged()),
Chris@95 116 this, SLOT(enableDisableActions()));
Chris@484 117 connect(m_hgTabs, SIGNAL(showAllChanged()),
Chris@484 118 this, SLOT(showAllChanged()));
Chris@95 119
jtkorhonen@0 120 setUnifiedTitleAndToolBarOnMac(true);
jtkorhonen@0 121 connectActions();
Chris@120 122 clearState();
jtkorhonen@0 123 enableDisableActions();
jtkorhonen@0 124
Chris@284 125 if (m_firstStart) {
Chris@64 126 startupDialog();
jtkorhonen@0 127 }
jtkorhonen@0 128
Chris@239 129 SettingsDialog::findDefaultLocations(m_myDirPath);
Chris@112 130
Chris@64 131 ColourSet *cs = ColourSet::instance();
Chris@64 132 cs->clearDefaultNames();
Chris@64 133 cs->addDefaultName("");
Chris@153 134 cs->addDefaultName("default");
Chris@64 135 cs->addDefaultName(getUserInfo());
Chris@62 136
Chris@491 137 VersionTester *vt = new VersionTester
Chris@507 138 ("easyhg.org", "/latest-version.txt", EASYHG_VERSION);
Chris@491 139 connect(vt, SIGNAL(newerVersionAvailable(QString)),
Chris@491 140 this, SLOT(newerVersionAvailable(QString)));
Chris@491 141
Chris@175 142 hgTest();
Chris@359 143 updateRecentMenu();
jtkorhonen@0 144 }
jtkorhonen@0 145
jtkorhonen@0 146
jtkorhonen@0 147 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 148 {
jtkorhonen@0 149 writeSettings();
Chris@284 150 delete m_fsWatcher;
jtkorhonen@0 151 }
jtkorhonen@0 152
jtkorhonen@0 153
Chris@64 154 QString MainWindow::getUserInfo() const
Chris@64 155 {
Chris@64 156 QSettings settings;
Chris@64 157 settings.beginGroup("User Information");
Chris@64 158 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 159 QString email = settings.value("email", "").toString();
Chris@64 160
Chris@64 161 QString identifier;
Chris@64 162
Chris@64 163 if (email != "") {
Chris@64 164 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 165 } else {
Chris@64 166 identifier = name;
Chris@64 167 }
Chris@64 168
Chris@64 169 return identifier;
Chris@64 170 }
Chris@64 171
jtkorhonen@0 172 void MainWindow::about()
jtkorhonen@0 173 {
Chris@97 174 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@229 175 tr("<qt><h2>EasyMercurial v%1</h2>"
Chris@228 176 #ifdef Q_OS_MAC
Chris@228 177 "<font size=-1>"
Chris@228 178 #endif
Chris@97 179 "<p>EasyMercurial is a simple user interface for the "
Chris@186 180 "Mercurial</a> version control system.</p>"
Chris@186 181 "<h4>Credits and Copyright</h4>"
Chris@186 182 "<p>Development carried out by Chris Cannam for "
Chris@186 183 "SoundSoftware.ac.uk at the Centre for Digital Music, "
Chris@186 184 "Queen Mary, University of London.</p>"
Chris@186 185 "<p>EasyMercurial is based on HgExplorer by "
Chris@186 186 "Jari Korhonen, with thanks.</p>"
Chris@186 187 "<p style=\"margin-left: 2em;\">"
Chris@244 188 "Copyright &copy; 2011 Queen Mary, University of London.<br>"
Chris@186 189 "Copyright &copy; 2010 Jari Korhonen.<br>"
Chris@244 190 "Copyright &copy; 2011 Chris Cannam."
Chris@186 191 "</p>"
Chris@186 192 "<p style=\"margin-left: 2em;\">"
Chris@186 193 "This program requires Mercurial, by Matt Mackall and others.<br>"
Chris@186 194 "This program uses Qt by Nokia.<br>"
Chris@186 195 "This program uses Nuvola icons by David Vignoni.<br>"
Chris@186 196 "This program may use KDiff3 by Joachim Eibl.<br>"
Chris@186 197 "This program may use PyQt by River Bank Computing.<br>"
Chris@186 198 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
Chris@186 199 "</p>"
Chris@186 200 "<h4>License</h4>"
Chris@186 201 "<p>This program is free software; you can redistribute it and/or "
Chris@97 202 "modify it under the terms of the GNU General Public License as "
Chris@97 203 "published by the Free Software Foundation; either version 2 of the "
Chris@97 204 "License, or (at your option) any later version. See the file "
Chris@223 205 "COPYING included with this distribution for more information.</p>"
Chris@228 206 #ifdef Q_OS_MAC
Chris@228 207 "</font>"
Chris@228 208 #endif
Chris@229 209 ).arg(EASYHG_VERSION));
jtkorhonen@0 210 }
jtkorhonen@0 211
Chris@94 212 void MainWindow::clearSelections()
Chris@94 213 {
Chris@284 214 m_hgTabs->clearSelections();
Chris@94 215 }
jtkorhonen@0 216
Chris@484 217 void MainWindow::showAllChanged()
Chris@199 218 {
Chris@199 219 hgQueryPaths();
Chris@199 220 }
Chris@199 221
Chris@120 222 void MainWindow::hgRefresh()
Chris@120 223 {
Chris@120 224 clearState();
Chris@120 225 hgQueryPaths();
Chris@120 226 }
Chris@120 227
Chris@175 228 void MainWindow::hgTest()
Chris@175 229 {
Chris@175 230 QStringList params;
Chris@175 231 params << "--version";
Chris@382 232 // The path is not necessarily set here, but we need something for
Chris@382 233 // this test or else HgRunner will (cautiously) refuse to run
Chris@382 234 QString path = m_myDirPath;
Chris@382 235 if (path == "") path = QDir::homePath();
Chris@382 236 m_runner->requestAction(HgAction(ACT_TEST_HG, path, params));
Chris@175 237 }
Chris@175 238
Chris@200 239 void MainWindow::hgTestExtension()
Chris@200 240 {
Chris@200 241 QStringList params;
Chris@200 242 params << "--version";
Chris@382 243 // The path is not necessarily set here, but we need something for
Chris@382 244 // this test or else HgRunner will (cautiously) refuse to run
Chris@382 245 QString path = m_myDirPath;
Chris@382 246 if (path == "") path = QDir::homePath();
Chris@382 247 m_runner->requestAction(HgAction(ACT_TEST_HG_EXT, path, params));
Chris@200 248 }
Chris@200 249
jtkorhonen@0 250 void MainWindow::hgStat()
jtkorhonen@0 251 {
Chris@109 252 QStringList params;
Chris@199 253
Chris@284 254 if (m_showAllFiles) {
Chris@199 255 params << "stat" << "-A";
Chris@199 256 } else {
Chris@199 257 params << "stat" << "-ardum";
Chris@199 258 }
Chris@153 259
Chris@284 260 m_lastStatOutput = "";
Chris@273 261
Chris@284 262 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
jtkorhonen@0 263 }
jtkorhonen@0 264
Chris@109 265 void MainWindow::hgQueryPaths()
Chris@74 266 {
Chris@484 267 m_showAllFiles = m_hgTabs->shouldShowAll();
Chris@484 268
Chris@210 269 // Quickest is to just read the file
Chris@198 270
Chris@284 271 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
Chris@198 272
Chris@210 273 QString path;
Chris@210 274
Chris@198 275 if (hgrc.exists()) {
Chris@198 276 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
Chris@198 277 s.beginGroup("paths");
Chris@210 278 path = s.value("default").toString();
Chris@210 279 }
Chris@198 280
Chris@284 281 m_remoteRepoPath = path;
Chris@198 282
Chris@210 283 // We have to do this here, because commandCompleted won't be called
Chris@284 284 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 285 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@287 286 updateWorkFolderAndRepoNames();
Chris@210 287
Chris@210 288 hgQueryBranch();
Chris@210 289 return;
Chris@210 290
Chris@210 291 /* The classic method!
Chris@198 292
Chris@109 293 QStringList params;
Chris@109 294 params << "paths";
Chris@284 295 m_runner->requestAction(HgAction(ACT_QUERY_PATHS, m_workFolderPath, params));
Chris@210 296 */
Chris@74 297 }
Chris@74 298
Chris@109 299 void MainWindow::hgQueryBranch()
Chris@106 300 {
Chris@210 301 // Quickest is to just read the file
Chris@198 302
Chris@284 303 QFile hgbr(m_workFolderPath + "/.hg/branch");
Chris@198 304
Chris@210 305 QString br = "default";
Chris@210 306
Chris@198 307 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
Chris@210 308 QByteArray ba = hgbr.readLine();
Chris@210 309 br = QString::fromUtf8(ba).trimmed();
Chris@210 310 }
Chris@210 311
Chris@284 312 m_currentBranch = br;
Chris@210 313
Chris@210 314 // We have to do this here, because commandCompleted won't be called
Chris@210 315 hgStat();
Chris@210 316 return;
Chris@198 317
Chris@210 318 /* The classic method!
Chris@198 319
Chris@109 320 QStringList params;
Chris@109 321 params << "branch";
Chris@284 322 m_runner->requestAction(HgAction(ACT_QUERY_BRANCH, m_workFolderPath, params));
Chris@210 323 */
Chris@106 324 }
Chris@106 325
Chris@519 326 void MainWindow::hgQueryBookmarks()
Chris@519 327 {
Chris@519 328 QStringList params;
Chris@519 329 params << "bookmarks";
Chris@519 330 m_runner->requestAction(HgAction(ACT_QUERY_BOOKMARKS, m_workFolderPath, params));
Chris@519 331 }
Chris@519 332
Chris@506 333 void MainWindow::hgQueryHeadsActive()
Chris@506 334 {
Chris@506 335 QStringList params;
Chris@514 336 params << "heads";
Chris@506 337 m_runner->requestAction(HgAction(ACT_QUERY_HEADS_ACTIVE, m_workFolderPath, params));
Chris@506 338 }
Chris@506 339
Chris@109 340 void MainWindow::hgQueryHeads()
jtkorhonen@0 341 {
Chris@109 342 QStringList params;
Chris@137 343 // On empty repos, "hg heads" will fail -- we don't care about
Chris@137 344 // that. Use --closed option so as to include closed branches;
Chris@137 345 // otherwise we'll be stuck if the user updates into one, and our
Chris@137 346 // incremental log will end up with spurious stuff in it because
Chris@137 347 // we won't be pruning at the ends of closed branches
Chris@137 348 params << "heads" << "--closed";
Chris@284 349 m_runner->requestAction(HgAction(ACT_QUERY_HEADS, m_workFolderPath, params));
jtkorhonen@0 350 }
jtkorhonen@0 351
jtkorhonen@0 352 void MainWindow::hgLog()
jtkorhonen@0 353 {
Chris@109 354 QStringList params;
Chris@109 355 params << "log";
Chris@109 356 params << "--template";
Chris@125 357 params << Changeset::getLogTemplate();
Chris@109 358
Chris@284 359 m_runner->requestAction(HgAction(ACT_LOG, m_workFolderPath, params));
Chris@109 360 }
Chris@109 361
Chris@150 362 void MainWindow::hgLogIncremental(QStringList prune)
Chris@120 363 {
Chris@305 364 // Sometimes we can be called with prune empty -- it represents
Chris@305 365 // the current heads, but if we have none already and for some
Chris@305 366 // reason are being prompted for an incremental update, we may run
Chris@305 367 // into trouble. In that case, make this a full log instead
Chris@305 368
Chris@305 369 if (prune.empty()) {
Chris@305 370 hgLog();
Chris@305 371 return;
Chris@305 372 }
Chris@305 373
Chris@120 374 QStringList params;
Chris@120 375 params << "log";
Chris@120 376
Chris@150 377 foreach (QString p, prune) {
Chris@153 378 params << "--prune" << Changeset::hashOf(p);
Chris@120 379 }
Chris@120 380
Chris@120 381 params << "--template";
Chris@125 382 params << Changeset::getLogTemplate();
Chris@120 383
Chris@284 384 m_runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, m_workFolderPath, params));
Chris@120 385 }
Chris@109 386
Chris@109 387 void MainWindow::hgQueryParents()
Chris@109 388 {
Chris@109 389 QStringList params;
Chris@109 390 params << "parents";
Chris@284 391 m_runner->requestAction(HgAction(ACT_QUERY_PARENTS, m_workFolderPath, params));
Chris@109 392 }
Chris@109 393
Chris@326 394 void MainWindow::hgAnnotateFiles(QStringList files)
Chris@326 395 {
Chris@326 396 QStringList params;
Chris@326 397
Chris@326 398 if (!files.isEmpty()) {
Chris@332 399 params << "annotate" << "-udqc" << "--" << files;
Chris@326 400 m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params));
Chris@326 401 }
Chris@326 402 }
Chris@326 403
Chris@109 404 void MainWindow::hgResolveList()
Chris@109 405 {
Chris@109 406 QStringList params;
jtkorhonen@0 407
Chris@109 408 params << "resolve" << "--list";
Chris@284 409 m_runner->requestAction(HgAction(ACT_RESOLVE_LIST, m_workFolderPath, params));
Chris@109 410 }
Chris@109 411
Chris@109 412 void MainWindow::hgAdd()
jtkorhonen@0 413 {
Chris@109 414 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@109 415 // that one is a good idea, let's require the user to select
jtkorhonen@0 416
Chris@326 417 hgAddFiles(m_hgTabs->getSelectedAddableFiles());
Chris@326 418 }
Chris@326 419
Chris@326 420 void MainWindow::hgAddFiles(QStringList files)
Chris@326 421 {
Chris@326 422 QStringList params;
Chris@109 423
Chris@109 424 if (!files.empty()) {
Chris@109 425 params << "add" << "--" << files;
Chris@284 426 m_runner->requestAction(HgAction(ACT_ADD, m_workFolderPath, params));
jtkorhonen@0 427 }
jtkorhonen@0 428 }
jtkorhonen@0 429
Chris@98 430 void MainWindow::hgRemove()
Chris@98 431 {
Chris@326 432 hgRemoveFiles(m_hgTabs->getSelectedRemovableFiles());
Chris@326 433 }
Chris@326 434
Chris@326 435 void MainWindow::hgRemoveFiles(QStringList files)
Chris@326 436 {
Chris@109 437 QStringList params;
Chris@98 438
Chris@109 439 if (!files.empty()) {
Chris@109 440 params << "remove" << "--after" << "--force" << "--" << files;
Chris@284 441 m_runner->requestAction(HgAction(ACT_REMOVE, m_workFolderPath, params));
Chris@109 442 }
jtkorhonen@0 443 }
jtkorhonen@0 444
jtkorhonen@0 445 void MainWindow::hgCommit()
jtkorhonen@0 446 {
Chris@326 447 hgCommitFiles(QStringList());
Chris@326 448 }
Chris@326 449
Chris@326 450 void MainWindow::hgCommitFiles(QStringList files)
Chris@326 451 {
Chris@109 452 QStringList params;
Chris@109 453 QString comment;
Chris@94 454
Chris@284 455 if (m_justMerged) {
Chris@284 456 comment = m_mergeCommitComment;
Chris@157 457 }
Chris@157 458
Chris@284 459 QStringList allFiles = m_hgTabs->getAllCommittableFiles();
Chris@127 460 QStringList reportFiles = files;
Chris@237 461 if (reportFiles.empty()) {
Chris@237 462 reportFiles = allFiles;
Chris@237 463 }
Chris@103 464
Chris@237 465 QString subsetNote;
Chris@237 466 if (reportFiles != allFiles) {
Chris@237 467 subsetNote = tr("<p><b>Note:</b> you are committing only the files you have selected, not all of the files that have been changed!");
Chris@237 468 }
Chris@237 469
Chris@155 470 QString cf(tr("Commit files"));
Chris@155 471
Chris@311 472 QString branchText;
Chris@311 473 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@311 474 branchText = tr("the default branch");
Chris@311 475 } else {
Chris@311 476 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@311 477 }
Chris@311 478
Chris@109 479 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@109 480 (this,
Chris@155 481 cf,
Chris@237 482 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@473 483 .arg(tr("You are about to commit changes to the following files in %1:").arg(branchText))
Chris@237 484 .arg(subsetNote),
Chris@237 485 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@473 486 .arg(tr("You are about to commit changes to %n file(s) in %1.", "", reportFiles.size()).arg(branchText))
Chris@237 487 .arg(subsetNote),
Chris@127 488 reportFiles,
Chris@193 489 comment,
Chris@365 490 tr("Co&mmit"))) {
Chris@103 491
Chris@284 492 if (!m_justMerged && !files.empty()) {
Chris@157 493 // User wants to commit selected file(s) (and this is not
Chris@157 494 // merge commit, which would fail if we selected files)
Chris@157 495 params << "commit" << "--message" << comment
Chris@157 496 << "--user" << getUserInfo() << "--" << files;
Chris@109 497 } else {
Chris@109 498 // Commit all changes
Chris@157 499 params << "commit" << "--message" << comment
Chris@157 500 << "--user" << getUserInfo();
jtkorhonen@0 501 }
Chris@109 502
Chris@284 503 m_runner->requestAction(HgAction(ACT_COMMIT, m_workFolderPath, params));
Chris@284 504 m_mergeCommitComment = "";
jtkorhonen@0 505 }
jtkorhonen@0 506 }
jtkorhonen@0 507
jtkorhonen@34 508 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 509 {
Chris@278 510 for(int i = 0; i < tag.size(); i++) {
Chris@278 511 if (tag[i].isLower() || tag[i].isUpper() ||
Chris@278 512 tag[i].isDigit() || (tag[i] == QChar('.'))) {
jtkorhonen@34 513 //ok
Chris@278 514 } else {
jtkorhonen@34 515 tag[i] = QChar('_');
jtkorhonen@34 516 }
jtkorhonen@34 517 }
jtkorhonen@34 518 return tag;
jtkorhonen@34 519 }
jtkorhonen@34 520
jtkorhonen@34 521
Chris@311 522 void MainWindow::hgNewBranch()
Chris@278 523 {
Chris@278 524 QStringList params;
Chris@278 525 QString branch;
Chris@278 526
Chris@278 527 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@278 528 (this,
Chris@278 529 tr("New Branch"),
Chris@278 530 tr("Enter new branch name:"),
Chris@278 531 branch,
Chris@365 532 tr("Start &Branch"))) {
Chris@278 533 if (!branch.isEmpty()) {//!!! do something better if it is empty
Chris@278 534
Chris@278 535 params << "branch" << filterTag(branch);
Chris@307 536 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
Chris@278 537 }
Chris@278 538 }
Chris@278 539 }
Chris@278 540
Chris@311 541 void MainWindow::hgNoBranch()
Chris@311 542 {
Chris@311 543 if (m_currentParents.empty()) return;
Chris@311 544
Chris@311 545 QString parentBranch = m_currentParents[0]->branch();
Chris@311 546 if (parentBranch == "") parentBranch = "default";
Chris@311 547
Chris@311 548 QStringList params;
Chris@311 549 params << "branch" << parentBranch;
Chris@311 550 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
Chris@311 551 }
Chris@311 552
Chris@514 553 void MainWindow::hgCloseBranch()
Chris@514 554 {
Chris@514 555 QStringList params;
Chris@514 556
Chris@514 557 //!!! how to ensure this doesn't happen when uncommitted changes present?
Chris@514 558
Chris@514 559 QString cf(tr("Close branch"));
Chris@514 560 QString comment;
Chris@514 561
Chris@514 562 QString defaultWarning;
Chris@514 563
Chris@514 564 QString branchText;
Chris@514 565 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@514 566 branchText = tr("the default branch");
Chris@514 567 defaultWarning = tr("<p><b>Warning:</b> you are asking to close the default branch. This is not usually a good idea!</p>");
Chris@514 568 } else {
Chris@514 569 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@514 570 }
Chris@514 571
Chris@514 572 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@514 573 (this,
Chris@514 574 cf,
Chris@514 575 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@518 576 .arg(tr("You are about to close %1.<p>This branch will be marked as closed and hidden from the history view.<p>You will still be able to see if it you select \"Show closed branches\" in the history view, and it will be reopened if you commit to it.<p>Please enter your comment for the commit log:").arg(branchText))
Chris@514 577 .arg(defaultWarning),
Chris@514 578 comment,
Chris@514 579 tr("C&lose branch"))) {
Chris@514 580
Chris@514 581 params << "commit" << "--message" << comment
Chris@514 582 << "--user" << getUserInfo() << "--close-branch";
Chris@514 583
Chris@514 584 m_runner->requestAction(HgAction(ACT_CLOSE_BRANCH, m_workFolderPath, params));
Chris@514 585 }
Chris@514 586 }
Chris@514 587
Chris@164 588 void MainWindow::hgTag(QString id)
jtkorhonen@34 589 {
Chris@109 590 QStringList params;
Chris@109 591 QString tag;
jtkorhonen@34 592
Chris@109 593 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@109 594 (this,
Chris@109 595 tr("Tag"),
Chris@109 596 tr("Enter tag:"),
Chris@193 597 tag,
Chris@365 598 tr("Add &Tag"))) {
Chris@164 599 if (!tag.isEmpty()) {//!!! do something better if it is empty
Chris@164 600
Chris@164 601 params << "tag" << "--user" << getUserInfo();
Chris@164 602 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
Chris@109 603
Chris@284 604 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params));
jtkorhonen@34 605 }
jtkorhonen@34 606 }
jtkorhonen@34 607 }
jtkorhonen@34 608
Chris@417 609 void MainWindow::initHgIgnore()
jtkorhonen@34 610 {
Chris@284 611 if (!QDir(m_workFolderPath).exists()) return;
Chris@417 612 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@417 613
Chris@249 614 QFile f(hgIgnorePath);
Chris@249 615 if (!f.exists()) {
Chris@249 616 f.open(QFile::WriteOnly);
Chris@249 617 QTextStream *ts = new QTextStream(&f);
Chris@249 618 *ts << "syntax: glob\n";
Chris@249 619 delete ts;
Chris@249 620 f.close();
Chris@249 621 }
Chris@417 622 }
Chris@417 623
Chris@425 624 void MainWindow::hgIgnore()
Chris@425 625 {
Chris@425 626 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@425 627 // that one is a good idea, let's require the user to select
Chris@425 628
Chris@425 629 hgIgnoreFiles(m_hgTabs->getSelectedAddableFiles());
Chris@425 630 }
Chris@425 631
Chris@417 632 void MainWindow::hgEditIgnore()
Chris@417 633 {
Chris@417 634 if (!QDir(m_workFolderPath).exists()) return;
Chris@417 635
Chris@417 636 initHgIgnore();
Chris@417 637
Chris@417 638 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@476 639
Chris@476 640 QFile f(hgIgnorePath);
Chris@476 641 if (!f.exists()) return; // shouldn't happen (after initHgIgnore called)
Chris@476 642
Chris@476 643 if (!f.open(QFile::ReadOnly)) return;
Chris@476 644 QTextStream sin(&f);
Chris@476 645 QString all = sin.readAll();
Chris@476 646 f.close();
Chris@476 647
Chris@476 648 QDialog d;
Chris@476 649 QGridLayout layout;
Chris@476 650 d.setLayout(&layout);
Chris@476 651
Chris@476 652 int row = 0;
Chris@476 653 layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs?
Chris@476 654
Chris@476 655 QTextEdit ed;
Chris@476 656 ed.setAcceptRichText(false);
Chris@476 657 ed.setLineWrapMode(QTextEdit::NoWrap);
Chris@476 658 layout.setRowStretch(row, 10);
Chris@476 659 layout.addWidget(&ed, row++, 0);
Chris@179 660
Chris@476 661 QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
Chris@476 662 connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()),
Chris@476 663 &d, SLOT(accept()));
Chris@476 664 connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
Chris@476 665 &d, SLOT(reject()));
Chris@476 666 layout.addWidget(&bb, row++, 0);
Chris@476 667
Chris@476 668 ed.document()->setPlainText(all);
Chris@476 669
Chris@476 670 d.resize(QSize(300, 400));
Chris@476 671
Chris@476 672 if (d.exec() == QDialog::Accepted) {
Chris@476 673 if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
Chris@476 674 QMessageBox::critical(this, tr("Write failed"),
Chris@476 675 tr("Failed to open file %1 for writing")
Chris@476 676 .arg(f.fileName()));
Chris@476 677 return;
Chris@476 678 }
Chris@476 679 QTextStream sout(&f);
Chris@476 680 sout << ed.document()->toPlainText();
Chris@476 681 f.close();
Chris@179 682 }
Chris@179 683 }
Chris@179 684
Chris@421 685 static QString regexEscape(QString filename)
Chris@421 686 {
Chris@421 687 return filename
Chris@421 688 .replace(".", "\\.")
Chris@421 689 .replace("[", "\\[")
Chris@421 690 .replace("]", "\\]")
Chris@421 691 .replace("(", "\\(")
Chris@421 692 .replace(")", "\\)")
Chris@421 693 .replace("?", "\\?");
Chris@421 694 }
Chris@421 695
Chris@326 696 void MainWindow::hgIgnoreFiles(QStringList files)
Chris@326 697 {
Chris@417 698 if (!QDir(m_workFolderPath).exists() || files.empty()) return;
Chris@413 699
Chris@413 700 // we should:
Chris@413 701 //
Chris@413 702 // * show the user the list of file names selected
Chris@413 703 //
Chris@413 704 // * offer a choice (depending on the files selected?)
Chris@413 705 //
Chris@413 706 // - ignore only these files
Chris@413 707 //
Chris@413 708 // - ignore files with these names, in any subdirectories?
Chris@413 709 //
Chris@413 710 // - ignore all files with this extension (if they have a common
Chris@413 711 // extension)?
Chris@413 712 //
Chris@413 713 // - ignore all files with these extensions (if they have any
Chris@413 714 // extensions?)
Chris@413 715
Chris@414 716 DEBUG << "MainWindow::hgIgnoreFiles: File names are:" << endl;
Chris@414 717 foreach (QString file, files) DEBUG << file << endl;
Chris@414 718
Chris@414 719 QSet<QString> suffixes;
Chris@414 720 foreach (QString file, files) {
Chris@414 721 QString s = QFileInfo(file).suffix();
Chris@414 722 if (s != "") suffixes.insert(s);
Chris@414 723 }
Chris@414 724
Chris@419 725 QString directory;
Chris@429 726 int dirCount = 0;
Chris@419 727 foreach (QString file, files) {
Chris@419 728 QString d = QFileInfo(file).path();
Chris@419 729 if (d != directory) {
Chris@419 730 ++dirCount;
Chris@419 731 directory = d;
Chris@419 732 }
Chris@419 733 }
Chris@421 734 if (dirCount != 1 || directory == ".") directory = "";
Chris@419 735
Chris@414 736 HgIgnoreDialog::IgnoreType itype =
Chris@415 737 HgIgnoreDialog::confirmIgnore
Chris@419 738 (this, files, QStringList::fromSet(suffixes), directory);
Chris@414 739
Chris@416 740 DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl;
Chris@417 741
Chris@421 742 if (itype == HgIgnoreDialog::IgnoreNothing) return;
Chris@421 743
Chris@417 744 // Now, .hgignore can be switched from regex to glob syntax
Chris@417 745 // part-way through -- and glob is much simpler for us, so we
Chris@417 746 // should do that if it's in regex mode at the end of the file.
Chris@417 747
Chris@417 748 initHgIgnore();
Chris@417 749
Chris@417 750 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@417 751
Chris@417 752 // hgignore file should now exist (initHgIgnore should have
Chris@417 753 // created it if it didn't). Check for glob status first
Chris@417 754
Chris@417 755 QFile f(hgIgnorePath);
Chris@417 756 if (!f.exists()) {
Chris@417 757 std::cerr << "MainWindow::ignoreFiles: Internal error: .hgignore file not found (even though we were supposed to have created it)" << std::endl;
Chris@417 758 return;
Chris@417 759 }
Chris@417 760
Chris@417 761 f.open(QFile::ReadOnly);
Chris@417 762 bool glob = false;
Chris@417 763 while (!f.atEnd()) {
Chris@417 764 QByteArray ba = f.readLine();
Chris@417 765 QString s = QString::fromLocal8Bit(ba).trimmed();
Chris@417 766 if (s.startsWith("syntax:")) {
Chris@417 767 if (s.endsWith("glob")) {
Chris@417 768 glob = true;
Chris@417 769 } else {
Chris@417 770 glob = false;
Chris@417 771 }
Chris@417 772 }
Chris@417 773 }
Chris@417 774 f.close();
Chris@417 775
Chris@417 776 f.open(QFile::Append);
Chris@417 777 QTextStream out(&f);
Chris@417 778
Chris@417 779 if (!glob) {
Chris@417 780 out << "syntax: glob" << endl;
Chris@417 781 }
Chris@417 782
Chris@421 783 QString info = "<qt><h3>" + tr("Ignored files") + "</h3><p>";
Chris@421 784 info += tr("The following lines have been added to the .hgignore file for this working copy:");
Chris@421 785 info += "</p><code>";
Chris@421 786
Chris@421 787 QStringList args;
Chris@417 788 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
Chris@421 789 args = QStringList::fromSet(suffixes);
Chris@421 790 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
Chris@421 791 args = files;
Chris@421 792 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
Chris@421 793 QSet<QString> names;
Chris@421 794 foreach (QString f, files) {
Chris@421 795 names << QFileInfo(f).fileName();
Chris@417 796 }
Chris@421 797 args = QStringList::fromSet(names);
Chris@421 798 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
Chris@421 799 args << directory;
Chris@421 800 }
Chris@421 801
Chris@421 802 bool first = true;
Chris@421 803
Chris@421 804 foreach (QString a, args) {
Chris@421 805 QString line;
Chris@421 806 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
Chris@421 807 line = "*." + a;
Chris@421 808 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
Chris@421 809 // Doesn't seem to be possible to do this with a glob,
Chris@421 810 // because the glob is always unanchored and there is no
Chris@421 811 // equivalent of ^ to anchor it
chris@423 812 line = "re:^" + regexEscape(a) + "$";
Chris@421 813 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
Chris@421 814 line = a;
Chris@421 815 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
Chris@421 816 line = "re:^" + regexEscape(a) + "/";
Chris@418 817 }
Chris@421 818 if (line != "") {
Chris@421 819 out << line << endl;
Chris@421 820 if (!first) info += "<br>";
Chris@421 821 first = false;
Chris@421 822 info += xmlEncode(line);
Chris@417 823 }
Chris@417 824 }
Chris@417 825
Chris@419 826 f.close();
Chris@419 827
Chris@421 828 info += "</code></qt>";
Chris@421 829
Chris@421 830 QMessageBox::information(this, tr("Ignored files"),
Chris@421 831 info);
Chris@421 832
Chris@417 833 hgRefresh();
Chris@326 834 }
Chris@326 835
Chris@326 836 void MainWindow::hgUnIgnoreFiles(QStringList files)
Chris@326 837 {
Chris@421 838 // Not implemented: edit the .hgignore instead
Chris@421 839 hgEditIgnore();
Chris@326 840 }
Chris@326 841
Chris@239 842 QString MainWindow::getDiffBinaryName()
Chris@179 843 {
Chris@179 844 QSettings settings;
Chris@179 845 settings.beginGroup("Locations");
Chris@239 846 return settings.value("extdiffbinary", "").toString();
Chris@179 847 }
Chris@179 848
Chris@239 849 QString MainWindow::getMergeBinaryName()
Chris@179 850 {
Chris@179 851 QSettings settings;
Chris@179 852 settings.beginGroup("Locations");
Chris@239 853 return settings.value("mergebinary", "").toString();
Chris@179 854 }
Chris@179 855
Chris@168 856 void MainWindow::hgShowSummary()
Chris@168 857 {
Chris@168 858 QStringList params;
Chris@168 859
Chris@168 860 params << "diff" << "--stat";
Chris@168 861
Chris@288 862 m_runner->requestAction(HgAction(ACT_UNCOMMITTED_SUMMARY, m_workFolderPath, params));
Chris@168 863 }
Chris@168 864
jtkorhonen@0 865 void MainWindow::hgFolderDiff()
jtkorhonen@0 866 {
Chris@326 867 hgDiffFiles(QStringList());
Chris@326 868 }
Chris@326 869
Chris@326 870 void MainWindow::hgDiffFiles(QStringList files)
Chris@326 871 {
Chris@239 872 QString diff = getDiffBinaryName();
Chris@179 873 if (diff == "") return;
Chris@112 874
Chris@109 875 QStringList params;
jtkorhonen@0 876
Chris@112 877 // Diff parent against working folder (folder diff)
Chris@112 878
Chris@148 879 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 880 params << "--program" << diff;
Chris@109 881
Chris@331 882 params << "--" << files; // may be none: whole dir
Chris@273 883
Chris@284 884 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
jtkorhonen@0 885 }
jtkorhonen@0 886
Chris@148 887 void MainWindow::hgDiffToCurrent(QString id)
jtkorhonen@0 888 {
Chris@239 889 QString diff = getDiffBinaryName();
Chris@179 890 if (diff == "") return;
Chris@163 891
Chris@148 892 QStringList params;
jtkorhonen@0 893
Chris@148 894 // Diff given revision against working folder
jtkorhonen@0 895
Chris@148 896 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 897 params << "--program" << diff;
Chris@153 898 params << "--rev" << Changeset::hashOf(id);
Chris@148 899
Chris@284 900 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
jtkorhonen@0 901 }
jtkorhonen@0 902
Chris@148 903 void MainWindow::hgDiffToParent(QString child, QString parent)
Chris@148 904 {
Chris@239 905 QString diff = getDiffBinaryName();
Chris@179 906 if (diff == "") return;
Chris@163 907
Chris@148 908 QStringList params;
Chris@148 909
Chris@281 910 // Diff given revision against parent revision
Chris@148 911
Chris@148 912 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 913 params << "--program" << diff;
Chris@153 914 params << "--rev" << Changeset::hashOf(parent)
Chris@153 915 << "--rev" << Changeset::hashOf(child);
Chris@148 916
Chris@284 917 m_runner->requestAction(HgAction(ACT_CHGSETDIFF, m_workFolderPath, params));
Chris@273 918 }
Chris@326 919
Chris@273 920
Chris@289 921 void MainWindow::hgShowSummaryFor(Changeset *cs)
Chris@288 922 {
Chris@288 923 QStringList params;
Chris@288 924
Chris@289 925 // This will pick a default parent if there is more than one
Chris@289 926 // (whereas with diff we need to supply one). But it does need a
Chris@289 927 // bit more parsing
Chris@289 928 params << "log" << "--stat" << "--rev" << Changeset::hashOf(cs->id());
Chris@289 929
Chris@289 930 m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath,
Chris@289 931 params, cs));
Chris@148 932 }
Chris@148 933
jtkorhonen@0 934
jtkorhonen@0 935 void MainWindow::hgUpdate()
jtkorhonen@0 936 {
Chris@109 937 QStringList params;
jtkorhonen@0 938
Chris@109 939 params << "update";
Chris@109 940
Chris@284 941 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
jtkorhonen@0 942 }
jtkorhonen@0 943
jtkorhonen@0 944
Chris@148 945 void MainWindow::hgUpdateToRev(QString id)
jtkorhonen@0 946 {
Chris@148 947 QStringList params;
jtkorhonen@0 948
Chris@153 949 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
jtkorhonen@0 950
Chris@284 951 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
jtkorhonen@0 952 }
jtkorhonen@0 953
jtkorhonen@0 954
jtkorhonen@0 955 void MainWindow::hgRevert()
jtkorhonen@0 956 {
Chris@326 957 hgRevertFiles(QStringList());
Chris@326 958 }
Chris@326 959
Chris@326 960 void MainWindow::hgRevertFiles(QStringList files)
Chris@326 961 {
Chris@109 962 QStringList params;
Chris@109 963 QString comment;
Chris@237 964 bool all = false;
Chris@98 965
Chris@284 966 QStringList allFiles = m_hgTabs->getAllRevertableFiles();
Chris@237 967 if (files.empty() || files == allFiles) {
Chris@237 968 files = allFiles;
Chris@237 969 all = true;
Chris@237 970 }
Chris@237 971
Chris@237 972 QString subsetNote;
Chris@237 973 if (!all) {
Chris@237 974 subsetNote = tr("<p><b>Note:</b> you are reverting only the files you have selected, not all of the files that have been changed!");
Chris@237 975 }
Chris@155 976
Chris@155 977 QString rf(tr("Revert files"));
Chris@237 978
Chris@237 979 // Set up params before asking for confirmation, because there is
Chris@237 980 // a failure case here that we would need to report on early
Chris@237 981
Chris@284 982 DEBUG << "hgRevert: m_justMerged = " << m_justMerged << ", m_mergeTargetRevision = " << m_mergeTargetRevision << endl;
Chris@273 983
Chris@284 984 if (m_justMerged) {
Chris@237 985
Chris@237 986 // This is a little fiddly. The proper way to "revert" the
Chris@237 987 // whole of an uncommitted merge is with "hg update --clean ."
Chris@237 988 // But if the user has selected only some files, we're sort of
Chris@237 989 // promising to revert only those, which means we need to
Chris@237 990 // specify which parent to revert to. We can only do that if
Chris@237 991 // we have a record of it, which we do if you just did the
Chris@237 992 // merge from within easyhg but don't if you've exited and
Chris@237 993 // restarted, or changed repository, since then. Hmmm.
Chris@237 994
Chris@237 995 if (all) {
Chris@237 996 params << "update" << "--clean" << ".";
Chris@237 997 } else {
Chris@284 998 if (m_mergeTargetRevision != "") {
Chris@237 999 params << "revert" << "--rev"
Chris@284 1000 << Changeset::hashOf(m_mergeTargetRevision)
Chris@237 1001 << "--" << files;
Chris@237 1002 } else {
Chris@237 1003 QMessageBox::information
Chris@237 1004 (this, tr("Unable to revert"),
Chris@237 1005 tr("<qt><b>Sorry, unable to revert these files</b><br><br>EasyMercurial can only revert a subset of files during a merge if it still has a record of which parent was the original merge target; that information is no longer available.<br><br>This is a limitation of EasyMercurial. Consider reverting all files, or using hg revert with a specific revision at the command-line instead.</qt>"));
Chris@237 1006 return;
Chris@237 1007 }
Chris@237 1008 }
Chris@237 1009 } else {
Chris@237 1010 params << "revert" << "--" << files;
Chris@237 1011 }
Chris@237 1012
Chris@109 1013 if (ConfirmCommentDialog::confirmDangerousFilesAction
Chris@109 1014 (this,
Chris@155 1015 rf,
Chris@237 1016 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 1017 .arg(tr("You are about to <b>revert</b> the following files to their previous committed state.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."))
Chris@237 1018 .arg(subsetNote),
Chris@237 1019 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 1020 .arg(tr("You are about to <b>revert</b> %n file(s).<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed.", "", files.size()))
Chris@237 1021 .arg(subsetNote),
Chris@193 1022 files,
Chris@365 1023 tr("Re&vert"))) {
Chris@163 1024
Chris@284 1025 m_lastRevertedFiles = files;
Chris@109 1026
Chris@284 1027 m_runner->requestAction(HgAction(ACT_REVERT, m_workFolderPath, params));
jtkorhonen@0 1028 }
jtkorhonen@0 1029 }
jtkorhonen@0 1030
Chris@163 1031
Chris@361 1032 void MainWindow::hgRenameFiles(QStringList files)
Chris@361 1033 {
Chris@361 1034 QString renameTo;
Chris@361 1035
Chris@361 1036 QString file;
Chris@361 1037 if (files.empty()) return;
Chris@361 1038 file = files[0];
Chris@361 1039
Chris@361 1040 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@361 1041 (this,
Chris@361 1042 tr("Rename"),
Chris@361 1043 tr("Rename <code>%1</code> to:").arg(xmlEncode(file)),
Chris@361 1044 renameTo,
Chris@365 1045 tr("Re&name"))) {
Chris@361 1046
Chris@361 1047 if (renameTo != "" && renameTo != file) {
Chris@361 1048
Chris@361 1049 QStringList params;
Chris@361 1050
Chris@361 1051 params << "rename" << "--" << file << renameTo;
Chris@361 1052
Chris@361 1053 m_runner->requestAction(HgAction(ACT_RENAME_FILE, m_workFolderPath, params));
Chris@361 1054 }
Chris@361 1055 }
Chris@361 1056 }
Chris@361 1057
Chris@361 1058
Chris@361 1059 void MainWindow::hgCopyFiles(QStringList files)
Chris@361 1060 {
Chris@361 1061 QString copyTo;
Chris@361 1062
Chris@361 1063 QString file;
Chris@361 1064 if (files.empty()) return;
Chris@361 1065 file = files[0];
Chris@361 1066
Chris@361 1067 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@361 1068 (this,
Chris@361 1069 tr("Copy"),
Chris@361 1070 tr("Copy <code>%1</code> to:").arg(xmlEncode(file)),
Chris@361 1071 copyTo,
Chris@365 1072 tr("Co&py"))) {
Chris@361 1073
Chris@361 1074 if (copyTo != "" && copyTo != file) {
Chris@361 1075
Chris@361 1076 QStringList params;
Chris@361 1077
Chris@361 1078 params << "copy" << "--" << file << copyTo;
Chris@361 1079
Chris@361 1080 m_runner->requestAction(HgAction(ACT_COPY_FILE, m_workFolderPath, params));
Chris@361 1081 }
Chris@361 1082 }
Chris@361 1083 }
Chris@361 1084
Chris@361 1085
Chris@326 1086 void MainWindow::hgMarkFilesResolved(QStringList files)
Chris@163 1087 {
Chris@163 1088 QStringList params;
Chris@163 1089
Chris@163 1090 params << "resolve" << "--mark";
Chris@163 1091
Chris@163 1092 if (files.empty()) {
Chris@163 1093 params << "--all";
Chris@163 1094 } else {
Chris@164 1095 params << "--" << files;
Chris@163 1096 }
Chris@163 1097
Chris@284 1098 m_runner->requestAction(HgAction(ACT_RESOLVE_MARK, m_workFolderPath, params));
Chris@163 1099 }
Chris@163 1100
Chris@163 1101
Chris@326 1102 void MainWindow::hgRedoMerge()
Chris@326 1103 {
Chris@326 1104 hgRedoFileMerges(QStringList());
Chris@326 1105 }
Chris@326 1106
Chris@326 1107
Chris@326 1108 void MainWindow::hgRedoFileMerges(QStringList files)
jtkorhonen@33 1109 {
Chris@109 1110 QStringList params;
jtkorhonen@33 1111
Chris@163 1112 params << "resolve";
Chris@163 1113
Chris@239 1114 QString merge = getMergeBinaryName();
Chris@179 1115 if (merge != "") {
Chris@179 1116 params << "--tool" << merge;
Chris@163 1117 }
Chris@163 1118
Chris@163 1119 if (files.empty()) {
Chris@163 1120 params << "--all";
Chris@163 1121 } else {
Chris@164 1122 params << "--" << files;
Chris@163 1123 }
Chris@163 1124
Chris@284 1125 if (m_currentParents.size() == 1) {
Chris@284 1126 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@237 1127 }
Chris@237 1128
Chris@284 1129 m_runner->requestAction(HgAction(ACT_RETRY_MERGE, m_workFolderPath, params));
Chris@273 1130
Chris@284 1131 m_mergeCommitComment = tr("Merge");
jtkorhonen@33 1132 }
Chris@326 1133
jtkorhonen@33 1134
jtkorhonen@0 1135 void MainWindow::hgMerge()
jtkorhonen@0 1136 {
Chris@284 1137 if (m_hgTabs->canResolve()) {
Chris@326 1138 hgRedoMerge();
Chris@163 1139 return;
Chris@163 1140 }
Chris@163 1141
Chris@109 1142 QStringList params;
jtkorhonen@0 1143
Chris@109 1144 params << "merge";
Chris@163 1145
Chris@239 1146 QString merge = getMergeBinaryName();
Chris@179 1147 if (merge != "") {
Chris@179 1148 params << "--tool" << merge;
Chris@163 1149 }
Chris@163 1150
Chris@284 1151 if (m_currentParents.size() == 1) {
Chris@284 1152 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@163 1153 }
Chris@163 1154
Chris@284 1155 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
Chris@273 1156
Chris@284 1157 m_mergeCommitComment = tr("Merge");
jtkorhonen@0 1158 }
jtkorhonen@0 1159
jtkorhonen@0 1160
Chris@148 1161 void MainWindow::hgMergeFrom(QString id)
Chris@148 1162 {
Chris@148 1163 QStringList params;
Chris@148 1164
Chris@148 1165 params << "merge";
Chris@153 1166 params << "--rev" << Changeset::hashOf(id);
Chris@163 1167
Chris@239 1168 QString merge = getMergeBinaryName();
Chris@179 1169 if (merge != "") {
Chris@179 1170 params << "--tool" << merge;
Chris@163 1171 }
Chris@148 1172
Chris@284 1173 if (m_currentParents.size() == 1) {
Chris@284 1174 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@237 1175 }
Chris@237 1176
Chris@284 1177 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
Chris@273 1178
Chris@284 1179 m_mergeCommitComment = "";
Chris@273 1180
Chris@284 1181 foreach (Changeset *cs, m_currentHeads) {
Chris@284 1182 if (cs->id() == id && !cs->isOnBranch(m_currentBranch)) {
Chris@157 1183 if (cs->branch() == "" || cs->branch() == "default") {
Chris@284 1184 m_mergeCommitComment = tr("Merge from the default branch");
Chris@157 1185 } else {
Chris@284 1186 m_mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
Chris@157 1187 }
Chris@157 1188 }
Chris@157 1189 }
Chris@157 1190
Chris@284 1191 if (m_mergeCommitComment == "") {
Chris@284 1192 m_mergeCommitComment = tr("Merge from %1").arg(id);
Chris@157 1193 }
Chris@148 1194 }
Chris@148 1195
Chris@148 1196
jtkorhonen@0 1197 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 1198 {
Chris@109 1199 QStringList params;
jtkorhonen@0 1200
Chris@284 1201 if (!QDir(m_workFolderPath).exists()) {
Chris@284 1202 if (!QDir().mkpath(m_workFolderPath)) {
Chris@109 1203 DEBUG << "hgCloneFromRemote: Failed to create target path "
Chris@284 1204 << m_workFolderPath << endl;
Chris@109 1205 //!!! report error
Chris@109 1206 return;
Chris@104 1207 }
Chris@109 1208 }
Chris@104 1209
Chris@284 1210 params << "clone" << m_remoteRepoPath << m_workFolderPath;
Chris@109 1211
Chris@287 1212 updateWorkFolderAndRepoNames();
Chris@284 1213 m_hgTabs->updateWorkFolderFileList("");
Chris@273 1214
Chris@284 1215 m_runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, m_workFolderPath, params));
jtkorhonen@0 1216 }
jtkorhonen@0 1217
jtkorhonen@0 1218 void MainWindow::hgInit()
jtkorhonen@0 1219 {
Chris@109 1220 QStringList params;
jtkorhonen@0 1221
Chris@109 1222 params << "init";
Chris@284 1223 params << m_workFolderPath;
Chris@273 1224
Chris@284 1225 m_runner->requestAction(HgAction(ACT_INIT, m_workFolderPath, params));
jtkorhonen@0 1226 }
jtkorhonen@0 1227
jtkorhonen@0 1228 void MainWindow::hgIncoming()
jtkorhonen@0 1229 {
Chris@109 1230 QStringList params;
jtkorhonen@0 1231
Chris@284 1232 params << "incoming" << "--newest-first" << m_remoteRepoPath;
Chris@125 1233 params << "--template" << Changeset::getLogTemplate();
jtkorhonen@0 1234
Chris@284 1235 m_runner->requestAction(HgAction(ACT_INCOMING, m_workFolderPath, params));
jtkorhonen@0 1236 }
jtkorhonen@0 1237
jtkorhonen@0 1238 void MainWindow::hgPull()
jtkorhonen@0 1239 {
Chris@193 1240 if (ConfirmCommentDialog::confirm
Chris@126 1241 (this, tr("Confirm pull"),
Chris@299 1242 tr("<qt><h3>Pull from remote repository?</h3></qt>"),
Chris@299 1243 tr("<qt><p>You are about to pull changes from the remote repository at <code>%1</code>.</p></qt>").arg(xmlEncode(m_remoteRepoPath)),
Chris@365 1244 tr("&Pull"))) {
jtkorhonen@0 1245
Chris@126 1246 QStringList params;
Chris@284 1247 params << "pull" << m_remoteRepoPath;
Chris@284 1248 m_runner->requestAction(HgAction(ACT_PULL, m_workFolderPath, params));
Chris@126 1249 }
jtkorhonen@0 1250 }
jtkorhonen@0 1251
jtkorhonen@0 1252 void MainWindow::hgPush()
jtkorhonen@0 1253 {
Chris@363 1254 if (m_remoteRepoPath.isEmpty()) {
Chris@363 1255 changeRemoteRepo(true);
Chris@363 1256 if (m_remoteRepoPath.isEmpty()) return;
Chris@363 1257 }
Chris@363 1258
Chris@356 1259 QString uncommittedNote;
Chris@356 1260 if (m_hgTabs->canCommit()) {
Chris@356 1261 uncommittedNote = tr("<p><b>Note:</b> You have uncommitted changes. If you want to push these changes to the remote repository, you need to commit them first.");
Chris@356 1262 }
Chris@356 1263
Chris@193 1264 if (ConfirmCommentDialog::confirm
Chris@126 1265 (this, tr("Confirm push"),
Chris@299 1266 tr("<qt><h3>Push to remote repository?</h3></qt>"),
Chris@356 1267 tr("<qt><p>You are about to push your commits to the remote repository at <code>%1</code>.</p>%2</qt>").arg(xmlEncode(m_remoteRepoPath)).arg(uncommittedNote),
Chris@365 1268 tr("&Push"))) {
jtkorhonen@0 1269
Chris@126 1270 QStringList params;
Chris@284 1271 params << "push" << "--new-branch" << m_remoteRepoPath;
Chris@284 1272 m_runner->requestAction(HgAction(ACT_PUSH, m_workFolderPath, params));
Chris@126 1273 }
jtkorhonen@0 1274 }
jtkorhonen@0 1275
Chris@182 1276 QStringList MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 1277 {
Chris@182 1278 QStringList ret;
jtkorhonen@26 1279 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 1280
Chris@182 1281 for (int i = 0; i < ifaces.count(); i++) {
jtkorhonen@26 1282 QNetworkInterface iface = ifaces.at(i);
Chris@182 1283 if (iface.flags().testFlag(QNetworkInterface::IsUp)
Chris@182 1284 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
Chris@182 1285 for (int j=0; j<iface.addressEntries().count(); j++) {
jtkorhonen@28 1286 QHostAddress tmp = iface.addressEntries().at(j).ip();
Chris@182 1287 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
Chris@182 1288 ret.push_back(tmp.toString());
jtkorhonen@24 1289 }
jtkorhonen@24 1290 }
jtkorhonen@22 1291 }
jtkorhonen@17 1292 }
jtkorhonen@28 1293 return ret;
jtkorhonen@28 1294 }
jtkorhonen@17 1295
Chris@120 1296 void MainWindow::clearState()
Chris@120 1297 {
Chris@305 1298 DEBUG << "MainWindow::clearState" << endl;
Chris@284 1299 foreach (Changeset *cs, m_currentParents) delete cs;
Chris@284 1300 m_currentParents.clear();
Chris@284 1301 foreach (Changeset *cs, m_currentHeads) delete cs;
Chris@284 1302 m_currentHeads.clear();
Chris@506 1303 m_closedHeadIds.clear();
Chris@284 1304 m_currentBranch = "";
Chris@284 1305 m_lastStatOutput = "";
Chris@284 1306 m_lastRevertedFiles.clear();
Chris@284 1307 m_mergeTargetRevision = "";
Chris@284 1308 m_mergeCommitComment = "";
Chris@284 1309 m_stateUnknown = true;
Chris@284 1310 m_needNewLog = true;
Chris@284 1311 if (m_fsWatcher) {
Chris@241 1312 delete m_fsWatcherGeneralTimer;
Chris@241 1313 m_fsWatcherGeneralTimer = 0;
Chris@241 1314 delete m_fsWatcherRestoreTimer;
Chris@241 1315 m_fsWatcherRestoreTimer = 0;
Chris@284 1316 delete m_fsWatcher;
Chris@284 1317 m_fsWatcher = 0;
Chris@199 1318 }
Chris@120 1319 }
jtkorhonen@17 1320
jtkorhonen@11 1321 void MainWindow::hgServe()
jtkorhonen@11 1322 {
Chris@109 1323 QStringList params;
Chris@109 1324 QString msg;
jtkorhonen@11 1325
Chris@182 1326 QStringList addrs = listAllUpIpV4Addresses();
Chris@182 1327
Chris@182 1328 if (addrs.empty()) {
Chris@182 1329 QMessageBox::critical
Chris@182 1330 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
Chris@182 1331 return;
Chris@182 1332 }
Chris@182 1333
Chris@182 1334 //!!! should find available port as well
Chris@182 1335
Chris@182 1336 QTextStream ts(&msg);
Chris@429 1337 ts << QString("<qt><h3>%1</h3><p>%2</p>")
Chris@425 1338 .arg(tr("Sharing Repository"))
Chris@429 1339 .arg(tr("Your local repository is now being made temporarily available via HTTP for workgroup access."));
Chris@429 1340 if (addrs.size() > 1) {
Chris@429 1341 ts << QString("<p>%3</p>")
Chris@429 1342 .arg(tr("Users who have network access to your computer can now clone your repository, by using one of the following URLs as a remote location:"));
Chris@429 1343 } else {
Chris@429 1344 ts << QString("<p>%3</p>")
Chris@429 1345 .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:"));
Chris@429 1346 }
Chris@182 1347 foreach (QString addr, addrs) {
Chris@182 1348 ts << QString("<pre>&nbsp;&nbsp;http://%1:8000</pre>").arg(xmlEncode(addr));
Chris@182 1349 }
Chris@425 1350 ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>");
Chris@182 1351 ts.flush();
Chris@182 1352
Chris@109 1353 params << "serve";
jtkorhonen@11 1354
Chris@284 1355 m_runner->requestAction(HgAction(ACT_SERVE, m_workFolderPath, params));
Chris@109 1356
Chris@425 1357 QMessageBox::information(this, tr("Share Repository"), msg, QMessageBox::Close);
Chris@182 1358
Chris@284 1359 m_runner->killCurrentActions();
jtkorhonen@11 1360 }
jtkorhonen@11 1361
Chris@64 1362 void MainWindow::startupDialog()
Chris@64 1363 {
Chris@64 1364 StartupDialog *dlg = new StartupDialog(this);
Chris@284 1365 if (dlg->exec()) m_firstStart = false;
Chris@344 1366 else exit(0);
Chris@64 1367 }
jtkorhonen@11 1368
Chris@69 1369 void MainWindow::open()
Chris@69 1370 {
Chris@86 1371 bool done = false;
Chris@69 1372
Chris@86 1373 while (!done) {
Chris@69 1374
Chris@86 1375 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 1376 (tr("Open Repository"),
Chris@86 1377 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 1378 this);
Chris@69 1379
Chris@345 1380 d->addChoice("remote",
Chris@345 1381 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@345 1382 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@345 1383 MultiChoiceDialog::UrlToDirectoryArg);
Chris@345 1384
Chris@339 1385 d->addChoice("local",
Chris@339 1386 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@339 1387 tr("Open an existing local Mercurial repository."),
Chris@339 1388 MultiChoiceDialog::DirectoryArg);
Chris@339 1389
Chris@339 1390 d->addChoice("init",
Chris@339 1391 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@339 1392 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@339 1393 MultiChoiceDialog::DirectoryArg);
Chris@339 1394
Chris@248 1395 QSettings settings;
Chris@484 1396 settings.beginGroup("");
Chris@359 1397 QString lastChoice = settings.value("lastopentype", "remote").toString();
Chris@248 1398 if (lastChoice != "local" &&
Chris@248 1399 lastChoice != "remote" &&
Chris@248 1400 lastChoice != "init") {
Chris@359 1401 lastChoice = "remote";
Chris@248 1402 }
Chris@248 1403
Chris@248 1404 d->setCurrentChoice(lastChoice);
Chris@86 1405
Chris@86 1406 if (d->exec() == QDialog::Accepted) {
Chris@86 1407
Chris@86 1408 QString choice = d->getCurrentChoice();
Chris@248 1409 settings.setValue("lastopentype", choice);
Chris@248 1410
Chris@86 1411 QString arg = d->getArgument().trimmed();
Chris@86 1412
Chris@86 1413 bool result = false;
Chris@86 1414
Chris@86 1415 if (choice == "local") {
Chris@86 1416 result = openLocal(arg);
Chris@86 1417 } else if (choice == "remote") {
Chris@86 1418 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 1419 } else if (choice == "init") {
Chris@86 1420 result = openInit(arg);
Chris@86 1421 }
Chris@86 1422
Chris@86 1423 if (result) {
Chris@86 1424 enableDisableActions();
Chris@120 1425 clearState();
Chris@109 1426 hgQueryPaths();
Chris@91 1427 done = true;
Chris@91 1428 }
Chris@86 1429
Chris@86 1430 } else {
Chris@86 1431
Chris@86 1432 // cancelled
Chris@86 1433 done = true;
Chris@69 1434 }
Chris@79 1435
Chris@86 1436 delete d;
Chris@69 1437 }
Chris@69 1438 }
Chris@69 1439
Chris@359 1440 void MainWindow::recentMenuActivated()
Chris@359 1441 {
Chris@359 1442 QAction *a = qobject_cast<QAction *>(sender());
Chris@359 1443 if (!a) return;
Chris@359 1444 QString local = a->text();
Chris@359 1445 open(local);
Chris@359 1446 }
Chris@359 1447
Chris@182 1448 void MainWindow::changeRemoteRepo()
Chris@182 1449 {
Chris@363 1450 changeRemoteRepo(false);
Chris@363 1451 }
Chris@363 1452
Chris@363 1453 void MainWindow::changeRemoteRepo(bool initial)
Chris@363 1454 {
Chris@183 1455 // This will involve rewriting the local .hgrc
Chris@183 1456
Chris@284 1457 QDir hgDir(m_workFolderPath + "/.hg");
Chris@184 1458 if (!hgDir.exists()) {
Chris@184 1459 //!!! visible error!
Chris@184 1460 return;
Chris@184 1461 }
Chris@184 1462
Chris@284 1463 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
Chris@184 1464 if (hgrc.exists() && !hgrc.isWritable()) {
Chris@183 1465 //!!! visible error!
Chris@183 1466 return;
Chris@183 1467 }
Chris@183 1468
Chris@183 1469 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@363 1470 (tr("Set Remote Location"),
Chris@363 1471 tr("<qt><big>Set the remote location</big></qt>"),
Chris@183 1472 this);
Chris@183 1473
Chris@363 1474 QString explanation;
Chris@363 1475 if (initial) {
Chris@363 1476 explanation = tr("Provide a URL to use for push and pull actions from the current local repository.<br>This will be the default for subsequent pushes and pulls.<br>You can change it using &ldquo;Set Remote Location&rdquo; on the File menu.");
Chris@363 1477 } else {
Chris@363 1478 explanation = tr("Provide a new URL to use for push and pull actions from the current local repository.");
Chris@363 1479 }
Chris@363 1480
Chris@183 1481 d->addChoice("remote",
Chris@183 1482 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@363 1483 explanation,
Chris@183 1484 MultiChoiceDialog::UrlArg);
Chris@183 1485
Chris@183 1486 if (d->exec() == QDialog::Accepted) {
Chris@210 1487
Chris@210 1488 // New block to ensure QSettings is deleted before
Chris@210 1489 // hgQueryPaths called. NB use of absoluteFilePath instead of
Chris@210 1490 // canonicalFilePath, which would fail if the file did not yet
Chris@210 1491 // exist
Chris@210 1492
Chris@210 1493 {
Chris@210 1494 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
Chris@210 1495 s.beginGroup("paths");
Chris@210 1496 s.setValue("default", d->getArgument());
Chris@210 1497 }
Chris@210 1498
Chris@284 1499 m_stateUnknown = true;
Chris@183 1500 hgQueryPaths();
Chris@183 1501 }
Chris@183 1502
Chris@183 1503 delete d;
Chris@182 1504 }
Chris@182 1505
Chris@145 1506 void MainWindow::open(QString local)
Chris@145 1507 {
Chris@145 1508 if (openLocal(local)) {
Chris@145 1509 enableDisableActions();
Chris@145 1510 clearState();
Chris@145 1511 hgQueryPaths();
Chris@145 1512 }
Chris@145 1513 }
Chris@145 1514
Chris@79 1515 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 1516 {
Chris@79 1517 QMessageBox::critical
Chris@79 1518 (this, tr("File chosen"),
Chris@84 1519 tr("<qt><b>Folder required</b><br><br>You asked to open \"%1\".<br>This is a file; to open a repository, you need to choose a folder.</qt>").arg(xmlEncode(arg)));
Chris@79 1520 return false;
Chris@79 1521 }
Chris@79 1522
Chris@248 1523 bool MainWindow::askAboutUnknownFolder(QString arg)
Chris@248 1524 {
Chris@248 1525 bool result = (QMessageBox::question
Chris@248 1526 (this, tr("Path does not exist"),
Chris@248 1527 tr("<qt><b>Path does not exist: create it?</b><br><br>You asked to open a remote repository by cloning it to \"%1\". This folder does not exist, and neither does its parent.<br><br>Would you like to create the parent folder as well?</qt>").arg(xmlEncode(arg)),
Chris@248 1528 QMessageBox::Ok | QMessageBox::Cancel,
Chris@248 1529 QMessageBox::Cancel)
Chris@248 1530 == QMessageBox::Ok);
Chris@248 1531 if (result) {
Chris@248 1532 QDir dir(arg);
Chris@248 1533 dir.cdUp();
Chris@248 1534 if (!dir.mkpath(dir.absolutePath())) {
Chris@248 1535 QMessageBox::critical
Chris@248 1536 (this, tr("Failed to create folder"),
Chris@248 1537 tr("<qt><b>Failed to create folder</b><br><br>Sorry, the path for the parent folder \"%1\" could not be created.</qt>").arg(dir.absolutePath()));
Chris@248 1538 return false;
Chris@248 1539 }
Chris@248 1540 return true;
Chris@248 1541 }
Chris@248 1542 return false;
Chris@248 1543 }
Chris@248 1544
Chris@79 1545 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 1546 {
Chris@79 1547 QMessageBox::critical
Chris@79 1548 (this, tr("Folder does not exist"),
Chris@84 1549 tr("<qt><b>Folder does not exist</b><br><br>You asked to open \"%1\".<br>This folder does not exist, and it cannot be created because its parent does not exist either.</qt>").arg(xmlEncode(arg)));
Chris@84 1550 return false;
Chris@84 1551 }
Chris@84 1552
Chris@84 1553 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 1554 {
Chris@84 1555 QMessageBox::critical
Chris@84 1556 (this, tr("Path is in existing repository"),
Chris@84 1557 tr("<qt><b>Path is in an existing repository</b><br><br>You asked to initialise a repository at \"%1\".<br>This path is already inside an existing repository.</qt>").arg(xmlEncode(arg)));
Chris@84 1558 return false;
Chris@84 1559 }
Chris@84 1560
Chris@84 1561 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 1562 {
Chris@84 1563 QMessageBox::critical
Chris@84 1564 (this, tr("Path is a file"),
Chris@84 1565 tr("<qt><b>Path is a file</b><br><br>You asked to initialise a repository at \"%1\".<br>This is an existing file; it is only possible to initialise in folders.</qt>").arg(xmlEncode(arg)));
Chris@84 1566 return false;
Chris@84 1567 }
Chris@84 1568
Chris@84 1569 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 1570 {
Chris@84 1571 QMessageBox::critical
Chris@84 1572 (this, tr("Path is in existing repository"),
Chris@237 1573 tr("<qt><b>Local path is in an existing repository</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is already inside an existing repository.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@84 1574 return false;
Chris@84 1575 }
Chris@84 1576
Chris@84 1577 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 1578 {
Chris@84 1579 QMessageBox::critical
Chris@84 1580 (this, tr("Path is a file"),
Chris@84 1581 tr("<qt><b>Local path is a file</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is an existing file.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@84 1582 return false;
Chris@84 1583 }
Chris@84 1584
Chris@237 1585 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
Chris@84 1586 {
Chris@348 1587 // If the directory "arg" exists but is empty, then we accept it.
Chris@348 1588
Chris@348 1589 // If the directory "arg" exists and is non-empty, but "arg" plus
Chris@348 1590 // the last path component of "remote" does not exist, then offer
Chris@348 1591 // the latter as an alternative path.
Chris@237 1592
Chris@237 1593 QString offer;
Chris@237 1594
Chris@237 1595 QDir d(arg);
Chris@348 1596
Chris@237 1597 if (d.exists()) {
Chris@348 1598
Chris@348 1599 if (d.entryList(QDir::Dirs | QDir::Files |
Chris@348 1600 QDir::NoDotAndDotDot |
Chris@348 1601 QDir::Hidden | QDir::System).empty()) {
Chris@348 1602 // directory is empty; accept it
Chris@348 1603 return arg;
Chris@348 1604 }
Chris@348 1605
Chris@237 1606 if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
Chris@237 1607 QString rpath = QUrl(remote).path();
Chris@237 1608 if (rpath != "") {
Chris@237 1609 rpath = QDir(rpath).dirName();
Chris@237 1610 if (rpath != "" && !d.exists(rpath)) {
Chris@237 1611 offer = d.filePath(rpath);
Chris@237 1612 }
Chris@237 1613 }
Chris@237 1614 }
Chris@237 1615 }
Chris@237 1616
Chris@237 1617 if (offer != "") {
Chris@237 1618 bool result = (QMessageBox::question
Chris@237 1619 (this, tr("Folder exists"),
Chris@237 1620 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this folder already exists and so cannot be cloned to.<br><br>Would you like to create the new folder \"%2\" instead?</qt>")
Chris@237 1621 .arg(xmlEncode(arg)).arg(xmlEncode(offer)),
Chris@237 1622 QMessageBox::Ok | QMessageBox::Cancel,
Chris@237 1623 QMessageBox::Cancel)
Chris@237 1624 == QMessageBox::Ok);
Chris@237 1625 if (result) return offer;
Chris@237 1626 else return "";
Chris@237 1627 }
Chris@237 1628
Chris@84 1629 QMessageBox::critical
Chris@84 1630 (this, tr("Folder exists"),
Chris@237 1631 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to \"%1\", but this file or folder already exists and so cannot be cloned to.<br>Please provide a different folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@237 1632 return "";
Chris@79 1633 }
Chris@79 1634
Chris@79 1635 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 1636 {
Chris@79 1637 return (QMessageBox::question
Chris@84 1638 (this, tr("Path is inside a repository"),
Chris@86 1639 tr("<qt><b>Open the repository that contains this path?</b><br><br>You asked to open \"%1\".<br>This is not the root folder of a repository.<br>But it is inside a repository, whose root is at \"%2\". <br><br>Would you like to open that repository instead?</qt>")
Chris@79 1640 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 1641 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1642 QMessageBox::Ok)
Chris@79 1643 == QMessageBox::Ok);
Chris@79 1644 }
Chris@79 1645
Chris@79 1646 bool MainWindow::askToInitExisting(QString arg)
Chris@79 1647 {
Chris@79 1648 return (QMessageBox::question
Chris@84 1649 (this, tr("Folder has no repository"),
Chris@359 1650 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder is not a Mercurial working copy.<br><br>Would you like to initialise a repository here?</qt>")
Chris@79 1651 .arg(xmlEncode(arg)),
Chris@79 1652 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1653 QMessageBox::Ok)
Chris@79 1654 == QMessageBox::Ok);
Chris@79 1655 }
Chris@79 1656
Chris@79 1657 bool MainWindow::askToInitNew(QString arg)
Chris@79 1658 {
Chris@79 1659 return (QMessageBox::question
Chris@84 1660 (this, tr("Folder does not exist"),
Chris@84 1661 tr("<qt><b>Initialise a new repository?</b><br><br>You asked to open \"%1\".<br>This folder does not yet exist.<br><br>Would you like to create the folder and initialise a new empty repository in it?</qt>")
Chris@84 1662 .arg(xmlEncode(arg)),
Chris@84 1663 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 1664 QMessageBox::Ok)
Chris@84 1665 == QMessageBox::Ok);
Chris@84 1666 }
Chris@84 1667
Chris@84 1668 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 1669 {
Chris@84 1670 return (QMessageBox::question
Chris@84 1671 (this, tr("Repository exists"),
Chris@84 1672 tr("<qt><b>Open existing repository?</b><br><br>You asked to initialise a new repository at \"%1\".<br>This folder already contains a repository. Would you like to open it?</qt>")
Chris@79 1673 .arg(xmlEncode(arg)),
Chris@79 1674 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1675 QMessageBox::Ok)
Chris@79 1676 == QMessageBox::Ok);
Chris@79 1677 }
Chris@79 1678
Chris@79 1679 bool MainWindow::openLocal(QString local)
Chris@79 1680 {
Chris@79 1681 DEBUG << "open " << local << endl;
Chris@79 1682
Chris@79 1683 FolderStatus status = getFolderStatus(local);
Chris@79 1684 QString containing = getContainingRepoFolder(local);
Chris@79 1685
Chris@79 1686 switch (status) {
Chris@79 1687
Chris@79 1688 case FolderHasRepo:
Chris@79 1689 // fine
Chris@79 1690 break;
Chris@79 1691
Chris@79 1692 case FolderExists:
Chris@79 1693 if (containing != "") {
Chris@79 1694 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1695 local = containing;
Chris@79 1696 } else {
Chris@86 1697 //!!! No -- this is likely to happen far more by accident
Chris@86 1698 // than because the user actually wanted to init something.
Chris@86 1699 // Don't ask, just politely reject.
Chris@79 1700 if (!askToInitExisting(local)) return false;
Chris@79 1701 return openInit(local);
Chris@79 1702 }
Chris@79 1703 break;
Chris@79 1704
Chris@79 1705 case FolderParentExists:
Chris@79 1706 if (containing != "") {
Chris@79 1707 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1708 local = containing;
Chris@79 1709 } else {
Chris@79 1710 if (!askToInitNew(local)) return false;
Chris@79 1711 return openInit(local);
Chris@79 1712 }
Chris@79 1713 break;
Chris@79 1714
Chris@79 1715 case FolderUnknown:
Chris@84 1716 if (containing != "") {
Chris@84 1717 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1718 local = containing;
Chris@84 1719 } else {
Chris@84 1720 return complainAboutUnknownFolder(local);
Chris@84 1721 }
Chris@84 1722 break;
Chris@79 1723
Chris@79 1724 case FolderIsFile:
Chris@79 1725 return complainAboutFilePath(local);
Chris@79 1726 }
Chris@79 1727
Chris@284 1728 m_workFolderPath = local;
Chris@284 1729 m_remoteRepoPath = "";
Chris@79 1730 return true;
Chris@79 1731 }
Chris@79 1732
Chris@79 1733 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 1734 {
Chris@79 1735 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 1736
Chris@84 1737 FolderStatus status = getFolderStatus(local);
Chris@84 1738 QString containing = getContainingRepoFolder(local);
Chris@84 1739
Chris@84 1740 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1741
Chris@84 1742 if (status == FolderHasRepo || containing != "") {
Chris@84 1743 return complainAboutCloneToExisting(local);
Chris@84 1744 }
Chris@84 1745
Chris@84 1746 if (status == FolderIsFile) {
Chris@84 1747 return complainAboutCloneToFile(local);
Chris@84 1748 }
Chris@84 1749
Chris@84 1750 if (status == FolderUnknown) {
Chris@248 1751 if (!askAboutUnknownFolder(local)) {
Chris@248 1752 return false;
Chris@248 1753 }
Chris@84 1754 }
Chris@84 1755
Chris@84 1756 if (status == FolderExists) {
Chris@237 1757 local = complainAboutCloneToExistingFolder(local, remote);
Chris@237 1758 if (local == "") return false;
Chris@84 1759 }
Chris@84 1760
Chris@284 1761 m_workFolderPath = local;
Chris@284 1762 m_remoteRepoPath = remote;
Chris@84 1763 hgCloneFromRemote();
Chris@84 1764
Chris@79 1765 return true;
Chris@79 1766 }
Chris@79 1767
Chris@84 1768 bool MainWindow::openInit(QString local)
Chris@79 1769 {
Chris@84 1770 DEBUG << "openInit " << local << endl;
Chris@84 1771
Chris@84 1772 FolderStatus status = getFolderStatus(local);
Chris@84 1773 QString containing = getContainingRepoFolder(local);
Chris@84 1774
Chris@84 1775 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1776
Chris@84 1777 if (status == FolderHasRepo) {
Chris@84 1778 if (!askToOpenInsteadOfInit(local)) return false;
Chris@84 1779 }
Chris@84 1780
Chris@84 1781 if (containing != "") {
Chris@84 1782 return complainAboutInitInRepo(local);
Chris@84 1783 }
Chris@84 1784
Chris@84 1785 if (status == FolderIsFile) {
Chris@84 1786 return complainAboutInitFile(local);
Chris@84 1787 }
Chris@84 1788
Chris@84 1789 if (status == FolderUnknown) {
Chris@84 1790 return complainAboutUnknownFolder(local);
Chris@84 1791 }
Chris@84 1792
Chris@284 1793 m_workFolderPath = local;
Chris@284 1794 m_remoteRepoPath = "";
Chris@84 1795 hgInit();
Chris@79 1796 return true;
Chris@79 1797 }
Chris@79 1798
jtkorhonen@0 1799 void MainWindow::settings()
jtkorhonen@0 1800 {
Chris@472 1801 settings(SettingsDialog::PersonalDetailsTab);
Chris@472 1802 }
Chris@472 1803
Chris@472 1804 void MainWindow::settings(SettingsDialog::Tab tab)
Chris@472 1805 {
jtkorhonen@0 1806 SettingsDialog *settingsDlg = new SettingsDialog(this);
Chris@472 1807 settingsDlg->setCurrentTab(tab);
jtkorhonen@0 1808 settingsDlg->exec();
Chris@230 1809
Chris@230 1810 if (settingsDlg->presentationChanged()) {
Chris@284 1811 m_hgTabs->updateFileStates();
Chris@230 1812 updateToolBarStyle();
Chris@273 1813 hgRefresh();
Chris@230 1814 }
jtkorhonen@0 1815 }
jtkorhonen@0 1816
Chris@90 1817 void MainWindow::updateFileSystemWatcher()
Chris@90 1818 {
Chris@199 1819 bool justCreated = false;
Chris@284 1820 if (!m_fsWatcher) {
Chris@284 1821 m_fsWatcher = new QFileSystemWatcher();
Chris@199 1822 justCreated = true;
Chris@199 1823 }
Chris@199 1824
Chris@199 1825 // QFileSystemWatcher will refuse to add a file or directory to
Chris@199 1826 // its watch list that it is already watching -- fine, that's what
Chris@199 1827 // we want -- but it prints a warning when this happens, which is
Chris@199 1828 // annoying because it would be the normal case for us. So we'll
Chris@199 1829 // check for duplicates ourselves.
Chris@199 1830 QSet<QString> alreadyWatched;
Chris@284 1831 QStringList dl(m_fsWatcher->directories());
Chris@199 1832 foreach (QString d, dl) alreadyWatched.insert(d);
Chris@199 1833
Chris@90 1834 std::deque<QString> pending;
Chris@284 1835 pending.push_back(m_workFolderPath);
Chris@199 1836
Chris@90 1837 while (!pending.empty()) {
Chris@199 1838
Chris@90 1839 QString path = pending.front();
Chris@90 1840 pending.pop_front();
Chris@199 1841 if (!alreadyWatched.contains(path)) {
Chris@284 1842 m_fsWatcher->addPath(path);
Chris@199 1843 DEBUG << "Added to file system watcher: " << path << endl;
Chris@199 1844 }
Chris@199 1845
Chris@90 1846 QDir d(path);
Chris@90 1847 if (d.exists()) {
Chris@199 1848 d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot |
Chris@199 1849 QDir::Readable | QDir::NoSymLinks);
Chris@90 1850 foreach (QString entry, d.entryList()) {
Chris@199 1851 if (entry.startsWith('.')) continue;
Chris@90 1852 QString entryPath = d.absoluteFilePath(entry);
Chris@90 1853 pending.push_back(entryPath);
Chris@90 1854 }
Chris@90 1855 }
Chris@90 1856 }
Chris@199 1857
Chris@238 1858 // The general timer isn't really related to the fs watcher
Chris@238 1859 // object, it just does something similar -- every now and then we
Chris@238 1860 // do a refresh just to update the history dates etc
Chris@238 1861
Chris@238 1862 m_fsWatcherGeneralTimer = new QTimer(this);
Chris@238 1863 connect(m_fsWatcherGeneralTimer, SIGNAL(timeout()),
Chris@238 1864 this, SLOT(checkFilesystem()));
Chris@238 1865 m_fsWatcherGeneralTimer->setInterval(30 * 60 * 1000); // half an hour
Chris@238 1866 m_fsWatcherGeneralTimer->start();
Chris@238 1867
Chris@199 1868 if (justCreated) {
Chris@284 1869 connect(m_fsWatcher, SIGNAL(directoryChanged(QString)),
Chris@199 1870 this, SLOT(fsDirectoryChanged(QString)));
Chris@284 1871 connect(m_fsWatcher, SIGNAL(fileChanged(QString)),
Chris@199 1872 this, SLOT(fsFileChanged(QString)));
Chris@199 1873 }
Chris@90 1874 }
Chris@90 1875
Chris@238 1876 void MainWindow::suspendFileSystemWatcher()
Chris@238 1877 {
Chris@238 1878 DEBUG << "MainWindow::suspendFileSystemWatcher" << endl;
Chris@284 1879 if (m_fsWatcher) {
Chris@241 1880 m_fsWatcherSuspended = true;
Chris@241 1881 if (m_fsWatcherRestoreTimer) {
Chris@241 1882 delete m_fsWatcherRestoreTimer;
Chris@241 1883 m_fsWatcherRestoreTimer = 0;
Chris@241 1884 }
Chris@238 1885 m_fsWatcherGeneralTimer->stop();
Chris@238 1886 }
Chris@238 1887 }
Chris@238 1888
Chris@238 1889 void MainWindow::restoreFileSystemWatcher()
Chris@238 1890 {
Chris@238 1891 DEBUG << "MainWindow::restoreFileSystemWatcher" << endl;
Chris@238 1892 if (m_fsWatcherRestoreTimer) delete m_fsWatcherRestoreTimer;
Chris@238 1893
Chris@238 1894 // The restore timer is used to leave a polite interval between
Chris@238 1895 // being asked to restore the watcher and actually doing so. It's
Chris@238 1896 // a single shot timer each time it's used, but we don't use
Chris@238 1897 // QTimer::singleShot because we want to stop the previous one if
Chris@238 1898 // it's running (via deleting it)
Chris@238 1899
Chris@238 1900 m_fsWatcherRestoreTimer = new QTimer(this);
Chris@238 1901 connect(m_fsWatcherRestoreTimer, SIGNAL(timeout()),
Chris@238 1902 this, SLOT(actuallyRestoreFileSystemWatcher()));
Chris@238 1903 m_fsWatcherRestoreTimer->setInterval(1000);
Chris@238 1904 m_fsWatcherRestoreTimer->setSingleShot(true);
Chris@238 1905 m_fsWatcherRestoreTimer->start();
Chris@238 1906 }
Chris@238 1907
Chris@238 1908 void MainWindow::actuallyRestoreFileSystemWatcher()
Chris@238 1909 {
Chris@238 1910 DEBUG << "MainWindow::actuallyRestoreFileSystemWatcher" << endl;
Chris@284 1911 if (m_fsWatcher) {
Chris@241 1912 m_fsWatcherSuspended = false;
Chris@241 1913 m_fsWatcherGeneralTimer->start();
Chris@241 1914 }
Chris@238 1915 }
Chris@238 1916
Chris@238 1917 void MainWindow::checkFilesystem()
Chris@238 1918 {
Chris@238 1919 DEBUG << "MainWindow::checkFilesystem" << endl;
Chris@273 1920 hgRefresh();
Chris@238 1921 }
Chris@238 1922
Chris@122 1923 void MainWindow::fsDirectoryChanged(QString d)
Chris@90 1924 {
Chris@122 1925 DEBUG << "MainWindow::fsDirectoryChanged " << d << endl;
Chris@241 1926 if (!m_fsWatcherSuspended) {
Chris@241 1927 hgStat();
Chris@241 1928 }
Chris@90 1929 }
Chris@90 1930
Chris@122 1931 void MainWindow::fsFileChanged(QString f)
Chris@90 1932 {
Chris@122 1933 DEBUG << "MainWindow::fsFileChanged " << f << endl;
Chris@241 1934 if (!m_fsWatcherSuspended) {
Chris@241 1935 hgStat();
Chris@241 1936 }
Chris@90 1937 }
Chris@90 1938
Chris@275 1939 QString MainWindow::format1(QString head)
Chris@275 1940 {
Chris@275 1941 return QString("<qt><h3>%1</h3></qt>").arg(head);
Chris@275 1942 }
Chris@275 1943
Chris@125 1944 QString MainWindow::format3(QString head, QString intro, QString code)
Chris@125 1945 {
Chris@196 1946 code = xmlEncode(code).replace("\n", "<br>")
Chris@196 1947 #ifndef Q_OS_WIN32
Chris@196 1948 // The hard hyphen comes out funny on Windows
Chris@196 1949 .replace("-", "&#8209;")
Chris@196 1950 #endif
Chris@196 1951 .replace(" ", "&nbsp;");
Chris@125 1952 if (intro == "") {
Chris@168 1953 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
Chris@168 1954 .arg(head).arg(code);
Chris@126 1955 } else if (code == "") {
Chris@126 1956 return QString("<qt><h3>%1</h3><p>%2</p>")
Chris@126 1957 .arg(head).arg(intro);
Chris@125 1958 } else {
Chris@168 1959 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
Chris@168 1960 .arg(head).arg(intro).arg(code);
Chris@125 1961 }
Chris@125 1962 }
Chris@125 1963
Chris@120 1964 void MainWindow::showIncoming(QString output)
Chris@120 1965 {
Chris@284 1966 m_runner->hide();
Chris@125 1967 IncomingDialog *d = new IncomingDialog(this, output);
Chris@125 1968 d->exec();
Chris@125 1969 delete d;
Chris@125 1970 }
Chris@125 1971
Chris@125 1972 int MainWindow::extractChangeCount(QString text)
Chris@125 1973 {
Chris@125 1974 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
Chris@125 1975 if (re.indexIn(text) >= 0) {
Chris@125 1976 return re.cap(1).toInt();
Chris@125 1977 } else if (text.contains("no changes")) {
Chris@125 1978 return 0;
Chris@125 1979 } else {
Chris@125 1980 return -1; // unknown
Chris@125 1981 }
Chris@120 1982 }
Chris@120 1983
Chris@120 1984 void MainWindow::showPushResult(QString output)
Chris@120 1985 {
Chris@291 1986 QString head;
Chris@125 1987 QString report;
Chris@125 1988 int n = extractChangeCount(output);
Chris@125 1989 if (n > 0) {
Chris@291 1990 head = tr("Pushed %n changeset(s)", "", n);
Chris@300 1991 report = tr("<qt>Successfully pushed to the remote repository at <code>%1</code>.</qt>").arg(xmlEncode(m_remoteRepoPath));
Chris@125 1992 } else if (n == 0) {
Chris@291 1993 head = tr("No changes to push");
Chris@291 1994 report = tr("The remote repository already contains all changes that have been committed locally.");
Chris@294 1995 if (m_hgTabs->canCommit()) {
Chris@291 1996 report = tr("%1<p>You do have some uncommitted changes. If you wish to push those to the remote repository, commit them locally first.").arg(report);
Chris@291 1997 }
Chris@125 1998 } else {
Chris@291 1999 head = tr("Push complete");
Chris@125 2000 }
Chris@284 2001 m_runner->hide();
Chris@291 2002
Chris@291 2003 MoreInformationDialog::information(this, tr("Push complete"),
Chris@291 2004 head, report, output);
Chris@120 2005 }
Chris@120 2006
Chris@120 2007 void MainWindow::showPullResult(QString output)
Chris@120 2008 {
Chris@291 2009 QString head;
Chris@125 2010 QString report;
Chris@125 2011 int n = extractChangeCount(output);
Chris@125 2012 if (n > 0) {
Chris@291 2013 head = tr("Pulled %n changeset(s)", "", n);
Chris@322 2014 report = tr("New changes will be highlighted in yellow in the history.");
Chris@125 2015 } else if (n == 0) {
Chris@291 2016 head = tr("No changes to pull");
Chris@291 2017 report = tr("Your local repository already contains all changes found in the remote repository.");
Chris@125 2018 } else {
Chris@291 2019 head = tr("Pull complete");
Chris@125 2020 }
Chris@284 2021 m_runner->hide();
Chris@275 2022
Chris@275 2023 MoreInformationDialog::information(this, tr("Pull complete"),
Chris@291 2024 head, report, output);
Chris@120 2025 }
Chris@120 2026
Chris@174 2027 void MainWindow::reportNewRemoteHeads(QString output)
Chris@174 2028 {
Chris@174 2029 bool headsAreLocal = false;
Chris@174 2030
Chris@284 2031 if (m_currentParents.size() == 1) {
Chris@506 2032 int currentBranchActiveHeads = 0;
Chris@174 2033 bool parentIsHead = false;
Chris@284 2034 Changeset *parent = m_currentParents[0];
Chris@506 2035 foreach (Changeset *head, m_activeHeads) {
Chris@284 2036 if (head->isOnBranch(m_currentBranch)) {
Chris@506 2037 ++currentBranchActiveHeads;
Chris@174 2038 }
Chris@174 2039 if (parent->id() == head->id()) {
Chris@174 2040 parentIsHead = true;
Chris@174 2041 }
Chris@174 2042 }
Chris@506 2043 if (currentBranchActiveHeads == 2 && parentIsHead) {
Chris@174 2044 headsAreLocal = true;
Chris@174 2045 }
Chris@174 2046 }
Chris@174 2047
Chris@174 2048 if (headsAreLocal) {
Chris@291 2049 MoreInformationDialog::warning
Chris@291 2050 (this,
Chris@291 2051 tr("Push failed"),
Chris@291 2052 tr("Push failed"),
Chris@291 2053 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first."),
Chris@291 2054 output);
Chris@318 2055 } else if (m_hgTabs->canCommit() && m_currentParents.size() > 1) {
Chris@318 2056 MoreInformationDialog::warning
Chris@318 2057 (this,
Chris@318 2058 tr("Push failed"),
Chris@318 2059 tr("Push failed"),
Chris@318 2060 tr("Your local repository could not be pushed to the remote repository.<br><br>You have an uncommitted merge in your local folder. You probably need to commit it before you push."),
Chris@318 2061 output);
Chris@174 2062 } else {
Chris@291 2063 MoreInformationDialog::warning
Chris@291 2064 (this,
Chris@291 2065 tr("Push failed"),
Chris@291 2066 tr("Push failed"),
Chris@291 2067 tr("Your local repository could not be pushed to the remote repository.<br><br>The remote repository may have been changed by someone else since you last pushed. Try pulling and merging their changes into your local repository first."),
Chris@291 2068 output);
Chris@174 2069 }
Chris@174 2070 }
Chris@174 2071
Chris@353 2072 void MainWindow::reportAuthFailed(QString output)
Chris@353 2073 {
Chris@353 2074 MoreInformationDialog::warning
Chris@353 2075 (this,
Chris@353 2076 tr("Authorization failed"),
Chris@353 2077 tr("Authorization failed"),
Chris@353 2078 tr("You may have entered an incorrect user name or password, or the remote URL may be wrong.<br><br>Or you may lack the necessary permissions on the remote repository.<br><br>Check with the administrator of your remote repository if necessary."),
Chris@353 2079 output);
Chris@353 2080 }
Chris@353 2081
Chris@238 2082 void MainWindow::commandStarting(HgAction action)
Chris@238 2083 {
Chris@238 2084 // Annoyingly, hg stat actually modifies the working directory --
Chris@238 2085 // it creates files called hg-checklink and hg-checkexec to test
Chris@238 2086 // properties of the filesystem. For safety's sake, suspend the
Chris@238 2087 // fs watcher while running commands, and restore it shortly after
Chris@238 2088 // a command has finished.
Chris@238 2089
Chris@246 2090 if (action.action == ACT_STAT) {
Chris@246 2091 suspendFileSystemWatcher();
Chris@246 2092 }
Chris@238 2093 }
Chris@238 2094
Chris@143 2095 void MainWindow::commandFailed(HgAction action, QString output)
Chris@62 2096 {
Chris@62 2097 DEBUG << "MainWindow::commandFailed" << endl;
Chris@238 2098 restoreFileSystemWatcher();
Chris@74 2099
Chris@210 2100 QString setstr;
Chris@210 2101 #ifdef Q_OS_MAC
Chris@210 2102 setstr = tr("Preferences");
Chris@210 2103 #else
Chris@210 2104 setstr = tr("Settings");
Chris@210 2105 #endif
Chris@210 2106
Chris@353 2107 // Some commands we just have to ignore bad return values from,
Chris@353 2108 // and some output gets special treatment.
Chris@353 2109
Chris@353 2110 // Note our fallback case should always be to report a
Chris@353 2111 // non-specific error and show the text -- in case output scraping
Chris@353 2112 // fails (as it surely will). Note also that we must force the
Chris@353 2113 // locale in order to ensure the output is scrapable; this happens
Chris@353 2114 // in HgRunner and may break some system encodings.
Chris@113 2115
Chris@113 2116 switch(action.action) {
Chris@113 2117 case ACT_NONE:
Chris@113 2118 // uh huh
Chris@113 2119 return;
Chris@175 2120 case ACT_TEST_HG:
Chris@291 2121 MoreInformationDialog::warning
Chris@291 2122 (this,
Chris@291 2123 tr("Failed to run Mercurial"),
Chris@291 2124 tr("Failed to run Mercurial"),
Chris@483 2125 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),
Chris@291 2126 output);
Chris@472 2127 settings(SettingsDialog::PathsTab);
Chris@200 2128 return;
Chris@200 2129 case ACT_TEST_HG_EXT:
Chris@309 2130 MoreInformationDialog::warning
Chris@291 2131 (this,
Chris@291 2132 tr("Failed to run Mercurial"),
Chris@291 2133 tr("Failed to run Mercurial with extension enabled"),
Chris@310 2134 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<br><br>You may be able to continue working if you switch off &ldquo;Use EasyHg Mercurial Extension&rdquo; in %1. Note that remote repositories that require authentication might not work if you do this.").arg(setstr),
Chris@291 2135 output);
Chris@472 2136 settings(SettingsDialog::PathsTab);
Chris@175 2137 return;
Chris@252 2138 case ACT_CLONEFROMREMOTE:
Chris@252 2139 // if clone fails, we have no repo
Chris@284 2140 m_workFolderPath = "";
Chris@252 2141 enableDisableActions();
Chris@330 2142 break; // go on to default report
Chris@113 2143 case ACT_INCOMING:
Chris@353 2144 if (output.contains("authorization failed")) {
Chris@353 2145 reportAuthFailed(output);
Chris@353 2146 return;
Chris@358 2147 } else if (output.contains("entry cancelled")) {
Chris@358 2148 // ignore this, user cancelled username or password dialog
Chris@358 2149 return;
Chris@353 2150 } else {
Chris@353 2151 // Incoming returns non-zero code and no output if the
Chris@353 2152 // check was successful but there are no changes
Chris@353 2153 // pending. This is the only case where we need to remove
Chris@353 2154 // warning messages, because it's the only case where a
Chris@353 2155 // non-zero code can be returned even though the command
Chris@353 2156 // has for our purposes succeeded
Chris@352 2157 QString replaced = output;
Chris@352 2158 while (1) {
Chris@352 2159 QString r1 = replaced;
Chris@352 2160 r1.replace(QRegExp("warning: [^\\n]*"), "");
Chris@352 2161 if (r1 == replaced) break;
Chris@352 2162 replaced = r1.trimmed();
Chris@352 2163 }
Chris@352 2164 if (replaced == "") {
Chris@352 2165 showIncoming("");
Chris@352 2166 return;
Chris@352 2167 }
Chris@211 2168 }
Chris@330 2169 break; // go on to default report
Chris@353 2170 case ACT_PULL:
Chris@353 2171 if (output.contains("authorization failed")) {
Chris@353 2172 reportAuthFailed(output);
Chris@353 2173 return;
Chris@358 2174 } else if (output.contains("entry cancelled")) {
Chris@358 2175 // ignore this, user cancelled username or password dialog
Chris@358 2176 return;
Chris@353 2177 }
Chris@353 2178 break; // go on to default report
Chris@353 2179 case ACT_PUSH:
Chris@488 2180 if (output.contains("creates new remote head")) {
Chris@353 2181 reportNewRemoteHeads(output);
Chris@353 2182 return;
Chris@353 2183 } else if (output.contains("authorization failed")) {
Chris@353 2184 reportAuthFailed(output);
Chris@353 2185 return;
Chris@358 2186 } else if (output.contains("entry cancelled")) {
Chris@358 2187 // ignore this, user cancelled username or password dialog
Chris@358 2188 return;
Chris@353 2189 }
Chris@353 2190 break; // go on to default report
Chris@506 2191 case ACT_QUERY_HEADS_ACTIVE:
Chris@162 2192 case ACT_QUERY_HEADS:
Chris@162 2193 // fails if repo is empty; we don't care (if there's a genuine
Chris@202 2194 // problem, something else will fail too). Pretend it
Chris@202 2195 // succeeded, so that any further actions that are contingent
Chris@202 2196 // on the success of the heads query get carried out properly.
Chris@202 2197 commandCompleted(action, "");
Chris@162 2198 return;
Chris@113 2199 case ACT_FOLDERDIFF:
Chris@113 2200 case ACT_CHGSETDIFF:
Chris@113 2201 // external program, unlikely to be anything useful in stderr
Chris@113 2202 // and some return with failure codes when something as basic
Chris@113 2203 // as the user closing the window via the wm happens
Chris@113 2204 return;
Chris@519 2205 case ACT_QUERY_BOOKMARKS:
Chris@519 2206 // probably just means we have an old Hg version: simply don't
Chris@519 2207 // display bookmarks
Chris@519 2208 return;
Chris@328 2209 case ACT_MERGE:
Chris@328 2210 case ACT_RETRY_MERGE:
Chris@328 2211 MoreInformationDialog::information
Chris@328 2212 (this, tr("Merge"), tr("Merge failed"),
Chris@328 2213 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."),
Chris@328 2214 output);
Chris@378 2215 m_mergeCommitComment = "";
Chris@328 2216 return;
Chris@199 2217 case ACT_STAT:
Chris@330 2218 break; // go on to default report
Chris@113 2219 default:
Chris@114 2220 break;
Chris@113 2221 }
Chris@113 2222
Chris@113 2223 QString command = action.executable;
Chris@113 2224 if (command == "") command = "hg";
Chris@113 2225 foreach (QString arg, action.params) {
Chris@113 2226 command += " " + arg;
Chris@113 2227 }
Chris@113 2228
Chris@309 2229 MoreInformationDialog::warning
Chris@309 2230 (this,
Chris@309 2231 tr("Command failed"),
Chris@309 2232 tr("Command failed"),
Chris@483 2233 (output == "" ?
Chris@483 2234 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") :
Chris@483 2235 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.")),
Chris@309 2236 output);
Chris@62 2237 }
Chris@62 2238
Chris@109 2239 void MainWindow::commandCompleted(HgAction completedAction, QString output)
jtkorhonen@0 2240 {
Chris@519 2241 std::cerr << "commandCompleted: " << completedAction.action << std::endl;
Chris@519 2242
Chris@238 2243 restoreFileSystemWatcher();
Chris@109 2244 HGACTIONS action = completedAction.action;
Chris@109 2245
Chris@109 2246 if (action == ACT_NONE) return;
Chris@109 2247
Chris@519 2248 output.replace("\r\n", "\n");
Chris@519 2249
Chris@150 2250 bool headsChanged = false;
Chris@150 2251 QStringList oldHeadIds;
Chris@150 2252
Chris@150 2253 switch (action) {
Chris@109 2254
Chris@175 2255 case ACT_TEST_HG:
Chris@377 2256 {
Chris@377 2257 QRegExp versionRE("^Mercurial.*version ([\\d+])\\.([\\d+])");
Chris@377 2258 int pos = versionRE.indexIn(output);
Chris@377 2259 if (pos >= 0) {
Chris@377 2260 int major = versionRE.cap(1).toInt();
Chris@377 2261 int minor = versionRE.cap(2).toInt();
Chris@377 2262 // We need v1.7 or newer
Chris@377 2263 if (major < 1 || (major == 1 && minor < 7)) {
Chris@377 2264 MoreInformationDialog::warning
Chris@377 2265 (this,
Chris@377 2266 tr("Newer Mercurial version required"),
Chris@377 2267 tr("Newer Mercurial version required"),
Chris@377 2268 tr("To use EasyMercurial, you should have at least Mercurial v1.7 installed.<br><br>The version found on this system (v%1.%2) does not support all of the features required by EasyMercurial.").arg(major).arg(minor),
Chris@377 2269 output);
Chris@377 2270 }
Chris@377 2271 }
Chris@175 2272 break;
Chris@377 2273 }
Chris@175 2274
Chris@200 2275 case ACT_TEST_HG_EXT:
Chris@200 2276 break;
Chris@200 2277
Chris@109 2278 case ACT_QUERY_PATHS:
jtkorhonen@0 2279 {
Chris@109 2280 DEBUG << "stdout is " << output << endl;
Chris@109 2281 LogParser lp(output, "=");
Chris@109 2282 LogList ll = lp.parse();
Chris@109 2283 DEBUG << ll.size() << " results" << endl;
Chris@109 2284 if (!ll.empty()) {
Chris@284 2285 m_remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@284 2286 DEBUG << "Set remote path to " << m_remoteRepoPath << endl;
Chris@210 2287 } else {
Chris@284 2288 m_remoteRepoPath = "";
Chris@109 2289 }
Chris@284 2290 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 2291 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@287 2292 updateWorkFolderAndRepoNames();
Chris@109 2293 break;
Chris@109 2294 }
jtkorhonen@0 2295
Chris@109 2296 case ACT_QUERY_BRANCH:
Chris@284 2297 m_currentBranch = output.trimmed();
Chris@109 2298 break;
jtkorhonen@0 2299
Chris@519 2300 case ACT_QUERY_BOOKMARKS:
Chris@519 2301 {
Chris@519 2302 m_bookmarks.clear();
Chris@519 2303 QStringList outList = output.split('\n', QString::SkipEmptyParts);
Chris@519 2304 foreach (QString line, outList) {
Chris@519 2305 QStringList items = line.split(' ', QString::SkipEmptyParts);
Chris@519 2306 if (items[0] == "*") {
Chris@519 2307 if (items.size() == 3) {
Chris@519 2308 m_bookmarks[items[2]].push_back(items[1]);
Chris@519 2309 }
Chris@519 2310 } else {
Chris@519 2311 if (items.size() == 2) {
Chris@519 2312 m_bookmarks[items[1]].push_back(items[0]);
Chris@519 2313 }
Chris@519 2314 }
Chris@519 2315 }
Chris@519 2316 m_hgTabs->setBookmarks(m_bookmarks);
Chris@519 2317 break;
Chris@519 2318 }
Chris@519 2319
Chris@109 2320 case ACT_STAT:
Chris@284 2321 m_lastStatOutput = output;
Chris@109 2322 updateFileSystemWatcher();
Chris@109 2323 break;
Chris@163 2324
Chris@163 2325 case ACT_RESOLVE_LIST:
Chris@505 2326 // This happens on every update, after the stat (above)
Chris@163 2327 if (output != "") {
Chris@163 2328 // Remove lines beginning with R (they are resolved,
Chris@163 2329 // and the file stat parser treats R as removed)
Chris@163 2330 QStringList outList = output.split('\n');
Chris@163 2331 QStringList winnowed;
Chris@163 2332 foreach (QString line, outList) {
Chris@163 2333 if (!line.startsWith("R ")) winnowed.push_back(line);
Chris@163 2334 }
Chris@163 2335 output = winnowed.join("\n");
Chris@163 2336 }
Chris@284 2337 DEBUG << "m_lastStatOutput = " << m_lastStatOutput << endl;
Chris@199 2338 DEBUG << "resolve output = " << output << endl;
Chris@284 2339 m_hgTabs->updateWorkFolderFileList(m_lastStatOutput + output);
Chris@163 2340 break;
Chris@163 2341
Chris@163 2342 case ACT_RESOLVE_MARK:
Chris@284 2343 m_shouldHgStat = true;
Chris@163 2344 break;
Chris@109 2345
Chris@109 2346 case ACT_INCOMING:
Chris@120 2347 showIncoming(output);
Chris@120 2348 break;
Chris@120 2349
Chris@109 2350 case ACT_ANNOTATE:
Chris@331 2351 {
Chris@331 2352 AnnotateDialog dialog(this, output);
Chris@331 2353 dialog.exec();
Chris@284 2354 m_shouldHgStat = true;
Chris@109 2355 break;
Chris@331 2356 }
Chris@109 2357
Chris@109 2358 case ACT_PULL:
Chris@120 2359 showPullResult(output);
Chris@284 2360 m_shouldHgStat = true;
Chris@109 2361 break;
Chris@109 2362
Chris@109 2363 case ACT_PUSH:
Chris@120 2364 showPushResult(output);
Chris@109 2365 break;
Chris@109 2366
Chris@109 2367 case ACT_INIT:
Chris@284 2368 MultiChoiceDialog::addRecentArgument("init", m_workFolderPath);
Chris@284 2369 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@109 2370 enableDisableActions();
Chris@284 2371 m_shouldHgStat = true;
Chris@109 2372 break;
Chris@109 2373
Chris@109 2374 case ACT_CLONEFROMREMOTE:
Chris@284 2375 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 2376 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@284 2377 MultiChoiceDialog::addRecentArgument("remote", m_workFolderPath, true);
Chris@291 2378 MoreInformationDialog::information
Chris@291 2379 (this,
Chris@291 2380 tr("Clone"),
Chris@384 2381 tr("Open successful"),
Chris@295 2382 tr("The remote repository was successfully cloned to the local folder <code>%1</code>.").arg(xmlEncode(m_workFolderPath)),
Chris@291 2383 output);
Chris@109 2384 enableDisableActions();
Chris@284 2385 m_shouldHgStat = true;
Chris@109 2386 break;
Chris@109 2387
Chris@109 2388 case ACT_LOG:
Chris@284 2389 m_hgTabs->setNewLog(output);
Chris@284 2390 m_needNewLog = false;
Chris@120 2391 break;
Chris@120 2392
Chris@120 2393 case ACT_LOG_INCREMENTAL:
Chris@284 2394 m_hgTabs->addIncrementalLog(output);
Chris@109 2395 break;
Chris@109 2396
Chris@109 2397 case ACT_QUERY_PARENTS:
Chris@152 2398 {
Chris@284 2399 foreach (Changeset *cs, m_currentParents) delete cs;
Chris@284 2400 m_currentParents = Changeset::parseChangesets(output);
Chris@284 2401 QStringList parentIds = Changeset::getIds(m_currentParents);
Chris@284 2402 m_hgTabs->setCurrent(parentIds, m_currentBranch);
Chris@152 2403 }
Chris@109 2404 break;
Chris@109 2405
Chris@506 2406 case ACT_QUERY_HEADS_ACTIVE:
Chris@506 2407 foreach (Changeset *cs, m_activeHeads) delete cs;
Chris@506 2408 m_activeHeads = Changeset::parseChangesets(output);
Chris@506 2409 break;
Chris@506 2410
Chris@109 2411 case ACT_QUERY_HEADS:
Chris@150 2412 {
Chris@284 2413 oldHeadIds = Changeset::getIds(m_currentHeads);
Chris@150 2414 Changesets newHeads = Changeset::parseChangesets(output);
Chris@150 2415 QStringList newHeadIds = Changeset::getIds(newHeads);
Chris@150 2416 if (oldHeadIds != newHeadIds) {
Chris@150 2417 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
Chris@305 2418 DEBUG << "Old heads: " << oldHeadIds.join(",") << endl;
Chris@305 2419 DEBUG << "New heads: " << newHeadIds.join(",") << endl;
Chris@150 2420 headsChanged = true;
Chris@284 2421 foreach (Changeset *cs, m_currentHeads) delete cs;
Chris@284 2422 m_currentHeads = newHeads;
Chris@506 2423 updateClosedHeads();
Chris@150 2424 }
Chris@150 2425 }
Chris@109 2426 break;
Chris@130 2427
Chris@130 2428 case ACT_COMMIT:
Chris@347 2429 if (m_currentParents.empty()) {
Chris@347 2430 // first commit to empty repo
Chris@347 2431 m_needNewLog = true;
Chris@347 2432 }
Chris@284 2433 m_hgTabs->clearSelections();
Chris@284 2434 m_justMerged = false;
Chris@284 2435 m_shouldHgStat = true;
Chris@130 2436 break;
Chris@163 2437
Chris@514 2438 case ACT_CLOSE_BRANCH:
Chris@514 2439 m_hgTabs->clearSelections();
Chris@514 2440 m_justMerged = false;
Chris@514 2441 m_shouldHgStat = true;
Chris@514 2442 break;
Chris@514 2443
Chris@163 2444 case ACT_REVERT:
Chris@326 2445 hgMarkFilesResolved(m_lastRevertedFiles);
Chris@284 2446 m_justMerged = false;
Chris@163 2447 break;
Chris@109 2448
Chris@109 2449 case ACT_REMOVE:
Chris@109 2450 case ACT_ADD:
Chris@284 2451 m_hgTabs->clearSelections();
Chris@284 2452 m_shouldHgStat = true;
Chris@116 2453 break;
Chris@116 2454
Chris@164 2455 case ACT_TAG:
Chris@284 2456 m_needNewLog = true;
Chris@284 2457 m_shouldHgStat = true;
Chris@164 2458 break;
Chris@164 2459
Chris@278 2460 case ACT_NEW_BRANCH:
Chris@307 2461 m_shouldHgStat = true;
Chris@278 2462 break;
Chris@278 2463
Chris@288 2464 case ACT_UNCOMMITTED_SUMMARY:
Chris@168 2465 QMessageBox::information(this, tr("Change summary"),
Chris@168 2466 format3(tr("Summary of uncommitted changes"),
Chris@168 2467 "",
Chris@168 2468 output));
Chris@168 2469 break;
Chris@168 2470
Chris@288 2471 case ACT_DIFF_SUMMARY:
Chris@289 2472 {
Chris@289 2473 // Output has log info first, diff following after a blank line
Chris@289 2474 QStringList olist = output.split("\n\n", QString::SkipEmptyParts);
Chris@289 2475 if (olist.size() > 1) output = olist[1];
Chris@289 2476
Chris@289 2477 Changeset *cs = (Changeset *)completedAction.extraData;
Chris@289 2478 if (cs) {
Chris@289 2479 QMessageBox::information
Chris@289 2480 (this, tr("Change summary"),
Chris@289 2481 format3(tr("Summary of changes"),
Chris@289 2482 cs->formatHtml(),
Chris@289 2483 output));
Chris@289 2484 } else if (output == "") {
Chris@289 2485 // Can happen, for a merge commit (depending on parent)
Chris@288 2486 QMessageBox::information(this, tr("Change summary"),
Chris@288 2487 format3(tr("Summary of changes"),
Chris@288 2488 tr("No changes"),
Chris@288 2489 output));
Chris@288 2490 } else {
Chris@288 2491 QMessageBox::information(this, tr("Change summary"),
Chris@288 2492 format3(tr("Summary of changes"),
Chris@288 2493 "",
Chris@288 2494 output));
Chris@288 2495 }
Chris@288 2496 break;
Chris@289 2497 }
Chris@288 2498
Chris@109 2499 case ACT_FOLDERDIFF:
Chris@109 2500 case ACT_CHGSETDIFF:
Chris@109 2501 case ACT_SERVE:
Chris@109 2502 case ACT_HG_IGNORE:
Chris@284 2503 m_shouldHgStat = true;
Chris@109 2504 break;
Chris@109 2505
Chris@109 2506 case ACT_UPDATE:
Chris@162 2507 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
Chris@284 2508 m_shouldHgStat = true;
Chris@109 2509 break;
Chris@109 2510
Chris@109 2511 case ACT_MERGE:
Chris@294 2512 MoreInformationDialog::information
Chris@294 2513 (this, tr("Merge"), tr("Merge successful"),
Chris@302 2514 tr("Remember to test and commit the result before making any further changes."),
Chris@294 2515 output);
Chris@284 2516 m_shouldHgStat = true;
Chris@284 2517 m_justMerged = true;
Chris@109 2518 break;
Chris@109 2519
Chris@109 2520 case ACT_RETRY_MERGE:
Chris@163 2521 QMessageBox::information(this, tr("Resolved"),
Chris@302 2522 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.<br>Remember to test and commit the result before making any further changes.</p>"));
Chris@284 2523 m_shouldHgStat = true;
Chris@284 2524 m_justMerged = true;
Chris@109 2525 break;
Chris@109 2526
Chris@109 2527 default:
Chris@109 2528 break;
Chris@109 2529 }
Chris@108 2530
Chris@121 2531 // Sequence when no full log required:
Chris@519 2532 // paths -> branch -> stat -> bookmarks -> resolve-list -> heads ->
Chris@150 2533 // incremental-log (only if heads changed) -> parents
Chris@150 2534 //
Chris@121 2535 // Sequence when full log required:
Chris@519 2536 // paths -> branch -> stat -> bookmarks -> resolve-list -> heads ->
Chris@519 2537 // parents -> log
Chris@150 2538 //
Chris@150 2539 // Note we want to call enableDisableActions only once, at the end
Chris@150 2540 // of whichever sequence is in use.
Chris@150 2541
Chris@156 2542 bool noMore = false;
Chris@156 2543
Chris@150 2544 switch (action) {
Chris@175 2545
Chris@175 2546 case ACT_TEST_HG:
Chris@248 2547 {
Chris@248 2548 QSettings settings;
Chris@248 2549 if (settings.value("useextension", true).toBool()) {
Chris@248 2550 hgTestExtension();
Chris@284 2551 } else if (m_workFolderPath == "") {
Chris@248 2552 open();
Chris@248 2553 } else {
Chris@248 2554 hgQueryPaths();
Chris@248 2555 }
Chris@200 2556 break;
Chris@248 2557 }
Chris@200 2558
Chris@200 2559 case ACT_TEST_HG_EXT:
Chris@284 2560 if (m_workFolderPath == "") {
Chris@248 2561 open();
Chris@248 2562 } else{
Chris@248 2563 hgQueryPaths();
Chris@248 2564 }
Chris@175 2565 break;
Chris@150 2566
Chris@150 2567 case ACT_QUERY_PATHS:
Chris@519 2568 // NB this call is duplicated in hgQueryPaths
Chris@109 2569 hgQueryBranch();
Chris@150 2570 break;
Chris@150 2571
Chris@150 2572 case ACT_QUERY_BRANCH:
Chris@519 2573 // NB this call is duplicated in hgQueryBranch
Chris@109 2574 hgStat();
Chris@150 2575 break;
Chris@150 2576
Chris@150 2577 case ACT_STAT:
Chris@519 2578 hgQueryBookmarks();
Chris@519 2579 break;
Chris@519 2580
Chris@519 2581 case ACT_QUERY_BOOKMARKS:
Chris@163 2582 hgResolveList();
Chris@163 2583 break;
Chris@519 2584
Chris@163 2585 case ACT_RESOLVE_LIST:
Chris@506 2586 hgQueryHeadsActive();
Chris@506 2587 break;
Chris@506 2588
Chris@506 2589 case ACT_QUERY_HEADS_ACTIVE:
Chris@150 2590 hgQueryHeads();
Chris@150 2591 break;
Chris@150 2592
Chris@150 2593 case ACT_QUERY_HEADS:
Chris@284 2594 if (headsChanged && !m_needNewLog) {
Chris@150 2595 hgLogIncremental(oldHeadIds);
Chris@121 2596 } else {
Chris@150 2597 hgQueryParents();
Chris@121 2598 }
Chris@150 2599 break;
Chris@150 2600
Chris@150 2601 case ACT_LOG_INCREMENTAL:
Chris@109 2602 hgQueryParents();
Chris@150 2603 break;
Chris@150 2604
Chris@150 2605 case ACT_QUERY_PARENTS:
Chris@284 2606 if (m_needNewLog) {
Chris@120 2607 hgLog();
Chris@150 2608 } else {
Chris@150 2609 // we're done
Chris@156 2610 noMore = true;
Chris@120 2611 }
Chris@150 2612 break;
Chris@150 2613
Chris@150 2614 case ACT_LOG:
Chris@150 2615 // we're done
Chris@156 2616 noMore = true;
Chris@198 2617 break;
Chris@150 2618
Chris@150 2619 default:
Chris@284 2620 if (m_shouldHgStat) {
Chris@284 2621 m_shouldHgStat = false;
Chris@109 2622 hgQueryPaths();
Chris@150 2623 } else {
Chris@156 2624 noMore = true;
jtkorhonen@0 2625 }
Chris@150 2626 break;
Chris@150 2627 }
Chris@156 2628
Chris@156 2629 if (noMore) {
Chris@284 2630 m_stateUnknown = false;
Chris@156 2631 enableDisableActions();
Chris@284 2632 m_hgTabs->updateHistory();
Chris@359 2633 updateRecentMenu();
Chris@156 2634 }
jtkorhonen@0 2635 }
jtkorhonen@0 2636
jtkorhonen@0 2637 void MainWindow::connectActions()
jtkorhonen@0 2638 {
Chris@284 2639 connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close()));
Chris@284 2640 connect(m_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
Chris@494 2641 connect(m_helpAct, SIGNAL(triggered()), this, SLOT(help()));
Chris@273 2642
Chris@284 2643 connect(m_hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
Chris@284 2644 connect(m_hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
Chris@284 2645 connect(m_hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
Chris@284 2646 connect(m_hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
Chris@425 2647 connect(m_hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
Chris@425 2648 connect(m_hgEditIgnoreAct, SIGNAL(triggered()), this, SLOT(hgEditIgnore()));
Chris@284 2649 connect(m_hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
Chris@284 2650 connect(m_hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
Chris@284 2651 connect(m_hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
Chris@284 2652 connect(m_hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
Chris@273 2653
Chris@284 2654 connect(m_settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@284 2655 connect(m_openAct, SIGNAL(triggered()), this, SLOT(open()));
Chris@284 2656 connect(m_changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
Chris@273 2657
Chris@284 2658 connect(m_hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
Chris@284 2659 connect(m_hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
Chris@284 2660 connect(m_hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
Chris@273 2661
Chris@284 2662 connect(m_hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
jtkorhonen@0 2663 }
Chris@141 2664
Chris@141 2665 void MainWindow::connectTabsSignals()
Chris@141 2666 {
Chris@327 2667 connect(m_hgTabs, SIGNAL(currentChanged(int)),
Chris@327 2668 this, SLOT(enableDisableActions()));
Chris@327 2669
Chris@284 2670 connect(m_hgTabs, SIGNAL(commit()),
Chris@141 2671 this, SLOT(hgCommit()));
Chris@141 2672
Chris@284 2673 connect(m_hgTabs, SIGNAL(revert()),
Chris@141 2674 this, SLOT(hgRevert()));
Chris@141 2675
Chris@284 2676 connect(m_hgTabs, SIGNAL(diffWorkingFolder()),
Chris@141 2677 this, SLOT(hgFolderDiff()));
Chris@168 2678
Chris@284 2679 connect(m_hgTabs, SIGNAL(showSummary()),
Chris@168 2680 this, SLOT(hgShowSummary()));
Chris@311 2681
Chris@311 2682 connect(m_hgTabs, SIGNAL(newBranch()),
Chris@311 2683 this, SLOT(hgNewBranch()));
Chris@311 2684
Chris@311 2685 connect(m_hgTabs, SIGNAL(noBranch()),
Chris@311 2686 this, SLOT(hgNoBranch()));
Chris@148 2687
Chris@284 2688 connect(m_hgTabs, SIGNAL(updateTo(QString)),
Chris@148 2689 this, SLOT(hgUpdateToRev(QString)));
Chris@141 2690
Chris@284 2691 connect(m_hgTabs, SIGNAL(diffToCurrent(QString)),
Chris@148 2692 this, SLOT(hgDiffToCurrent(QString)));
Chris@141 2693
Chris@284 2694 connect(m_hgTabs, SIGNAL(diffToParent(QString, QString)),
Chris@148 2695 this, SLOT(hgDiffToParent(QString, QString)));
Chris@141 2696
Chris@289 2697 connect(m_hgTabs, SIGNAL(showSummary(Changeset *)),
Chris@289 2698 this, SLOT(hgShowSummaryFor(Changeset *)));
Chris@288 2699
Chris@284 2700 connect(m_hgTabs, SIGNAL(mergeFrom(QString)),
Chris@148 2701 this, SLOT(hgMergeFrom(QString)));
Chris@164 2702
Chris@307 2703 connect(m_hgTabs, SIGNAL(newBranch(QString)),
Chris@311 2704 this, SLOT(hgNewBranch()));
Chris@278 2705
Chris@514 2706 connect(m_hgTabs, SIGNAL(closeBranch(QString)),
Chris@514 2707 this, SLOT(hgCloseBranch()));
Chris@514 2708
Chris@284 2709 connect(m_hgTabs, SIGNAL(tag(QString)),
Chris@148 2710 this, SLOT(hgTag(QString)));
Chris@326 2711
Chris@326 2712 connect(m_hgTabs, SIGNAL(annotateFiles(QStringList)),
Chris@326 2713 this, SLOT(hgAnnotateFiles(QStringList)));
Chris@326 2714
Chris@326 2715 connect(m_hgTabs, SIGNAL(diffFiles(QStringList)),
Chris@326 2716 this, SLOT(hgDiffFiles(QStringList)));
Chris@326 2717
Chris@326 2718 connect(m_hgTabs, SIGNAL(commitFiles(QStringList)),
Chris@326 2719 this, SLOT(hgCommitFiles(QStringList)));
Chris@326 2720
Chris@326 2721 connect(m_hgTabs, SIGNAL(revertFiles(QStringList)),
Chris@326 2722 this, SLOT(hgRevertFiles(QStringList)));
Chris@326 2723
Chris@361 2724 connect(m_hgTabs, SIGNAL(renameFiles(QStringList)),
Chris@361 2725 this, SLOT(hgRenameFiles(QStringList)));
Chris@361 2726
Chris@361 2727 connect(m_hgTabs, SIGNAL(copyFiles(QStringList)),
Chris@361 2728 this, SLOT(hgCopyFiles(QStringList)));
Chris@361 2729
Chris@326 2730 connect(m_hgTabs, SIGNAL(addFiles(QStringList)),
Chris@326 2731 this, SLOT(hgAddFiles(QStringList)));
Chris@326 2732
Chris@326 2733 connect(m_hgTabs, SIGNAL(removeFiles(QStringList)),
Chris@326 2734 this, SLOT(hgRemoveFiles(QStringList)));
Chris@326 2735
Chris@326 2736 connect(m_hgTabs, SIGNAL(redoFileMerges(QStringList)),
Chris@326 2737 this, SLOT(hgRedoFileMerges(QStringList)));
Chris@326 2738
Chris@326 2739 connect(m_hgTabs, SIGNAL(markFilesResolved(QStringList)),
Chris@326 2740 this, SLOT(hgMarkFilesResolved(QStringList)));
Chris@326 2741
Chris@326 2742 connect(m_hgTabs, SIGNAL(ignoreFiles(QStringList)),
Chris@326 2743 this, SLOT(hgIgnoreFiles(QStringList)));
Chris@326 2744
Chris@326 2745 connect(m_hgTabs, SIGNAL(unIgnoreFiles(QStringList)),
Chris@326 2746 this, SLOT(hgUnIgnoreFiles(QStringList)));
Chris@141 2747 }
Chris@141 2748
jtkorhonen@0 2749 void MainWindow::enableDisableActions()
jtkorhonen@0 2750 {
Chris@90 2751 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 2752
Chris@284 2753 QString dirname = QDir(m_workFolderPath).dirName();
Chris@340 2754
Chris@340 2755 if (m_workFolderPath != "") { // dirname of "" is ".", so test path instead
Chris@202 2756 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
Chris@202 2757 } else {
Chris@202 2758 setWindowTitle(tr("EasyMercurial"));
Chris@202 2759 }
Chris@202 2760
Chris@115 2761 //!!! should also do things like set the status texts for the
Chris@115 2762 //!!! actions appropriately by context
Chris@115 2763
jtkorhonen@0 2764 QDir localRepoDir;
jtkorhonen@0 2765 QDir workFolderDir;
jtkorhonen@0 2766
Chris@284 2767 m_remoteRepoActionsEnabled = true;
Chris@284 2768 if (m_remoteRepoPath.isEmpty()) {
Chris@284 2769 m_remoteRepoActionsEnabled = false;
jtkorhonen@0 2770 }
jtkorhonen@0 2771
Chris@284 2772 m_localRepoActionsEnabled = true;
Chris@284 2773 if (m_workFolderPath.isEmpty()) {
Chris@284 2774 m_localRepoActionsEnabled = false;
jtkorhonen@0 2775 }
jtkorhonen@0 2776
Chris@284 2777 if (m_workFolderPath == "" || !workFolderDir.exists(m_workFolderPath)) {
Chris@284 2778 m_localRepoActionsEnabled = false;
jtkorhonen@0 2779 }
jtkorhonen@0 2780
Chris@284 2781 if (!localRepoDir.exists(m_workFolderPath + "/.hg")) {
Chris@284 2782 m_localRepoActionsEnabled = false;
jtkorhonen@0 2783 }
jtkorhonen@0 2784
Chris@179 2785 bool haveDiff = false;
Chris@179 2786 QSettings settings;
Chris@179 2787 settings.beginGroup("Locations");
Chris@179 2788 if (settings.value("extdiffbinary", "").toString() != "") {
Chris@179 2789 haveDiff = true;
Chris@179 2790 }
Chris@179 2791 settings.endGroup();
Chris@112 2792
Chris@505 2793 m_hgTabs->setHaveMerge(m_currentParents.size() == 2);
Chris@505 2794
Chris@365 2795 m_hgRefreshAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2796 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && haveDiff);
Chris@365 2797 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2798 m_hgAddAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2799 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled);
Chris@425 2800 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2801 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2802 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2803 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2804 m_hgServeAct->setEnabled(m_localRepoActionsEnabled);
Chris@413 2805 m_hgEditIgnoreAct->setEnabled(m_localRepoActionsEnabled);
Chris@273 2806
Chris@284 2807 DEBUG << "m_localRepoActionsEnabled = " << m_localRepoActionsEnabled << endl;
Chris@284 2808 DEBUG << "canCommit = " << m_hgTabs->canCommit() << endl;
Chris@273 2809
Chris@284 2810 m_hgAddAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canAdd());
Chris@284 2811 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRemove());
Chris@284 2812 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canCommit());
Chris@284 2813 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRevert());
Chris@284 2814 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canDiff());
Chris@425 2815 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canIgnore());
Chris@90 2816
Chris@108 2817 // A default merge makes sense if:
Chris@108 2818 // * there is only one parent (if there are two, we have an uncommitted merge) and
Chris@108 2819 // * there are exactly two heads that have the same branch as the current branch and
Chris@108 2820 // * our parent is one of those heads
Chris@108 2821 //
Chris@108 2822 // A default update makes sense if:
Chris@108 2823 // * there is only one parent and
Chris@108 2824 // * the parent is not one of the current heads
Chris@156 2825
Chris@108 2826 bool canMerge = false;
Chris@108 2827 bool canUpdate = false;
Chris@156 2828 bool haveMerge = false;
Chris@162 2829 bool emptyRepo = false;
Chris@225 2830 bool noWorkingCopy = false;
Chris@235 2831 bool newBranch = false;
Chris@506 2832 bool closedBranch = false;
Chris@506 2833 int currentBranchActiveHeads = 0;
Chris@273 2834
Chris@284 2835 if (m_currentParents.size() == 1) {
Chris@156 2836 bool parentIsHead = false;
Chris@506 2837 bool parentIsActiveHead = false;
Chris@284 2838 Changeset *parent = m_currentParents[0];
Chris@506 2839 foreach (Changeset *head, m_activeHeads) {
Chris@284 2840 if (head->isOnBranch(m_currentBranch)) {
Chris@506 2841 ++currentBranchActiveHeads;
Chris@235 2842 }
Chris@235 2843 if (parent->id() == head->id()) {
Chris@506 2844 parentIsActiveHead = parentIsHead = true;
Chris@108 2845 }
Chris@108 2846 }
Chris@506 2847 if (!parentIsActiveHead) {
Chris@506 2848 foreach (Changeset *head, m_currentHeads) {
Chris@506 2849 if (parent->id() == head->id()) {
Chris@506 2850 parentIsHead = true;
Chris@506 2851 }
Chris@506 2852 }
Chris@506 2853 }
Chris@506 2854 if (currentBranchActiveHeads == 2 && parentIsActiveHead) {
Chris@108 2855 canMerge = true;
Chris@108 2856 }
Chris@506 2857 if (currentBranchActiveHeads == 0 && parentIsActiveHead) {
Chris@235 2858 // Just created a new branch
Chris@235 2859 newBranch = true;
Chris@235 2860 }
Chris@108 2861 if (!parentIsHead) {
Chris@108 2862 canUpdate = true;
Chris@108 2863 DEBUG << "parent id = " << parent->id() << endl;
Chris@108 2864 DEBUG << " head ids "<<endl;
Chris@284 2865 foreach (Changeset *h, m_currentHeads) {
Chris@108 2866 DEBUG << "head id = " << h->id() << endl;
Chris@108 2867 }
Chris@506 2868 } else if (!parentIsActiveHead) {
Chris@506 2869 closedBranch = true;
Chris@108 2870 }
Chris@284 2871 m_justMerged = false;
Chris@284 2872 } else if (m_currentParents.size() == 0) {
Chris@284 2873 if (m_currentHeads.size() == 0) {
Chris@225 2874 // No heads -> empty repo
Chris@225 2875 emptyRepo = true;
Chris@225 2876 } else {
Chris@225 2877 // Heads, but no parents -> no working copy, e.g. we have
Chris@225 2878 // just converted this repo but haven't updated in it yet.
Chris@225 2879 // Uncommon but confusing; probably merits a special case
Chris@225 2880 noWorkingCopy = true;
Chris@225 2881 canUpdate = true;
Chris@225 2882 }
Chris@284 2883 m_justMerged = false;
Chris@156 2884 } else {
Chris@156 2885 haveMerge = true;
Chris@284 2886 m_justMerged = true;
Chris@108 2887 }
Chris@505 2888
Chris@363 2889 m_hgIncomingAct->setEnabled(m_remoteRepoActionsEnabled);
Chris@363 2890 m_hgPullAct->setEnabled(m_remoteRepoActionsEnabled);
Chris@363 2891 // permit push even if no remote yet; we'll ask for one
Chris@363 2892 m_hgPushAct->setEnabled(m_localRepoActionsEnabled && !emptyRepo);
Chris@363 2893
Chris@284 2894 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled &&
Chris@506 2895 (canMerge || m_hgTabs->canResolve()));
Chris@284 2896 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled &&
Chris@506 2897 (canUpdate && !m_hgTabs->haveChangesToCommit()));
Chris@115 2898
Chris@115 2899 // Set the state field on the file status widget
Chris@115 2900
Chris@115 2901 QString branchText;
Chris@284 2902 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@115 2903 branchText = tr("the default branch");
Chris@115 2904 } else {
Chris@284 2905 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@115 2906 }
Chris@156 2907
Chris@284 2908 if (m_stateUnknown) {
Chris@284 2909 if (m_workFolderPath == "") {
Chris@287 2910 m_workStatus->setState(tr("No repository open"));
Chris@248 2911 } else {
Chris@287 2912 m_workStatus->setState(tr("(Examining repository)"));
Chris@248 2913 }
Chris@173 2914 } else if (emptyRepo) {
Chris@287 2915 m_workStatus->setState(tr("Nothing committed to this repository yet"));
Chris@225 2916 } else if (noWorkingCopy) {
Chris@287 2917 m_workStatus->setState(tr("No working copy yet: consider updating"));
Chris@162 2918 } else if (canMerge) {
Chris@287 2919 m_workStatus->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
Chris@284 2920 } else if (!m_hgTabs->getAllUnresolvedFiles().empty()) {
Chris@287 2921 m_workStatus->setState(tr("Have unresolved files following merge on %1").arg(branchText));
Chris@156 2922 } else if (haveMerge) {
Chris@287 2923 m_workStatus->setState(tr("Have merged but not yet committed on %1").arg(branchText));
Chris@235 2924 } else if (newBranch) {
Chris@287 2925 m_workStatus->setState(tr("On %1. New branch: has not yet been committed").arg(branchText));
Chris@506 2926 } else if (closedBranch) {
Chris@506 2927 if (canUpdate) {
Chris@506 2928 m_workStatus->setState(tr("On a closed branch. Not at the head of the branch"));
Chris@506 2929 } else {
Chris@506 2930 m_workStatus->setState(tr("At the head of a closed branch"));
Chris@506 2931 }
Chris@156 2932 } else if (canUpdate) {
Chris@284 2933 if (m_hgTabs->haveChangesToCommit()) {
Chris@163 2934 // have uncommitted changes
Chris@287 2935 m_workStatus->setState(tr("On %1. Not at the head of the branch").arg(branchText));
Chris@163 2936 } else {
Chris@163 2937 // no uncommitted changes
Chris@287 2938 m_workStatus->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
Chris@163 2939 }
Chris@506 2940 } else if (currentBranchActiveHeads > 1) {
Chris@506 2941 m_workStatus->setState(tr("At one of %n heads of %1", "", currentBranchActiveHeads).arg(branchText));
Chris@115 2942 } else {
Chris@287 2943 m_workStatus->setState(tr("At the head of %1").arg(branchText));
Chris@115 2944 }
jtkorhonen@0 2945 }
jtkorhonen@0 2946
Chris@359 2947
Chris@506 2948 void MainWindow::updateClosedHeads()
Chris@506 2949 {
Chris@506 2950 m_closedHeadIds.clear();
Chris@506 2951 QSet<QString> activeIds;
Chris@506 2952 foreach (Changeset *cs, m_activeHeads) {
Chris@506 2953 activeIds.insert(cs->id());
Chris@506 2954 }
Chris@506 2955 foreach (Changeset *cs, m_currentHeads) {
Chris@506 2956 if (!activeIds.contains(cs->id())) {
Chris@506 2957 m_closedHeadIds.insert(cs->id());
Chris@506 2958 }
Chris@506 2959 }
Chris@506 2960 m_hgTabs->setClosedHeadIds(m_closedHeadIds);
Chris@506 2961 }
Chris@506 2962
Chris@359 2963 void MainWindow::updateRecentMenu()
Chris@359 2964 {
Chris@359 2965 m_recentMenu->clear();
Chris@359 2966 RecentFiles rf("Recent-local");
Chris@359 2967 QStringList recent = rf.getRecent();
Chris@359 2968 if (recent.empty()) {
Chris@359 2969 QLabel *label = new QLabel(tr("No recent local repositories"));
Chris@359 2970 QWidgetAction *wa = new QWidgetAction(m_recentMenu);
Chris@359 2971 wa->setDefaultWidget(label);
Chris@359 2972 return;
Chris@359 2973 }
Chris@359 2974 foreach (QString r, recent) {
Chris@359 2975 QAction *a = m_recentMenu->addAction(r);
Chris@359 2976 connect(a, SIGNAL(activated()), this, SLOT(recentMenuActivated()));
Chris@359 2977 }
Chris@359 2978 }
Chris@359 2979
jtkorhonen@0 2980 void MainWindow::createActions()
jtkorhonen@0 2981 {
jtkorhonen@0 2982 //File actions
Chris@365 2983 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("&Open..."), this);
Chris@365 2984 m_openAct->setStatusTip(tr("Open an existing repository or working folder"));
Chris@365 2985 m_openAct->setShortcut(tr("Ctrl+O"));
Chris@365 2986
Chris@365 2987 m_changeRemoteRepoAct = new QAction(tr("Set Remote &Location..."), this);
Chris@363 2988 m_changeRemoteRepoAct->setStatusTip(tr("Set or change the default remote repository for pull and push actions"));
Chris@273 2989
Chris@365 2990 m_settingsAct = new QAction(QIcon(":/images/settings.png"), tr("&Settings..."), this);
Chris@365 2991 m_settingsAct->setStatusTip(tr("View and change application settings"));
Chris@273 2992
Chris@343 2993 #ifdef Q_OS_WIN32
Chris@365 2994 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("E&xit"), this);
Chris@343 2995 #else
Chris@365 2996 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("&Quit"), this);
Chris@343 2997 #endif
Chris@284 2998 m_exitAct->setShortcuts(QKeySequence::Quit);
Chris@365 2999 m_exitAct->setStatusTip(tr("Exit EasyMercurial"));
jtkorhonen@0 3000
jtkorhonen@0 3001 //Repository actions
Chris@365 3002 m_hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("&Refresh"), this);
Chris@365 3003 m_hgRefreshAct->setShortcut(tr("Ctrl+R"));
Chris@284 3004 m_hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
Chris@273 3005
Chris@365 3006 m_hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Pre&view Incoming Changes"), this);
Chris@365 3007 m_hgIncomingAct->setIconText(tr("Preview"));
Chris@365 3008 m_hgIncomingAct->setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
Chris@365 3009
Chris@365 3010 m_hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pu&ll from Remote Repository"), this);
Chris@365 3011 m_hgPullAct->setIconText(tr("Pull"));
Chris@365 3012 m_hgPullAct->setShortcut(tr("Ctrl+L"));
Chris@365 3013 m_hgPullAct->setStatusTip(tr("Pull changes from the remote repository to the local repository"));
Chris@365 3014
Chris@365 3015 m_hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Pus&h to Remote Repository"), this);
Chris@365 3016 m_hgPushAct->setIconText(tr("Push"));
Chris@365 3017 m_hgPushAct->setShortcut(tr("Ctrl+H"));
Chris@284 3018 m_hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
jtkorhonen@0 3019
jtkorhonen@0 3020 //Workfolder actions
Chris@365 3021 m_hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("&Diff"), this);
Chris@365 3022 m_hgFolderDiffAct->setIconText(tr("Diff"));
Chris@365 3023 m_hgFolderDiffAct->setShortcut(tr("Ctrl+D"));
Chris@284 3024 m_hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
Chris@273 3025
Chris@365 3026 m_hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Re&vert"), this);
Chris@284 3027 m_hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
Chris@273 3028
Chris@365 3029 m_hgAddAct = new QAction(QIcon(":/images/add.png"), tr("&Add Files"), this);
Chris@365 3030 m_hgAddAct->setIconText(tr("Add"));
Chris@365 3031 m_hgAddAct->setShortcut(tr("+"));
Chris@365 3032 m_hgAddAct->setStatusTip(tr("Mark the selected files to be added on the next commit"));
Chris@365 3033
Chris@365 3034 m_hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("&Remove Files"), this);
Chris@365 3035 m_hgRemoveAct->setIconText(tr("Remove"));
Chris@365 3036 m_hgRemoveAct->setShortcut(tr("Del"));
Chris@365 3037 m_hgRemoveAct->setStatusTip(tr("Mark the selected files to be removed from version control on the next commit"));
Chris@365 3038
Chris@425 3039 m_hgIgnoreAct = new QAction(tr("&Ignore Files..."), this);
Chris@425 3040 m_hgIgnoreAct->setStatusTip(tr("Add the selected filenames to the ignored list, of files that should never be tracked in this repository"));
Chris@425 3041
Chris@425 3042 m_hgEditIgnoreAct = new QAction(tr("Edit Ignored List"), this);
Chris@425 3043 m_hgEditIgnoreAct->setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
Chris@425 3044
Chris@365 3045 m_hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("&Update to Branch Head"), this);
Chris@365 3046 m_hgUpdateAct->setIconText(tr("Update"));
Chris@365 3047 m_hgUpdateAct->setShortcut(tr("Ctrl+U"));
Chris@284 3048 m_hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
jtkorhonen@0 3049
Chris@365 3050 m_hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("&Commit..."), this);
Chris@365 3051 m_hgCommitAct->setShortcut(tr("Ctrl+Return"));
Chris@284 3052 m_hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
Chris@273 3053
Chris@365 3054 m_hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("&Merge"), this);
Chris@365 3055 m_hgMergeAct->setShortcut(tr("Ctrl+M"));
Chris@284 3056 m_hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
jtkorhonen@0 3057
Chris@425 3058 m_hgServeAct = new QAction(tr("Share Repository"), this);
Chris@425 3059 m_hgServeAct->setStatusTip(tr("Serve local repository temporarily via HTTP for workgroup access"));
jtkorhonen@11 3060
jtkorhonen@0 3061 //Help actions
Chris@494 3062 #ifdef Q_OS_MAC
Chris@494 3063 m_helpAct = new QAction(tr("EasyMercurial Help"), this);
Chris@494 3064 #else
Chris@494 3065 m_helpAct = new QAction(tr("Help Topics"), this);
Chris@494 3066 #endif
Chris@494 3067 m_helpAct->setShortcuts(QKeySequence::HelpContents);
Chris@284 3068 m_aboutAct = new QAction(tr("About EasyMercurial"), this);
Chris@94 3069
Chris@94 3070 // Miscellaneous
Chris@199 3071 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
Chris@199 3072 connect(clearSelectionsShortcut, SIGNAL(activated()),
Chris@199 3073 this, SLOT(clearSelections()));
jtkorhonen@0 3074 }
jtkorhonen@0 3075
jtkorhonen@0 3076 void MainWindow::createMenus()
jtkorhonen@0 3077 {
Chris@365 3078 m_fileMenu = menuBar()->addMenu(tr("&File"));
Chris@365 3079
Chris@365 3080 m_fileMenu->addAction(m_openAct);
Chris@365 3081 m_recentMenu = m_fileMenu->addMenu(tr("Open Re&cent"));
Chris@365 3082 m_fileMenu->addAction(m_hgRefreshAct);
Chris@365 3083 m_fileMenu->addSeparator();
Chris@425 3084 m_fileMenu->addAction(m_hgServeAct);
Chris@425 3085 m_fileMenu->addSeparator();
Chris@365 3086 m_fileMenu->addAction(m_settingsAct);
Chris@365 3087 m_fileMenu->addSeparator();
Chris@365 3088 m_fileMenu->addAction(m_exitAct);
Chris@365 3089
Chris@365 3090 QMenu *workMenu;
Chris@365 3091 workMenu = menuBar()->addMenu(tr("&Work"));
Chris@365 3092 workMenu->addAction(m_hgFolderDiffAct);
Chris@365 3093 workMenu->addSeparator();
Chris@365 3094 workMenu->addAction(m_hgUpdateAct);
Chris@365 3095 workMenu->addAction(m_hgCommitAct);
Chris@365 3096 workMenu->addAction(m_hgMergeAct);
Chris@365 3097 workMenu->addSeparator();
Chris@365 3098 workMenu->addAction(m_hgAddAct);
Chris@365 3099 workMenu->addAction(m_hgRemoveAct);
Chris@365 3100 workMenu->addSeparator();
Chris@425 3101 workMenu->addAction(m_hgIgnoreAct);
Chris@425 3102 workMenu->addAction(m_hgEditIgnoreAct);
Chris@425 3103 workMenu->addSeparator();
Chris@365 3104 workMenu->addAction(m_hgRevertAct);
Chris@365 3105
Chris@365 3106 QMenu *remoteMenu;
Chris@365 3107 remoteMenu = menuBar()->addMenu(tr("&Remote"));
Chris@425 3108 remoteMenu->addAction(m_changeRemoteRepoAct);
Chris@425 3109 remoteMenu->addSeparator();
Chris@365 3110 remoteMenu->addAction(m_hgIncomingAct);
Chris@365 3111 remoteMenu->addSeparator();
Chris@365 3112 remoteMenu->addAction(m_hgPullAct);
Chris@365 3113 remoteMenu->addAction(m_hgPushAct);
Chris@273 3114
Chris@378 3115 m_helpMenu = menuBar()->addMenu(tr("&Help"));
Chris@494 3116 m_helpMenu->addAction(m_helpAct);
Chris@284 3117 m_helpMenu->addAction(m_aboutAct);
jtkorhonen@0 3118 }
jtkorhonen@0 3119
jtkorhonen@0 3120 void MainWindow::createToolBars()
jtkorhonen@0 3121 {
Chris@442 3122 int sz = 32;
Chris@442 3123
Chris@284 3124 m_fileToolBar = addToolBar(tr("File"));
Chris@442 3125 m_fileToolBar->setIconSize(QSize(sz, sz));
Chris@365 3126 m_fileToolBar->addAction(m_openAct);
Chris@365 3127 m_fileToolBar->addAction(m_hgRefreshAct);
Chris@365 3128 m_fileToolBar->setMovable(false);
Chris@273 3129
Chris@442 3130 m_repoToolBar = addToolBar(tr("Remote"));
Chris@442 3131 m_repoToolBar->setIconSize(QSize(sz, sz));
Chris@284 3132 m_repoToolBar->addAction(m_hgIncomingAct);
Chris@284 3133 m_repoToolBar->addAction(m_hgPullAct);
Chris@284 3134 m_repoToolBar->addAction(m_hgPushAct);
Chris@365 3135 m_repoToolBar->setMovable(false);
Chris@273 3136
Chris@442 3137 m_workFolderToolBar = addToolBar(tr("Work"));
Chris@284 3138 addToolBar(Qt::LeftToolBarArea, m_workFolderToolBar);
Chris@442 3139 m_workFolderToolBar->setIconSize(QSize(sz, sz));
Chris@284 3140 m_workFolderToolBar->addAction(m_hgFolderDiffAct);
Chris@284 3141 m_workFolderToolBar->addSeparator();
Chris@284 3142 m_workFolderToolBar->addAction(m_hgRevertAct);
Chris@284 3143 m_workFolderToolBar->addAction(m_hgUpdateAct);
Chris@284 3144 m_workFolderToolBar->addAction(m_hgCommitAct);
Chris@284 3145 m_workFolderToolBar->addAction(m_hgMergeAct);
Chris@284 3146 m_workFolderToolBar->addSeparator();
Chris@284 3147 m_workFolderToolBar->addAction(m_hgAddAct);
Chris@284 3148 m_workFolderToolBar->addAction(m_hgRemoveAct);
Chris@365 3149 m_workFolderToolBar->setMovable(false);
Chris@61 3150
Chris@230 3151 updateToolBarStyle();
jtkorhonen@0 3152 }
jtkorhonen@0 3153
Chris@230 3154 void MainWindow::updateToolBarStyle()
Chris@230 3155 {
Chris@230 3156 QSettings settings;
Chris@230 3157 settings.beginGroup("Presentation");
Chris@230 3158 bool showText = settings.value("showiconlabels", true).toBool();
Chris@230 3159 settings.endGroup();
Chris@230 3160
Chris@230 3161 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@230 3162 tb->setToolButtonStyle(showText ?
Chris@230 3163 Qt::ToolButtonTextUnderIcon :
Chris@230 3164 Qt::ToolButtonIconOnly);
Chris@230 3165 }
Chris@230 3166 }
jtkorhonen@0 3167
Chris@287 3168 void MainWindow::updateWorkFolderAndRepoNames()
Chris@287 3169 {
Chris@287 3170 m_hgTabs->setLocalPath(m_workFolderPath);
Chris@287 3171
Chris@287 3172 m_workStatus->setLocalPath(m_workFolderPath);
Chris@287 3173 m_workStatus->setRemoteURL(m_remoteRepoPath);
Chris@287 3174 }
Chris@287 3175
jtkorhonen@0 3176 void MainWindow::createStatusBar()
jtkorhonen@0 3177 {
jtkorhonen@0 3178 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 3179 }
jtkorhonen@0 3180
jtkorhonen@0 3181 void MainWindow::readSettings()
jtkorhonen@0 3182 {
jtkorhonen@0 3183 QDir workFolder;
jtkorhonen@0 3184
Chris@61 3185 QSettings settings;
jtkorhonen@0 3186
Chris@284 3187 m_remoteRepoPath = settings.value("remoterepopath", "").toString();
Chris@284 3188 m_workFolderPath = settings.value("workfolderpath", "").toString();
Chris@284 3189 if (!workFolder.exists(m_workFolderPath))
jtkorhonen@0 3190 {
Chris@284 3191 m_workFolderPath = "";
jtkorhonen@0 3192 }
jtkorhonen@0 3193
jtkorhonen@0 3194 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
Chris@340 3195 QSize size = settings.value("size", QSize(550, 550)).toSize();
Chris@284 3196 m_firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 3197
jtkorhonen@0 3198 resize(size);
jtkorhonen@0 3199 move(pos);
jtkorhonen@0 3200 }
jtkorhonen@0 3201
jtkorhonen@0 3202 void MainWindow::writeSettings()
jtkorhonen@0 3203 {
Chris@61 3204 QSettings settings;
jtkorhonen@0 3205 settings.setValue("pos", pos());
jtkorhonen@0 3206 settings.setValue("size", size());
Chris@284 3207 settings.setValue("remoterepopath", m_remoteRepoPath);
Chris@284 3208 settings.setValue("workfolderpath", m_workFolderPath);
Chris@284 3209 settings.setValue("firststart", m_firstStart);
jtkorhonen@0 3210 }
jtkorhonen@0 3211
Chris@491 3212 void MainWindow::newerVersionAvailable(QString version)
Chris@491 3213 {
Chris@491 3214 QSettings settings;
Chris@491 3215 settings.beginGroup("NewerVersionWarning");
Chris@491 3216 QString tag = QString("version-%1-available-show").arg(version);
Chris@491 3217 if (settings.value(tag, true).toBool()) {
Chris@491 3218 QString title(tr("Newer version available"));
Chris@491 3219 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of EasyMercurial, but version %3 is now available.</p><p>Please see the <a href=\"http://easymercurial.org/\">EasyMercurial website</a> for more information.</p>").arg(EASYHG_VERSION).arg(version));
Chris@491 3220 QMessageBox::information(this, title, text);
Chris@491 3221 settings.setValue(tag, false);
Chris@491 3222 }
Chris@491 3223 settings.endGroup();
Chris@491 3224 }
Chris@491 3225
Chris@494 3226 void MainWindow::help()
Chris@494 3227 {
Chris@494 3228 if (!m_helpDialog) {
Chris@494 3229 m_helpDialog = new QDialog;
Chris@494 3230 QGridLayout *layout = new QGridLayout;
Chris@494 3231 m_helpDialog->setLayout(layout);
Chris@498 3232 QPushButton *home = new QPushButton;
Chris@498 3233 home->setIcon(QIcon(":images/home.png"));
Chris@498 3234 layout->addWidget(home, 0, 0);
Chris@498 3235 QPushButton *back = new QPushButton;
Chris@498 3236 back->setIcon(QIcon(":images/back.png"));
Chris@498 3237 layout->addWidget(back, 0, 1);
Chris@498 3238 QPushButton *fwd = new QPushButton;
Chris@498 3239 fwd->setIcon(QIcon(":images/forward.png"));
Chris@498 3240 layout->addWidget(fwd, 0, 2);
Chris@494 3241 QTextBrowser *text = new QTextBrowser;
Chris@494 3242 text->setOpenExternalLinks(true);
Chris@498 3243 layout->addWidget(text, 1, 0, 1, 4);
Chris@494 3244 text->setSource(QUrl("qrc:help/topics.html"));
Chris@494 3245 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@494 3246 connect(bb, SIGNAL(rejected()), m_helpDialog, SLOT(hide()));
Chris@498 3247 connect(text, SIGNAL(backwardAvailable(bool)),
Chris@498 3248 back, SLOT(setEnabled(bool)));
Chris@498 3249 connect(text, SIGNAL(forwardAvailable(bool)),
Chris@498 3250 fwd, SLOT(setEnabled(bool)));
Chris@498 3251 connect(home, SIGNAL(clicked()), text, SLOT(home()));
Chris@498 3252 connect(back, SIGNAL(clicked()), text, SLOT(backward()));
Chris@498 3253 connect(fwd, SIGNAL(clicked()), text, SLOT(forward()));
Chris@498 3254 back->setEnabled(false);
Chris@498 3255 fwd->setEnabled(false);
Chris@498 3256 layout->addWidget(bb, 2, 0, 1, 4);
Chris@498 3257 layout->setColumnStretch(3, 20);
Chris@494 3258 m_helpDialog->resize(450, 500);
Chris@494 3259 }
Chris@494 3260 QTextBrowser *tb = m_helpDialog->findChild<QTextBrowser *>();
Chris@494 3261 if (tb) tb->home();
Chris@494 3262 m_helpDialog->show();
Chris@494 3263 m_helpDialog->raise();
Chris@494 3264 }
Chris@494 3265