annotate mainwindow.cpp @ 237:c9a7e4ec2f78

* Try to do the right thing when completely reverting a merge (forget that the merge took place) * When trying to clone from remote repo to existing local dir, offer to create a subdir instead * Tidy up clone-successful notification * Add a note to commit and revert confirmation dialogs to tell user if they are committing/reverting only a subset of available files
author Chris Cannam
date Mon, 10 Jan 2011 12:44:03 +0000
parents 2f4d401ce47c
children e2f2c6e3c01b
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@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 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@125 32 #include <QRegExp>
Chris@199 33 #include <QShortcut>
Chris@237 34 #include <QUrl>
jtkorhonen@0 35
Chris@53 36 #include "mainwindow.h"
Chris@69 37 #include "multichoicedialog.h"
Chris@64 38 #include "startupdialog.h"
Chris@53 39 #include "colourset.h"
Chris@62 40 #include "debug.h"
Chris@74 41 #include "logparser.h"
Chris@103 42 #include "confirmcommentdialog.h"
Chris@125 43 #include "incomingdialog.h"
Chris@175 44 #include "settingsdialog.h"
Chris@229 45 #include "version.h"
Chris@53 46
jtkorhonen@0 47
Chris@172 48 MainWindow::MainWindow(QString myDirPath) :
Chris@172 49 m_myDirPath(myDirPath)
jtkorhonen@0 50 {
Chris@197 51 setWindowIcon(QIcon(":images/easyhg-icon.png"));
Chris@197 52
jtkorhonen@0 53 QString wndTitle;
jtkorhonen@0 54
Chris@199 55 showAllFiles = false;
Chris@199 56
Chris@90 57 fsWatcher = 0;
Chris@133 58 commitsSincePush = 0;
Chris@163 59 shouldHgStat = true;
Chris@90 60
jtkorhonen@0 61 createActions();
jtkorhonen@0 62 createMenus();
jtkorhonen@0 63 createToolBars();
jtkorhonen@0 64 createStatusBar();
jtkorhonen@0 65
Chris@172 66 runner = new HgRunner(myDirPath, this);
Chris@109 67 connect(runner, SIGNAL(commandCompleted(HgAction, QString)),
Chris@109 68 this, SLOT(commandCompleted(HgAction, QString)));
Chris@109 69 connect(runner, SIGNAL(commandFailed(HgAction, QString)),
Chris@109 70 this, SLOT(commandFailed(HgAction, QString)));
jtkorhonen@0 71 statusBar()->addPermanentWidget(runner);
jtkorhonen@0 72
Chris@61 73 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 74
jtkorhonen@0 75 remoteRepoPath = "";
jtkorhonen@0 76 workFolderPath = "";
jtkorhonen@0 77
jtkorhonen@0 78 readSettings();
jtkorhonen@0 79
jtkorhonen@33 80 justMerged = false;
Chris@210 81
Chris@210 82 QWidget *central = new QWidget(this);
Chris@210 83 setCentralWidget(central);
Chris@210 84
Chris@210 85 hgTabs = new HgTabWidget(central, remoteRepoPath, workFolderPath);
Chris@141 86 connectTabsSignals();
Chris@210 87
Chris@210 88 // Instead of setting the tab widget as our central widget
Chris@210 89 // directly, put it in a layout, so that we can have some space
Chris@210 90 // around it on the Mac where it looks very strange without
Chris@210 91
Chris@210 92 QGridLayout *cl = new QGridLayout(central);
Chris@210 93 cl->addWidget(hgTabs, 0, 0);
Chris@210 94
Chris@210 95 #ifndef Q_OS_MAC
Chris@210 96 cl->setMargin(0);
Chris@210 97 #endif
jtkorhonen@0 98
Chris@98 99 connect(hgTabs, SIGNAL(selectionChanged()),
Chris@95 100 this, SLOT(enableDisableActions()));
Chris@199 101 connect(hgTabs, SIGNAL(showAllChanged(bool)),
Chris@199 102 this, SLOT(showAllChanged(bool)));
Chris@95 103
jtkorhonen@0 104 setUnifiedTitleAndToolBarOnMac(true);
jtkorhonen@0 105 connectActions();
Chris@120 106 clearState();
jtkorhonen@0 107 enableDisableActions();
jtkorhonen@0 108
Chris@64 109 if (firstStart) {
Chris@64 110 startupDialog();
jtkorhonen@0 111 }
jtkorhonen@0 112
Chris@179 113 (void)findDiffBinaryName();
Chris@179 114 (void)findMergeBinaryName();
Chris@179 115 (void)findEditorBinaryName();
Chris@112 116
Chris@64 117 ColourSet *cs = ColourSet::instance();
Chris@64 118 cs->clearDefaultNames();
Chris@64 119 cs->addDefaultName("");
Chris@153 120 cs->addDefaultName("default");
Chris@64 121 cs->addDefaultName(getUserInfo());
Chris@62 122
Chris@72 123 if (workFolderPath == "") {
Chris@72 124 open();
Chris@72 125 }
Chris@72 126
Chris@175 127 hgTest();
jtkorhonen@0 128 }
jtkorhonen@0 129
jtkorhonen@0 130
jtkorhonen@0 131 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 132 {
jtkorhonen@0 133 writeSettings();
Chris@90 134 delete fsWatcher;
jtkorhonen@0 135 }
jtkorhonen@0 136
jtkorhonen@0 137
Chris@64 138 QString MainWindow::getUserInfo() const
Chris@64 139 {
Chris@64 140 QSettings settings;
Chris@64 141 settings.beginGroup("User Information");
Chris@64 142 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 143 QString email = settings.value("email", "").toString();
Chris@64 144
Chris@64 145 QString identifier;
Chris@64 146
Chris@64 147 if (email != "") {
Chris@64 148 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 149 } else {
Chris@64 150 identifier = name;
Chris@64 151 }
Chris@64 152
Chris@64 153 return identifier;
Chris@64 154 }
Chris@64 155
jtkorhonen@0 156 void MainWindow::about()
jtkorhonen@0 157 {
Chris@97 158 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@229 159 tr("<qt><h2>EasyMercurial v%1</h2>"
Chris@228 160 #ifdef Q_OS_MAC
Chris@228 161 "<font size=-1>"
Chris@228 162 #endif
Chris@97 163 "<p>EasyMercurial is a simple user interface for the "
Chris@186 164 "Mercurial</a> version control system.</p>"
Chris@186 165 "<h4>Credits and Copyright</h4>"
Chris@186 166 "<p>Development carried out by Chris Cannam for "
Chris@186 167 "SoundSoftware.ac.uk at the Centre for Digital Music, "
Chris@186 168 "Queen Mary, University of London.</p>"
Chris@186 169 "<p>EasyMercurial is based on HgExplorer by "
Chris@186 170 "Jari Korhonen, with thanks.</p>"
Chris@186 171 "<p style=\"margin-left: 2em;\">"
Chris@186 172 "Copyright &copy; 2010 Queen Mary, University of London.<br>"
Chris@186 173 "Copyright &copy; 2010 Jari Korhonen.<br>"
Chris@186 174 "Copyright &copy; 2010 Chris Cannam."
Chris@186 175 "</p>"
Chris@186 176 "<p style=\"margin-left: 2em;\">"
Chris@186 177 "This program requires Mercurial, by Matt Mackall and others.<br>"
Chris@186 178 "This program uses Qt by Nokia.<br>"
Chris@186 179 "This program uses Nuvola icons by David Vignoni.<br>"
Chris@186 180 "This program may use KDiff3 by Joachim Eibl.<br>"
Chris@186 181 "This program may use PyQt by River Bank Computing.<br>"
Chris@186 182 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
Chris@186 183 "</p>"
Chris@186 184 "<h4>License</h4>"
Chris@186 185 "<p>This program is free software; you can redistribute it and/or "
Chris@97 186 "modify it under the terms of the GNU General Public License as "
Chris@97 187 "published by the Free Software Foundation; either version 2 of the "
Chris@97 188 "License, or (at your option) any later version. See the file "
Chris@223 189 "COPYING included with this distribution for more information.</p>"
Chris@228 190 #ifdef Q_OS_MAC
Chris@228 191 "</font>"
Chris@228 192 #endif
Chris@229 193 ).arg(EASYHG_VERSION));
jtkorhonen@0 194 }
jtkorhonen@0 195
Chris@94 196 void MainWindow::clearSelections()
Chris@94 197 {
Chris@98 198 hgTabs->clearSelections();
Chris@94 199 }
jtkorhonen@0 200
Chris@199 201 void MainWindow::showAllChanged(bool s)
Chris@199 202 {
Chris@199 203 showAllFiles = s;
Chris@199 204 hgQueryPaths();
Chris@199 205 }
Chris@199 206
Chris@120 207 void MainWindow::hgRefresh()
Chris@120 208 {
Chris@120 209 clearState();
Chris@120 210 hgQueryPaths();
Chris@120 211 }
Chris@120 212
Chris@175 213 void MainWindow::hgTest()
Chris@175 214 {
Chris@175 215 QStringList params;
Chris@207 216 //!!! should we test version output? Really we want at least 1.7.x
Chris@207 217 //!!! for options such as merge --tool
Chris@175 218 params << "--version";
Chris@175 219 runner->requestAction(HgAction(ACT_TEST_HG, m_myDirPath, params));
Chris@175 220 }
Chris@175 221
Chris@200 222 void MainWindow::hgTestExtension()
Chris@200 223 {
Chris@200 224 QStringList params;
Chris@200 225 params << "--version";
Chris@200 226 runner->requestAction(HgAction(ACT_TEST_HG_EXT, m_myDirPath, params));
Chris@200 227 }
Chris@200 228
jtkorhonen@0 229 void MainWindow::hgStat()
jtkorhonen@0 230 {
Chris@109 231 QStringList params;
Chris@199 232
Chris@199 233 if (showAllFiles) {
Chris@199 234 params << "stat" << "-A";
Chris@199 235 } else {
Chris@199 236 params << "stat" << "-ardum";
Chris@199 237 }
Chris@153 238
Chris@163 239 lastStatOutput = "";
Chris@163 240
Chris@153 241 // annoyingly, hg stat actually modifies the working directory --
Chris@153 242 // it creates files called hg-checklink and hg-checkexec to test
Chris@153 243 // properties of the filesystem
Chris@153 244 if (fsWatcher) fsWatcher->blockSignals(true);
Chris@153 245
Chris@109 246 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params));
jtkorhonen@0 247 }
jtkorhonen@0 248
Chris@109 249 void MainWindow::hgQueryPaths()
Chris@74 250 {
Chris@210 251 // Quickest is to just read the file
Chris@198 252
Chris@198 253 QFileInfo hgrc(workFolderPath + "/.hg/hgrc");
Chris@198 254
Chris@210 255 QString path;
Chris@210 256
Chris@198 257 if (hgrc.exists()) {
Chris@198 258 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
Chris@198 259 s.beginGroup("paths");
Chris@210 260 path = s.value("default").toString();
Chris@210 261 }
Chris@198 262
Chris@210 263 remoteRepoPath = path;
Chris@198 264
Chris@210 265 // We have to do this here, because commandCompleted won't be called
Chris@210 266 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@210 267 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@210 268 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@210 269
Chris@210 270 hgQueryBranch();
Chris@210 271 return;
Chris@210 272
Chris@210 273 /* The classic method!
Chris@198 274
Chris@109 275 QStringList params;
Chris@109 276 params << "paths";
Chris@109 277 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params));
Chris@210 278 */
Chris@74 279 }
Chris@74 280
Chris@109 281 void MainWindow::hgQueryBranch()
Chris@106 282 {
Chris@210 283 // Quickest is to just read the file
Chris@198 284
Chris@198 285 QFile hgbr(workFolderPath + "/.hg/branch");
Chris@198 286
Chris@210 287 QString br = "default";
Chris@210 288
Chris@198 289 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
Chris@210 290 QByteArray ba = hgbr.readLine();
Chris@210 291 br = QString::fromUtf8(ba).trimmed();
Chris@210 292 }
Chris@210 293
Chris@210 294 currentBranch = br;
Chris@210 295
Chris@210 296 // We have to do this here, because commandCompleted won't be called
Chris@210 297 hgStat();
Chris@210 298 return;
Chris@198 299
Chris@210 300 /* The classic method!
Chris@198 301
Chris@109 302 QStringList params;
Chris@109 303 params << "branch";
Chris@109 304 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params));
Chris@210 305 */
Chris@106 306 }
Chris@106 307
Chris@109 308 void MainWindow::hgQueryHeads()
jtkorhonen@0 309 {
Chris@109 310 QStringList params;
Chris@137 311 // On empty repos, "hg heads" will fail -- we don't care about
Chris@137 312 // that. Use --closed option so as to include closed branches;
Chris@137 313 // otherwise we'll be stuck if the user updates into one, and our
Chris@137 314 // incremental log will end up with spurious stuff in it because
Chris@137 315 // we won't be pruning at the ends of closed branches
Chris@137 316 params << "heads" << "--closed";
Chris@109 317 runner->requestAction(HgAction(ACT_QUERY_HEADS, workFolderPath, params));
jtkorhonen@0 318 }
jtkorhonen@0 319
jtkorhonen@0 320 void MainWindow::hgLog()
jtkorhonen@0 321 {
Chris@109 322 QStringList params;
Chris@109 323 params << "log";
Chris@109 324 params << "--template";
Chris@125 325 params << Changeset::getLogTemplate();
Chris@109 326
Chris@109 327 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
Chris@109 328 }
Chris@109 329
Chris@150 330 void MainWindow::hgLogIncremental(QStringList prune)
Chris@120 331 {
Chris@120 332 QStringList params;
Chris@120 333 params << "log";
Chris@120 334
Chris@150 335 foreach (QString p, prune) {
Chris@153 336 params << "--prune" << Changeset::hashOf(p);
Chris@120 337 }
Chris@120 338
Chris@120 339 params << "--template";
Chris@125 340 params << Changeset::getLogTemplate();
Chris@120 341
Chris@120 342 runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, workFolderPath, params));
Chris@120 343 }
Chris@109 344
Chris@109 345 void MainWindow::hgQueryParents()
Chris@109 346 {
Chris@109 347 QStringList params;
Chris@109 348 params << "parents";
Chris@109 349 runner->requestAction(HgAction(ACT_QUERY_PARENTS, workFolderPath, params));
Chris@109 350 }
Chris@109 351
Chris@109 352 void MainWindow::hgAnnotate()
Chris@109 353 {
Chris@109 354 QStringList params;
Chris@109 355 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
Chris@109 356
Chris@109 357 if (!currentFile.isEmpty())
jtkorhonen@0 358 {
Chris@109 359 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 360
Chris@109 361 runner->requestAction(HgAction(ACT_ANNOTATE, workFolderPath, params));
jtkorhonen@0 362 }
jtkorhonen@0 363 }
jtkorhonen@0 364
Chris@109 365 void MainWindow::hgResolveList()
Chris@109 366 {
Chris@109 367 QStringList params;
jtkorhonen@0 368
Chris@109 369 params << "resolve" << "--list";
Chris@109 370 runner->requestAction(HgAction(ACT_RESOLVE_LIST, workFolderPath, params));
Chris@109 371 }
Chris@109 372
Chris@109 373 void MainWindow::hgAdd()
jtkorhonen@0 374 {
Chris@109 375 QStringList params;
jtkorhonen@0 376
Chris@109 377 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@109 378 // that one is a good idea, let's require the user to select
jtkorhonen@0 379
Chris@109 380 QStringList files = hgTabs->getSelectedAddableFiles();
Chris@109 381
Chris@109 382 if (!files.empty()) {
Chris@109 383 params << "add" << "--" << files;
Chris@109 384 runner->requestAction(HgAction(ACT_ADD, workFolderPath, params));
jtkorhonen@0 385 }
jtkorhonen@0 386 }
jtkorhonen@0 387
jtkorhonen@0 388
Chris@98 389 void MainWindow::hgRemove()
Chris@98 390 {
Chris@109 391 QStringList params;
Chris@98 392
Chris@109 393 QStringList files = hgTabs->getSelectedRemovableFiles();
Chris@98 394
Chris@109 395 if (!files.empty()) {
Chris@109 396 params << "remove" << "--after" << "--force" << "--" << files;
Chris@109 397 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params));
Chris@109 398 }
jtkorhonen@0 399 }
jtkorhonen@0 400
jtkorhonen@0 401 void MainWindow::hgCommit()
jtkorhonen@0 402 {
Chris@109 403 QStringList params;
Chris@109 404 QString comment;
Chris@94 405
Chris@157 406 if (justMerged) {
Chris@157 407 comment = mergeCommitComment;
Chris@157 408 }
Chris@157 409
Chris@109 410 QStringList files = hgTabs->getSelectedCommittableFiles();
Chris@237 411 QStringList allFiles = hgTabs->getAllCommittableFiles();
Chris@127 412 QStringList reportFiles = files;
Chris@237 413 if (reportFiles.empty()) {
Chris@237 414 reportFiles = allFiles;
Chris@237 415 }
Chris@103 416
Chris@237 417 QString subsetNote;
Chris@237 418 if (reportFiles != allFiles) {
Chris@237 419 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 420 }
Chris@237 421
Chris@155 422 QString cf(tr("Commit files"));
Chris@155 423
Chris@109 424 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@109 425 (this,
Chris@155 426 cf,
Chris@237 427 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@237 428 .arg(tr("You are about to commit the following files."))
Chris@237 429 .arg(subsetNote),
Chris@237 430 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@237 431 .arg(tr("You are about to commit %n file(s).", "", reportFiles.size()))
Chris@237 432 .arg(subsetNote),
Chris@127 433 reportFiles,
Chris@193 434 comment,
Chris@193 435 tr("Commit"))) {
Chris@103 436
Chris@157 437 if (!justMerged && !files.empty()) {
Chris@157 438 // User wants to commit selected file(s) (and this is not
Chris@157 439 // merge commit, which would fail if we selected files)
Chris@157 440 params << "commit" << "--message" << comment
Chris@157 441 << "--user" << getUserInfo() << "--" << files;
Chris@109 442 } else {
Chris@109 443 // Commit all changes
Chris@157 444 params << "commit" << "--message" << comment
Chris@157 445 << "--user" << getUserInfo();
jtkorhonen@0 446 }
Chris@109 447
Chris@109 448 runner->requestAction(HgAction(ACT_COMMIT, workFolderPath, params));
Chris@173 449 mergeCommitComment = "";
jtkorhonen@0 450 }
jtkorhonen@0 451 }
jtkorhonen@0 452
jtkorhonen@34 453 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 454 {
jtkorhonen@34 455 for(int i = 0; i < tag.size(); i++)
jtkorhonen@34 456 {
jtkorhonen@34 457 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
jtkorhonen@34 458 {
jtkorhonen@34 459 //ok
jtkorhonen@34 460 }
jtkorhonen@34 461 else
jtkorhonen@34 462 {
jtkorhonen@34 463 tag[i] = QChar('_');
jtkorhonen@34 464 }
jtkorhonen@34 465 }
jtkorhonen@34 466 return tag;
jtkorhonen@34 467 }
jtkorhonen@34 468
jtkorhonen@34 469
Chris@164 470 void MainWindow::hgTag(QString id)
jtkorhonen@34 471 {
Chris@109 472 QStringList params;
Chris@109 473 QString tag;
jtkorhonen@34 474
Chris@109 475 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@109 476 (this,
Chris@109 477 tr("Tag"),
Chris@109 478 tr("Enter tag:"),
Chris@193 479 tag,
Chris@193 480 tr("Add Tag"))) {
Chris@164 481 if (!tag.isEmpty()) {//!!! do something better if it is empty
Chris@164 482
Chris@164 483 params << "tag" << "--user" << getUserInfo();
Chris@164 484 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
Chris@109 485
Chris@109 486 runner->requestAction(HgAction(ACT_TAG, workFolderPath, params));
jtkorhonen@34 487 }
jtkorhonen@34 488 }
jtkorhonen@34 489 }
jtkorhonen@34 490
jtkorhonen@34 491
jtkorhonen@34 492 void MainWindow::hgIgnore()
jtkorhonen@34 493 {
Chris@109 494 QString hgIgnorePath;
Chris@109 495 QStringList params;
Chris@178 496
Chris@109 497 hgIgnorePath = workFolderPath;
Chris@178 498 hgIgnorePath += "/.hgignore";
Chris@109 499
Chris@109 500 params << hgIgnorePath;
Chris@179 501
Chris@179 502 QString editor = findEditorBinaryName();
Chris@112 503
Chris@179 504 if (editor == "") {
Chris@179 505 DEBUG << "Failed to find a text editor" << endl;
Chris@179 506 //!!! visible error!
Chris@179 507 return;
Chris@179 508 }
Chris@179 509
Chris@179 510 HgAction action(ACT_HG_IGNORE, workFolderPath, params);
Chris@179 511 action.executable = editor;
Chris@179 512
Chris@179 513 runner->requestAction(action);
Chris@179 514 }
Chris@179 515
Chris@179 516 QString MainWindow::findDiffBinaryName()
Chris@179 517 {
Chris@179 518 QSettings settings;
Chris@179 519 settings.beginGroup("Locations");
Chris@179 520 QString diff = settings.value("extdiffbinary", "").toString();
Chris@179 521 if (diff == "") {
Chris@179 522 QStringList bases;
Chris@212 523 #ifdef Q_OS_MAC
Chris@212 524 bases << "easyhg-extdiff-osx.sh";
Chris@212 525 #endif
Chris@212 526 bases << "kompare" << "kdiff3" << "meld";
Chris@179 527 bool found = false;
Chris@179 528 foreach (QString base, bases) {
Chris@179 529 diff = findInPath(base, m_myDirPath, true);
Chris@213 530 if (diff != "") {
Chris@179 531 found = true;
Chris@179 532 break;
Chris@179 533 }
Chris@179 534 }
Chris@179 535 if (found) {
Chris@179 536 settings.setValue("extdiffbinary", diff);
Chris@179 537 } else {
Chris@179 538 diff = "";
Chris@179 539 }
Chris@179 540 }
Chris@179 541 return diff;
Chris@179 542 }
Chris@179 543
Chris@179 544 QString MainWindow::findMergeBinaryName()
Chris@179 545 {
Chris@179 546 QSettings settings;
Chris@179 547 settings.beginGroup("Locations");
Chris@237 548 if (settings.contains("mergebinary")) {
Chris@237 549 // use it even if empty: user may have specified no external tool
Chris@237 550 QVariant v = settings.value("mergebinary");
Chris@237 551 DEBUG << "v = " << v << endl;
Chris@237 552 return v.toString();
Chris@195 553 }
Chris@195 554 QString merge;
Chris@195 555 QStringList bases;
Chris@212 556 #ifdef Q_OS_MAC
Chris@212 557 bases << "easyhg-merge-osx.sh";
Chris@212 558 #endif
Chris@237 559 // I think this is too dangerous, given command line ordering
Chris@237 560 // differences and suchlike. Need to make sure the hg
Chris@237 561 // installation is configured OK instead
Chris@237 562 // bases << "meld" << "diffuse" << "kdiff3";
Chris@195 563 bool found = false;
Chris@195 564 foreach (QString base, bases) {
Chris@195 565 merge = findInPath(base, m_myDirPath, true);
Chris@213 566 if (merge != "") {
Chris@195 567 found = true;
Chris@195 568 break;
Chris@179 569 }
Chris@195 570 }
Chris@195 571 if (found) {
Chris@195 572 settings.setValue("mergebinary", merge);
Chris@195 573 } else {
Chris@195 574 merge = "";
Chris@179 575 }
Chris@179 576 return merge;
Chris@179 577 }
Chris@179 578
Chris@179 579 QString MainWindow::findEditorBinaryName()
Chris@179 580 {
Chris@178 581 QSettings settings;
Chris@178 582 settings.beginGroup("Locations");
Chris@178 583 QString editor = settings.value("editorbinary", "").toString();
Chris@178 584 if (editor == "") {
Chris@178 585 QStringList bases;
Chris@178 586 bases
Chris@178 587 #if defined Q_OS_WIN32
Chris@178 588 << "wordpad.exe"
Chris@178 589 << "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"
Chris@178 590 << "notepad.exe"
Chris@178 591 #elif defined Q_OS_MAC
Chris@212 592 << "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
Chris@178 593 #else
Chris@178 594 << "gedit" << "kate"
Chris@178 595 #endif
Chris@178 596 ;
Chris@178 597 bool found = false;
Chris@178 598 foreach (QString base, bases) {
Chris@178 599 editor = findInPath(base, m_myDirPath, true);
Chris@213 600 if (editor != "") {
Chris@178 601 found = true;
Chris@178 602 break;
Chris@178 603 }
Chris@178 604 }
Chris@178 605 if (found) {
Chris@178 606 settings.setValue("editorbinary", editor);
Chris@178 607 } else {
Chris@178 608 editor = "";
Chris@178 609 }
Chris@178 610 }
Chris@179 611 return editor;
Chris@163 612 }
Chris@163 613
Chris@168 614 void MainWindow::hgShowSummary()
Chris@168 615 {
Chris@168 616 QStringList params;
Chris@168 617
Chris@168 618 params << "diff" << "--stat";
Chris@168 619
Chris@168 620 runner->requestAction(HgAction(ACT_DIFF_SUMMARY, workFolderPath, params));
Chris@168 621 }
Chris@168 622
jtkorhonen@0 623 void MainWindow::hgFolderDiff()
jtkorhonen@0 624 {
Chris@179 625 QString diff = findDiffBinaryName();
Chris@179 626 if (diff == "") return;
Chris@112 627
Chris@109 628 QStringList params;
jtkorhonen@0 629
Chris@112 630 // Diff parent against working folder (folder diff)
Chris@112 631
Chris@148 632 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 633 params << "--program" << diff;
Chris@109 634
Chris@153 635 params << hgTabs->getSelectedCommittableFiles(); // may be none: whole dir
Chris@153 636
Chris@109 637 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
jtkorhonen@0 638 }
jtkorhonen@0 639
jtkorhonen@0 640
Chris@148 641 void MainWindow::hgDiffToCurrent(QString id)
jtkorhonen@0 642 {
Chris@179 643 QString diff = findDiffBinaryName();
Chris@179 644 if (diff == "") return;
Chris@163 645
Chris@148 646 QStringList params;
jtkorhonen@0 647
Chris@148 648 // Diff given revision against working folder
jtkorhonen@0 649
Chris@148 650 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 651 params << "--program" << diff;
Chris@153 652 params << "--rev" << Changeset::hashOf(id);
Chris@148 653
Chris@148 654 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
jtkorhonen@0 655 }
jtkorhonen@0 656
jtkorhonen@0 657
Chris@148 658 void MainWindow::hgDiffToParent(QString child, QString parent)
Chris@148 659 {
Chris@179 660 QString diff = findDiffBinaryName();
Chris@179 661 if (diff == "") return;
Chris@163 662
Chris@148 663 QStringList params;
Chris@148 664
Chris@148 665 // Diff given revision against working folder
Chris@148 666
Chris@148 667 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 668 params << "--program" << diff;
Chris@153 669 params << "--rev" << Changeset::hashOf(parent)
Chris@153 670 << "--rev" << Changeset::hashOf(child);
Chris@148 671
Chris@148 672 runner->requestAction(HgAction(ACT_CHGSETDIFF, workFolderPath, params));
Chris@148 673 }
Chris@148 674
jtkorhonen@0 675
jtkorhonen@0 676 void MainWindow::hgUpdate()
jtkorhonen@0 677 {
Chris@109 678 QStringList params;
jtkorhonen@0 679
Chris@109 680 params << "update";
Chris@109 681
Chris@109 682 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
jtkorhonen@0 683 }
jtkorhonen@0 684
jtkorhonen@0 685
Chris@148 686 void MainWindow::hgUpdateToRev(QString id)
jtkorhonen@0 687 {
Chris@148 688 QStringList params;
jtkorhonen@0 689
Chris@153 690 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
jtkorhonen@0 691
Chris@148 692 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
jtkorhonen@0 693 }
jtkorhonen@0 694
jtkorhonen@0 695
jtkorhonen@0 696 void MainWindow::hgRevert()
jtkorhonen@0 697 {
Chris@109 698 QStringList params;
Chris@109 699 QString comment;
Chris@237 700 bool all = false;
Chris@98 701
Chris@109 702 QStringList files = hgTabs->getSelectedRevertableFiles();
Chris@237 703 QStringList allFiles = hgTabs->getAllRevertableFiles();
Chris@237 704 if (files.empty() || files == allFiles) {
Chris@237 705 files = allFiles;
Chris@237 706 all = true;
Chris@237 707 }
Chris@237 708
Chris@237 709 QString subsetNote;
Chris@237 710 if (!all) {
Chris@237 711 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 712 }
Chris@155 713
Chris@155 714 QString rf(tr("Revert files"));
Chris@237 715
Chris@237 716 // Set up params before asking for confirmation, because there is
Chris@237 717 // a failure case here that we would need to report on early
Chris@237 718
Chris@237 719 DEBUG << "hgRevert: justMerged = " << justMerged << ", mergeTargetRevision = " << mergeTargetRevision << endl;
Chris@237 720
Chris@237 721 if (justMerged) {
Chris@237 722
Chris@237 723 // This is a little fiddly. The proper way to "revert" the
Chris@237 724 // whole of an uncommitted merge is with "hg update --clean ."
Chris@237 725 // But if the user has selected only some files, we're sort of
Chris@237 726 // promising to revert only those, which means we need to
Chris@237 727 // specify which parent to revert to. We can only do that if
Chris@237 728 // we have a record of it, which we do if you just did the
Chris@237 729 // merge from within easyhg but don't if you've exited and
Chris@237 730 // restarted, or changed repository, since then. Hmmm.
Chris@237 731
Chris@237 732 if (all) {
Chris@237 733 params << "update" << "--clean" << ".";
Chris@237 734 } else {
Chris@237 735 if (mergeTargetRevision != "") {
Chris@237 736 params << "revert" << "--rev"
Chris@237 737 << Changeset::hashOf(mergeTargetRevision)
Chris@237 738 << "--" << files;
Chris@237 739 } else {
Chris@237 740 QMessageBox::information
Chris@237 741 (this, tr("Unable to revert"),
Chris@237 742 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 743 return;
Chris@237 744 }
Chris@237 745 }
Chris@237 746 } else {
Chris@237 747 params << "revert" << "--" << files;
Chris@237 748 }
Chris@237 749
Chris@109 750 if (ConfirmCommentDialog::confirmDangerousFilesAction
Chris@109 751 (this,
Chris@155 752 rf,
Chris@237 753 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 754 .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 755 .arg(subsetNote),
Chris@237 756 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 757 .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 758 .arg(subsetNote),
Chris@193 759 files,
Chris@193 760 tr("Revert"))) {
Chris@163 761
Chris@163 762 lastRevertedFiles = files;
Chris@109 763
Chris@109 764 runner->requestAction(HgAction(ACT_REVERT, workFolderPath, params));
jtkorhonen@0 765 }
jtkorhonen@0 766 }
jtkorhonen@0 767
Chris@163 768
Chris@163 769 void MainWindow::hgMarkResolved(QStringList files)
Chris@163 770 {
Chris@163 771 QStringList params;
Chris@163 772
Chris@163 773 params << "resolve" << "--mark";
Chris@163 774
Chris@163 775 if (files.empty()) {
Chris@163 776 params << "--all";
Chris@163 777 } else {
Chris@164 778 params << "--" << files;
Chris@163 779 }
Chris@163 780
Chris@163 781 runner->requestAction(HgAction(ACT_RESOLVE_MARK, workFolderPath, params));
Chris@163 782 }
Chris@163 783
Chris@163 784
jtkorhonen@33 785 void MainWindow::hgRetryMerge()
jtkorhonen@33 786 {
Chris@109 787 QStringList params;
jtkorhonen@33 788
Chris@163 789 params << "resolve";
Chris@163 790
Chris@179 791 QString merge = findMergeBinaryName();
Chris@179 792 if (merge != "") {
Chris@179 793 params << "--tool" << merge;
Chris@163 794 }
Chris@163 795
Chris@163 796 QStringList files = hgTabs->getSelectedUnresolvedFiles();
Chris@163 797 if (files.empty()) {
Chris@163 798 params << "--all";
Chris@163 799 } else {
Chris@164 800 params << "--" << files;
Chris@163 801 }
Chris@163 802
Chris@237 803 if (currentParents.size() == 1) {
Chris@237 804 mergeTargetRevision = currentParents[0]->id();
Chris@237 805 }
Chris@237 806
Chris@109 807 runner->requestAction(HgAction(ACT_RETRY_MERGE, workFolderPath, params));
Chris@163 808
Chris@163 809 mergeCommitComment = tr("Merge");
jtkorhonen@33 810 }
jtkorhonen@33 811
jtkorhonen@33 812
jtkorhonen@0 813 void MainWindow::hgMerge()
jtkorhonen@0 814 {
Chris@163 815 if (hgTabs->canResolve()) {
Chris@163 816 hgRetryMerge();
Chris@163 817 return;
Chris@163 818 }
Chris@163 819
Chris@109 820 QStringList params;
jtkorhonen@0 821
Chris@109 822 params << "merge";
Chris@163 823
Chris@179 824 QString merge = findMergeBinaryName();
Chris@179 825 if (merge != "") {
Chris@179 826 params << "--tool" << merge;
Chris@163 827 }
Chris@163 828
Chris@163 829 if (currentParents.size() == 1) {
Chris@163 830 mergeTargetRevision = currentParents[0]->id();
Chris@163 831 }
Chris@163 832
Chris@109 833 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
Chris@157 834
Chris@157 835 mergeCommitComment = tr("Merge");
jtkorhonen@0 836 }
jtkorhonen@0 837
jtkorhonen@0 838
Chris@148 839 void MainWindow::hgMergeFrom(QString id)
Chris@148 840 {
Chris@148 841 QStringList params;
Chris@148 842
Chris@148 843 params << "merge";
Chris@153 844 params << "--rev" << Changeset::hashOf(id);
Chris@163 845
Chris@179 846 QString merge = findMergeBinaryName();
Chris@179 847 if (merge != "") {
Chris@179 848 params << "--tool" << merge;
Chris@163 849 }
Chris@148 850
Chris@237 851 if (currentParents.size() == 1) {
Chris@237 852 mergeTargetRevision = currentParents[0]->id();
Chris@237 853 }
Chris@237 854
Chris@148 855 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
Chris@157 856
Chris@157 857 mergeCommitComment = "";
Chris@157 858
Chris@157 859 foreach (Changeset *cs, currentHeads) {
Chris@157 860 if (cs->id() == id && !cs->isOnBranch(currentBranch)) {
Chris@157 861 if (cs->branch() == "" || cs->branch() == "default") {
Chris@157 862 mergeCommitComment = tr("Merge from the default branch");
Chris@157 863 } else {
Chris@157 864 mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
Chris@157 865 }
Chris@157 866 }
Chris@157 867 }
Chris@157 868
Chris@157 869 if (mergeCommitComment == "") {
Chris@157 870 mergeCommitComment = tr("Merge from %1").arg(id);
Chris@157 871 }
Chris@148 872 }
Chris@148 873
Chris@148 874
jtkorhonen@0 875 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 876 {
Chris@109 877 QStringList params;
jtkorhonen@0 878
Chris@109 879 if (!QDir(workFolderPath).exists()) {
Chris@109 880 if (!QDir().mkpath(workFolderPath)) {
Chris@109 881 DEBUG << "hgCloneFromRemote: Failed to create target path "
Chris@109 882 << workFolderPath << endl;
Chris@109 883 //!!! report error
Chris@109 884 return;
Chris@104 885 }
Chris@109 886 }
Chris@104 887
Chris@109 888 params << "clone" << remoteRepoPath << workFolderPath;
Chris@109 889
Chris@109 890 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@113 891 hgTabs->updateWorkFolderFileList("");
jtkorhonen@0 892
Chris@109 893 runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, workFolderPath, params));
jtkorhonen@0 894 }
jtkorhonen@0 895
jtkorhonen@0 896 void MainWindow::hgInit()
jtkorhonen@0 897 {
Chris@109 898 QStringList params;
jtkorhonen@0 899
Chris@109 900 params << "init";
Chris@109 901 params << workFolderPath;
jtkorhonen@0 902
Chris@109 903 runner->requestAction(HgAction(ACT_INIT, workFolderPath, params));
jtkorhonen@0 904 }
jtkorhonen@0 905
jtkorhonen@0 906 void MainWindow::hgIncoming()
jtkorhonen@0 907 {
Chris@109 908 QStringList params;
jtkorhonen@0 909
Chris@109 910 params << "incoming" << "--newest-first" << remoteRepoPath;
Chris@125 911 params << "--template" << Changeset::getLogTemplate();
jtkorhonen@0 912
Chris@109 913 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params));
jtkorhonen@0 914 }
jtkorhonen@0 915
jtkorhonen@0 916 void MainWindow::hgPull()
jtkorhonen@0 917 {
Chris@193 918 if (ConfirmCommentDialog::confirm
Chris@126 919 (this, tr("Confirm pull"),
Chris@126 920 format3(tr("Confirm pull from remote repository"),
Chris@192 921 tr("You are about to pull changes from the following remote repository:"),
Chris@126 922 remoteRepoPath),
Chris@194 923 tr("Pull"))) {
jtkorhonen@0 924
Chris@126 925 QStringList params;
Chris@126 926 params << "pull" << remoteRepoPath;
Chris@126 927 runner->requestAction(HgAction(ACT_PULL, workFolderPath, params));
Chris@126 928 }
jtkorhonen@0 929 }
jtkorhonen@0 930
jtkorhonen@0 931 void MainWindow::hgPush()
jtkorhonen@0 932 {
Chris@193 933 if (ConfirmCommentDialog::confirm
Chris@126 934 (this, tr("Confirm push"),
Chris@126 935 format3(tr("Confirm push to remote repository"),
Chris@192 936 tr("You are about to push your changes to the following remote repository:"),
Chris@126 937 remoteRepoPath),
Chris@194 938 tr("Push"))) {
jtkorhonen@0 939
Chris@126 940 QStringList params;
Chris@154 941 params << "push" << "--new-branch" << remoteRepoPath;
Chris@126 942 runner->requestAction(HgAction(ACT_PUSH, workFolderPath, params));
Chris@126 943 }
jtkorhonen@0 944 }
jtkorhonen@0 945
Chris@182 946 QStringList MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 947 {
Chris@182 948 QStringList ret;
jtkorhonen@26 949 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 950
Chris@182 951 for (int i = 0; i < ifaces.count(); i++) {
jtkorhonen@26 952 QNetworkInterface iface = ifaces.at(i);
Chris@182 953 if (iface.flags().testFlag(QNetworkInterface::IsUp)
Chris@182 954 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
Chris@182 955 for (int j=0; j<iface.addressEntries().count(); j++) {
jtkorhonen@28 956 QHostAddress tmp = iface.addressEntries().at(j).ip();
Chris@182 957 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
Chris@182 958 ret.push_back(tmp.toString());
jtkorhonen@24 959 }
jtkorhonen@24 960 }
jtkorhonen@22 961 }
jtkorhonen@17 962 }
jtkorhonen@28 963 return ret;
jtkorhonen@28 964 }
jtkorhonen@17 965
Chris@120 966 void MainWindow::clearState()
Chris@120 967 {
Chris@120 968 foreach (Changeset *cs, currentParents) delete cs;
Chris@120 969 currentParents.clear();
Chris@120 970 foreach (Changeset *cs, currentHeads) delete cs;
Chris@120 971 currentHeads.clear();
Chris@120 972 currentBranch = "";
Chris@163 973 lastStatOutput = "";
Chris@163 974 lastRevertedFiles.clear();
Chris@163 975 mergeTargetRevision = "";
Chris@163 976 mergeCommitComment = "";
Chris@173 977 stateUnknown = true;
Chris@120 978 needNewLog = true;
Chris@199 979 if (fsWatcher) {
Chris@199 980 delete fsWatcher;
Chris@199 981 fsWatcher = 0;
Chris@199 982 }
Chris@120 983 }
jtkorhonen@17 984
jtkorhonen@11 985 void MainWindow::hgServe()
jtkorhonen@11 986 {
Chris@109 987 QStringList params;
Chris@109 988 QString msg;
jtkorhonen@11 989
Chris@182 990 QStringList addrs = listAllUpIpV4Addresses();
Chris@182 991
Chris@182 992 if (addrs.empty()) {
Chris@182 993 QMessageBox::critical
Chris@182 994 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
Chris@182 995 return;
Chris@182 996 }
Chris@182 997
Chris@182 998 //!!! should find available port as well
Chris@182 999
Chris@182 1000 QTextStream ts(&msg);
Chris@182 1001 ts << QString("<qt><p>%1</p>")
Chris@182 1002 .arg(tr("Running temporary server at %n address(es):", "", addrs.size()));
Chris@182 1003 foreach (QString addr, addrs) {
Chris@182 1004 ts << QString("<pre>&nbsp;&nbsp;http://%1:8000</pre>").arg(xmlEncode(addr));
Chris@182 1005 }
Chris@182 1006 ts << tr("<p>Press Close to stop the server and return.</p>");
Chris@182 1007 ts.flush();
Chris@182 1008
Chris@109 1009 params << "serve";
jtkorhonen@11 1010
Chris@109 1011 runner->requestAction(HgAction(ACT_SERVE, workFolderPath, params));
Chris@109 1012
Chris@182 1013 QMessageBox::information(this, tr("Serve"), msg, QMessageBox::Close);
Chris@182 1014
Chris@182 1015 runner->killCurrentActions();
jtkorhonen@11 1016 }
jtkorhonen@11 1017
Chris@64 1018 void MainWindow::startupDialog()
Chris@64 1019 {
Chris@64 1020 StartupDialog *dlg = new StartupDialog(this);
Chris@65 1021 if (dlg->exec()) firstStart = false;
Chris@64 1022 }
jtkorhonen@11 1023
Chris@69 1024 void MainWindow::open()
Chris@69 1025 {
Chris@86 1026 bool done = false;
Chris@69 1027
Chris@86 1028 while (!done) {
Chris@69 1029
Chris@86 1030 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 1031 (tr("Open Repository"),
Chris@86 1032 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 1033 this);
Chris@69 1034
Chris@86 1035 d->addChoice("remote",
Chris@86 1036 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@86 1037 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@86 1038 MultiChoiceDialog::UrlToDirectoryArg);
Chris@69 1039
Chris@86 1040 d->addChoice("local",
Chris@86 1041 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@86 1042 tr("Open an existing local Mercurial repository."),
Chris@86 1043 MultiChoiceDialog::DirectoryArg);
Chris@69 1044
Chris@86 1045 d->addChoice("init",
Chris@86 1046 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@86 1047 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@86 1048 MultiChoiceDialog::DirectoryArg);
Chris@79 1049
Chris@86 1050 d->setCurrentChoice("local");
Chris@86 1051
Chris@86 1052 if (d->exec() == QDialog::Accepted) {
Chris@86 1053
Chris@86 1054 QString choice = d->getCurrentChoice();
Chris@86 1055 QString arg = d->getArgument().trimmed();
Chris@86 1056
Chris@86 1057 bool result = false;
Chris@86 1058
Chris@86 1059 if (choice == "local") {
Chris@86 1060 result = openLocal(arg);
Chris@86 1061 } else if (choice == "remote") {
Chris@86 1062 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 1063 } else if (choice == "init") {
Chris@86 1064 result = openInit(arg);
Chris@86 1065 }
Chris@86 1066
Chris@86 1067 if (result) {
Chris@86 1068 enableDisableActions();
Chris@120 1069 clearState();
Chris@109 1070 hgQueryPaths();
Chris@91 1071 done = true;
Chris@91 1072 }
Chris@86 1073
Chris@86 1074 } else {
Chris@86 1075
Chris@86 1076 // cancelled
Chris@86 1077 done = true;
Chris@69 1078 }
Chris@79 1079
Chris@86 1080 delete d;
Chris@69 1081 }
Chris@69 1082 }
Chris@69 1083
Chris@182 1084 void MainWindow::changeRemoteRepo()
Chris@182 1085 {
Chris@183 1086 // This will involve rewriting the local .hgrc
Chris@183 1087
Chris@184 1088 QDir hgDir(workFolderPath + "/.hg");
Chris@184 1089 if (!hgDir.exists()) {
Chris@184 1090 //!!! visible error!
Chris@184 1091 return;
Chris@184 1092 }
Chris@184 1093
Chris@183 1094 QFileInfo hgrc(workFolderPath + "/.hg/hgrc");
Chris@184 1095 if (hgrc.exists() && !hgrc.isWritable()) {
Chris@183 1096 //!!! visible error!
Chris@183 1097 return;
Chris@183 1098 }
Chris@183 1099
Chris@183 1100 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@183 1101 (tr("Change Remote Location"),
Chris@183 1102 tr("<qt><big>Change the remote location</big></qt>"),
Chris@183 1103 this);
Chris@183 1104
Chris@183 1105 d->addChoice("remote",
Chris@183 1106 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@183 1107 tr("Provide a new URL to use for push and pull actions from the current local repository."),
Chris@183 1108 MultiChoiceDialog::UrlArg);
Chris@183 1109
Chris@183 1110 if (d->exec() == QDialog::Accepted) {
Chris@210 1111
Chris@210 1112 // New block to ensure QSettings is deleted before
Chris@210 1113 // hgQueryPaths called. NB use of absoluteFilePath instead of
Chris@210 1114 // canonicalFilePath, which would fail if the file did not yet
Chris@210 1115 // exist
Chris@210 1116
Chris@210 1117 {
Chris@210 1118 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
Chris@210 1119 s.beginGroup("paths");
Chris@210 1120 s.setValue("default", d->getArgument());
Chris@210 1121 }
Chris@210 1122
Chris@186 1123 stateUnknown = true;
Chris@183 1124 hgQueryPaths();
Chris@183 1125 }
Chris@183 1126
Chris@183 1127 delete d;
Chris@182 1128 }
Chris@182 1129
Chris@145 1130 void MainWindow::open(QString local)
Chris@145 1131 {
Chris@145 1132 if (openLocal(local)) {
Chris@145 1133 enableDisableActions();
Chris@145 1134 clearState();
Chris@145 1135 hgQueryPaths();
Chris@145 1136 }
Chris@145 1137 }
Chris@145 1138
Chris@79 1139 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 1140 {
Chris@79 1141 QMessageBox::critical
Chris@79 1142 (this, tr("File chosen"),
Chris@84 1143 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 1144 return false;
Chris@79 1145 }
Chris@79 1146
Chris@79 1147 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 1148 {
Chris@79 1149 QMessageBox::critical
Chris@79 1150 (this, tr("Folder does not exist"),
Chris@84 1151 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 1152 return false;
Chris@84 1153 }
Chris@84 1154
Chris@84 1155 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 1156 {
Chris@84 1157 QMessageBox::critical
Chris@84 1158 (this, tr("Path is in existing repository"),
Chris@84 1159 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 1160 return false;
Chris@84 1161 }
Chris@84 1162
Chris@84 1163 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 1164 {
Chris@84 1165 QMessageBox::critical
Chris@84 1166 (this, tr("Path is a file"),
Chris@84 1167 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 1168 return false;
Chris@84 1169 }
Chris@84 1170
Chris@84 1171 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 1172 {
Chris@84 1173 QMessageBox::critical
Chris@84 1174 (this, tr("Path is in existing repository"),
Chris@237 1175 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 1176 return false;
Chris@84 1177 }
Chris@84 1178
Chris@84 1179 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 1180 {
Chris@84 1181 QMessageBox::critical
Chris@84 1182 (this, tr("Path is a file"),
Chris@84 1183 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 1184 return false;
Chris@84 1185 }
Chris@84 1186
Chris@237 1187 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
Chris@84 1188 {
Chris@237 1189 // If the directory "arg" exists but "arg" plus the last path
Chris@237 1190 // component of "remote" does not, then offer the latter as an
Chris@237 1191 // alternative path
Chris@237 1192
Chris@237 1193 QString offer;
Chris@237 1194
Chris@237 1195 QDir d(arg);
Chris@237 1196 if (d.exists()) {
Chris@237 1197 if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
Chris@237 1198 QString rpath = QUrl(remote).path();
Chris@237 1199 if (rpath != "") {
Chris@237 1200 rpath = QDir(rpath).dirName();
Chris@237 1201 if (rpath != "" && !d.exists(rpath)) {
Chris@237 1202 offer = d.filePath(rpath);
Chris@237 1203 }
Chris@237 1204 }
Chris@237 1205 }
Chris@237 1206 }
Chris@237 1207
Chris@237 1208 if (offer != "") {
Chris@237 1209 bool result = (QMessageBox::question
Chris@237 1210 (this, tr("Folder exists"),
Chris@237 1211 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 1212 .arg(xmlEncode(arg)).arg(xmlEncode(offer)),
Chris@237 1213 QMessageBox::Ok | QMessageBox::Cancel,
Chris@237 1214 QMessageBox::Cancel)
Chris@237 1215 == QMessageBox::Ok);
Chris@237 1216 if (result) return offer;
Chris@237 1217 else return "";
Chris@237 1218 }
Chris@237 1219
Chris@84 1220 QMessageBox::critical
Chris@84 1221 (this, tr("Folder exists"),
Chris@237 1222 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 1223 return "";
Chris@79 1224 }
Chris@79 1225
Chris@79 1226 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 1227 {
Chris@79 1228 return (QMessageBox::question
Chris@84 1229 (this, tr("Path is inside a repository"),
Chris@86 1230 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 1231 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 1232 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1233 QMessageBox::Ok)
Chris@79 1234 == QMessageBox::Ok);
Chris@79 1235 }
Chris@79 1236
Chris@79 1237 bool MainWindow::askToInitExisting(QString arg)
Chris@79 1238 {
Chris@79 1239 return (QMessageBox::question
Chris@84 1240 (this, tr("Folder has no repository"),
Chris@84 1241 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder does not contain a Mercurial repository.<br><br>Would you like to initialise a repository here?</qt>")
Chris@79 1242 .arg(xmlEncode(arg)),
Chris@79 1243 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1244 QMessageBox::Ok)
Chris@79 1245 == QMessageBox::Ok);
Chris@79 1246 }
Chris@79 1247
Chris@79 1248 bool MainWindow::askToInitNew(QString arg)
Chris@79 1249 {
Chris@79 1250 return (QMessageBox::question
Chris@84 1251 (this, tr("Folder does not exist"),
Chris@84 1252 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 1253 .arg(xmlEncode(arg)),
Chris@84 1254 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 1255 QMessageBox::Ok)
Chris@84 1256 == QMessageBox::Ok);
Chris@84 1257 }
Chris@84 1258
Chris@84 1259 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 1260 {
Chris@84 1261 return (QMessageBox::question
Chris@84 1262 (this, tr("Repository exists"),
Chris@84 1263 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 1264 .arg(xmlEncode(arg)),
Chris@79 1265 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1266 QMessageBox::Ok)
Chris@79 1267 == QMessageBox::Ok);
Chris@79 1268 }
Chris@79 1269
Chris@79 1270 bool MainWindow::openLocal(QString local)
Chris@79 1271 {
Chris@79 1272 DEBUG << "open " << local << endl;
Chris@79 1273
Chris@79 1274 FolderStatus status = getFolderStatus(local);
Chris@79 1275 QString containing = getContainingRepoFolder(local);
Chris@79 1276
Chris@79 1277 switch (status) {
Chris@79 1278
Chris@79 1279 case FolderHasRepo:
Chris@79 1280 // fine
Chris@79 1281 break;
Chris@79 1282
Chris@79 1283 case FolderExists:
Chris@79 1284 if (containing != "") {
Chris@79 1285 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1286 local = containing;
Chris@79 1287 } else {
Chris@86 1288 //!!! No -- this is likely to happen far more by accident
Chris@86 1289 // than because the user actually wanted to init something.
Chris@86 1290 // Don't ask, just politely reject.
Chris@79 1291 if (!askToInitExisting(local)) return false;
Chris@79 1292 return openInit(local);
Chris@79 1293 }
Chris@79 1294 break;
Chris@79 1295
Chris@79 1296 case FolderParentExists:
Chris@79 1297 if (containing != "") {
Chris@79 1298 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1299 local = containing;
Chris@79 1300 } else {
Chris@79 1301 if (!askToInitNew(local)) return false;
Chris@79 1302 return openInit(local);
Chris@79 1303 }
Chris@79 1304 break;
Chris@79 1305
Chris@79 1306 case FolderUnknown:
Chris@84 1307 if (containing != "") {
Chris@84 1308 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1309 local = containing;
Chris@84 1310 } else {
Chris@84 1311 return complainAboutUnknownFolder(local);
Chris@84 1312 }
Chris@84 1313 break;
Chris@79 1314
Chris@79 1315 case FolderIsFile:
Chris@79 1316 return complainAboutFilePath(local);
Chris@79 1317 }
Chris@79 1318
Chris@79 1319 workFolderPath = local;
Chris@79 1320 remoteRepoPath = "";
Chris@79 1321 return true;
Chris@79 1322 }
Chris@79 1323
Chris@79 1324 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 1325 {
Chris@79 1326 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 1327
Chris@84 1328 FolderStatus status = getFolderStatus(local);
Chris@84 1329 QString containing = getContainingRepoFolder(local);
Chris@84 1330
Chris@84 1331 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1332
Chris@84 1333 if (status == FolderHasRepo || containing != "") {
Chris@84 1334 return complainAboutCloneToExisting(local);
Chris@84 1335 }
Chris@84 1336
Chris@84 1337 if (status == FolderIsFile) {
Chris@84 1338 return complainAboutCloneToFile(local);
Chris@84 1339 }
Chris@84 1340
Chris@84 1341 if (status == FolderUnknown) {
Chris@84 1342 return complainAboutUnknownFolder(local);
Chris@84 1343 }
Chris@84 1344
Chris@84 1345 if (status == FolderExists) {
Chris@237 1346 local = complainAboutCloneToExistingFolder(local, remote);
Chris@237 1347 if (local == "") return false;
Chris@84 1348 }
Chris@84 1349
Chris@84 1350 workFolderPath = local;
Chris@84 1351 remoteRepoPath = remote;
Chris@84 1352 hgCloneFromRemote();
Chris@84 1353
Chris@79 1354 return true;
Chris@79 1355 }
Chris@79 1356
Chris@84 1357 bool MainWindow::openInit(QString local)
Chris@79 1358 {
Chris@84 1359 DEBUG << "openInit " << local << endl;
Chris@84 1360
Chris@84 1361 FolderStatus status = getFolderStatus(local);
Chris@84 1362 QString containing = getContainingRepoFolder(local);
Chris@84 1363
Chris@84 1364 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1365
Chris@84 1366 if (status == FolderHasRepo) {
Chris@84 1367 if (!askToOpenInsteadOfInit(local)) return false;
Chris@84 1368 }
Chris@84 1369
Chris@84 1370 if (containing != "") {
Chris@84 1371 return complainAboutInitInRepo(local);
Chris@84 1372 }
Chris@84 1373
Chris@84 1374 if (status == FolderIsFile) {
Chris@84 1375 return complainAboutInitFile(local);
Chris@84 1376 }
Chris@84 1377
Chris@84 1378 if (status == FolderUnknown) {
Chris@84 1379 return complainAboutUnknownFolder(local);
Chris@84 1380 }
Chris@84 1381
Chris@84 1382 workFolderPath = local;
Chris@84 1383 remoteRepoPath = "";
Chris@84 1384 hgInit();
Chris@79 1385 return true;
Chris@79 1386 }
Chris@79 1387
jtkorhonen@0 1388 void MainWindow::settings()
jtkorhonen@0 1389 {
jtkorhonen@0 1390 SettingsDialog *settingsDlg = new SettingsDialog(this);
jtkorhonen@0 1391 settingsDlg->exec();
Chris@230 1392
Chris@230 1393 if (settingsDlg->presentationChanged()) {
Chris@230 1394 hgTabs->updateFileStates();
Chris@230 1395 updateToolBarStyle();
Chris@230 1396 }
jtkorhonen@0 1397 }
jtkorhonen@0 1398
jtkorhonen@2 1399 #define STDOUT_NEEDS_BIG_WINDOW 512
jtkorhonen@2 1400 #define SMALL_WND_W 500
jtkorhonen@2 1401 #define SMALL_WND_H 300
jtkorhonen@2 1402
jtkorhonen@2 1403 #define BIG_WND_W 1024
jtkorhonen@2 1404 #define BIG_WND_H 768
jtkorhonen@2 1405
jtkorhonen@2 1406
jtkorhonen@2 1407 void MainWindow::presentLongStdoutToUser(QString stdo)
jtkorhonen@0 1408 {
jtkorhonen@2 1409 if (!stdo.isEmpty())
jtkorhonen@2 1410 {
jtkorhonen@2 1411 QDialog dlg;
jtkorhonen@0 1412
jtkorhonen@2 1413 if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW)
jtkorhonen@2 1414 {
jtkorhonen@2 1415 dlg.setMinimumWidth(BIG_WND_W);
jtkorhonen@2 1416 dlg.setMinimumHeight(BIG_WND_H);
jtkorhonen@2 1417 }
jtkorhonen@2 1418 else
jtkorhonen@2 1419 {
jtkorhonen@2 1420 dlg.setMinimumWidth(SMALL_WND_W);
jtkorhonen@2 1421 dlg.setMinimumHeight(SMALL_WND_H);
jtkorhonen@2 1422 }
jtkorhonen@0 1423
jtkorhonen@2 1424 QVBoxLayout *box = new QVBoxLayout;
jtkorhonen@2 1425 QListWidget *list = new QListWidget;
jtkorhonen@2 1426 list-> addItems(stdo.split("\n"));
jtkorhonen@2 1427 QPushButton *btn = new QPushButton(tr("Ok"));
jtkorhonen@2 1428 connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept()));
jtkorhonen@0 1429
jtkorhonen@2 1430 box -> addWidget(list);
jtkorhonen@2 1431 box -> addWidget(btn);
jtkorhonen@2 1432 dlg.setLayout(box);
jtkorhonen@2 1433
jtkorhonen@2 1434 dlg.exec();
jtkorhonen@2 1435 }
jtkorhonen@2 1436 else
jtkorhonen@2 1437 {
Chris@98 1438 QMessageBox::information(this, tr("EasyMercurial"), tr("Mercurial command did not return any output."));
jtkorhonen@2 1439 }
jtkorhonen@0 1440 }
jtkorhonen@0 1441
Chris@90 1442 void MainWindow::updateFileSystemWatcher()
Chris@90 1443 {
Chris@199 1444 bool justCreated = false;
Chris@199 1445 if (!fsWatcher) {
Chris@199 1446 fsWatcher = new QFileSystemWatcher();
Chris@199 1447 justCreated = true;
Chris@199 1448 }
Chris@199 1449
Chris@199 1450 // QFileSystemWatcher will refuse to add a file or directory to
Chris@199 1451 // its watch list that it is already watching -- fine, that's what
Chris@199 1452 // we want -- but it prints a warning when this happens, which is
Chris@199 1453 // annoying because it would be the normal case for us. So we'll
Chris@199 1454 // check for duplicates ourselves.
Chris@199 1455 QSet<QString> alreadyWatched;
Chris@199 1456 QStringList dl(fsWatcher->directories());
Chris@199 1457 foreach (QString d, dl) alreadyWatched.insert(d);
Chris@199 1458
Chris@90 1459 std::deque<QString> pending;
Chris@90 1460 pending.push_back(workFolderPath);
Chris@199 1461
Chris@90 1462 while (!pending.empty()) {
Chris@199 1463
Chris@90 1464 QString path = pending.front();
Chris@90 1465 pending.pop_front();
Chris@199 1466 if (!alreadyWatched.contains(path)) {
Chris@199 1467 fsWatcher->addPath(path);
Chris@199 1468 DEBUG << "Added to file system watcher: " << path << endl;
Chris@199 1469 }
Chris@199 1470
Chris@90 1471 QDir d(path);
Chris@90 1472 if (d.exists()) {
Chris@199 1473 d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot |
Chris@199 1474 QDir::Readable | QDir::NoSymLinks);
Chris@90 1475 foreach (QString entry, d.entryList()) {
Chris@199 1476 if (entry.startsWith('.')) continue;
Chris@90 1477 QString entryPath = d.absoluteFilePath(entry);
Chris@90 1478 pending.push_back(entryPath);
Chris@90 1479 }
Chris@90 1480 }
Chris@90 1481 }
Chris@199 1482
Chris@199 1483 if (justCreated) {
Chris@199 1484 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
Chris@199 1485 this, SLOT(fsDirectoryChanged(QString)));
Chris@199 1486 connect(fsWatcher, SIGNAL(fileChanged(QString)),
Chris@199 1487 this, SLOT(fsFileChanged(QString)));
Chris@199 1488 }
Chris@90 1489 }
Chris@90 1490
Chris@122 1491 void MainWindow::fsDirectoryChanged(QString d)
Chris@90 1492 {
Chris@122 1493 DEBUG << "MainWindow::fsDirectoryChanged " << d << endl;
Chris@90 1494 hgStat();
Chris@90 1495 }
Chris@90 1496
Chris@122 1497 void MainWindow::fsFileChanged(QString f)
Chris@90 1498 {
Chris@122 1499 DEBUG << "MainWindow::fsFileChanged " << f << endl;
Chris@90 1500 hgStat();
Chris@90 1501 }
Chris@90 1502
Chris@125 1503 QString MainWindow::format3(QString head, QString intro, QString code)
Chris@125 1504 {
Chris@196 1505 code = xmlEncode(code).replace("\n", "<br>")
Chris@196 1506 #ifndef Q_OS_WIN32
Chris@196 1507 // The hard hyphen comes out funny on Windows
Chris@196 1508 .replace("-", "&#8209;")
Chris@196 1509 #endif
Chris@196 1510 .replace(" ", "&nbsp;");
Chris@125 1511 if (intro == "") {
Chris@168 1512 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
Chris@168 1513 .arg(head).arg(code);
Chris@126 1514 } else if (code == "") {
Chris@126 1515 return QString("<qt><h3>%1</h3><p>%2</p>")
Chris@126 1516 .arg(head).arg(intro);
Chris@125 1517 } else {
Chris@168 1518 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
Chris@168 1519 .arg(head).arg(intro).arg(code);
Chris@125 1520 }
Chris@125 1521 }
Chris@125 1522
Chris@120 1523 void MainWindow::showIncoming(QString output)
Chris@120 1524 {
Chris@120 1525 runner->hide();
Chris@125 1526 IncomingDialog *d = new IncomingDialog(this, output);
Chris@125 1527 d->exec();
Chris@125 1528 delete d;
Chris@125 1529 }
Chris@125 1530
Chris@125 1531 int MainWindow::extractChangeCount(QString text)
Chris@125 1532 {
Chris@125 1533 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
Chris@125 1534 if (re.indexIn(text) >= 0) {
Chris@125 1535 return re.cap(1).toInt();
Chris@125 1536 } else if (text.contains("no changes")) {
Chris@125 1537 return 0;
Chris@125 1538 } else {
Chris@125 1539 return -1; // unknown
Chris@125 1540 }
Chris@120 1541 }
Chris@120 1542
Chris@120 1543 void MainWindow::showPushResult(QString output)
Chris@120 1544 {
Chris@125 1545 QString report;
Chris@125 1546 int n = extractChangeCount(output);
Chris@125 1547 if (n > 0) {
Chris@125 1548 report = tr("Pushed %n changeset(s)", "", n);
Chris@125 1549 } else if (n == 0) {
Chris@125 1550 report = tr("No changes to push");
Chris@125 1551 } else {
Chris@125 1552 report = tr("Push complete");
Chris@125 1553 }
Chris@125 1554 report = format3(report, tr("The push command output was:"), output);
Chris@120 1555 runner->hide();
Chris@125 1556 QMessageBox::information(this, "Push complete", report);
Chris@120 1557 }
Chris@120 1558
Chris@120 1559 void MainWindow::showPullResult(QString output)
Chris@120 1560 {
Chris@125 1561 QString report;
Chris@125 1562 int n = extractChangeCount(output);
Chris@125 1563 if (n > 0) {
Chris@125 1564 report = tr("Pulled %n changeset(s)", "", n);
Chris@125 1565 } else if (n == 0) {
Chris@125 1566 report = tr("No changes to pull");
Chris@125 1567 } else {
Chris@125 1568 report = tr("Pull complete");
Chris@125 1569 }
Chris@125 1570 report = format3(report, tr("The pull command output was:"), output);
Chris@120 1571 runner->hide();
Chris@125 1572
Chris@125 1573 //!!! and something about updating
Chris@125 1574
Chris@125 1575 QMessageBox::information(this, "Pull complete", report);
Chris@120 1576 }
Chris@120 1577
Chris@174 1578 void MainWindow::reportNewRemoteHeads(QString output)
Chris@174 1579 {
Chris@174 1580 bool headsAreLocal = false;
Chris@174 1581
Chris@174 1582 if (currentParents.size() == 1) {
Chris@174 1583 int currentBranchHeads = 0;
Chris@174 1584 bool parentIsHead = false;
Chris@174 1585 Changeset *parent = currentParents[0];
Chris@174 1586 foreach (Changeset *head, currentHeads) {
Chris@174 1587 if (head->isOnBranch(currentBranch)) {
Chris@174 1588 ++currentBranchHeads;
Chris@174 1589 }
Chris@174 1590 if (parent->id() == head->id()) {
Chris@174 1591 parentIsHead = true;
Chris@174 1592 }
Chris@174 1593 }
Chris@174 1594 if (currentBranchHeads == 2 && parentIsHead) {
Chris@174 1595 headsAreLocal = true;
Chris@174 1596 }
Chris@174 1597 }
Chris@174 1598
Chris@174 1599 if (headsAreLocal) {
Chris@174 1600 QMessageBox::warning
Chris@174 1601 (this, tr("Push failed"),
Chris@174 1602 format3(tr("Push failed"),
Chris@174 1603 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first.<br><br>The output of the push command was:"),
Chris@174 1604 output));
Chris@174 1605 } else {
Chris@174 1606 QMessageBox::warning
Chris@174 1607 (this, tr("Push failed"),
Chris@174 1608 format3(tr("Push failed"),
Chris@174 1609 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.<br><br>The output of the push command was:"),
Chris@174 1610 output));
Chris@174 1611 }
Chris@174 1612 }
Chris@174 1613
Chris@143 1614 void MainWindow::commandFailed(HgAction action, QString output)
Chris@62 1615 {
Chris@62 1616 DEBUG << "MainWindow::commandFailed" << endl;
Chris@74 1617
Chris@210 1618 QString setstr;
Chris@210 1619 #ifdef Q_OS_MAC
Chris@210 1620 setstr = tr("Preferences");
Chris@210 1621 #else
Chris@210 1622 setstr = tr("Settings");
Chris@210 1623 #endif
Chris@210 1624
Chris@113 1625 // Some commands we just have to ignore bad return values from:
Chris@113 1626
Chris@113 1627 switch(action.action) {
Chris@113 1628 case ACT_NONE:
Chris@113 1629 // uh huh
Chris@113 1630 return;
Chris@175 1631 case ACT_TEST_HG:
Chris@175 1632 QMessageBox::warning
Chris@175 1633 (this, tr("Failed to run Mercurial"),
Chris@175 1634 format3(tr("Failed to run Mercurial"),
Chris@210 1635 tr("The Mercurial program either could not be found or failed to run.<br>Check that the Mercurial program path is correct in %1.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")),
Chris@200 1636 output));
Chris@200 1637 settings();
Chris@200 1638 return;
Chris@200 1639 case ACT_TEST_HG_EXT:
Chris@200 1640 QMessageBox::warning
Chris@200 1641 (this, tr("Failed to run Mercurial"),
Chris@200 1642 format3(tr("Failed to run Mercurial with extension enabled"),
Chris@210 1643 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem with EasyMercurial.<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 may not work if you do this.<br><br>%2").arg(setstr).arg(output == "" ? QString("") : tr("The test command said:")),
Chris@175 1644 output));
Chris@175 1645 settings();
Chris@175 1646 return;
Chris@113 1647 case ACT_INCOMING:
Chris@211 1648 // returns non-zero code and no output if the check was
Chris@211 1649 // successful but there are no changes pending
Chris@211 1650 if (output.trimmed() == "") {
Chris@211 1651 showIncoming("");
Chris@211 1652 return;
Chris@211 1653 }
Chris@211 1654 break;
Chris@162 1655 case ACT_QUERY_HEADS:
Chris@162 1656 // fails if repo is empty; we don't care (if there's a genuine
Chris@202 1657 // problem, something else will fail too). Pretend it
Chris@202 1658 // succeeded, so that any further actions that are contingent
Chris@202 1659 // on the success of the heads query get carried out properly.
Chris@202 1660 commandCompleted(action, "");
Chris@162 1661 return;
Chris@113 1662 case ACT_FOLDERDIFF:
Chris@113 1663 case ACT_CHGSETDIFF:
Chris@113 1664 // external program, unlikely to be anything useful in stderr
Chris@113 1665 // and some return with failure codes when something as basic
Chris@113 1666 // as the user closing the window via the wm happens
Chris@113 1667 return;
Chris@174 1668 case ACT_PUSH:
Chris@174 1669 if (output.contains("creates new remote heads")) {
Chris@174 1670 reportNewRemoteHeads(output);
Chris@174 1671 return;
Chris@174 1672 }
Chris@199 1673 case ACT_STAT:
Chris@199 1674 if (fsWatcher) fsWatcher->blockSignals(false);
Chris@199 1675 break; // go on and report
Chris@113 1676 default:
Chris@114 1677 break;
Chris@113 1678 }
Chris@113 1679
Chris@113 1680 QString command = action.executable;
Chris@113 1681 if (command == "") command = "hg";
Chris@113 1682 foreach (QString arg, action.params) {
Chris@113 1683 command += " " + arg;
Chris@113 1684 }
Chris@113 1685
Chris@113 1686 QString message = tr("<qt><h3>Command failed</h3>"
Chris@113 1687 "<p>The following command failed:</p>"
Chris@113 1688 "<code>%1</code>"
Chris@113 1689 "%2</qt>")
Chris@113 1690 .arg(command)
Chris@143 1691 .arg((output.trimmed() != "") ?
Chris@113 1692 tr("<p>Its output said:</p><code>%1</code>")
Chris@143 1693 .arg(xmlEncode(output.left(800))
Chris@113 1694 .replace("\n", "<br>"))
Chris@113 1695 : "");
Chris@113 1696
Chris@113 1697 QMessageBox::warning(this, tr("Command failed"), message);
Chris@62 1698 }
Chris@62 1699
Chris@109 1700 void MainWindow::commandCompleted(HgAction completedAction, QString output)
jtkorhonen@0 1701 {
Chris@109 1702 HGACTIONS action = completedAction.action;
Chris@109 1703
Chris@109 1704 if (action == ACT_NONE) return;
Chris@109 1705
Chris@150 1706 bool headsChanged = false;
Chris@150 1707 QStringList oldHeadIds;
Chris@150 1708
Chris@150 1709 switch (action) {
Chris@109 1710
Chris@175 1711 case ACT_TEST_HG:
Chris@175 1712 break;
Chris@175 1713
Chris@200 1714 case ACT_TEST_HG_EXT:
Chris@200 1715 break;
Chris@200 1716
Chris@109 1717 case ACT_QUERY_PATHS:
jtkorhonen@0 1718 {
Chris@109 1719 DEBUG << "stdout is " << output << endl;
Chris@109 1720 LogParser lp(output, "=");
Chris@109 1721 LogList ll = lp.parse();
Chris@109 1722 DEBUG << ll.size() << " results" << endl;
Chris@109 1723 if (!ll.empty()) {
Chris@109 1724 remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@109 1725 DEBUG << "Set remote path to " << remoteRepoPath << endl;
Chris@210 1726 } else {
Chris@210 1727 remoteRepoPath = "";
Chris@109 1728 }
Chris@109 1729 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1730 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1731 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@109 1732 break;
Chris@109 1733 }
jtkorhonen@0 1734
Chris@109 1735 case ACT_QUERY_BRANCH:
Chris@109 1736 currentBranch = output.trimmed();
Chris@109 1737 break;
jtkorhonen@0 1738
Chris@109 1739 case ACT_STAT:
Chris@163 1740 lastStatOutput = output;
Chris@109 1741 updateFileSystemWatcher();
Chris@199 1742 if (fsWatcher) fsWatcher->blockSignals(false);
Chris@109 1743 break;
Chris@163 1744
Chris@163 1745 case ACT_RESOLVE_LIST:
Chris@163 1746 if (output != "") {
Chris@163 1747 // Remove lines beginning with R (they are resolved,
Chris@163 1748 // and the file stat parser treats R as removed)
Chris@163 1749 QStringList outList = output.split('\n');
Chris@163 1750 QStringList winnowed;
Chris@163 1751 foreach (QString line, outList) {
Chris@163 1752 if (!line.startsWith("R ")) winnowed.push_back(line);
Chris@163 1753 }
Chris@163 1754 output = winnowed.join("\n");
Chris@163 1755 }
Chris@163 1756 DEBUG << "lastStatOutput = " << lastStatOutput << endl;
Chris@199 1757 DEBUG << "resolve output = " << output << endl;
Chris@163 1758 hgTabs->updateWorkFolderFileList(lastStatOutput + output);
Chris@163 1759 break;
Chris@163 1760
Chris@163 1761 case ACT_RESOLVE_MARK:
Chris@163 1762 shouldHgStat = true;
Chris@163 1763 break;
Chris@109 1764
Chris@109 1765 case ACT_INCOMING:
Chris@120 1766 showIncoming(output);
Chris@120 1767 break;
Chris@120 1768
Chris@109 1769 case ACT_ANNOTATE:
Chris@109 1770 presentLongStdoutToUser(output);
Chris@109 1771 shouldHgStat = true;
Chris@109 1772 break;
Chris@109 1773
Chris@109 1774 case ACT_PULL:
Chris@120 1775 showPullResult(output);
Chris@109 1776 shouldHgStat = true;
Chris@109 1777 break;
Chris@109 1778
Chris@109 1779 case ACT_PUSH:
Chris@120 1780 showPushResult(output);
Chris@109 1781 break;
Chris@109 1782
Chris@109 1783 case ACT_INIT:
Chris@109 1784 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
Chris@109 1785 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1786 enableDisableActions();
Chris@109 1787 shouldHgStat = true;
Chris@109 1788 break;
Chris@109 1789
Chris@109 1790 case ACT_CLONEFROMREMOTE:
Chris@109 1791 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1792 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1793 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
Chris@237 1794 QMessageBox::information(this, tr("Clone"), tr("<qt><h3>Clone successful</h3><pre>%1</pre>").arg(xmlEncode(output)));
Chris@109 1795 enableDisableActions();
Chris@109 1796 shouldHgStat = true;
Chris@109 1797 break;
Chris@109 1798
Chris@109 1799 case ACT_LOG:
Chris@120 1800 hgTabs->setNewLog(output);
Chris@120 1801 needNewLog = false;
Chris@120 1802 break;
Chris@120 1803
Chris@120 1804 case ACT_LOG_INCREMENTAL:
Chris@120 1805 hgTabs->addIncrementalLog(output);
Chris@109 1806 break;
Chris@109 1807
Chris@109 1808 case ACT_QUERY_PARENTS:
Chris@152 1809 {
Chris@109 1810 foreach (Changeset *cs, currentParents) delete cs;
Chris@109 1811 currentParents = Changeset::parseChangesets(output);
Chris@152 1812 QStringList parentIds = Changeset::getIds(currentParents);
Chris@153 1813 hgTabs->setCurrent(parentIds, currentBranch);
Chris@152 1814 }
Chris@109 1815 break;
Chris@109 1816
Chris@109 1817 case ACT_QUERY_HEADS:
Chris@150 1818 {
Chris@150 1819 oldHeadIds = Changeset::getIds(currentHeads);
Chris@150 1820 Changesets newHeads = Changeset::parseChangesets(output);
Chris@150 1821 QStringList newHeadIds = Changeset::getIds(newHeads);
Chris@150 1822 if (oldHeadIds != newHeadIds) {
Chris@150 1823 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
Chris@150 1824 headsChanged = true;
Chris@150 1825 foreach (Changeset *cs, currentHeads) delete cs;
Chris@150 1826 currentHeads = newHeads;
Chris@150 1827 }
Chris@150 1828 }
Chris@109 1829 break;
Chris@130 1830
Chris@130 1831 case ACT_COMMIT:
Chris@130 1832 hgTabs->clearSelections();
Chris@163 1833 justMerged = false;
Chris@130 1834 shouldHgStat = true;
Chris@130 1835 break;
Chris@163 1836
Chris@163 1837 case ACT_REVERT:
Chris@163 1838 hgMarkResolved(lastRevertedFiles);
Chris@163 1839 justMerged = false;
Chris@163 1840 break;
Chris@109 1841
Chris@109 1842 case ACT_REMOVE:
Chris@109 1843 case ACT_ADD:
Chris@116 1844 hgTabs->clearSelections();
Chris@116 1845 shouldHgStat = true;
Chris@116 1846 break;
Chris@116 1847
Chris@164 1848 case ACT_TAG:
Chris@164 1849 needNewLog = true;
Chris@164 1850 shouldHgStat = true;
Chris@164 1851 break;
Chris@164 1852
Chris@168 1853 case ACT_DIFF_SUMMARY:
Chris@168 1854 QMessageBox::information(this, tr("Change summary"),
Chris@168 1855 format3(tr("Summary of uncommitted changes"),
Chris@168 1856 "",
Chris@168 1857 output));
Chris@168 1858 break;
Chris@168 1859
Chris@109 1860 case ACT_FOLDERDIFF:
Chris@109 1861 case ACT_CHGSETDIFF:
Chris@109 1862 case ACT_SERVE:
Chris@109 1863 case ACT_HG_IGNORE:
Chris@109 1864 shouldHgStat = true;
Chris@109 1865 break;
Chris@109 1866
Chris@109 1867 case ACT_UPDATE:
Chris@162 1868 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
Chris@109 1869 shouldHgStat = true;
Chris@109 1870 break;
Chris@109 1871
Chris@109 1872 case ACT_MERGE:
Chris@196 1873 //!!! use format3?
Chris@196 1874 QMessageBox::information(this, tr("Merge"), tr("<qt><h3>Merge successful</h3><pre>%1</pre>").arg(xmlEncode(output)));
Chris@109 1875 shouldHgStat = true;
Chris@109 1876 justMerged = true;
Chris@109 1877 break;
Chris@109 1878
Chris@109 1879 case ACT_RETRY_MERGE:
Chris@163 1880 QMessageBox::information(this, tr("Resolved"),
Chris@163 1881 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.</p>"));
Chris@109 1882 shouldHgStat = true;
Chris@109 1883 justMerged = true;
Chris@109 1884 break;
Chris@109 1885
Chris@109 1886 default:
Chris@109 1887 break;
Chris@109 1888 }
Chris@108 1889
Chris@121 1890 // Sequence when no full log required:
Chris@163 1891 // paths -> branch -> stat -> resolve-list -> heads ->
Chris@150 1892 // incremental-log (only if heads changed) -> parents
Chris@150 1893 //
Chris@121 1894 // Sequence when full log required:
Chris@163 1895 // paths -> branch -> stat -> resolve-list -> heads -> parents -> log
Chris@150 1896 //
Chris@150 1897 // Note we want to call enableDisableActions only once, at the end
Chris@150 1898 // of whichever sequence is in use.
Chris@150 1899
Chris@156 1900 bool noMore = false;
Chris@156 1901
Chris@150 1902 switch (action) {
Chris@175 1903
Chris@175 1904 case ACT_TEST_HG:
Chris@200 1905 hgTestExtension();
Chris@200 1906 break;
Chris@200 1907
Chris@200 1908 case ACT_TEST_HG_EXT:
Chris@175 1909 hgQueryPaths();
Chris@175 1910 break;
Chris@150 1911
Chris@150 1912 case ACT_QUERY_PATHS:
Chris@109 1913 hgQueryBranch();
Chris@150 1914 break;
Chris@150 1915
Chris@150 1916 case ACT_QUERY_BRANCH:
Chris@109 1917 hgStat();
Chris@150 1918 break;
Chris@150 1919
Chris@150 1920 case ACT_STAT:
Chris@163 1921 hgResolveList();
Chris@163 1922 break;
Chris@163 1923
Chris@163 1924 case ACT_RESOLVE_LIST:
Chris@150 1925 hgQueryHeads();
Chris@150 1926 break;
Chris@150 1927
Chris@150 1928 case ACT_QUERY_HEADS:
Chris@150 1929 if (headsChanged && !needNewLog) {
Chris@150 1930 hgLogIncremental(oldHeadIds);
Chris@121 1931 } else {
Chris@150 1932 hgQueryParents();
Chris@121 1933 }
Chris@150 1934 break;
Chris@150 1935
Chris@150 1936 case ACT_LOG_INCREMENTAL:
Chris@109 1937 hgQueryParents();
Chris@150 1938 break;
Chris@150 1939
Chris@150 1940 case ACT_QUERY_PARENTS:
Chris@120 1941 if (needNewLog) {
Chris@120 1942 hgLog();
Chris@150 1943 } else {
Chris@150 1944 // we're done
Chris@156 1945 noMore = true;
Chris@120 1946 }
Chris@150 1947 break;
Chris@150 1948
Chris@150 1949 case ACT_LOG:
Chris@150 1950 // we're done
Chris@156 1951 noMore = true;
Chris@198 1952 break;
Chris@150 1953
Chris@150 1954 default:
Chris@109 1955 if (shouldHgStat) {
Chris@163 1956 shouldHgStat = false;
Chris@109 1957 hgQueryPaths();
Chris@150 1958 } else {
Chris@156 1959 noMore = true;
jtkorhonen@0 1960 }
Chris@150 1961 break;
Chris@150 1962 }
Chris@156 1963
Chris@156 1964 if (noMore) {
Chris@173 1965 stateUnknown = false;
Chris@156 1966 enableDisableActions();
Chris@156 1967 hgTabs->updateHistory();
Chris@156 1968 }
jtkorhonen@0 1969 }
jtkorhonen@0 1970
jtkorhonen@0 1971 void MainWindow::connectActions()
jtkorhonen@0 1972 {
jtkorhonen@0 1973 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
jtkorhonen@0 1974 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
jtkorhonen@0 1975
Chris@120 1976 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
jtkorhonen@0 1977 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
jtkorhonen@0 1978 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
jtkorhonen@0 1979 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
jtkorhonen@0 1980 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
jtkorhonen@0 1981 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
jtkorhonen@0 1982 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
jtkorhonen@0 1983 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
jtkorhonen@34 1984 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
jtkorhonen@0 1985
jtkorhonen@0 1986 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@69 1987 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
Chris@182 1988 connect(changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
jtkorhonen@0 1989
jtkorhonen@0 1990 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
jtkorhonen@0 1991 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
jtkorhonen@0 1992 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
jtkorhonen@0 1993
jtkorhonen@0 1994 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
jtkorhonen@11 1995 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
jtkorhonen@0 1996 }
Chris@141 1997
Chris@141 1998 void MainWindow::connectTabsSignals()
Chris@141 1999 {
Chris@141 2000 connect(hgTabs, SIGNAL(commit()),
Chris@141 2001 this, SLOT(hgCommit()));
Chris@141 2002
Chris@141 2003 connect(hgTabs, SIGNAL(revert()),
Chris@141 2004 this, SLOT(hgRevert()));
Chris@141 2005
Chris@141 2006 connect(hgTabs, SIGNAL(diffWorkingFolder()),
Chris@141 2007 this, SLOT(hgFolderDiff()));
Chris@168 2008
Chris@168 2009 connect(hgTabs, SIGNAL(showSummary()),
Chris@168 2010 this, SLOT(hgShowSummary()));
Chris@148 2011
Chris@141 2012 connect(hgTabs, SIGNAL(updateTo(QString)),
Chris@148 2013 this, SLOT(hgUpdateToRev(QString)));
Chris@141 2014
Chris@141 2015 connect(hgTabs, SIGNAL(diffToCurrent(QString)),
Chris@148 2016 this, SLOT(hgDiffToCurrent(QString)));
Chris@141 2017
Chris@148 2018 connect(hgTabs, SIGNAL(diffToParent(QString, QString)),
Chris@148 2019 this, SLOT(hgDiffToParent(QString, QString)));
Chris@141 2020
Chris@141 2021 connect(hgTabs, SIGNAL(mergeFrom(QString)),
Chris@148 2022 this, SLOT(hgMergeFrom(QString)));
Chris@164 2023
Chris@141 2024 connect(hgTabs, SIGNAL(tag(QString)),
Chris@148 2025 this, SLOT(hgTag(QString)));
Chris@141 2026 }
Chris@141 2027
jtkorhonen@0 2028 void MainWindow::enableDisableActions()
jtkorhonen@0 2029 {
Chris@90 2030 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 2031
Chris@202 2032 QString dirname = QDir(workFolderPath).dirName();
Chris@202 2033 if (dirname != "") {
Chris@202 2034 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
Chris@202 2035 } else {
Chris@202 2036 setWindowTitle(tr("EasyMercurial"));
Chris@202 2037 }
Chris@202 2038
Chris@115 2039 //!!! should also do things like set the status texts for the
Chris@115 2040 //!!! actions appropriately by context
Chris@115 2041
jtkorhonen@0 2042 QDir localRepoDir;
jtkorhonen@0 2043 QDir workFolderDir;
Chris@145 2044 bool workFolderExist = true;
Chris@145 2045 bool localRepoExist = true;
jtkorhonen@0 2046
jtkorhonen@0 2047 remoteRepoActionsEnabled = true;
Chris@90 2048 if (remoteRepoPath.isEmpty()) {
jtkorhonen@0 2049 remoteRepoActionsEnabled = false;
jtkorhonen@0 2050 }
jtkorhonen@0 2051
jtkorhonen@0 2052 localRepoActionsEnabled = true;
Chris@90 2053 if (workFolderPath.isEmpty()) {
jtkorhonen@0 2054 localRepoActionsEnabled = false;
jtkorhonen@0 2055 workFolderExist = false;
jtkorhonen@0 2056 }
jtkorhonen@0 2057
Chris@90 2058 if (!workFolderDir.exists(workFolderPath)) {
jtkorhonen@0 2059 localRepoActionsEnabled = false;
jtkorhonen@0 2060 workFolderExist = false;
Chris@90 2061 } else {
jtkorhonen@0 2062 workFolderExist = true;
jtkorhonen@0 2063 }
jtkorhonen@0 2064
Chris@112 2065 if (!localRepoDir.exists(workFolderPath + "/.hg")) {
jtkorhonen@0 2066 localRepoActionsEnabled = false;
jtkorhonen@0 2067 localRepoExist = false;
jtkorhonen@0 2068 }
jtkorhonen@0 2069
jtkorhonen@0 2070 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 2071 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 2072 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
Chris@169 2073
Chris@179 2074 bool haveDiff = false;
Chris@179 2075 QSettings settings;
Chris@179 2076 settings.beginGroup("Locations");
Chris@179 2077 if (settings.value("extdiffbinary", "").toString() != "") {
Chris@179 2078 haveDiff = true;
Chris@179 2079 }
Chris@179 2080 settings.endGroup();
Chris@112 2081
Chris@120 2082 hgRefreshAct -> setEnabled(localRepoActionsEnabled);
Chris@112 2083 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
jtkorhonen@0 2084 hgRevertAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2085 hgAddAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2086 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2087 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2088 hgCommitAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2089 hgMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 2090 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@11 2091 hgServeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 2092 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 2093
Chris@90 2094 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
Chris@98 2095 DEBUG << "canCommit = " << hgTabs->canCommit() << endl;
Chris@90 2096
Chris@98 2097 hgAddAct->setEnabled(localRepoActionsEnabled && hgTabs->canAdd());
Chris@98 2098 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
Chris@98 2099 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
Chris@163 2100 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canRevert());
Chris@163 2101 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDiff());
Chris@90 2102
Chris@108 2103 // A default merge makes sense if:
Chris@108 2104 // * there is only one parent (if there are two, we have an uncommitted merge) and
Chris@108 2105 // * there are exactly two heads that have the same branch as the current branch and
Chris@108 2106 // * our parent is one of those heads
Chris@108 2107 //
Chris@108 2108 // A default update makes sense if:
Chris@108 2109 // * there is only one parent and
Chris@108 2110 // * the parent is not one of the current heads
Chris@156 2111
Chris@108 2112 bool canMerge = false;
Chris@108 2113 bool canUpdate = false;
Chris@156 2114 bool haveMerge = false;
Chris@162 2115 bool emptyRepo = false;
Chris@225 2116 bool noWorkingCopy = false;
Chris@235 2117 bool newBranch = false;
Chris@156 2118 int currentBranchHeads = 0;
Chris@156 2119
Chris@108 2120 if (currentParents.size() == 1) {
Chris@156 2121 bool parentIsHead = false;
Chris@108 2122 Changeset *parent = currentParents[0];
Chris@108 2123 foreach (Changeset *head, currentHeads) {
Chris@108 2124 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
Chris@108 2125 if (head->isOnBranch(currentBranch)) {
Chris@108 2126 ++currentBranchHeads;
Chris@235 2127 }
Chris@235 2128 if (parent->id() == head->id()) {
Chris@235 2129 parentIsHead = true;
Chris@108 2130 }
Chris@108 2131 }
Chris@108 2132 if (currentBranchHeads == 2 && parentIsHead) {
Chris@108 2133 canMerge = true;
Chris@108 2134 }
Chris@235 2135 if (currentBranchHeads == 0 && parentIsHead) {
Chris@235 2136 // Just created a new branch
Chris@235 2137 newBranch = true;
Chris@235 2138 }
Chris@108 2139 if (!parentIsHead) {
Chris@108 2140 canUpdate = true;
Chris@108 2141 DEBUG << "parent id = " << parent->id() << endl;
Chris@108 2142 DEBUG << " head ids "<<endl;
Chris@108 2143 foreach (Changeset *h, currentHeads) {
Chris@108 2144 DEBUG << "head id = " << h->id() << endl;
Chris@108 2145 }
Chris@108 2146 }
Chris@237 2147 justMerged = false;
Chris@162 2148 } else if (currentParents.size() == 0) {
Chris@225 2149 if (currentHeads.size() == 0) {
Chris@225 2150 // No heads -> empty repo
Chris@225 2151 emptyRepo = true;
Chris@225 2152 } else {
Chris@225 2153 // Heads, but no parents -> no working copy, e.g. we have
Chris@225 2154 // just converted this repo but haven't updated in it yet.
Chris@225 2155 // Uncommon but confusing; probably merits a special case
Chris@225 2156 noWorkingCopy = true;
Chris@225 2157 canUpdate = true;
Chris@225 2158 }
Chris@237 2159 justMerged = false;
Chris@156 2160 } else {
Chris@156 2161 haveMerge = true;
Chris@163 2162 justMerged = true;
Chris@108 2163 }
Chris@156 2164
Chris@163 2165 hgMergeAct->setEnabled(localRepoActionsEnabled &&
Chris@163 2166 (canMerge || hgTabs->canResolve()));
Chris@163 2167 hgUpdateAct->setEnabled(localRepoActionsEnabled &&
Chris@172 2168 (canUpdate && !hgTabs->haveChangesToCommit()));
Chris@115 2169
Chris@115 2170 // Set the state field on the file status widget
Chris@115 2171
Chris@115 2172 QString branchText;
Chris@115 2173 if (currentBranch == "" || currentBranch == "default") {
Chris@115 2174 branchText = tr("the default branch");
Chris@115 2175 } else {
Chris@115 2176 branchText = tr("branch \"%1\"").arg(currentBranch);
Chris@115 2177 }
Chris@156 2178
Chris@173 2179 if (stateUnknown) {
Chris@173 2180 hgTabs->setState(tr("(Examining repository)"));
Chris@173 2181 } else if (emptyRepo) {
Chris@162 2182 hgTabs->setState(tr("Nothing committed to this repository yet"));
Chris@225 2183 } else if (noWorkingCopy) {
Chris@225 2184 hgTabs->setState(tr("No working copy yet: consider updating"));
Chris@162 2185 } else if (canMerge) {
Chris@156 2186 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
Chris@163 2187 } else if (!hgTabs->getAllUnresolvedFiles().empty()) {
Chris@163 2188 hgTabs->setState(tr("Have unresolved files following merge on %1").arg(branchText));
Chris@156 2189 } else if (haveMerge) {
Chris@157 2190 hgTabs->setState(tr("Have merged but not yet committed on %1").arg(branchText));
Chris@235 2191 } else if (newBranch) {
Chris@235 2192 hgTabs->setState(tr("On %1. New branch: has not yet been committed").arg(branchText));
Chris@156 2193 } else if (canUpdate) {
Chris@172 2194 if (hgTabs->haveChangesToCommit()) {
Chris@163 2195 // have uncommitted changes
Chris@163 2196 hgTabs->setState(tr("On %1. Not at the head of the branch").arg(branchText));
Chris@163 2197 } else {
Chris@163 2198 // no uncommitted changes
Chris@163 2199 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
Chris@163 2200 }
Chris@156 2201 } else if (currentBranchHeads > 1) {
Chris@156 2202 hgTabs->setState(tr("At one of %n heads of %1", "", currentBranchHeads).arg(branchText));
Chris@115 2203 } else {
Chris@115 2204 hgTabs->setState(tr("At the head of %1").arg(branchText));
Chris@115 2205 }
jtkorhonen@0 2206 }
jtkorhonen@0 2207
jtkorhonen@0 2208 void MainWindow::createActions()
jtkorhonen@0 2209 {
jtkorhonen@0 2210 //File actions
Chris@69 2211 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
Chris@199 2212 openAct -> setStatusTip(tr("Open an existing repository or working folder"));
Chris@69 2213
Chris@182 2214 changeRemoteRepoAct = new QAction(tr("Change Remote Location..."), this);
Chris@182 2215 changeRemoteRepoAct->setStatusTip(tr("Change the default remote repository for pull and push actions"));
Chris@182 2216
jtkorhonen@0 2217 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
jtkorhonen@0 2218 settingsAct -> setStatusTip(tr("View and change application settings"));
jtkorhonen@0 2219
Chris@169 2220 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Quit"), this);
jtkorhonen@0 2221 exitAct->setShortcuts(QKeySequence::Quit);
Chris@169 2222 exitAct->setStatusTip(tr("Quit EasyMercurial"));
jtkorhonen@0 2223
jtkorhonen@0 2224 //Repository actions
Chris@120 2225 hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
Chris@178 2226 hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
Chris@61 2227
Chris@61 2228 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
Chris@169 2229 hgIncomingAct -> setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
jtkorhonen@0 2230
Chris@61 2231 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
Chris@169 2232 hgPullAct -> setStatusTip(tr("Pull changes from the remote repository to the local repository"));
jtkorhonen@0 2233
Chris@61 2234 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
Chris@169 2235 hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
jtkorhonen@0 2236
jtkorhonen@0 2237 //Workfolder actions
Chris@99 2238 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
Chris@169 2239 hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
jtkorhonen@0 2240
Chris@61 2241 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
Chris@169 2242 hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
jtkorhonen@0 2243
Chris@61 2244 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
Chris@169 2245 hgAddAct -> setStatusTip(tr("Mark the selected file(s) to be added on the next commit"));
jtkorhonen@0 2246
Chris@169 2247 //!!! needs to be modified for number
Chris@61 2248 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
Chris@169 2249 hgRemoveAct -> setStatusTip(tr("Mark the selected file(s) to be removed from version control on the next commit"));
jtkorhonen@0 2250
Chris@61 2251 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
Chris@169 2252 hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
jtkorhonen@0 2253
Chris@169 2254 //!!! needs to be modified when files selected
Chris@61 2255 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
Chris@169 2256 hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
jtkorhonen@0 2257
jtkorhonen@0 2258 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
Chris@169 2259 hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
jtkorhonen@0 2260
jtkorhonen@0 2261 //Advanced actions
Chris@169 2262 //!!! needs to be modified for number
jtkorhonen@0 2263 hgAnnotateAct = new QAction(tr("Annotate"), this);
jtkorhonen@0 2264 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
jtkorhonen@0 2265
Chris@182 2266 hgIgnoreAct = new QAction(tr("Edit .hgignore File"), this);
Chris@169 2267 hgIgnoreAct -> setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
jtkorhonen@34 2268
Chris@182 2269 hgServeAct = new QAction(tr("Serve via HTTP"), this);
jtkorhonen@11 2270 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
jtkorhonen@11 2271
jtkorhonen@0 2272 //Help actions
Chris@190 2273 aboutAct = new QAction(tr("About EasyMercurial"), this);
Chris@94 2274
Chris@94 2275 // Miscellaneous
Chris@199 2276 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
Chris@199 2277 connect(clearSelectionsShortcut, SIGNAL(activated()),
Chris@199 2278 this, SLOT(clearSelections()));
jtkorhonen@0 2279 }
jtkorhonen@0 2280
jtkorhonen@0 2281 void MainWindow::createMenus()
jtkorhonen@0 2282 {
jtkorhonen@0 2283 fileMenu = menuBar()->addMenu(tr("File"));
Chris@169 2284
Chris@69 2285 fileMenu -> addAction(openAct);
Chris@182 2286 fileMenu -> addAction(changeRemoteRepoAct);
Chris@191 2287 fileMenu -> addSeparator();
Chris@191 2288
Chris@191 2289 advancedMenu = fileMenu->addMenu(tr("Advanced"));
Chris@191 2290
jtkorhonen@0 2291 fileMenu -> addAction(settingsAct);
Chris@191 2292
jtkorhonen@0 2293 fileMenu -> addSeparator();
jtkorhonen@0 2294 fileMenu -> addAction(exitAct);
jtkorhonen@0 2295
jtkorhonen@34 2296 advancedMenu -> addAction(hgIgnoreAct);
Chris@199 2297 advancedMenu -> addSeparator();
jtkorhonen@11 2298 advancedMenu -> addAction(hgServeAct);
jtkorhonen@0 2299
jtkorhonen@0 2300 helpMenu = menuBar()->addMenu(tr("Help"));
jtkorhonen@0 2301 helpMenu->addAction(aboutAct);
jtkorhonen@0 2302 }
jtkorhonen@0 2303
jtkorhonen@0 2304 void MainWindow::createToolBars()
jtkorhonen@0 2305 {
jtkorhonen@0 2306 fileToolBar = addToolBar(tr("File"));
jtkorhonen@0 2307 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@69 2308 fileToolBar -> addAction(openAct);
Chris@120 2309 fileToolBar -> addAction(hgRefreshAct);
jtkorhonen@0 2310 fileToolBar -> addSeparator();
jtkorhonen@0 2311 fileToolBar -> setMovable(false);
jtkorhonen@0 2312
jtkorhonen@0 2313 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
jtkorhonen@0 2314 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
jtkorhonen@0 2315 repoToolBar->addAction(hgIncomingAct);
jtkorhonen@0 2316 repoToolBar->addAction(hgPullAct);
jtkorhonen@0 2317 repoToolBar->addAction(hgPushAct);
jtkorhonen@0 2318 repoToolBar -> setMovable(false);
jtkorhonen@0 2319
jtkorhonen@0 2320 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
jtkorhonen@0 2321 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
jtkorhonen@0 2322 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@95 2323 workFolderToolBar->addAction(hgFolderDiffAct);
jtkorhonen@0 2324 workFolderToolBar->addSeparator();
jtkorhonen@0 2325 workFolderToolBar->addAction(hgRevertAct);
jtkorhonen@0 2326 workFolderToolBar->addAction(hgUpdateAct);
jtkorhonen@0 2327 workFolderToolBar->addAction(hgCommitAct);
jtkorhonen@0 2328 workFolderToolBar->addAction(hgMergeAct);
jtkorhonen@0 2329 workFolderToolBar->addSeparator();
jtkorhonen@0 2330 workFolderToolBar->addAction(hgAddAct);
jtkorhonen@0 2331 workFolderToolBar->addAction(hgRemoveAct);
jtkorhonen@0 2332 workFolderToolBar -> setMovable(false);
Chris@61 2333
Chris@230 2334 updateToolBarStyle();
jtkorhonen@0 2335 }
jtkorhonen@0 2336
Chris@230 2337 void MainWindow::updateToolBarStyle()
Chris@230 2338 {
Chris@230 2339 QSettings settings;
Chris@230 2340 settings.beginGroup("Presentation");
Chris@230 2341 bool showText = settings.value("showiconlabels", true).toBool();
Chris@230 2342 settings.endGroup();
Chris@230 2343
Chris@230 2344 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@230 2345 tb->setToolButtonStyle(showText ?
Chris@230 2346 Qt::ToolButtonTextUnderIcon :
Chris@230 2347 Qt::ToolButtonIconOnly);
Chris@230 2348 }
Chris@230 2349 }
jtkorhonen@0 2350
jtkorhonen@0 2351 void MainWindow::createStatusBar()
jtkorhonen@0 2352 {
jtkorhonen@0 2353 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 2354 }
jtkorhonen@0 2355
Chris@69 2356
Chris@69 2357 //!!! review these:
Chris@69 2358
jtkorhonen@0 2359 void MainWindow::readSettings()
jtkorhonen@0 2360 {
jtkorhonen@0 2361 QDir workFolder;
jtkorhonen@0 2362
Chris@61 2363 QSettings settings;
jtkorhonen@0 2364
jtkorhonen@30 2365 remoteRepoPath = settings.value("remoterepopath", "").toString();
jtkorhonen@0 2366 workFolderPath = settings.value("workfolderpath", "").toString();
jtkorhonen@0 2367 if (!workFolder.exists(workFolderPath))
jtkorhonen@0 2368 {
jtkorhonen@0 2369 workFolderPath = "";
jtkorhonen@0 2370 }
jtkorhonen@0 2371
jtkorhonen@0 2372 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
jtkorhonen@0 2373 QSize size = settings.value("size", QSize(400, 400)).toSize();
jtkorhonen@0 2374 firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 2375
Chris@109 2376 //!!! initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
jtkorhonen@0 2377 resize(size);
jtkorhonen@0 2378 move(pos);
jtkorhonen@0 2379 }
jtkorhonen@0 2380
jtkorhonen@17 2381
jtkorhonen@0 2382 void MainWindow::writeSettings()
jtkorhonen@0 2383 {
Chris@61 2384 QSettings settings;
jtkorhonen@0 2385 settings.setValue("pos", pos());
jtkorhonen@0 2386 settings.setValue("size", size());
jtkorhonen@0 2387 settings.setValue("remoterepopath", remoteRepoPath);
jtkorhonen@0 2388 settings.setValue("workfolderpath", workFolderPath);
jtkorhonen@0 2389 settings.setValue("firststart", firstStart);
Chris@98 2390 //!!!settings.setValue("viewFileTypes", hgTabs -> getFileTypesBits());
jtkorhonen@0 2391 }
jtkorhonen@0 2392
jtkorhonen@0 2393
jtkorhonen@0 2394
jtkorhonen@0 2395