annotate mainwindow.cpp @ 240:53ad43d5a463

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