annotate mainwindow.cpp @ 227:5d8a5ce96163

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