annotate mainwindow.cpp @ 229:a1f4b5359051

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