annotate mainwindow.cpp @ 212:4c5993d860f3

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