annotate src/mainwindow.cpp @ 645:e2f6bb97cc22

Toolbar spacing adjustments; avoid using unified toolbar on Mac because it breaks the left toolbar with Qt 4.8
author Chris Cannam
date Fri, 11 Jan 2013 10:29:04 +0000
parents b16e8ef6919b
children a03264984ef8
rev   line source
Chris@585 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@560 8 Copyright (c) 2012 Chris Cannam
Chris@560 9 Copyright (c) 2012 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@359 32 #include <QWidgetAction>
Chris@125 33 #include <QRegExp>
Chris@199 34 #include <QShortcut>
Chris@237 35 #include <QUrl>
Chris@476 36 #include <QDialogButtonBox>
Chris@238 37 #include <QTimer>
Chris@494 38 #include <QTextBrowser>
jtkorhonen@0 39
Chris@53 40 #include "mainwindow.h"
Chris@69 41 #include "multichoicedialog.h"
Chris@64 42 #include "startupdialog.h"
Chris@53 43 #include "colourset.h"
Chris@62 44 #include "debug.h"
Chris@74 45 #include "logparser.h"
Chris@103 46 #include "confirmcommentdialog.h"
Chris@125 47 #include "incomingdialog.h"
Chris@175 48 #include "settingsdialog.h"
Chris@275 49 #include "moreinformationdialog.h"
Chris@331 50 #include "annotatedialog.h"
Chris@229 51 #include "version.h"
Chris@287 52 #include "workstatuswidget.h"
Chris@414 53 #include "hgignoredialog.h"
Chris@491 54 #include "versiontester.h"
Chris@540 55 #include "fswatcher.h"
Chris@53 56
jtkorhonen@0 57
Chris@172 58 MainWindow::MainWindow(QString myDirPath) :
Chris@238 59 m_myDirPath(myDirPath),
Chris@540 60 m_helpDialog(0)
jtkorhonen@0 61 {
Chris@197 62 setWindowIcon(QIcon(":images/easyhg-icon.png"));
Chris@197 63
jtkorhonen@0 64 QString wndTitle;
jtkorhonen@0 65
Chris@284 66 m_showAllFiles = false;
Chris@273 67
Chris@540 68 m_fsWatcher = new FsWatcher();
Chris@540 69 m_fsWatcherToken = m_fsWatcher->getNewToken();
Chris@540 70 m_commandSequenceInProgress = false;
Chris@541 71 connect(m_fsWatcher, SIGNAL(changed()), this, SLOT(checkFilesystem()));
Chris@540 72
Chris@284 73 m_commitsSincePush = 0;
Chris@284 74 m_shouldHgStat = true;
Chris@90 75
jtkorhonen@0 76 createActions();
jtkorhonen@0 77 createMenus();
jtkorhonen@0 78 createToolBars();
jtkorhonen@0 79 createStatusBar();
jtkorhonen@0 80
Chris@284 81 m_runner = new HgRunner(m_myDirPath, this);
Chris@284 82 connect(m_runner, SIGNAL(commandStarting(HgAction)),
Chris@241 83 this, SLOT(commandStarting(HgAction)));
Chris@284 84 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)),
Chris@109 85 this, SLOT(commandCompleted(HgAction, QString)));
Chris@537 86 connect(m_runner, SIGNAL(commandFailed(HgAction, QString, QString)),
Chris@537 87 this, SLOT(commandFailed(HgAction, QString, QString)));
Chris@564 88 connect(m_runner, SIGNAL(commandCancelled(HgAction)),
Chris@564 89 this, SLOT(commandCancelled(HgAction)));
Chris@284 90 statusBar()->addPermanentWidget(m_runner);
jtkorhonen@0 91
Chris@61 92 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 93
Chris@284 94 m_remoteRepoPath = "";
Chris@284 95 m_workFolderPath = "";
jtkorhonen@0 96
jtkorhonen@0 97 readSettings();
jtkorhonen@0 98
Chris@284 99 m_justMerged = false;
Chris@210 100
Chris@210 101 QWidget *central = new QWidget(this);
Chris@210 102 setCentralWidget(central);
Chris@210 103
Chris@210 104 QGridLayout *cl = new QGridLayout(central);
Chris@287 105 int row = 0;
Chris@210 106
Chris@210 107 #ifndef Q_OS_MAC
Chris@210 108 cl->setMargin(0);
Chris@210 109 #endif
jtkorhonen@0 110
Chris@287 111 m_workStatus = new WorkStatusWidget(this);
Chris@558 112 cl->addWidget(m_workStatus, row++, 0);
Chris@287 113
Chris@287 114 m_hgTabs = new HgTabWidget(central, m_workFolderPath);
Chris@287 115 connectTabsSignals();
Chris@287 116
Chris@554 117 cl->addWidget(m_hgTabs, row++, 0, 1, 2);
Chris@287 118
Chris@284 119 connect(m_hgTabs, SIGNAL(selectionChanged()),
Chris@95 120 this, SLOT(enableDisableActions()));
Chris@484 121 connect(m_hgTabs, SIGNAL(showAllChanged()),
Chris@484 122 this, SLOT(showAllChanged()));
Chris@95 123
jtkorhonen@0 124 connectActions();
Chris@120 125 clearState();
jtkorhonen@0 126 enableDisableActions();
jtkorhonen@0 127
Chris@284 128 if (m_firstStart) {
Chris@64 129 startupDialog();
jtkorhonen@0 130 }
jtkorhonen@0 131
Chris@239 132 SettingsDialog::findDefaultLocations(m_myDirPath);
Chris@112 133
Chris@64 134 ColourSet *cs = ColourSet::instance();
Chris@64 135 cs->clearDefaultNames();
Chris@64 136 cs->addDefaultName("");
Chris@153 137 cs->addDefaultName("default");
Chris@64 138 cs->addDefaultName(getUserInfo());
Chris@62 139
Chris@491 140 VersionTester *vt = new VersionTester
Chris@507 141 ("easyhg.org", "/latest-version.txt", EASYHG_VERSION);
Chris@491 142 connect(vt, SIGNAL(newerVersionAvailable(QString)),
Chris@491 143 this, SLOT(newerVersionAvailable(QString)));
Chris@491 144
Chris@175 145 hgTest();
Chris@359 146 updateRecentMenu();
jtkorhonen@0 147 }
jtkorhonen@0 148
jtkorhonen@0 149
jtkorhonen@0 150 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 151 {
jtkorhonen@0 152 writeSettings();
Chris@284 153 delete m_fsWatcher;
jtkorhonen@0 154 }
jtkorhonen@0 155
jtkorhonen@0 156
Chris@554 157 void MainWindow::resizeEvent(QResizeEvent *)
Chris@554 158 {
Chris@554 159 }
Chris@554 160
Chris@554 161
Chris@64 162 QString MainWindow::getUserInfo() const
Chris@64 163 {
Chris@64 164 QSettings settings;
Chris@64 165 settings.beginGroup("User Information");
Chris@64 166 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 167 QString email = settings.value("email", "").toString();
Chris@64 168
Chris@64 169 QString identifier;
Chris@64 170
Chris@64 171 if (email != "") {
Chris@64 172 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 173 } else {
Chris@64 174 identifier = name;
Chris@64 175 }
Chris@64 176
Chris@64 177 return identifier;
Chris@64 178 }
Chris@64 179
jtkorhonen@0 180 void MainWindow::about()
jtkorhonen@0 181 {
Chris@97 182 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@229 183 tr("<qt><h2>EasyMercurial v%1</h2>"
Chris@228 184 #ifdef Q_OS_MAC
Chris@228 185 "<font size=-1>"
Chris@228 186 #endif
Chris@97 187 "<p>EasyMercurial is a simple user interface for the "
Chris@186 188 "Mercurial</a> version control system.</p>"
Chris@186 189 "<h4>Credits and Copyright</h4>"
Chris@186 190 "<p>Development carried out by Chris Cannam for "
Chris@186 191 "SoundSoftware.ac.uk at the Centre for Digital Music, "
Chris@186 192 "Queen Mary, University of London.</p>"
Chris@186 193 "<p>EasyMercurial is based on HgExplorer by "
Chris@186 194 "Jari Korhonen, with thanks.</p>"
Chris@186 195 "<p style=\"margin-left: 2em;\">"
Chris@560 196 "Copyright &copy; 2012 Queen Mary, University of London.<br>"
Chris@186 197 "Copyright &copy; 2010 Jari Korhonen.<br>"
Chris@560 198 "Copyright &copy; 2012 Chris Cannam."
Chris@186 199 "</p>"
Chris@186 200 "<p style=\"margin-left: 2em;\">"
Chris@186 201 "This program requires Mercurial, by Matt Mackall and others.<br>"
Chris@186 202 "This program uses Qt by Nokia.<br>"
Chris@186 203 "This program uses Nuvola icons by David Vignoni.<br>"
Chris@186 204 "This program may use KDiff3 by Joachim Eibl.<br>"
Chris@186 205 "This program may use PyQt by River Bank Computing.<br>"
Chris@186 206 "Packaging for Mercurial and other dependencies on Windows is derived from TortoiseHg by Steve Borho and others."
Chris@186 207 "</p>"
Chris@186 208 "<h4>License</h4>"
Chris@186 209 "<p>This program is free software; you can redistribute it and/or "
Chris@97 210 "modify it under the terms of the GNU General Public License as "
Chris@97 211 "published by the Free Software Foundation; either version 2 of the "
Chris@97 212 "License, or (at your option) any later version. See the file "
Chris@223 213 "COPYING included with this distribution for more information.</p>"
Chris@228 214 #ifdef Q_OS_MAC
Chris@228 215 "</font>"
Chris@228 216 #endif
Chris@229 217 ).arg(EASYHG_VERSION));
jtkorhonen@0 218 }
jtkorhonen@0 219
Chris@94 220 void MainWindow::clearSelections()
Chris@94 221 {
Chris@284 222 m_hgTabs->clearSelections();
Chris@94 223 }
jtkorhonen@0 224
Chris@484 225 void MainWindow::showAllChanged()
Chris@199 226 {
Chris@199 227 hgQueryPaths();
Chris@199 228 }
Chris@199 229
Chris@120 230 void MainWindow::hgRefresh()
Chris@120 231 {
Chris@120 232 clearState();
Chris@120 233 hgQueryPaths();
Chris@120 234 }
Chris@120 235
Chris@175 236 void MainWindow::hgTest()
Chris@175 237 {
Chris@175 238 QStringList params;
Chris@175 239 params << "--version";
Chris@382 240 // The path is not necessarily set here, but we need something for
Chris@382 241 // this test or else HgRunner will (cautiously) refuse to run
Chris@382 242 QString path = m_myDirPath;
Chris@382 243 if (path == "") path = QDir::homePath();
Chris@382 244 m_runner->requestAction(HgAction(ACT_TEST_HG, path, params));
Chris@175 245 }
Chris@175 246
Chris@200 247 void MainWindow::hgTestExtension()
Chris@200 248 {
Chris@200 249 QStringList params;
Chris@200 250 params << "--version";
Chris@382 251 // The path is not necessarily set here, but we need something for
Chris@382 252 // this test or else HgRunner will (cautiously) refuse to run
Chris@382 253 QString path = m_myDirPath;
Chris@382 254 if (path == "") path = QDir::homePath();
Chris@382 255 m_runner->requestAction(HgAction(ACT_TEST_HG_EXT, path, params));
Chris@200 256 }
Chris@200 257
jtkorhonen@0 258 void MainWindow::hgStat()
jtkorhonen@0 259 {
Chris@109 260 QStringList params;
Chris@199 261
Chris@542 262 // We always stat all files, regardless of whether we're showing
Chris@542 263 // them all, because we need them for the filesystem monitor
Chris@542 264 params << "stat" << "-A";
Chris@153 265
Chris@284 266 m_lastStatOutput = "";
Chris@273 267
Chris@541 268 // We're about to do a stat, so we can silently bring ourselves
Chris@541 269 // up-to-date on any file changes to this point
Chris@541 270 (void)m_fsWatcher->getChangedPaths(m_fsWatcherToken);
Chris@541 271
Chris@284 272 m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
jtkorhonen@0 273 }
jtkorhonen@0 274
Chris@109 275 void MainWindow::hgQueryPaths()
Chris@74 276 {
Chris@484 277 m_showAllFiles = m_hgTabs->shouldShowAll();
Chris@484 278
Chris@210 279 // Quickest is to just read the file
Chris@198 280
Chris@284 281 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
Chris@198 282
Chris@210 283 QString path;
Chris@210 284
Chris@198 285 if (hgrc.exists()) {
Chris@198 286 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
Chris@198 287 s.beginGroup("paths");
Chris@210 288 path = s.value("default").toString();
Chris@210 289 }
Chris@198 290
Chris@565 291 // std::cerr << "hgQueryPaths: setting m_remoteRepoPath to " << m_remoteRepoPath << " from file " << hgrc.absoluteFilePath() << std::endl;
Chris@553 292
Chris@284 293 m_remoteRepoPath = path;
Chris@198 294
Chris@210 295 // We have to do this here, because commandCompleted won't be called
Chris@284 296 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 297 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@287 298 updateWorkFolderAndRepoNames();
Chris@210 299
Chris@210 300 hgQueryBranch();
Chris@210 301 return;
Chris@210 302
Chris@210 303 /* The classic method!
Chris@198 304
Chris@109 305 QStringList params;
Chris@109 306 params << "paths";
Chris@284 307 m_runner->requestAction(HgAction(ACT_QUERY_PATHS, m_workFolderPath, params));
Chris@210 308 */
Chris@74 309 }
Chris@74 310
Chris@109 311 void MainWindow::hgQueryBranch()
Chris@106 312 {
Chris@210 313 // Quickest is to just read the file
Chris@198 314
Chris@284 315 QFile hgbr(m_workFolderPath + "/.hg/branch");
Chris@198 316
Chris@210 317 QString br = "default";
Chris@210 318
Chris@198 319 if (hgbr.exists() && hgbr.open(QFile::ReadOnly)) {
Chris@210 320 QByteArray ba = hgbr.readLine();
Chris@210 321 br = QString::fromUtf8(ba).trimmed();
Chris@210 322 }
Chris@210 323
Chris@284 324 m_currentBranch = br;
Chris@210 325
Chris@210 326 // We have to do this here, because commandCompleted won't be called
Chris@210 327 hgStat();
Chris@210 328 return;
Chris@198 329
Chris@210 330 /* The classic method!
Chris@198 331
Chris@109 332 QStringList params;
Chris@109 333 params << "branch";
Chris@284 334 m_runner->requestAction(HgAction(ACT_QUERY_BRANCH, m_workFolderPath, params));
Chris@210 335 */
Chris@106 336 }
Chris@106 337
Chris@506 338 void MainWindow::hgQueryHeadsActive()
Chris@506 339 {
Chris@506 340 QStringList params;
Chris@514 341 params << "heads";
Chris@506 342 m_runner->requestAction(HgAction(ACT_QUERY_HEADS_ACTIVE, m_workFolderPath, params));
Chris@506 343 }
Chris@506 344
Chris@109 345 void MainWindow::hgQueryHeads()
jtkorhonen@0 346 {
Chris@109 347 QStringList params;
Chris@137 348 // On empty repos, "hg heads" will fail -- we don't care about
Chris@137 349 // that. Use --closed option so as to include closed branches;
Chris@137 350 // otherwise we'll be stuck if the user updates into one, and our
Chris@137 351 // incremental log will end up with spurious stuff in it because
Chris@137 352 // we won't be pruning at the ends of closed branches
Chris@137 353 params << "heads" << "--closed";
Chris@284 354 m_runner->requestAction(HgAction(ACT_QUERY_HEADS, m_workFolderPath, params));
jtkorhonen@0 355 }
jtkorhonen@0 356
jtkorhonen@0 357 void MainWindow::hgLog()
jtkorhonen@0 358 {
mikel@617 359 QSettings settings;
mikel@617 360 settings.beginGroup("Presentation");
mikel@617 361
Chris@109 362 QStringList params;
Chris@109 363 params << "log";
mikel@617 364 params << "--date";
mikel@617 365 params << settings.value("datefrom", QDate(2000, 1, 1)).toDate().toString("yyyy-MM-dd") + " to " + QDate::currentDate().toString("yyyy-MM-dd");
Chris@109 366 params << "--template";
Chris@125 367 params << Changeset::getLogTemplate();
Chris@109 368
Chris@284 369 m_runner->requestAction(HgAction(ACT_LOG, m_workFolderPath, params));
Chris@109 370 }
Chris@109 371
Chris@150 372 void MainWindow::hgLogIncremental(QStringList prune)
Chris@120 373 {
Chris@305 374 // Sometimes we can be called with prune empty -- it represents
Chris@305 375 // the current heads, but if we have none already and for some
Chris@305 376 // reason are being prompted for an incremental update, we may run
Chris@305 377 // into trouble. In that case, make this a full log instead
Chris@305 378
Chris@305 379 if (prune.empty()) {
Chris@305 380 hgLog();
Chris@305 381 return;
Chris@305 382 }
Chris@305 383
Chris@120 384 QStringList params;
Chris@120 385 params << "log";
Chris@120 386
Chris@150 387 foreach (QString p, prune) {
Chris@153 388 params << "--prune" << Changeset::hashOf(p);
Chris@120 389 }
Chris@120 390
Chris@120 391 params << "--template";
Chris@125 392 params << Changeset::getLogTemplate();
Chris@120 393
Chris@284 394 m_runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, m_workFolderPath, params));
Chris@120 395 }
Chris@109 396
Chris@109 397 void MainWindow::hgQueryParents()
Chris@109 398 {
Chris@109 399 QStringList params;
Chris@109 400 params << "parents";
Chris@284 401 m_runner->requestAction(HgAction(ACT_QUERY_PARENTS, m_workFolderPath, params));
Chris@109 402 }
Chris@109 403
Chris@326 404 void MainWindow::hgAnnotateFiles(QStringList files)
Chris@326 405 {
Chris@326 406 QStringList params;
Chris@326 407
Chris@326 408 if (!files.isEmpty()) {
Chris@332 409 params << "annotate" << "-udqc" << "--" << files;
Chris@326 410 m_runner->requestAction(HgAction(ACT_ANNOTATE, m_workFolderPath, params));
Chris@326 411 }
Chris@326 412 }
Chris@326 413
Chris@109 414 void MainWindow::hgResolveList()
Chris@109 415 {
Chris@109 416 QStringList params;
jtkorhonen@0 417
Chris@109 418 params << "resolve" << "--list";
Chris@284 419 m_runner->requestAction(HgAction(ACT_RESOLVE_LIST, m_workFolderPath, params));
Chris@109 420 }
Chris@109 421
Chris@109 422 void MainWindow::hgAdd()
jtkorhonen@0 423 {
Chris@109 424 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@109 425 // that one is a good idea, let's require the user to select
jtkorhonen@0 426
Chris@326 427 hgAddFiles(m_hgTabs->getSelectedAddableFiles());
Chris@326 428 }
Chris@326 429
Chris@326 430 void MainWindow::hgAddFiles(QStringList files)
Chris@326 431 {
Chris@326 432 QStringList params;
Chris@109 433
Chris@109 434 if (!files.empty()) {
Chris@109 435 params << "add" << "--" << files;
Chris@284 436 m_runner->requestAction(HgAction(ACT_ADD, m_workFolderPath, params));
jtkorhonen@0 437 }
jtkorhonen@0 438 }
jtkorhonen@0 439
Chris@98 440 void MainWindow::hgRemove()
Chris@98 441 {
Chris@326 442 hgRemoveFiles(m_hgTabs->getSelectedRemovableFiles());
Chris@326 443 }
Chris@326 444
Chris@326 445 void MainWindow::hgRemoveFiles(QStringList files)
Chris@326 446 {
Chris@109 447 QStringList params;
Chris@98 448
Chris@109 449 if (!files.empty()) {
Chris@109 450 params << "remove" << "--after" << "--force" << "--" << files;
Chris@284 451 m_runner->requestAction(HgAction(ACT_REMOVE, m_workFolderPath, params));
Chris@109 452 }
jtkorhonen@0 453 }
jtkorhonen@0 454
jtkorhonen@0 455 void MainWindow::hgCommit()
jtkorhonen@0 456 {
Chris@326 457 hgCommitFiles(QStringList());
Chris@326 458 }
Chris@326 459
Chris@326 460 void MainWindow::hgCommitFiles(QStringList files)
Chris@326 461 {
Chris@109 462 QStringList params;
Chris@109 463 QString comment;
Chris@94 464
Chris@284 465 if (m_justMerged) {
Chris@284 466 comment = m_mergeCommitComment;
Chris@157 467 }
Chris@157 468
Chris@284 469 QStringList allFiles = m_hgTabs->getAllCommittableFiles();
Chris@127 470 QStringList reportFiles = files;
Chris@237 471 if (reportFiles.empty()) {
Chris@237 472 reportFiles = allFiles;
Chris@237 473 }
Chris@103 474
Chris@237 475 QString subsetNote;
Chris@237 476 if (reportFiles != allFiles) {
Chris@237 477 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 478 }
Chris@237 479
Chris@155 480 QString cf(tr("Commit files"));
Chris@155 481
Chris@311 482 QString branchText;
Chris@311 483 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@311 484 branchText = tr("the default branch");
Chris@311 485 } else {
Chris@311 486 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@311 487 }
Chris@311 488
Chris@109 489 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@109 490 (this,
Chris@155 491 cf,
Chris@237 492 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@473 493 .arg(tr("You are about to commit changes to the following files in %1:").arg(branchText))
Chris@237 494 .arg(subsetNote),
Chris@237 495 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@473 496 .arg(tr("You are about to commit changes to %n file(s) in %1.", "", reportFiles.size()).arg(branchText))
Chris@237 497 .arg(subsetNote),
Chris@127 498 reportFiles,
Chris@193 499 comment,
Chris@365 500 tr("Co&mmit"))) {
Chris@103 501
Chris@284 502 if (!m_justMerged && !files.empty()) {
Chris@157 503 // User wants to commit selected file(s) (and this is not
Chris@157 504 // merge commit, which would fail if we selected files)
Chris@157 505 params << "commit" << "--message" << comment
Chris@157 506 << "--user" << getUserInfo() << "--" << files;
Chris@109 507 } else {
Chris@109 508 // Commit all changes
Chris@157 509 params << "commit" << "--message" << comment
Chris@157 510 << "--user" << getUserInfo();
jtkorhonen@0 511 }
Chris@109 512
Chris@284 513 m_runner->requestAction(HgAction(ACT_COMMIT, m_workFolderPath, params));
Chris@284 514 m_mergeCommitComment = "";
jtkorhonen@0 515 }
jtkorhonen@0 516 }
jtkorhonen@0 517
jtkorhonen@34 518 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 519 {
Chris@278 520 for(int i = 0; i < tag.size(); i++) {
Chris@278 521 if (tag[i].isLower() || tag[i].isUpper() ||
Chris@278 522 tag[i].isDigit() || (tag[i] == QChar('.'))) {
jtkorhonen@34 523 //ok
Chris@278 524 } else {
jtkorhonen@34 525 tag[i] = QChar('_');
jtkorhonen@34 526 }
jtkorhonen@34 527 }
jtkorhonen@34 528 return tag;
jtkorhonen@34 529 }
jtkorhonen@34 530
jtkorhonen@34 531
Chris@311 532 void MainWindow::hgNewBranch()
Chris@278 533 {
Chris@278 534 QStringList params;
Chris@278 535 QString branch;
Chris@278 536
Chris@278 537 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@278 538 (this,
Chris@278 539 tr("New Branch"),
Chris@278 540 tr("Enter new branch name:"),
Chris@278 541 branch,
Chris@365 542 tr("Start &Branch"))) {
Chris@278 543 if (!branch.isEmpty()) {//!!! do something better if it is empty
Chris@278 544
Chris@278 545 params << "branch" << filterTag(branch);
Chris@307 546 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
Chris@278 547 }
Chris@278 548 }
Chris@278 549 }
Chris@278 550
Chris@311 551 void MainWindow::hgNoBranch()
Chris@311 552 {
Chris@311 553 if (m_currentParents.empty()) return;
Chris@311 554
Chris@311 555 QString parentBranch = m_currentParents[0]->branch();
Chris@311 556 if (parentBranch == "") parentBranch = "default";
Chris@311 557
Chris@311 558 QStringList params;
Chris@311 559 params << "branch" << parentBranch;
Chris@311 560 m_runner->requestAction(HgAction(ACT_NEW_BRANCH, m_workFolderPath, params));
Chris@311 561 }
Chris@311 562
Chris@514 563 void MainWindow::hgCloseBranch()
Chris@514 564 {
Chris@514 565 QStringList params;
Chris@514 566
Chris@514 567 //!!! how to ensure this doesn't happen when uncommitted changes present?
Chris@514 568
Chris@514 569 QString cf(tr("Close branch"));
Chris@514 570 QString comment;
Chris@514 571
Chris@514 572 QString defaultWarning;
Chris@514 573
Chris@514 574 QString branchText;
Chris@514 575 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@514 576 branchText = tr("the default branch");
Chris@514 577 defaultWarning = tr("<p><b>Warning:</b> you are asking to close the default branch. This is not usually a good idea!</p>");
Chris@514 578 } else {
Chris@514 579 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@514 580 }
Chris@514 581
Chris@514 582 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@514 583 (this,
Chris@514 584 cf,
Chris@514 585 tr("<h3>%1</h3><p>%2%3").arg(cf)
Chris@518 586 .arg(tr("You are about to close %1.<p>This branch will be marked as closed and hidden from the history view.<p>You will still be able to see if it you select \"Show closed branches\" in the history view, and it will be reopened if you commit to it.<p>Please enter your comment for the commit log:").arg(branchText))
Chris@514 587 .arg(defaultWarning),
Chris@514 588 comment,
Chris@514 589 tr("C&lose branch"))) {
Chris@514 590
Chris@514 591 params << "commit" << "--message" << comment
Chris@514 592 << "--user" << getUserInfo() << "--close-branch";
Chris@514 593
Chris@514 594 m_runner->requestAction(HgAction(ACT_CLOSE_BRANCH, m_workFolderPath, params));
Chris@514 595 }
Chris@514 596 }
Chris@514 597
Chris@164 598 void MainWindow::hgTag(QString id)
jtkorhonen@34 599 {
Chris@109 600 QStringList params;
Chris@109 601 QString tag;
jtkorhonen@34 602
Chris@109 603 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@109 604 (this,
Chris@109 605 tr("Tag"),
Chris@109 606 tr("Enter tag:"),
Chris@193 607 tag,
Chris@365 608 tr("Add &Tag"))) {
Chris@164 609 if (!tag.isEmpty()) {//!!! do something better if it is empty
Chris@164 610
Chris@164 611 params << "tag" << "--user" << getUserInfo();
Chris@164 612 params << "--rev" << Changeset::hashOf(id) << filterTag(tag);
Chris@109 613
Chris@284 614 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params));
jtkorhonen@34 615 }
jtkorhonen@34 616 }
jtkorhonen@34 617 }
jtkorhonen@34 618
Chris@417 619 void MainWindow::initHgIgnore()
jtkorhonen@34 620 {
Chris@284 621 if (!QDir(m_workFolderPath).exists()) return;
Chris@417 622 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@417 623
Chris@249 624 QFile f(hgIgnorePath);
Chris@249 625 if (!f.exists()) {
Chris@249 626 f.open(QFile::WriteOnly);
Chris@249 627 QTextStream *ts = new QTextStream(&f);
Chris@249 628 *ts << "syntax: glob\n";
Chris@249 629 delete ts;
Chris@249 630 f.close();
Chris@249 631 }
Chris@417 632 }
Chris@417 633
Chris@425 634 void MainWindow::hgIgnore()
Chris@425 635 {
Chris@425 636 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@425 637 // that one is a good idea, let's require the user to select
Chris@425 638
Chris@425 639 hgIgnoreFiles(m_hgTabs->getSelectedAddableFiles());
Chris@425 640 }
Chris@425 641
Chris@417 642 void MainWindow::hgEditIgnore()
Chris@417 643 {
Chris@417 644 if (!QDir(m_workFolderPath).exists()) return;
Chris@417 645
Chris@417 646 initHgIgnore();
Chris@417 647
Chris@417 648 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@476 649
Chris@476 650 QFile f(hgIgnorePath);
Chris@476 651 if (!f.exists()) return; // shouldn't happen (after initHgIgnore called)
Chris@476 652
Chris@476 653 if (!f.open(QFile::ReadOnly)) return;
Chris@476 654 QTextStream sin(&f);
Chris@476 655 QString all = sin.readAll();
Chris@476 656 f.close();
Chris@476 657
Chris@476 658 QDialog d;
Chris@476 659 QGridLayout layout;
Chris@476 660 d.setLayout(&layout);
Chris@476 661
Chris@476 662 int row = 0;
Chris@476 663 layout.addWidget(new QLabel(tr("<qt><h3>Ignored File Patterns</h3></qt>")), row++, 0);//!!! todo: link to Hg docs?
Chris@476 664
Chris@476 665 QTextEdit ed;
Chris@476 666 ed.setAcceptRichText(false);
Chris@476 667 ed.setLineWrapMode(QTextEdit::NoWrap);
Chris@476 668 layout.setRowStretch(row, 10);
Chris@476 669 layout.addWidget(&ed, row++, 0);
Chris@179 670
Chris@476 671 QDialogButtonBox bb(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
Chris@476 672 connect(bb.button(QDialogButtonBox::Save), SIGNAL(clicked()),
Chris@476 673 &d, SLOT(accept()));
Chris@476 674 connect(bb.button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
Chris@476 675 &d, SLOT(reject()));
Chris@476 676 layout.addWidget(&bb, row++, 0);
Chris@476 677
Chris@476 678 ed.document()->setPlainText(all);
Chris@476 679
Chris@476 680 d.resize(QSize(300, 400));
Chris@476 681
Chris@476 682 if (d.exec() == QDialog::Accepted) {
Chris@476 683 if (!f.open(QFile::WriteOnly | QFile::Truncate)) {
Chris@476 684 QMessageBox::critical(this, tr("Write failed"),
Chris@476 685 tr("Failed to open file %1 for writing")
Chris@476 686 .arg(f.fileName()));
Chris@476 687 return;
Chris@476 688 }
Chris@476 689 QTextStream sout(&f);
Chris@476 690 sout << ed.document()->toPlainText();
Chris@476 691 f.close();
Chris@179 692 }
Chris@179 693 }
Chris@179 694
Chris@421 695 static QString regexEscape(QString filename)
Chris@421 696 {
Chris@421 697 return filename
Chris@421 698 .replace(".", "\\.")
Chris@421 699 .replace("[", "\\[")
Chris@421 700 .replace("]", "\\]")
Chris@421 701 .replace("(", "\\(")
Chris@421 702 .replace(")", "\\)")
Chris@421 703 .replace("?", "\\?");
Chris@421 704 }
Chris@421 705
Chris@326 706 void MainWindow::hgIgnoreFiles(QStringList files)
Chris@326 707 {
Chris@417 708 if (!QDir(m_workFolderPath).exists() || files.empty()) return;
Chris@413 709
Chris@413 710 // we should:
Chris@413 711 //
Chris@413 712 // * show the user the list of file names selected
Chris@413 713 //
Chris@413 714 // * offer a choice (depending on the files selected?)
Chris@413 715 //
Chris@413 716 // - ignore only these files
Chris@413 717 //
Chris@413 718 // - ignore files with these names, in any subdirectories?
Chris@413 719 //
Chris@413 720 // - ignore all files with this extension (if they have a common
Chris@413 721 // extension)?
Chris@413 722 //
Chris@413 723 // - ignore all files with these extensions (if they have any
Chris@413 724 // extensions?)
Chris@413 725
Chris@414 726 DEBUG << "MainWindow::hgIgnoreFiles: File names are:" << endl;
Chris@414 727 foreach (QString file, files) DEBUG << file << endl;
Chris@414 728
Chris@414 729 QSet<QString> suffixes;
Chris@414 730 foreach (QString file, files) {
Chris@414 731 QString s = QFileInfo(file).suffix();
Chris@414 732 if (s != "") suffixes.insert(s);
Chris@414 733 }
Chris@414 734
Chris@419 735 QString directory;
Chris@429 736 int dirCount = 0;
Chris@419 737 foreach (QString file, files) {
Chris@419 738 QString d = QFileInfo(file).path();
Chris@419 739 if (d != directory) {
Chris@419 740 ++dirCount;
Chris@419 741 directory = d;
Chris@419 742 }
Chris@419 743 }
Chris@421 744 if (dirCount != 1 || directory == ".") directory = "";
Chris@419 745
Chris@414 746 HgIgnoreDialog::IgnoreType itype =
Chris@415 747 HgIgnoreDialog::confirmIgnore
Chris@419 748 (this, files, QStringList::fromSet(suffixes), directory);
Chris@414 749
Chris@416 750 DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl;
Chris@417 751
Chris@421 752 if (itype == HgIgnoreDialog::IgnoreNothing) return;
Chris@421 753
Chris@417 754 // Now, .hgignore can be switched from regex to glob syntax
Chris@417 755 // part-way through -- and glob is much simpler for us, so we
Chris@417 756 // should do that if it's in regex mode at the end of the file.
Chris@417 757
Chris@417 758 initHgIgnore();
Chris@417 759
Chris@417 760 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
Chris@417 761
Chris@417 762 // hgignore file should now exist (initHgIgnore should have
Chris@417 763 // created it if it didn't). Check for glob status first
Chris@417 764
Chris@417 765 QFile f(hgIgnorePath);
Chris@417 766 if (!f.exists()) {
Chris@417 767 std::cerr << "MainWindow::ignoreFiles: Internal error: .hgignore file not found (even though we were supposed to have created it)" << std::endl;
Chris@417 768 return;
Chris@417 769 }
Chris@417 770
Chris@417 771 f.open(QFile::ReadOnly);
Chris@417 772 bool glob = false;
Chris@606 773 bool cr = false; // whether the last line examined ended with a CR
Chris@417 774 while (!f.atEnd()) {
Chris@417 775 QByteArray ba = f.readLine();
Chris@606 776 QString s = QString::fromLocal8Bit(ba);
Chris@606 777 cr = (s.endsWith('\n') || s.endsWith('\r'));
Chris@606 778 s = s.trimmed();
Chris@417 779 if (s.startsWith("syntax:")) {
Chris@417 780 if (s.endsWith("glob")) {
Chris@417 781 glob = true;
Chris@417 782 } else {
Chris@417 783 glob = false;
Chris@417 784 }
Chris@417 785 }
Chris@417 786 }
Chris@417 787 f.close();
Chris@417 788
Chris@417 789 f.open(QFile::Append);
Chris@417 790 QTextStream out(&f);
Chris@417 791
Chris@606 792 if (!cr) {
Chris@606 793 out << endl;
Chris@606 794 }
Chris@606 795
Chris@417 796 if (!glob) {
Chris@417 797 out << "syntax: glob" << endl;
Chris@417 798 }
Chris@417 799
Chris@421 800 QString info = "<qt><h3>" + tr("Ignored files") + "</h3><p>";
Chris@421 801 info += tr("The following lines have been added to the .hgignore file for this working copy:");
Chris@421 802 info += "</p><code>";
Chris@421 803
Chris@421 804 QStringList args;
Chris@417 805 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
Chris@421 806 args = QStringList::fromSet(suffixes);
Chris@421 807 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
Chris@421 808 args = files;
Chris@421 809 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
Chris@421 810 QSet<QString> names;
Chris@421 811 foreach (QString f, files) {
Chris@421 812 names << QFileInfo(f).fileName();
Chris@417 813 }
Chris@421 814 args = QStringList::fromSet(names);
Chris@421 815 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
Chris@421 816 args << directory;
Chris@421 817 }
Chris@421 818
Chris@421 819 bool first = true;
Chris@421 820
Chris@421 821 foreach (QString a, args) {
Chris@421 822 QString line;
Chris@421 823 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
Chris@421 824 line = "*." + a;
Chris@421 825 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
Chris@421 826 // Doesn't seem to be possible to do this with a glob,
Chris@421 827 // because the glob is always unanchored and there is no
Chris@421 828 // equivalent of ^ to anchor it
chris@423 829 line = "re:^" + regexEscape(a) + "$";
Chris@421 830 } else if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenNames) {
Chris@421 831 line = a;
Chris@421 832 } else if (itype == HgIgnoreDialog::IgnoreWholeDirectory) {
Chris@421 833 line = "re:^" + regexEscape(a) + "/";
Chris@418 834 }
Chris@421 835 if (line != "") {
Chris@421 836 out << line << endl;
Chris@421 837 if (!first) info += "<br>";
Chris@421 838 first = false;
Chris@421 839 info += xmlEncode(line);
Chris@417 840 }
Chris@417 841 }
Chris@417 842
Chris@419 843 f.close();
Chris@419 844
Chris@421 845 info += "</code></qt>";
Chris@421 846
Chris@421 847 QMessageBox::information(this, tr("Ignored files"),
Chris@421 848 info);
Chris@421 849
Chris@417 850 hgRefresh();
Chris@326 851 }
Chris@326 852
Chris@326 853 void MainWindow::hgUnIgnoreFiles(QStringList files)
Chris@326 854 {
Chris@421 855 // Not implemented: edit the .hgignore instead
Chris@421 856 hgEditIgnore();
Chris@326 857 }
Chris@326 858
sam@624 859 void MainWindow::hgShowIn(QStringList files)
sam@624 860 {
sam@624 861 foreach (QString file, files)
sam@624 862 {
sam@624 863 QStringList args;
Chris@638 864 #if defined Q_OS_WIN32
sam@624 865 // Although the Win32 API is quite happy to have
sam@624 866 // forward slashes as directory separators, Windows
sam@624 867 // Explorer is not
sam@635 868 int last = m_workFolderPath.length() - 1;
sam@635 869 char c = m_workFolderPath[last].toAscii();
sam@635 870 if (c == '\\' || c == '/') {
sam@635 871 m_workFolderPath.chop(1);
sam@635 872 }
sam@635 873 file = m_workFolderPath + "\\" + file;
sam@624 874 file = file.replace('/', '\\');
sam@624 875 args << "/select," << file;
sam@624 876 // FIXME: This shouldn't be using a hardcoded path.
sam@624 877 QProcess::execute("c:/windows/explorer.exe", args);
Chris@638 878 #elif defined(Q_OS_MAC)
sam@637 879 file = m_workFolderPath + "/" + file;
sam@637 880 args << "--reveal" << file;
sam@624 881 QProcess::execute("/usr/bin/open", args);
Chris@638 882 #endif
sam@624 883 }
sam@624 884 }
sam@624 885
Chris@239 886 QString MainWindow::getDiffBinaryName()
Chris@179 887 {
Chris@179 888 QSettings settings;
Chris@179 889 settings.beginGroup("Locations");
Chris@239 890 return settings.value("extdiffbinary", "").toString();
Chris@179 891 }
Chris@179 892
Chris@239 893 QString MainWindow::getMergeBinaryName()
Chris@179 894 {
Chris@179 895 QSettings settings;
Chris@179 896 settings.beginGroup("Locations");
Chris@239 897 return settings.value("mergebinary", "").toString();
Chris@179 898 }
Chris@179 899
Chris@168 900 void MainWindow::hgShowSummary()
Chris@168 901 {
Chris@168 902 QStringList params;
Chris@168 903
Chris@168 904 params << "diff" << "--stat";
Chris@168 905
Chris@288 906 m_runner->requestAction(HgAction(ACT_UNCOMMITTED_SUMMARY, m_workFolderPath, params));
Chris@168 907 }
Chris@168 908
jtkorhonen@0 909 void MainWindow::hgFolderDiff()
jtkorhonen@0 910 {
Chris@326 911 hgDiffFiles(QStringList());
Chris@326 912 }
Chris@326 913
Chris@326 914 void MainWindow::hgDiffFiles(QStringList files)
Chris@326 915 {
Chris@239 916 QString diff = getDiffBinaryName();
Chris@179 917 if (diff == "") return;
Chris@112 918
Chris@109 919 QStringList params;
jtkorhonen@0 920
Chris@112 921 // Diff parent against working folder (folder diff)
Chris@112 922
Chris@148 923 params << "--config" << "extensions.extdiff=" << "extdiff";
sam@633 924 params << "--program" << diff << "--";
sam@633 925
sam@633 926 QSettings settings;
sam@633 927 if (settings.value("multipleDiffInstances", false).toBool()) {
sam@633 928 foreach (QString file, files) {
sam@633 929 QStringList p = params;
sam@633 930 p << file;
sam@633 931 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, p));
sam@633 932 }
sam@633 933 }
sam@633 934 else {
sam@633 935 params << files; // may be none: whole dir
sam@633 936 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
sam@633 937 }
jtkorhonen@0 938 }
jtkorhonen@0 939
Chris@148 940 void MainWindow::hgDiffToCurrent(QString id)
jtkorhonen@0 941 {
Chris@239 942 QString diff = getDiffBinaryName();
Chris@179 943 if (diff == "") return;
Chris@163 944
Chris@148 945 QStringList params;
jtkorhonen@0 946
Chris@148 947 // Diff given revision against working folder
jtkorhonen@0 948
Chris@148 949 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 950 params << "--program" << diff;
Chris@153 951 params << "--rev" << Changeset::hashOf(id);
Chris@148 952
Chris@284 953 m_runner->requestAction(HgAction(ACT_FOLDERDIFF, m_workFolderPath, params));
jtkorhonen@0 954 }
jtkorhonen@0 955
Chris@148 956 void MainWindow::hgDiffToParent(QString child, QString parent)
Chris@148 957 {
Chris@239 958 QString diff = getDiffBinaryName();
Chris@179 959 if (diff == "") return;
Chris@163 960
Chris@148 961 QStringList params;
Chris@148 962
Chris@281 963 // Diff given revision against parent revision
Chris@148 964
Chris@148 965 params << "--config" << "extensions.extdiff=" << "extdiff";
Chris@179 966 params << "--program" << diff;
Chris@153 967 params << "--rev" << Changeset::hashOf(parent)
Chris@153 968 << "--rev" << Changeset::hashOf(child);
Chris@148 969
Chris@284 970 m_runner->requestAction(HgAction(ACT_CHGSETDIFF, m_workFolderPath, params));
Chris@273 971 }
Chris@326 972
Chris@273 973
Chris@289 974 void MainWindow::hgShowSummaryFor(Changeset *cs)
Chris@288 975 {
Chris@288 976 QStringList params;
Chris@288 977
Chris@289 978 // This will pick a default parent if there is more than one
Chris@289 979 // (whereas with diff we need to supply one). But it does need a
Chris@289 980 // bit more parsing
Chris@289 981 params << "log" << "--stat" << "--rev" << Changeset::hashOf(cs->id());
Chris@289 982
Chris@289 983 m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath,
Chris@289 984 params, cs));
Chris@148 985 }
Chris@148 986
jtkorhonen@0 987
jtkorhonen@0 988 void MainWindow::hgUpdate()
jtkorhonen@0 989 {
Chris@109 990 QStringList params;
jtkorhonen@0 991
Chris@109 992 params << "update";
Chris@109 993
Chris@284 994 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
jtkorhonen@0 995 }
jtkorhonen@0 996
jtkorhonen@0 997
Chris@148 998 void MainWindow::hgUpdateToRev(QString id)
jtkorhonen@0 999 {
Chris@148 1000 QStringList params;
jtkorhonen@0 1001
Chris@153 1002 params << "update" << "--rev" << Changeset::hashOf(id) << "--check";
jtkorhonen@0 1003
Chris@284 1004 m_runner->requestAction(HgAction(ACT_UPDATE, m_workFolderPath, params));
jtkorhonen@0 1005 }
jtkorhonen@0 1006
jtkorhonen@0 1007
jtkorhonen@0 1008 void MainWindow::hgRevert()
jtkorhonen@0 1009 {
Chris@326 1010 hgRevertFiles(QStringList());
Chris@326 1011 }
Chris@326 1012
Chris@326 1013 void MainWindow::hgRevertFiles(QStringList files)
Chris@326 1014 {
Chris@109 1015 QStringList params;
Chris@109 1016 QString comment;
Chris@237 1017 bool all = false;
Chris@98 1018
Chris@284 1019 QStringList allFiles = m_hgTabs->getAllRevertableFiles();
Chris@237 1020 if (files.empty() || files == allFiles) {
Chris@237 1021 files = allFiles;
Chris@237 1022 all = true;
Chris@237 1023 }
Chris@237 1024
Chris@237 1025 QString subsetNote;
Chris@237 1026 if (!all) {
Chris@237 1027 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 1028 }
Chris@155 1029
Chris@155 1030 QString rf(tr("Revert files"));
Chris@237 1031
Chris@237 1032 // Set up params before asking for confirmation, because there is
Chris@237 1033 // a failure case here that we would need to report on early
Chris@237 1034
Chris@284 1035 DEBUG << "hgRevert: m_justMerged = " << m_justMerged << ", m_mergeTargetRevision = " << m_mergeTargetRevision << endl;
Chris@273 1036
Chris@284 1037 if (m_justMerged) {
Chris@237 1038
Chris@237 1039 // This is a little fiddly. The proper way to "revert" the
Chris@237 1040 // whole of an uncommitted merge is with "hg update --clean ."
Chris@237 1041 // But if the user has selected only some files, we're sort of
Chris@237 1042 // promising to revert only those, which means we need to
Chris@237 1043 // specify which parent to revert to. We can only do that if
Chris@237 1044 // we have a record of it, which we do if you just did the
Chris@237 1045 // merge from within easyhg but don't if you've exited and
Chris@237 1046 // restarted, or changed repository, since then. Hmmm.
Chris@237 1047
Chris@237 1048 if (all) {
Chris@237 1049 params << "update" << "--clean" << ".";
Chris@237 1050 } else {
Chris@284 1051 if (m_mergeTargetRevision != "") {
Chris@237 1052 params << "revert" << "--rev"
Chris@284 1053 << Changeset::hashOf(m_mergeTargetRevision)
Chris@237 1054 << "--" << files;
Chris@237 1055 } else {
Chris@237 1056 QMessageBox::information
Chris@237 1057 (this, tr("Unable to revert"),
Chris@237 1058 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 1059 return;
Chris@237 1060 }
Chris@237 1061 }
Chris@237 1062 } else {
Chris@237 1063 params << "revert" << "--" << files;
Chris@237 1064 }
Chris@237 1065
Chris@109 1066 if (ConfirmCommentDialog::confirmDangerousFilesAction
Chris@109 1067 (this,
Chris@155 1068 rf,
Chris@237 1069 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 1070 .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 1071 .arg(subsetNote),
Chris@237 1072 tr("<h3>%1</h3><p>%2%3").arg(rf)
Chris@237 1073 .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 1074 .arg(subsetNote),
Chris@193 1075 files,
Chris@365 1076 tr("Re&vert"))) {
Chris@163 1077
Chris@284 1078 m_lastRevertedFiles = files;
Chris@109 1079
Chris@284 1080 m_runner->requestAction(HgAction(ACT_REVERT, m_workFolderPath, params));
jtkorhonen@0 1081 }
jtkorhonen@0 1082 }
jtkorhonen@0 1083
Chris@163 1084
Chris@361 1085 void MainWindow::hgRenameFiles(QStringList files)
Chris@361 1086 {
Chris@361 1087 QString renameTo;
Chris@361 1088
Chris@361 1089 QString file;
Chris@361 1090 if (files.empty()) return;
Chris@361 1091 file = files[0];
Chris@361 1092
Chris@361 1093 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@361 1094 (this,
Chris@361 1095 tr("Rename"),
Chris@361 1096 tr("Rename <code>%1</code> to:").arg(xmlEncode(file)),
Chris@361 1097 renameTo,
Chris@365 1098 tr("Re&name"))) {
Chris@361 1099
Chris@361 1100 if (renameTo != "" && renameTo != file) {
Chris@361 1101
Chris@361 1102 QStringList params;
Chris@361 1103
Chris@361 1104 params << "rename" << "--" << file << renameTo;
Chris@361 1105
Chris@361 1106 m_runner->requestAction(HgAction(ACT_RENAME_FILE, m_workFolderPath, params));
Chris@361 1107 }
Chris@361 1108 }
Chris@361 1109 }
Chris@361 1110
Chris@361 1111
Chris@361 1112 void MainWindow::hgCopyFiles(QStringList files)
Chris@361 1113 {
Chris@361 1114 QString copyTo;
Chris@361 1115
Chris@361 1116 QString file;
Chris@361 1117 if (files.empty()) return;
Chris@361 1118 file = files[0];
Chris@361 1119
Chris@361 1120 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@361 1121 (this,
Chris@361 1122 tr("Copy"),
Chris@361 1123 tr("Copy <code>%1</code> to:").arg(xmlEncode(file)),
Chris@361 1124 copyTo,
Chris@365 1125 tr("Co&py"))) {
Chris@361 1126
Chris@361 1127 if (copyTo != "" && copyTo != file) {
Chris@361 1128
Chris@361 1129 QStringList params;
Chris@361 1130
Chris@361 1131 params << "copy" << "--" << file << copyTo;
Chris@361 1132
Chris@361 1133 m_runner->requestAction(HgAction(ACT_COPY_FILE, m_workFolderPath, params));
Chris@361 1134 }
Chris@361 1135 }
Chris@361 1136 }
Chris@361 1137
Chris@361 1138
Chris@326 1139 void MainWindow::hgMarkFilesResolved(QStringList files)
Chris@163 1140 {
Chris@163 1141 QStringList params;
Chris@163 1142
Chris@163 1143 params << "resolve" << "--mark";
Chris@163 1144
Chris@163 1145 if (files.empty()) {
Chris@163 1146 params << "--all";
Chris@163 1147 } else {
Chris@164 1148 params << "--" << files;
Chris@163 1149 }
Chris@163 1150
Chris@284 1151 m_runner->requestAction(HgAction(ACT_RESOLVE_MARK, m_workFolderPath, params));
Chris@163 1152 }
Chris@163 1153
Chris@163 1154
Chris@326 1155 void MainWindow::hgRedoMerge()
Chris@326 1156 {
Chris@326 1157 hgRedoFileMerges(QStringList());
Chris@326 1158 }
Chris@326 1159
Chris@326 1160
Chris@326 1161 void MainWindow::hgRedoFileMerges(QStringList files)
jtkorhonen@33 1162 {
Chris@109 1163 QStringList params;
jtkorhonen@33 1164
Chris@163 1165 params << "resolve";
Chris@163 1166
Chris@239 1167 QString merge = getMergeBinaryName();
Chris@179 1168 if (merge != "") {
Chris@179 1169 params << "--tool" << merge;
Chris@163 1170 }
Chris@163 1171
Chris@163 1172 if (files.empty()) {
Chris@163 1173 params << "--all";
Chris@163 1174 } else {
Chris@164 1175 params << "--" << files;
Chris@163 1176 }
Chris@163 1177
Chris@284 1178 if (m_currentParents.size() == 1) {
Chris@284 1179 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@237 1180 }
Chris@237 1181
Chris@284 1182 m_runner->requestAction(HgAction(ACT_RETRY_MERGE, m_workFolderPath, params));
Chris@273 1183
Chris@284 1184 m_mergeCommitComment = tr("Merge");
jtkorhonen@33 1185 }
Chris@326 1186
jtkorhonen@33 1187
jtkorhonen@0 1188 void MainWindow::hgMerge()
jtkorhonen@0 1189 {
Chris@284 1190 if (m_hgTabs->canResolve()) {
Chris@326 1191 hgRedoMerge();
Chris@163 1192 return;
Chris@163 1193 }
Chris@163 1194
Chris@109 1195 QStringList params;
jtkorhonen@0 1196
Chris@109 1197 params << "merge";
Chris@163 1198
Chris@239 1199 QString merge = getMergeBinaryName();
Chris@179 1200 if (merge != "") {
Chris@179 1201 params << "--tool" << merge;
Chris@163 1202 }
Chris@163 1203
Chris@284 1204 if (m_currentParents.size() == 1) {
Chris@284 1205 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@163 1206 }
Chris@163 1207
Chris@284 1208 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
Chris@273 1209
Chris@284 1210 m_mergeCommitComment = tr("Merge");
jtkorhonen@0 1211 }
jtkorhonen@0 1212
jtkorhonen@0 1213
Chris@148 1214 void MainWindow::hgMergeFrom(QString id)
Chris@148 1215 {
Chris@148 1216 QStringList params;
Chris@148 1217
Chris@148 1218 params << "merge";
Chris@153 1219 params << "--rev" << Changeset::hashOf(id);
Chris@163 1220
Chris@239 1221 QString merge = getMergeBinaryName();
Chris@179 1222 if (merge != "") {
Chris@179 1223 params << "--tool" << merge;
Chris@163 1224 }
Chris@148 1225
Chris@284 1226 if (m_currentParents.size() == 1) {
Chris@284 1227 m_mergeTargetRevision = m_currentParents[0]->id();
Chris@237 1228 }
Chris@237 1229
Chris@284 1230 m_runner->requestAction(HgAction(ACT_MERGE, m_workFolderPath, params));
Chris@273 1231
Chris@284 1232 m_mergeCommitComment = "";
Chris@273 1233
Chris@284 1234 foreach (Changeset *cs, m_currentHeads) {
Chris@284 1235 if (cs->id() == id && !cs->isOnBranch(m_currentBranch)) {
Chris@157 1236 if (cs->branch() == "" || cs->branch() == "default") {
Chris@284 1237 m_mergeCommitComment = tr("Merge from the default branch");
Chris@157 1238 } else {
Chris@284 1239 m_mergeCommitComment = tr("Merge from branch \"%1\"").arg(cs->branch());
Chris@157 1240 }
Chris@157 1241 }
Chris@157 1242 }
Chris@157 1243
Chris@284 1244 if (m_mergeCommitComment == "") {
Chris@284 1245 m_mergeCommitComment = tr("Merge from %1").arg(id);
Chris@157 1246 }
Chris@148 1247 }
Chris@148 1248
Chris@148 1249
jtkorhonen@0 1250 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 1251 {
Chris@109 1252 QStringList params;
jtkorhonen@0 1253
Chris@284 1254 if (!QDir(m_workFolderPath).exists()) {
Chris@284 1255 if (!QDir().mkpath(m_workFolderPath)) {
Chris@109 1256 DEBUG << "hgCloneFromRemote: Failed to create target path "
Chris@284 1257 << m_workFolderPath << endl;
Chris@607 1258 QMessageBox::critical
Chris@607 1259 (this, tr("Could not create target folder"),
Chris@607 1260 tr("<qt><b>Could not create target folder</b><br><br>The local target folder \"%1\" does not exist<br>and could not be created.</qt>").arg(xmlEncode(m_workFolderPath)));
Chris@608 1261 m_workFolderPath = "";
Chris@109 1262 return;
Chris@104 1263 }
Chris@109 1264 }
Chris@104 1265
Chris@284 1266 params << "clone" << m_remoteRepoPath << m_workFolderPath;
Chris@109 1267
Chris@287 1268 updateWorkFolderAndRepoNames();
Chris@284 1269 m_hgTabs->updateWorkFolderFileList("");
Chris@608 1270 m_hgTabs->clearAll();
Chris@273 1271
Chris@284 1272 m_runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, m_workFolderPath, params));
jtkorhonen@0 1273 }
jtkorhonen@0 1274
jtkorhonen@0 1275 void MainWindow::hgInit()
jtkorhonen@0 1276 {
Chris@109 1277 QStringList params;
jtkorhonen@0 1278
Chris@109 1279 params << "init";
Chris@284 1280 params << m_workFolderPath;
Chris@273 1281
Chris@284 1282 m_runner->requestAction(HgAction(ACT_INIT, m_workFolderPath, params));
jtkorhonen@0 1283 }
jtkorhonen@0 1284
jtkorhonen@0 1285 void MainWindow::hgIncoming()
jtkorhonen@0 1286 {
Chris@109 1287 QStringList params;
jtkorhonen@0 1288
Chris@284 1289 params << "incoming" << "--newest-first" << m_remoteRepoPath;
Chris@125 1290 params << "--template" << Changeset::getLogTemplate();
jtkorhonen@0 1291
Chris@284 1292 m_runner->requestAction(HgAction(ACT_INCOMING, m_workFolderPath, params));
jtkorhonen@0 1293 }
jtkorhonen@0 1294
jtkorhonen@0 1295 void MainWindow::hgPull()
jtkorhonen@0 1296 {
Chris@193 1297 if (ConfirmCommentDialog::confirm
Chris@126 1298 (this, tr("Confirm pull"),
Chris@299 1299 tr("<qt><h3>Pull from remote repository?</h3></qt>"),
Chris@299 1300 tr("<qt><p>You are about to pull changes from the remote repository at <code>%1</code>.</p></qt>").arg(xmlEncode(m_remoteRepoPath)),
Chris@365 1301 tr("&Pull"))) {
jtkorhonen@0 1302
Chris@126 1303 QStringList params;
Chris@284 1304 params << "pull" << m_remoteRepoPath;
Chris@284 1305 m_runner->requestAction(HgAction(ACT_PULL, m_workFolderPath, params));
Chris@126 1306 }
jtkorhonen@0 1307 }
jtkorhonen@0 1308
jtkorhonen@0 1309 void MainWindow::hgPush()
jtkorhonen@0 1310 {
Chris@363 1311 if (m_remoteRepoPath.isEmpty()) {
Chris@363 1312 changeRemoteRepo(true);
Chris@363 1313 if (m_remoteRepoPath.isEmpty()) return;
Chris@363 1314 }
Chris@363 1315
Chris@356 1316 QString uncommittedNote;
Chris@356 1317 if (m_hgTabs->canCommit()) {
Chris@356 1318 uncommittedNote = tr("<p><b>Note:</b> You have uncommitted changes. If you want to push these changes to the remote repository, you need to commit them first.");
Chris@356 1319 }
Chris@356 1320
Chris@193 1321 if (ConfirmCommentDialog::confirm
Chris@126 1322 (this, tr("Confirm push"),
Chris@299 1323 tr("<qt><h3>Push to remote repository?</h3></qt>"),
Chris@356 1324 tr("<qt><p>You are about to push your commits to the remote repository at <code>%1</code>.</p>%2</qt>").arg(xmlEncode(m_remoteRepoPath)).arg(uncommittedNote),
Chris@365 1325 tr("&Push"))) {
jtkorhonen@0 1326
Chris@126 1327 QStringList params;
Chris@284 1328 params << "push" << "--new-branch" << m_remoteRepoPath;
Chris@284 1329 m_runner->requestAction(HgAction(ACT_PUSH, m_workFolderPath, params));
Chris@126 1330 }
jtkorhonen@0 1331 }
jtkorhonen@0 1332
Chris@182 1333 QStringList MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 1334 {
Chris@182 1335 QStringList ret;
jtkorhonen@26 1336 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 1337
Chris@182 1338 for (int i = 0; i < ifaces.count(); i++) {
jtkorhonen@26 1339 QNetworkInterface iface = ifaces.at(i);
Chris@182 1340 if (iface.flags().testFlag(QNetworkInterface::IsUp)
Chris@182 1341 && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
Chris@182 1342 for (int j=0; j<iface.addressEntries().count(); j++) {
jtkorhonen@28 1343 QHostAddress tmp = iface.addressEntries().at(j).ip();
Chris@182 1344 if (QAbstractSocket::IPv4Protocol == tmp.protocol()) {
Chris@182 1345 ret.push_back(tmp.toString());
jtkorhonen@24 1346 }
jtkorhonen@24 1347 }
jtkorhonen@22 1348 }
jtkorhonen@17 1349 }
jtkorhonen@28 1350 return ret;
jtkorhonen@28 1351 }
jtkorhonen@17 1352
Chris@120 1353 void MainWindow::clearState()
Chris@120 1354 {
Chris@305 1355 DEBUG << "MainWindow::clearState" << endl;
Chris@284 1356 foreach (Changeset *cs, m_currentParents) delete cs;
Chris@284 1357 m_currentParents.clear();
Chris@284 1358 foreach (Changeset *cs, m_currentHeads) delete cs;
Chris@284 1359 m_currentHeads.clear();
Chris@506 1360 m_closedHeadIds.clear();
Chris@284 1361 m_currentBranch = "";
Chris@284 1362 m_lastStatOutput = "";
Chris@284 1363 m_lastRevertedFiles.clear();
Chris@284 1364 m_mergeTargetRevision = "";
Chris@284 1365 m_mergeCommitComment = "";
Chris@284 1366 m_stateUnknown = true;
Chris@284 1367 m_needNewLog = true;
Chris@120 1368 }
jtkorhonen@17 1369
jtkorhonen@11 1370 void MainWindow::hgServe()
jtkorhonen@11 1371 {
Chris@109 1372 QStringList params;
Chris@109 1373 QString msg;
jtkorhonen@11 1374
Chris@182 1375 QStringList addrs = listAllUpIpV4Addresses();
Chris@182 1376
Chris@182 1377 if (addrs.empty()) {
Chris@182 1378 QMessageBox::critical
Chris@182 1379 (this, tr("Serve"), tr("Failed to identify an active IPv4 address"));
Chris@182 1380 return;
Chris@182 1381 }
Chris@182 1382
Chris@526 1383 // See #202. We really want to display the port that the server
Chris@526 1384 // ends up using -- but we don't get that information until after
Chris@526 1385 // it has exited! However, we can improve the likelihood of
Chris@526 1386 // showing the right port by at least checking whether a port is
Chris@526 1387 // defined in the hgrc file.
Chris@526 1388
Chris@526 1389 QFileInfo hgrc(QDir::homePath() + "/.hgrc");
Chris@526 1390 QString path;
Chris@526 1391 int port = 8000; // the default
Chris@526 1392 if (hgrc.exists()) {
Chris@526 1393 QSettings s(hgrc.canonicalFilePath(), QSettings::IniFormat);
Chris@526 1394 s.beginGroup("web");
Chris@527 1395 int p = s.value("port").toInt();
Chris@527 1396 if (p) port = p;
Chris@526 1397 }
Chris@182 1398
Chris@182 1399 QTextStream ts(&msg);
Chris@429 1400 ts << QString("<qt><h3>%1</h3><p>%2</p>")
Chris@425 1401 .arg(tr("Sharing Repository"))
Chris@429 1402 .arg(tr("Your local repository is now being made temporarily available via HTTP for workgroup access."));
Chris@429 1403 if (addrs.size() > 1) {
Chris@429 1404 ts << QString("<p>%3</p>")
Chris@429 1405 .arg(tr("Users who have network access to your computer can now clone your repository, by using one of the following URLs as a remote location:"));
Chris@429 1406 } else {
Chris@429 1407 ts << QString("<p>%3</p>")
Chris@429 1408 .arg(tr("Users who have network access to your computer can now clone your repository, by using the following URL as a remote location:"));
Chris@429 1409 }
Chris@182 1410 foreach (QString addr, addrs) {
Chris@526 1411 ts << QString("<pre>&nbsp;&nbsp;http://%1:%2</pre>").arg(xmlEncode(addr)).arg(port);
Chris@182 1412 }
Chris@425 1413 ts << tr("<p>Press Close to terminate this server, end remote access, and return.</p>");
Chris@182 1414 ts.flush();
Chris@182 1415
Chris@109 1416 params << "serve";
jtkorhonen@11 1417
Chris@284 1418 m_runner->requestAction(HgAction(ACT_SERVE, m_workFolderPath, params));
Chris@109 1419
Chris@425 1420 QMessageBox::information(this, tr("Share Repository"), msg, QMessageBox::Close);
Chris@182 1421
Chris@284 1422 m_runner->killCurrentActions();
jtkorhonen@11 1423 }
jtkorhonen@11 1424
Chris@64 1425 void MainWindow::startupDialog()
Chris@64 1426 {
Chris@64 1427 StartupDialog *dlg = new StartupDialog(this);
Chris@284 1428 if (dlg->exec()) m_firstStart = false;
Chris@344 1429 else exit(0);
Chris@64 1430 }
jtkorhonen@11 1431
Chris@69 1432 void MainWindow::open()
Chris@69 1433 {
Chris@86 1434 bool done = false;
Chris@69 1435
Chris@86 1436 while (!done) {
Chris@69 1437
Chris@86 1438 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 1439 (tr("Open Repository"),
Chris@86 1440 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 1441 this);
Chris@69 1442
Chris@345 1443 d->addChoice("remote",
Chris@345 1444 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@345 1445 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@345 1446 MultiChoiceDialog::UrlToDirectoryArg);
Chris@345 1447
Chris@339 1448 d->addChoice("local",
Chris@339 1449 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@339 1450 tr("Open an existing local Mercurial repository."),
Chris@339 1451 MultiChoiceDialog::DirectoryArg);
Chris@339 1452
Chris@339 1453 d->addChoice("init",
Chris@339 1454 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@339 1455 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@339 1456 MultiChoiceDialog::DirectoryArg);
Chris@339 1457
Chris@248 1458 QSettings settings;
Chris@484 1459 settings.beginGroup("");
Chris@359 1460 QString lastChoice = settings.value("lastopentype", "remote").toString();
Chris@248 1461 if (lastChoice != "local" &&
Chris@248 1462 lastChoice != "remote" &&
Chris@248 1463 lastChoice != "init") {
Chris@359 1464 lastChoice = "remote";
Chris@248 1465 }
Chris@248 1466
Chris@248 1467 d->setCurrentChoice(lastChoice);
Chris@86 1468
Chris@86 1469 if (d->exec() == QDialog::Accepted) {
Chris@86 1470
Chris@86 1471 QString choice = d->getCurrentChoice();
Chris@248 1472 settings.setValue("lastopentype", choice);
Chris@248 1473
Chris@86 1474 QString arg = d->getArgument().trimmed();
Chris@86 1475
Chris@86 1476 bool result = false;
Chris@86 1477
Chris@86 1478 if (choice == "local") {
Chris@86 1479 result = openLocal(arg);
Chris@86 1480 } else if (choice == "remote") {
Chris@86 1481 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 1482 } else if (choice == "init") {
Chris@86 1483 result = openInit(arg);
Chris@86 1484 }
Chris@86 1485
Chris@86 1486 if (result) {
Chris@86 1487 enableDisableActions();
Chris@120 1488 clearState();
Chris@109 1489 hgQueryPaths();
Chris@91 1490 done = true;
Chris@91 1491 }
Chris@86 1492
Chris@86 1493 } else {
Chris@86 1494
Chris@86 1495 // cancelled
Chris@86 1496 done = true;
Chris@69 1497 }
Chris@79 1498
Chris@86 1499 delete d;
Chris@69 1500 }
Chris@69 1501 }
Chris@69 1502
Chris@359 1503 void MainWindow::recentMenuActivated()
Chris@359 1504 {
Chris@359 1505 QAction *a = qobject_cast<QAction *>(sender());
Chris@359 1506 if (!a) return;
Chris@359 1507 QString local = a->text();
Chris@359 1508 open(local);
Chris@359 1509 }
Chris@359 1510
Chris@182 1511 void MainWindow::changeRemoteRepo()
Chris@182 1512 {
Chris@363 1513 changeRemoteRepo(false);
Chris@363 1514 }
Chris@363 1515
Chris@363 1516 void MainWindow::changeRemoteRepo(bool initial)
Chris@363 1517 {
Chris@183 1518 // This will involve rewriting the local .hgrc
Chris@183 1519
Chris@284 1520 QDir hgDir(m_workFolderPath + "/.hg");
Chris@184 1521 if (!hgDir.exists()) {
Chris@184 1522 //!!! visible error!
Chris@184 1523 return;
Chris@184 1524 }
Chris@184 1525
Chris@284 1526 QFileInfo hgrc(m_workFolderPath + "/.hg/hgrc");
Chris@184 1527 if (hgrc.exists() && !hgrc.isWritable()) {
Chris@183 1528 //!!! visible error!
Chris@183 1529 return;
Chris@183 1530 }
Chris@183 1531
Chris@183 1532 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@363 1533 (tr("Set Remote Location"),
Chris@363 1534 tr("<qt><big>Set the remote location</big></qt>"),
Chris@183 1535 this);
Chris@183 1536
Chris@363 1537 QString explanation;
Chris@363 1538 if (initial) {
Chris@609 1539 explanation = tr("Provide a remote URL to use when pushing from, or pulling to, the local<br>repository <code>%1</code>.<br>This will be the default for subsequent pushes and pulls.<br>You can change it using &ldquo;Set Remote Location&rdquo; on the File menu.").arg(m_workFolderPath);
Chris@363 1540 } else {
Chris@609 1541 explanation = tr("Provide a new remote URL to use when pushing from, or pulling to, the local<br>repository <code>%1</code>.").arg(m_workFolderPath);
Chris@363 1542 }
Chris@363 1543
Chris@183 1544 d->addChoice("remote",
Chris@183 1545 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@363 1546 explanation,
Chris@553 1547 MultiChoiceDialog::UrlArg,
Chris@553 1548 true); // default empty
Chris@183 1549
Chris@183 1550 if (d->exec() == QDialog::Accepted) {
Chris@210 1551
Chris@210 1552 // New block to ensure QSettings is deleted before
Chris@210 1553 // hgQueryPaths called. NB use of absoluteFilePath instead of
Chris@210 1554 // canonicalFilePath, which would fail if the file did not yet
Chris@210 1555 // exist
Chris@210 1556
Chris@210 1557 {
Chris@210 1558 QSettings s(hgrc.absoluteFilePath(), QSettings::IniFormat);
Chris@210 1559 s.beginGroup("paths");
Chris@210 1560 s.setValue("default", d->getArgument());
Chris@210 1561 }
Chris@210 1562
Chris@284 1563 m_stateUnknown = true;
Chris@183 1564 hgQueryPaths();
Chris@183 1565 }
Chris@183 1566
Chris@183 1567 delete d;
Chris@182 1568 }
Chris@182 1569
Chris@145 1570 void MainWindow::open(QString local)
Chris@145 1571 {
Chris@145 1572 if (openLocal(local)) {
Chris@145 1573 enableDisableActions();
Chris@145 1574 clearState();
Chris@145 1575 hgQueryPaths();
Chris@145 1576 }
Chris@145 1577 }
Chris@145 1578
Chris@79 1579 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 1580 {
Chris@79 1581 QMessageBox::critical
Chris@79 1582 (this, tr("File chosen"),
Chris@84 1583 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 1584 return false;
Chris@79 1585 }
Chris@79 1586
Chris@248 1587 bool MainWindow::askAboutUnknownFolder(QString arg)
Chris@248 1588 {
Chris@248 1589 bool result = (QMessageBox::question
Chris@248 1590 (this, tr("Path does not exist"),
Chris@248 1591 tr("<qt><b>Path does not exist: create it?</b><br><br>You asked to open a remote repository by cloning it to \"%1\". This folder does not exist, and neither does its parent.<br><br>Would you like to create the parent folder as well?</qt>").arg(xmlEncode(arg)),
Chris@248 1592 QMessageBox::Ok | QMessageBox::Cancel,
Chris@248 1593 QMessageBox::Cancel)
Chris@248 1594 == QMessageBox::Ok);
Chris@248 1595 if (result) {
Chris@248 1596 QDir dir(arg);
Chris@248 1597 dir.cdUp();
Chris@248 1598 if (!dir.mkpath(dir.absolutePath())) {
Chris@248 1599 QMessageBox::critical
Chris@248 1600 (this, tr("Failed to create folder"),
Chris@248 1601 tr("<qt><b>Failed to create folder</b><br><br>Sorry, the path for the parent folder \"%1\" could not be created.</qt>").arg(dir.absolutePath()));
Chris@248 1602 return false;
Chris@248 1603 }
Chris@248 1604 return true;
Chris@248 1605 }
Chris@248 1606 return false;
Chris@248 1607 }
Chris@248 1608
Chris@79 1609 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 1610 {
Chris@79 1611 QMessageBox::critical
Chris@79 1612 (this, tr("Folder does not exist"),
Chris@84 1613 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 1614 return false;
Chris@84 1615 }
Chris@84 1616
Chris@84 1617 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 1618 {
Chris@84 1619 QMessageBox::critical
Chris@84 1620 (this, tr("Path is in existing repository"),
Chris@84 1621 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 1622 return false;
Chris@84 1623 }
Chris@84 1624
Chris@84 1625 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 1626 {
Chris@84 1627 QMessageBox::critical
Chris@84 1628 (this, tr("Path is a file"),
Chris@84 1629 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 1630 return false;
Chris@84 1631 }
Chris@84 1632
Chris@84 1633 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 1634 {
Chris@84 1635 QMessageBox::critical
Chris@84 1636 (this, tr("Path is in existing repository"),
Chris@237 1637 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 1638 return false;
Chris@84 1639 }
Chris@84 1640
Chris@84 1641 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 1642 {
Chris@84 1643 QMessageBox::critical
Chris@84 1644 (this, tr("Path is a file"),
Chris@84 1645 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 1646 return false;
Chris@84 1647 }
Chris@84 1648
Chris@237 1649 QString MainWindow::complainAboutCloneToExistingFolder(QString arg, QString remote)
Chris@84 1650 {
Chris@348 1651 // If the directory "arg" exists but is empty, then we accept it.
Chris@348 1652
Chris@348 1653 // If the directory "arg" exists and is non-empty, but "arg" plus
Chris@348 1654 // the last path component of "remote" does not exist, then offer
Chris@348 1655 // the latter as an alternative path.
Chris@237 1656
Chris@237 1657 QString offer;
Chris@237 1658
Chris@237 1659 QDir d(arg);
Chris@348 1660
Chris@237 1661 if (d.exists()) {
Chris@348 1662
Chris@348 1663 if (d.entryList(QDir::Dirs | QDir::Files |
Chris@348 1664 QDir::NoDotAndDotDot |
Chris@348 1665 QDir::Hidden | QDir::System).empty()) {
Chris@348 1666 // directory is empty; accept it
Chris@348 1667 return arg;
Chris@348 1668 }
Chris@348 1669
Chris@237 1670 if (QRegExp("^\\w+://").indexIn(remote) >= 0) {
Chris@237 1671 QString rpath = QUrl(remote).path();
Chris@237 1672 if (rpath != "") {
Chris@237 1673 rpath = QDir(rpath).dirName();
Chris@237 1674 if (rpath != "" && !d.exists(rpath)) {
Chris@237 1675 offer = d.filePath(rpath);
Chris@237 1676 }
Chris@237 1677 }
Chris@237 1678 }
Chris@237 1679 }
Chris@237 1680
Chris@237 1681 if (offer != "") {
Chris@237 1682 bool result = (QMessageBox::question
Chris@237 1683 (this, tr("Folder exists"),
Chris@237 1684 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 1685 .arg(xmlEncode(arg)).arg(xmlEncode(offer)),
Chris@237 1686 QMessageBox::Ok | QMessageBox::Cancel,
Chris@237 1687 QMessageBox::Cancel)
Chris@237 1688 == QMessageBox::Ok);
Chris@237 1689 if (result) return offer;
Chris@237 1690 else return "";
Chris@237 1691 }
Chris@237 1692
Chris@84 1693 QMessageBox::critical
Chris@84 1694 (this, tr("Folder exists"),
Chris@237 1695 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 1696 return "";
Chris@79 1697 }
Chris@79 1698
Chris@79 1699 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 1700 {
Chris@79 1701 return (QMessageBox::question
Chris@84 1702 (this, tr("Path is inside a repository"),
Chris@86 1703 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 1704 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 1705 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1706 QMessageBox::Ok)
Chris@79 1707 == QMessageBox::Ok);
Chris@79 1708 }
Chris@79 1709
Chris@79 1710 bool MainWindow::askToInitExisting(QString arg)
Chris@79 1711 {
Chris@79 1712 return (QMessageBox::question
Chris@84 1713 (this, tr("Folder has no repository"),
Chris@359 1714 tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder is not a Mercurial working copy.<br><br>Would you like to initialise a repository here?</qt>")
Chris@79 1715 .arg(xmlEncode(arg)),
Chris@79 1716 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1717 QMessageBox::Ok)
Chris@79 1718 == QMessageBox::Ok);
Chris@79 1719 }
Chris@79 1720
Chris@79 1721 bool MainWindow::askToInitNew(QString arg)
Chris@79 1722 {
Chris@79 1723 return (QMessageBox::question
Chris@84 1724 (this, tr("Folder does not exist"),
Chris@84 1725 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 1726 .arg(xmlEncode(arg)),
Chris@84 1727 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 1728 QMessageBox::Ok)
Chris@84 1729 == QMessageBox::Ok);
Chris@84 1730 }
Chris@84 1731
Chris@84 1732 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 1733 {
Chris@84 1734 return (QMessageBox::question
Chris@84 1735 (this, tr("Repository exists"),
Chris@84 1736 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 1737 .arg(xmlEncode(arg)),
Chris@79 1738 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 1739 QMessageBox::Ok)
Chris@79 1740 == QMessageBox::Ok);
Chris@79 1741 }
Chris@79 1742
Chris@79 1743 bool MainWindow::openLocal(QString local)
Chris@79 1744 {
Chris@79 1745 DEBUG << "open " << local << endl;
Chris@79 1746
Chris@79 1747 FolderStatus status = getFolderStatus(local);
Chris@79 1748 QString containing = getContainingRepoFolder(local);
Chris@79 1749
Chris@79 1750 switch (status) {
Chris@79 1751
Chris@79 1752 case FolderHasRepo:
Chris@79 1753 // fine
Chris@79 1754 break;
Chris@79 1755
Chris@79 1756 case FolderExists:
Chris@79 1757 if (containing != "") {
Chris@79 1758 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1759 local = containing;
Chris@79 1760 } else {
Chris@86 1761 //!!! No -- this is likely to happen far more by accident
Chris@86 1762 // than because the user actually wanted to init something.
Chris@86 1763 // Don't ask, just politely reject.
Chris@79 1764 if (!askToInitExisting(local)) return false;
Chris@79 1765 return openInit(local);
Chris@79 1766 }
Chris@79 1767 break;
Chris@79 1768
Chris@79 1769 case FolderParentExists:
Chris@79 1770 if (containing != "") {
Chris@79 1771 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1772 local = containing;
Chris@79 1773 } else {
Chris@79 1774 if (!askToInitNew(local)) return false;
Chris@79 1775 return openInit(local);
Chris@79 1776 }
Chris@79 1777 break;
Chris@79 1778
Chris@79 1779 case FolderUnknown:
Chris@84 1780 if (containing != "") {
Chris@84 1781 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 1782 local = containing;
Chris@84 1783 } else {
Chris@84 1784 return complainAboutUnknownFolder(local);
Chris@84 1785 }
Chris@84 1786 break;
Chris@79 1787
Chris@79 1788 case FolderIsFile:
Chris@79 1789 return complainAboutFilePath(local);
Chris@79 1790 }
Chris@79 1791
Chris@284 1792 m_workFolderPath = local;
Chris@284 1793 m_remoteRepoPath = "";
Chris@79 1794 return true;
Chris@79 1795 }
Chris@79 1796
Chris@79 1797 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 1798 {
Chris@79 1799 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 1800
Chris@84 1801 FolderStatus status = getFolderStatus(local);
Chris@84 1802 QString containing = getContainingRepoFolder(local);
Chris@84 1803
Chris@84 1804 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1805
Chris@84 1806 if (status == FolderHasRepo || containing != "") {
Chris@84 1807 return complainAboutCloneToExisting(local);
Chris@84 1808 }
Chris@84 1809
Chris@84 1810 if (status == FolderIsFile) {
Chris@84 1811 return complainAboutCloneToFile(local);
Chris@84 1812 }
Chris@84 1813
Chris@84 1814 if (status == FolderUnknown) {
Chris@248 1815 if (!askAboutUnknownFolder(local)) {
Chris@248 1816 return false;
Chris@248 1817 }
Chris@84 1818 }
Chris@84 1819
Chris@84 1820 if (status == FolderExists) {
Chris@237 1821 local = complainAboutCloneToExistingFolder(local, remote);
Chris@237 1822 if (local == "") return false;
Chris@84 1823 }
Chris@84 1824
Chris@284 1825 m_workFolderPath = local;
Chris@284 1826 m_remoteRepoPath = remote;
Chris@84 1827 hgCloneFromRemote();
Chris@84 1828
Chris@79 1829 return true;
Chris@79 1830 }
Chris@79 1831
Chris@84 1832 bool MainWindow::openInit(QString local)
Chris@79 1833 {
Chris@84 1834 DEBUG << "openInit " << local << endl;
Chris@84 1835
Chris@84 1836 FolderStatus status = getFolderStatus(local);
Chris@84 1837 QString containing = getContainingRepoFolder(local);
Chris@84 1838
Chris@84 1839 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 1840
Chris@84 1841 if (status == FolderHasRepo) {
Chris@84 1842 if (!askToOpenInsteadOfInit(local)) return false;
Chris@552 1843 return openLocal(local);
Chris@84 1844 }
Chris@84 1845
Chris@84 1846 if (containing != "") {
Chris@84 1847 return complainAboutInitInRepo(local);
Chris@84 1848 }
Chris@84 1849
Chris@84 1850 if (status == FolderIsFile) {
Chris@84 1851 return complainAboutInitFile(local);
Chris@84 1852 }
Chris@84 1853
Chris@84 1854 if (status == FolderUnknown) {
Chris@84 1855 return complainAboutUnknownFolder(local);
Chris@84 1856 }
Chris@84 1857
Chris@284 1858 m_workFolderPath = local;
Chris@284 1859 m_remoteRepoPath = "";
Chris@84 1860 hgInit();
Chris@79 1861 return true;
Chris@79 1862 }
Chris@79 1863
jtkorhonen@0 1864 void MainWindow::settings()
jtkorhonen@0 1865 {
Chris@472 1866 settings(SettingsDialog::PersonalDetailsTab);
Chris@472 1867 }
Chris@472 1868
Chris@472 1869 void MainWindow::settings(SettingsDialog::Tab tab)
Chris@472 1870 {
jtkorhonen@0 1871 SettingsDialog *settingsDlg = new SettingsDialog(this);
Chris@472 1872 settingsDlg->setCurrentTab(tab);
jtkorhonen@0 1873 settingsDlg->exec();
Chris@230 1874
Chris@230 1875 if (settingsDlg->presentationChanged()) {
Chris@284 1876 m_hgTabs->updateFileStates();
Chris@230 1877 updateToolBarStyle();
Chris@273 1878 hgRefresh();
Chris@230 1879 }
jtkorhonen@0 1880 }
jtkorhonen@0 1881
Chris@541 1882 void MainWindow::updateFsWatcher()
Chris@541 1883 {
Chris@541 1884 m_fsWatcher->setWorkDirPath(m_workFolderPath);
Chris@541 1885 m_fsWatcher->setTrackedFilePaths(m_hgTabs->getFileStates().trackedFiles());
Chris@541 1886 }
Chris@541 1887
Chris@238 1888 void MainWindow::checkFilesystem()
Chris@238 1889 {
Chris@238 1890 DEBUG << "MainWindow::checkFilesystem" << endl;
Chris@541 1891 if (!m_commandSequenceInProgress) {
Chris@541 1892 if (!m_fsWatcher->getChangedPaths(m_fsWatcherToken).empty()) {
Chris@541 1893 hgRefresh();
Chris@541 1894 return;
Chris@541 1895 }
Chris@549 1896 updateFsWatcher();
Chris@541 1897 }
Chris@90 1898 }
Chris@90 1899
Chris@275 1900 QString MainWindow::format1(QString head)
Chris@275 1901 {
Chris@275 1902 return QString("<qt><h3>%1</h3></qt>").arg(head);
Chris@275 1903 }
Chris@275 1904
Chris@125 1905 QString MainWindow::format3(QString head, QString intro, QString code)
Chris@125 1906 {
Chris@196 1907 code = xmlEncode(code).replace("\n", "<br>")
Chris@196 1908 #ifndef Q_OS_WIN32
Chris@196 1909 // The hard hyphen comes out funny on Windows
Chris@196 1910 .replace("-", "&#8209;")
Chris@196 1911 #endif
Chris@196 1912 .replace(" ", "&nbsp;");
Chris@125 1913 if (intro == "") {
Chris@168 1914 return QString("<qt><h3>%1</h3><p><code>%2</code></p>")
Chris@168 1915 .arg(head).arg(code);
Chris@126 1916 } else if (code == "") {
Chris@126 1917 return QString("<qt><h3>%1</h3><p>%2</p>")
Chris@126 1918 .arg(head).arg(intro);
Chris@125 1919 } else {
Chris@168 1920 return QString("<qt><h3>%1</h3><p>%2</p><p><code>%3</code></p>")
Chris@168 1921 .arg(head).arg(intro).arg(code);
Chris@125 1922 }
Chris@125 1923 }
Chris@125 1924
Chris@120 1925 void MainWindow::showIncoming(QString output)
Chris@120 1926 {
Chris@284 1927 m_runner->hide();
Chris@125 1928 IncomingDialog *d = new IncomingDialog(this, output);
Chris@125 1929 d->exec();
Chris@125 1930 delete d;
Chris@125 1931 }
Chris@125 1932
Chris@125 1933 int MainWindow::extractChangeCount(QString text)
Chris@125 1934 {
Chris@125 1935 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
Chris@125 1936 if (re.indexIn(text) >= 0) {
Chris@125 1937 return re.cap(1).toInt();
Chris@125 1938 } else if (text.contains("no changes")) {
Chris@125 1939 return 0;
Chris@125 1940 } else {
Chris@125 1941 return -1; // unknown
Chris@125 1942 }
Chris@120 1943 }
Chris@120 1944
Chris@120 1945 void MainWindow::showPushResult(QString output)
Chris@120 1946 {
Chris@291 1947 QString head;
Chris@125 1948 QString report;
Chris@125 1949 int n = extractChangeCount(output);
Chris@125 1950 if (n > 0) {
Chris@291 1951 head = tr("Pushed %n changeset(s)", "", n);
Chris@300 1952 report = tr("<qt>Successfully pushed to the remote repository at <code>%1</code>.</qt>").arg(xmlEncode(m_remoteRepoPath));
Chris@125 1953 } else if (n == 0) {
Chris@291 1954 head = tr("No changes to push");
Chris@291 1955 report = tr("The remote repository already contains all changes that have been committed locally.");
Chris@294 1956 if (m_hgTabs->canCommit()) {
Chris@291 1957 report = tr("%1<p>You do have some uncommitted changes. If you wish to push those to the remote repository, commit them locally first.").arg(report);
Chris@291 1958 }
Chris@125 1959 } else {
Chris@291 1960 head = tr("Push complete");
Chris@125 1961 }
Chris@284 1962 m_runner->hide();
Chris@291 1963
Chris@291 1964 MoreInformationDialog::information(this, tr("Push complete"),
Chris@291 1965 head, report, output);
Chris@120 1966 }
Chris@120 1967
Chris@120 1968 void MainWindow::showPullResult(QString output)
Chris@120 1969 {
Chris@291 1970 QString head;
Chris@125 1971 QString report;
Chris@125 1972 int n = extractChangeCount(output);
Chris@125 1973 if (n > 0) {
Chris@291 1974 head = tr("Pulled %n changeset(s)", "", n);
Chris@322 1975 report = tr("New changes will be highlighted in yellow in the history.");
Chris@125 1976 } else if (n == 0) {
Chris@291 1977 head = tr("No changes to pull");
Chris@291 1978 report = tr("Your local repository already contains all changes found in the remote repository.");
Chris@125 1979 } else {
Chris@291 1980 head = tr("Pull complete");
Chris@125 1981 }
Chris@284 1982 m_runner->hide();
Chris@275 1983
Chris@275 1984 MoreInformationDialog::information(this, tr("Pull complete"),
Chris@291 1985 head, report, output);
Chris@120 1986 }
Chris@120 1987
Chris@174 1988 void MainWindow::reportNewRemoteHeads(QString output)
Chris@174 1989 {
Chris@174 1990 bool headsAreLocal = false;
Chris@174 1991
Chris@284 1992 if (m_currentParents.size() == 1) {
Chris@506 1993 int currentBranchActiveHeads = 0;
Chris@174 1994 bool parentIsHead = false;
Chris@284 1995 Changeset *parent = m_currentParents[0];
Chris@506 1996 foreach (Changeset *head, m_activeHeads) {
Chris@284 1997 if (head->isOnBranch(m_currentBranch)) {
Chris@506 1998 ++currentBranchActiveHeads;
Chris@174 1999 }
Chris@174 2000 if (parent->id() == head->id()) {
Chris@174 2001 parentIsHead = true;
Chris@174 2002 }
Chris@174 2003 }
Chris@506 2004 if (currentBranchActiveHeads == 2 && parentIsHead) {
Chris@174 2005 headsAreLocal = true;
Chris@174 2006 }
Chris@174 2007 }
Chris@174 2008
Chris@174 2009 if (headsAreLocal) {
Chris@291 2010 MoreInformationDialog::warning
Chris@291 2011 (this,
Chris@291 2012 tr("Push failed"),
Chris@291 2013 tr("Push failed"),
Chris@291 2014 tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first."),
Chris@291 2015 output);
Chris@318 2016 } else if (m_hgTabs->canCommit() && m_currentParents.size() > 1) {
Chris@318 2017 MoreInformationDialog::warning
Chris@318 2018 (this,
Chris@318 2019 tr("Push failed"),
Chris@318 2020 tr("Push failed"),
Chris@318 2021 tr("Your local repository could not be pushed to the remote repository.<br><br>You have an uncommitted merge in your local folder. You probably need to commit it before you push."),
Chris@318 2022 output);
Chris@174 2023 } else {
Chris@291 2024 MoreInformationDialog::warning
Chris@291 2025 (this,
Chris@291 2026 tr("Push failed"),
Chris@291 2027 tr("Push failed"),
Chris@291 2028 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."),
Chris@291 2029 output);
Chris@174 2030 }
Chris@174 2031 }
Chris@174 2032
Chris@353 2033 void MainWindow::reportAuthFailed(QString output)
Chris@353 2034 {
Chris@353 2035 MoreInformationDialog::warning
Chris@353 2036 (this,
Chris@353 2037 tr("Authorization failed"),
Chris@353 2038 tr("Authorization failed"),
Chris@353 2039 tr("You may have entered an incorrect user name or password, or the remote URL may be wrong.<br><br>Or you may lack the necessary permissions on the remote repository.<br><br>Check with the administrator of your remote repository if necessary."),
Chris@353 2040 output);
Chris@353 2041 }
Chris@353 2042
Chris@238 2043 void MainWindow::commandStarting(HgAction action)
Chris@238 2044 {
Chris@540 2045 m_commandSequenceInProgress = true;
Chris@238 2046 }
Chris@238 2047
Chris@546 2048 void MainWindow::commandFailed(HgAction action, QString stdErr, QString stdOut)
Chris@62 2049 {
Chris@62 2050 DEBUG << "MainWindow::commandFailed" << endl;
Chris@540 2051
Chris@540 2052 m_commandSequenceInProgress = false;
Chris@74 2053
Chris@210 2054 QString setstr;
Chris@210 2055 #ifdef Q_OS_MAC
Chris@210 2056 setstr = tr("Preferences");
Chris@210 2057 #else
Chris@210 2058 setstr = tr("Settings");
Chris@210 2059 #endif
Chris@210 2060
Chris@353 2061 // Some commands we just have to ignore bad return values from,
Chris@353 2062 // and some output gets special treatment.
Chris@353 2063
Chris@353 2064 // Note our fallback case should always be to report a
Chris@353 2065 // non-specific error and show the text -- in case output scraping
Chris@353 2066 // fails (as it surely will). Note also that we must force the
Chris@353 2067 // locale in order to ensure the output is scrapable; this happens
Chris@353 2068 // in HgRunner and may break some system encodings.
Chris@113 2069
Chris@113 2070 switch(action.action) {
Chris@113 2071 case ACT_NONE:
Chris@113 2072 // uh huh
Chris@113 2073 return;
Chris@175 2074 case ACT_TEST_HG:
Chris@291 2075 MoreInformationDialog::warning
Chris@291 2076 (this,
Chris@291 2077 tr("Failed to run Mercurial"),
Chris@291 2078 tr("Failed to run Mercurial"),
Chris@483 2079 tr("The Mercurial program either could not be found or failed to run.<br><br>Check that the Mercurial program path is correct in %1.").arg(setstr),
Chris@545 2080 stdErr);
Chris@472 2081 settings(SettingsDialog::PathsTab);
Chris@200 2082 return;
Chris@200 2083 case ACT_TEST_HG_EXT:
Chris@309 2084 MoreInformationDialog::warning
Chris@291 2085 (this,
Chris@291 2086 tr("Failed to run Mercurial"),
Chris@291 2087 tr("Failed to run Mercurial with extension enabled"),
Chris@310 2088 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<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 might not work if you do this.").arg(setstr),
Chris@545 2089 stdErr);
Chris@642 2090 settings(SettingsDialog::ExtensionsTab);
Chris@175 2091 return;
Chris@252 2092 case ACT_CLONEFROMREMOTE:
Chris@252 2093 // if clone fails, we have no repo
Chris@284 2094 m_workFolderPath = "";
Chris@252 2095 enableDisableActions();
Chris@330 2096 break; // go on to default report
Chris@113 2097 case ACT_INCOMING:
Chris@545 2098 if (stdErr.contains("authorization failed")) {
Chris@545 2099 reportAuthFailed(stdErr);
Chris@353 2100 return;
Chris@545 2101 } else if (stdErr.contains("entry cancelled")) {
Chris@358 2102 // ignore this, user cancelled username or password dialog
Chris@358 2103 return;
Chris@353 2104 } else {
Chris@545 2105 // Incoming returns non-zero code and no stdErr if the
Chris@353 2106 // check was successful but there are no changes
Chris@353 2107 // pending. This is the only case where we need to remove
Chris@353 2108 // warning messages, because it's the only case where a
Chris@353 2109 // non-zero code can be returned even though the command
Chris@353 2110 // has for our purposes succeeded
Chris@545 2111 QString replaced = stdErr;
Chris@352 2112 while (1) {
Chris@352 2113 QString r1 = replaced;
Chris@352 2114 r1.replace(QRegExp("warning: [^\\n]*"), "");
Chris@352 2115 if (r1 == replaced) break;
Chris@352 2116 replaced = r1.trimmed();
Chris@352 2117 }
Chris@352 2118 if (replaced == "") {
Chris@352 2119 showIncoming("");
Chris@352 2120 return;
Chris@352 2121 }
Chris@211 2122 }
Chris@330 2123 break; // go on to default report
Chris@353 2124 case ACT_PULL:
Chris@545 2125 if (stdErr.contains("authorization failed")) {
Chris@545 2126 reportAuthFailed(stdErr);
Chris@353 2127 return;
Chris@545 2128 } else if (stdErr.contains("entry cancelled")) {
Chris@358 2129 // ignore this, user cancelled username or password dialog
Chris@358 2130 return;
Chris@546 2131 } else if (stdErr.contains("no changes found") || stdOut.contains("no changes found")) {
Chris@537 2132 // success: hg 2.1 starts returning failure code for empty pull/push
Chris@540 2133 m_commandSequenceInProgress = true; // there may be further commands
Chris@546 2134 commandCompleted(action, stdOut);
Chris@537 2135 return;
Chris@353 2136 }
Chris@353 2137 break; // go on to default report
Chris@353 2138 case ACT_PUSH:
Chris@545 2139 if (stdErr.contains("creates new remote head")) {
Chris@545 2140 reportNewRemoteHeads(stdErr);
Chris@353 2141 return;
Chris@545 2142 } else if (stdErr.contains("authorization failed")) {
Chris@545 2143 reportAuthFailed(stdErr);
Chris@353 2144 return;
Chris@545 2145 } else if (stdErr.contains("entry cancelled")) {
Chris@358 2146 // ignore this, user cancelled username or password dialog
Chris@358 2147 return;
Chris@546 2148 } else if (stdErr.contains("no changes found") || stdOut.contains("no changes found")) {
Chris@537 2149 // success: hg 2.1 starts returning failure code for empty pull/push
Chris@540 2150 m_commandSequenceInProgress = true; // there may be further commands
Chris@546 2151 commandCompleted(action, stdOut);
Chris@537 2152 return;
Chris@353 2153 }
Chris@353 2154 break; // go on to default report
Chris@506 2155 case ACT_QUERY_HEADS_ACTIVE:
Chris@162 2156 case ACT_QUERY_HEADS:
Chris@162 2157 // fails if repo is empty; we don't care (if there's a genuine
Chris@202 2158 // problem, something else will fail too). Pretend it
Chris@202 2159 // succeeded, so that any further actions that are contingent
Chris@202 2160 // on the success of the heads query get carried out properly.
Chris@540 2161 m_commandSequenceInProgress = true; // there may be further commands
Chris@202 2162 commandCompleted(action, "");
Chris@162 2163 return;
Chris@113 2164 case ACT_FOLDERDIFF:
Chris@113 2165 case ACT_CHGSETDIFF:
Chris@545 2166 // external program, unlikely to be anything useful in stdErr
Chris@113 2167 // and some return with failure codes when something as basic
Chris@113 2168 // as the user closing the window via the wm happens
Chris@113 2169 return;
Chris@328 2170 case ACT_MERGE:
Chris@545 2171 if (stdErr.contains("working directory ancestor")) {
Chris@530 2172 // arguably we should prevent this upfront, but that's
Chris@530 2173 // trickier!
Chris@530 2174 MoreInformationDialog::information
Chris@530 2175 (this, tr("Merge"), tr("Merge has no effect"),
Chris@530 2176 tr("You asked to merge a revision with one of its ancestors.<p>This has no effect, because the ancestor's changes already exist in both revisions."),
Chris@545 2177 stdErr);
Chris@530 2178 return;
Chris@530 2179 }
Chris@530 2180 // else fall through
Chris@328 2181 case ACT_RETRY_MERGE:
Chris@328 2182 MoreInformationDialog::information
Chris@328 2183 (this, tr("Merge"), tr("Merge failed"),
Chris@328 2184 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."),
Chris@545 2185 stdErr);
Chris@378 2186 m_mergeCommitComment = "";
Chris@603 2187 hgQueryPaths();
Chris@328 2188 return;
Chris@199 2189 case ACT_STAT:
Chris@330 2190 break; // go on to default report
Chris@113 2191 default:
Chris@114 2192 break;
Chris@113 2193 }
Chris@113 2194
Chris@113 2195 QString command = action.executable;
Chris@113 2196 if (command == "") command = "hg";
Chris@113 2197 foreach (QString arg, action.params) {
Chris@113 2198 command += " " + arg;
Chris@113 2199 }
Chris@113 2200
Chris@309 2201 MoreInformationDialog::warning
Chris@309 2202 (this,
Chris@309 2203 tr("Command failed"),
Chris@309 2204 tr("Command failed"),
Chris@545 2205 (stdErr == "" ?
Chris@483 2206 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") :
Chris@483 2207 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output.")),
Chris@545 2208 stdErr);
Chris@62 2209 }
Chris@62 2210
Chris@109 2211 void MainWindow::commandCompleted(HgAction completedAction, QString output)
jtkorhonen@0 2212 {
Chris@521 2213 // std::cerr << "commandCompleted: " << completedAction.action << std::endl;
Chris@519 2214
Chris@109 2215 HGACTIONS action = completedAction.action;
Chris@109 2216
Chris@109 2217 if (action == ACT_NONE) return;
Chris@109 2218
Chris@519 2219 output.replace("\r\n", "\n");
Chris@519 2220
Chris@150 2221 bool headsChanged = false;
Chris@150 2222 QStringList oldHeadIds;
Chris@150 2223
Chris@150 2224 switch (action) {
Chris@109 2225
Chris@175 2226 case ACT_TEST_HG:
Chris@377 2227 {
Chris@377 2228 QRegExp versionRE("^Mercurial.*version ([\\d+])\\.([\\d+])");
Chris@377 2229 int pos = versionRE.indexIn(output);
Chris@377 2230 if (pos >= 0) {
Chris@377 2231 int major = versionRE.cap(1).toInt();
Chris@377 2232 int minor = versionRE.cap(2).toInt();
Chris@377 2233 // We need v1.7 or newer
Chris@377 2234 if (major < 1 || (major == 1 && minor < 7)) {
Chris@377 2235 MoreInformationDialog::warning
Chris@377 2236 (this,
Chris@377 2237 tr("Newer Mercurial version required"),
Chris@377 2238 tr("Newer Mercurial version required"),
Chris@377 2239 tr("To use EasyMercurial, you should have at least Mercurial v1.7 installed.<br><br>The version found on this system (v%1.%2) does not support all of the features required by EasyMercurial.").arg(major).arg(minor),
Chris@377 2240 output);
Chris@377 2241 }
Chris@377 2242 }
Chris@175 2243 break;
Chris@377 2244 }
Chris@175 2245
Chris@200 2246 case ACT_TEST_HG_EXT:
Chris@200 2247 break;
Chris@200 2248
Chris@109 2249 case ACT_QUERY_PATHS:
jtkorhonen@0 2250 {
Chris@109 2251 DEBUG << "stdout is " << output << endl;
Chris@109 2252 LogParser lp(output, "=");
Chris@109 2253 LogList ll = lp.parse();
Chris@109 2254 DEBUG << ll.size() << " results" << endl;
Chris@109 2255 if (!ll.empty()) {
Chris@284 2256 m_remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@284 2257 DEBUG << "Set remote path to " << m_remoteRepoPath << endl;
Chris@210 2258 } else {
Chris@284 2259 m_remoteRepoPath = "";
Chris@109 2260 }
Chris@284 2261 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 2262 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@287 2263 updateWorkFolderAndRepoNames();
Chris@109 2264 break;
Chris@109 2265 }
jtkorhonen@0 2266
Chris@109 2267 case ACT_QUERY_BRANCH:
Chris@284 2268 m_currentBranch = output.trimmed();
Chris@109 2269 break;
jtkorhonen@0 2270
Chris@109 2271 case ACT_STAT:
Chris@284 2272 m_lastStatOutput = output;
Chris@109 2273 break;
Chris@163 2274
Chris@163 2275 case ACT_RESOLVE_LIST:
Chris@505 2276 // This happens on every update, after the stat (above)
Chris@163 2277 if (output != "") {
Chris@163 2278 // Remove lines beginning with R (they are resolved,
Chris@163 2279 // and the file stat parser treats R as removed)
Chris@163 2280 QStringList outList = output.split('\n');
Chris@163 2281 QStringList winnowed;
Chris@163 2282 foreach (QString line, outList) {
Chris@163 2283 if (!line.startsWith("R ")) winnowed.push_back(line);
Chris@163 2284 }
Chris@163 2285 output = winnowed.join("\n");
Chris@163 2286 }
Chris@284 2287 DEBUG << "m_lastStatOutput = " << m_lastStatOutput << endl;
Chris@199 2288 DEBUG << "resolve output = " << output << endl;
Chris@284 2289 m_hgTabs->updateWorkFolderFileList(m_lastStatOutput + output);
Chris@163 2290 break;
Chris@163 2291
Chris@163 2292 case ACT_RESOLVE_MARK:
Chris@284 2293 m_shouldHgStat = true;
Chris@163 2294 break;
Chris@109 2295
Chris@109 2296 case ACT_INCOMING:
Chris@120 2297 showIncoming(output);
Chris@120 2298 break;
Chris@120 2299
Chris@109 2300 case ACT_ANNOTATE:
Chris@331 2301 {
Chris@331 2302 AnnotateDialog dialog(this, output);
Chris@331 2303 dialog.exec();
Chris@284 2304 m_shouldHgStat = true;
Chris@109 2305 break;
Chris@331 2306 }
Chris@109 2307
Chris@109 2308 case ACT_PULL:
Chris@120 2309 showPullResult(output);
Chris@284 2310 m_shouldHgStat = true;
Chris@109 2311 break;
Chris@109 2312
Chris@109 2313 case ACT_PUSH:
Chris@120 2314 showPushResult(output);
Chris@109 2315 break;
Chris@109 2316
Chris@109 2317 case ACT_INIT:
Chris@284 2318 MultiChoiceDialog::addRecentArgument("init", m_workFolderPath);
Chris@284 2319 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@109 2320 enableDisableActions();
Chris@284 2321 m_shouldHgStat = true;
Chris@109 2322 break;
Chris@109 2323
Chris@109 2324 case ACT_CLONEFROMREMOTE:
Chris@284 2325 MultiChoiceDialog::addRecentArgument("local", m_workFolderPath);
Chris@284 2326 MultiChoiceDialog::addRecentArgument("remote", m_remoteRepoPath);
Chris@284 2327 MultiChoiceDialog::addRecentArgument("remote", m_workFolderPath, true);
Chris@291 2328 MoreInformationDialog::information
Chris@291 2329 (this,
Chris@291 2330 tr("Clone"),
Chris@384 2331 tr("Open successful"),
Chris@295 2332 tr("The remote repository was successfully cloned to the local folder <code>%1</code>.").arg(xmlEncode(m_workFolderPath)),
Chris@291 2333 output);
Chris@109 2334 enableDisableActions();
Chris@284 2335 m_shouldHgStat = true;
Chris@109 2336 break;
Chris@109 2337
Chris@109 2338 case ACT_LOG:
Chris@284 2339 m_hgTabs->setNewLog(output);
Chris@284 2340 m_needNewLog = false;
Chris@120 2341 break;
Chris@120 2342
Chris@120 2343 case ACT_LOG_INCREMENTAL:
Chris@284 2344 m_hgTabs->addIncrementalLog(output);
Chris@109 2345 break;
Chris@109 2346
Chris@109 2347 case ACT_QUERY_PARENTS:
Chris@152 2348 {
Chris@284 2349 foreach (Changeset *cs, m_currentParents) delete cs;
Chris@284 2350 m_currentParents = Changeset::parseChangesets(output);
Chris@284 2351 QStringList parentIds = Changeset::getIds(m_currentParents);
Chris@284 2352 m_hgTabs->setCurrent(parentIds, m_currentBranch);
Chris@152 2353 }
Chris@109 2354 break;
Chris@109 2355
Chris@506 2356 case ACT_QUERY_HEADS_ACTIVE:
Chris@506 2357 foreach (Changeset *cs, m_activeHeads) delete cs;
Chris@506 2358 m_activeHeads = Changeset::parseChangesets(output);
Chris@506 2359 break;
Chris@506 2360
Chris@109 2361 case ACT_QUERY_HEADS:
Chris@150 2362 {
Chris@284 2363 oldHeadIds = Changeset::getIds(m_currentHeads);
Chris@150 2364 Changesets newHeads = Changeset::parseChangesets(output);
Chris@150 2365 QStringList newHeadIds = Changeset::getIds(newHeads);
Chris@150 2366 if (oldHeadIds != newHeadIds) {
Chris@150 2367 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
Chris@305 2368 DEBUG << "Old heads: " << oldHeadIds.join(",") << endl;
Chris@305 2369 DEBUG << "New heads: " << newHeadIds.join(",") << endl;
Chris@150 2370 headsChanged = true;
Chris@284 2371 foreach (Changeset *cs, m_currentHeads) delete cs;
Chris@284 2372 m_currentHeads = newHeads;
Chris@506 2373 updateClosedHeads();
Chris@150 2374 }
Chris@150 2375 }
Chris@109 2376 break;
Chris@130 2377
Chris@130 2378 case ACT_COMMIT:
Chris@347 2379 if (m_currentParents.empty()) {
Chris@347 2380 // first commit to empty repo
Chris@347 2381 m_needNewLog = true;
Chris@347 2382 }
Chris@284 2383 m_hgTabs->clearSelections();
Chris@284 2384 m_justMerged = false;
Chris@284 2385 m_shouldHgStat = true;
Chris@130 2386 break;
Chris@163 2387
Chris@514 2388 case ACT_CLOSE_BRANCH:
Chris@514 2389 m_hgTabs->clearSelections();
Chris@514 2390 m_justMerged = false;
Chris@514 2391 m_shouldHgStat = true;
Chris@514 2392 break;
Chris@514 2393
Chris@163 2394 case ACT_REVERT:
Chris@326 2395 hgMarkFilesResolved(m_lastRevertedFiles);
Chris@284 2396 m_justMerged = false;
Chris@163 2397 break;
Chris@109 2398
Chris@109 2399 case ACT_REMOVE:
Chris@109 2400 case ACT_ADD:
Chris@284 2401 m_hgTabs->clearSelections();
Chris@284 2402 m_shouldHgStat = true;
Chris@116 2403 break;
Chris@116 2404
Chris@164 2405 case ACT_TAG:
Chris@284 2406 m_needNewLog = true;
Chris@284 2407 m_shouldHgStat = true;
Chris@164 2408 break;
Chris@164 2409
Chris@278 2410 case ACT_NEW_BRANCH:
Chris@307 2411 m_shouldHgStat = true;
Chris@278 2412 break;
Chris@278 2413
Chris@288 2414 case ACT_UNCOMMITTED_SUMMARY:
Chris@168 2415 QMessageBox::information(this, tr("Change summary"),
Chris@168 2416 format3(tr("Summary of uncommitted changes"),
Chris@168 2417 "",
Chris@168 2418 output));
Chris@168 2419 break;
Chris@168 2420
Chris@288 2421 case ACT_DIFF_SUMMARY:
Chris@289 2422 {
Chris@289 2423 // Output has log info first, diff following after a blank line
Chris@289 2424 QStringList olist = output.split("\n\n", QString::SkipEmptyParts);
Chris@289 2425 if (olist.size() > 1) output = olist[1];
Chris@289 2426
Chris@289 2427 Changeset *cs = (Changeset *)completedAction.extraData;
Chris@289 2428 if (cs) {
Chris@289 2429 QMessageBox::information
Chris@289 2430 (this, tr("Change summary"),
Chris@289 2431 format3(tr("Summary of changes"),
Chris@289 2432 cs->formatHtml(),
Chris@289 2433 output));
Chris@289 2434 } else if (output == "") {
Chris@289 2435 // Can happen, for a merge commit (depending on parent)
Chris@288 2436 QMessageBox::information(this, tr("Change summary"),
Chris@288 2437 format3(tr("Summary of changes"),
Chris@288 2438 tr("No changes"),
Chris@288 2439 output));
Chris@288 2440 } else {
Chris@288 2441 QMessageBox::information(this, tr("Change summary"),
Chris@288 2442 format3(tr("Summary of changes"),
Chris@288 2443 "",
Chris@288 2444 output));
Chris@288 2445 }
Chris@288 2446 break;
Chris@289 2447 }
Chris@288 2448
Chris@109 2449 case ACT_FOLDERDIFF:
Chris@109 2450 case ACT_CHGSETDIFF:
Chris@109 2451 case ACT_SERVE:
Chris@109 2452 case ACT_HG_IGNORE:
Chris@284 2453 m_shouldHgStat = true;
Chris@109 2454 break;
Chris@109 2455
Chris@109 2456 case ACT_UPDATE:
Chris@162 2457 QMessageBox::information(this, tr("Update"), tr("<qt><h3>Update successful</h3><p>%1</p>").arg(xmlEncode(output)));
Chris@284 2458 m_shouldHgStat = true;
Chris@109 2459 break;
Chris@109 2460
Chris@109 2461 case ACT_MERGE:
Chris@294 2462 MoreInformationDialog::information
Chris@294 2463 (this, tr("Merge"), tr("Merge successful"),
Chris@302 2464 tr("Remember to test and commit the result before making any further changes."),
Chris@294 2465 output);
Chris@284 2466 m_shouldHgStat = true;
Chris@284 2467 m_justMerged = true;
Chris@109 2468 break;
Chris@109 2469
Chris@109 2470 case ACT_RETRY_MERGE:
Chris@163 2471 QMessageBox::information(this, tr("Resolved"),
Chris@302 2472 tr("<qt><h3>Merge resolved</h3><p>Merge resolved successfully.<br>Remember to test and commit the result before making any further changes.</p>"));
Chris@284 2473 m_shouldHgStat = true;
Chris@284 2474 m_justMerged = true;
Chris@109 2475 break;
Chris@109 2476
Chris@109 2477 default:
Chris@109 2478 break;
Chris@109 2479 }
Chris@108 2480
Chris@121 2481 // Sequence when no full log required:
Chris@520 2482 // paths -> branch -> stat -> resolve-list -> heads ->
Chris@150 2483 // incremental-log (only if heads changed) -> parents
Chris@150 2484 //
Chris@121 2485 // Sequence when full log required:
Chris@520 2486 // paths -> branch -> stat -> resolve-list -> heads ->
Chris@519 2487 // parents -> log
Chris@150 2488 //
Chris@150 2489 // Note we want to call enableDisableActions only once, at the end
Chris@150 2490 // of whichever sequence is in use.
Chris@150 2491
Chris@156 2492 bool noMore = false;
Chris@156 2493
Chris@150 2494 switch (action) {
Chris@175 2495
Chris@175 2496 case ACT_TEST_HG:
Chris@248 2497 {
Chris@248 2498 QSettings settings;
Chris@248 2499 if (settings.value("useextension", true).toBool()) {
Chris@248 2500 hgTestExtension();
Chris@284 2501 } else if (m_workFolderPath == "") {
Chris@248 2502 open();
Chris@248 2503 } else {
Chris@248 2504 hgQueryPaths();
Chris@248 2505 }
Chris@200 2506 break;
Chris@248 2507 }
Chris@200 2508
Chris@200 2509 case ACT_TEST_HG_EXT:
Chris@284 2510 if (m_workFolderPath == "") {
Chris@248 2511 open();
Chris@248 2512 } else{
Chris@248 2513 hgQueryPaths();
Chris@248 2514 }
Chris@175 2515 break;
Chris@150 2516
Chris@150 2517 case ACT_QUERY_PATHS:
Chris@519 2518 // NB this call is duplicated in hgQueryPaths
Chris@109 2519 hgQueryBranch();
Chris@150 2520 break;
Chris@150 2521
Chris@150 2522 case ACT_QUERY_BRANCH:
Chris@519 2523 // NB this call is duplicated in hgQueryBranch
Chris@109 2524 hgStat();
Chris@150 2525 break;
Chris@150 2526
Chris@150 2527 case ACT_STAT:
Chris@163 2528 hgResolveList();
Chris@163 2529 break;
Chris@519 2530
Chris@163 2531 case ACT_RESOLVE_LIST:
Chris@506 2532 hgQueryHeadsActive();
Chris@506 2533 break;
Chris@506 2534
Chris@506 2535 case ACT_QUERY_HEADS_ACTIVE:
Chris@150 2536 hgQueryHeads();
Chris@150 2537 break;
Chris@150 2538
Chris@150 2539 case ACT_QUERY_HEADS:
Chris@284 2540 if (headsChanged && !m_needNewLog) {
Chris@150 2541 hgLogIncremental(oldHeadIds);
Chris@121 2542 } else {
Chris@150 2543 hgQueryParents();
Chris@121 2544 }
Chris@150 2545 break;
Chris@150 2546
Chris@150 2547 case ACT_LOG_INCREMENTAL:
Chris@109 2548 hgQueryParents();
Chris@150 2549 break;
Chris@150 2550
Chris@150 2551 case ACT_QUERY_PARENTS:
Chris@284 2552 if (m_needNewLog) {
Chris@120 2553 hgLog();
Chris@150 2554 } else {
Chris@150 2555 // we're done
Chris@156 2556 noMore = true;
Chris@120 2557 }
Chris@150 2558 break;
Chris@150 2559
Chris@150 2560 case ACT_LOG:
Chris@150 2561 // we're done
Chris@156 2562 noMore = true;
Chris@198 2563 break;
Chris@150 2564
Chris@150 2565 default:
Chris@284 2566 if (m_shouldHgStat) {
Chris@284 2567 m_shouldHgStat = false;
Chris@109 2568 hgQueryPaths();
Chris@150 2569 } else {
Chris@156 2570 noMore = true;
jtkorhonen@0 2571 }
Chris@150 2572 break;
Chris@150 2573 }
Chris@156 2574
Chris@156 2575 if (noMore) {
Chris@540 2576 m_commandSequenceInProgress = false;
Chris@284 2577 m_stateUnknown = false;
Chris@156 2578 enableDisableActions();
Chris@284 2579 m_hgTabs->updateHistory();
Chris@359 2580 updateRecentMenu();
Chris@541 2581 checkFilesystem();
Chris@156 2582 }
jtkorhonen@0 2583 }
jtkorhonen@0 2584
Chris@564 2585 void MainWindow::commandCancelled(HgAction cancelledAction)
Chris@564 2586 {
Chris@564 2587 // Originally I had this checking whether the cancelled action was
Chris@564 2588 // a network one and, if so, calling hgQueryPaths to update the
Chris@564 2589 // local view in case it had changed anything. But that doesn't
Chris@564 2590 // work properly -- because at this point, although the command
Chris@564 2591 // has been cancelled and a kill signal sent, it hasn't actually
Chris@564 2592 // exited yet. If we request another command now, it will go on
Chris@564 2593 // the stack and be associated with the failed exit forthcoming
Chris@564 2594 // from the cancelled command -- giving the user a disturbing
Chris@564 2595 // command-failed dialog
Chris@564 2596 }
Chris@564 2597
jtkorhonen@0 2598 void MainWindow::connectActions()
jtkorhonen@0 2599 {
Chris@284 2600 connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close()));
Chris@284 2601 connect(m_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
Chris@494 2602 connect(m_helpAct, SIGNAL(triggered()), this, SLOT(help()));
Chris@273 2603
Chris@284 2604 connect(m_hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
Chris@284 2605 connect(m_hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
Chris@284 2606 connect(m_hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
Chris@284 2607 connect(m_hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
Chris@425 2608 connect(m_hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
Chris@425 2609 connect(m_hgEditIgnoreAct, SIGNAL(triggered()), this, SLOT(hgEditIgnore()));
Chris@284 2610 connect(m_hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
Chris@284 2611 connect(m_hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
Chris@284 2612 connect(m_hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
Chris@284 2613 connect(m_hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
Chris@273 2614
Chris@284 2615 connect(m_settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@284 2616 connect(m_openAct, SIGNAL(triggered()), this, SLOT(open()));
Chris@284 2617 connect(m_changeRemoteRepoAct, SIGNAL(triggered()), this, SLOT(changeRemoteRepo()));
Chris@273 2618
Chris@284 2619 connect(m_hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
Chris@284 2620 connect(m_hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
Chris@284 2621 connect(m_hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
Chris@273 2622
Chris@284 2623 connect(m_hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
jtkorhonen@0 2624 }
Chris@141 2625
Chris@141 2626 void MainWindow::connectTabsSignals()
Chris@141 2627 {
Chris@327 2628 connect(m_hgTabs, SIGNAL(currentChanged(int)),
Chris@327 2629 this, SLOT(enableDisableActions()));
Chris@327 2630
Chris@284 2631 connect(m_hgTabs, SIGNAL(commit()),
Chris@141 2632 this, SLOT(hgCommit()));
Chris@141 2633
Chris@284 2634 connect(m_hgTabs, SIGNAL(revert()),
Chris@141 2635 this, SLOT(hgRevert()));
Chris@141 2636
Chris@284 2637 connect(m_hgTabs, SIGNAL(diffWorkingFolder()),
Chris@141 2638 this, SLOT(hgFolderDiff()));
Chris@168 2639
Chris@284 2640 connect(m_hgTabs, SIGNAL(showSummary()),
Chris@168 2641 this, SLOT(hgShowSummary()));
Chris@311 2642
Chris@311 2643 connect(m_hgTabs, SIGNAL(newBranch()),
Chris@311 2644 this, SLOT(hgNewBranch()));
Chris@311 2645
Chris@311 2646 connect(m_hgTabs, SIGNAL(noBranch()),
Chris@311 2647 this, SLOT(hgNoBranch()));
Chris@148 2648
Chris@284 2649 connect(m_hgTabs, SIGNAL(updateTo(QString)),
Chris@148 2650 this, SLOT(hgUpdateToRev(QString)));
Chris@141 2651
Chris@284 2652 connect(m_hgTabs, SIGNAL(diffToCurrent(QString)),
Chris@148 2653 this, SLOT(hgDiffToCurrent(QString)));
Chris@141 2654
Chris@284 2655 connect(m_hgTabs, SIGNAL(diffToParent(QString, QString)),
Chris@148 2656 this, SLOT(hgDiffToParent(QString, QString)));
Chris@141 2657
Chris@289 2658 connect(m_hgTabs, SIGNAL(showSummary(Changeset *)),
Chris@289 2659 this, SLOT(hgShowSummaryFor(Changeset *)));
Chris@288 2660
Chris@284 2661 connect(m_hgTabs, SIGNAL(mergeFrom(QString)),
Chris@148 2662 this, SLOT(hgMergeFrom(QString)));
Chris@164 2663
Chris@307 2664 connect(m_hgTabs, SIGNAL(newBranch(QString)),
Chris@311 2665 this, SLOT(hgNewBranch()));
Chris@278 2666
Chris@514 2667 connect(m_hgTabs, SIGNAL(closeBranch(QString)),
Chris@514 2668 this, SLOT(hgCloseBranch()));
Chris@514 2669
Chris@284 2670 connect(m_hgTabs, SIGNAL(tag(QString)),
Chris@148 2671 this, SLOT(hgTag(QString)));
Chris@326 2672
Chris@326 2673 connect(m_hgTabs, SIGNAL(annotateFiles(QStringList)),
Chris@326 2674 this, SLOT(hgAnnotateFiles(QStringList)));
Chris@326 2675
Chris@326 2676 connect(m_hgTabs, SIGNAL(diffFiles(QStringList)),
Chris@326 2677 this, SLOT(hgDiffFiles(QStringList)));
Chris@326 2678
Chris@326 2679 connect(m_hgTabs, SIGNAL(commitFiles(QStringList)),
Chris@326 2680 this, SLOT(hgCommitFiles(QStringList)));
Chris@326 2681
Chris@326 2682 connect(m_hgTabs, SIGNAL(revertFiles(QStringList)),
Chris@326 2683 this, SLOT(hgRevertFiles(QStringList)));
Chris@326 2684
Chris@361 2685 connect(m_hgTabs, SIGNAL(renameFiles(QStringList)),
Chris@361 2686 this, SLOT(hgRenameFiles(QStringList)));
Chris@361 2687
Chris@361 2688 connect(m_hgTabs, SIGNAL(copyFiles(QStringList)),
Chris@361 2689 this, SLOT(hgCopyFiles(QStringList)));
Chris@361 2690
Chris@326 2691 connect(m_hgTabs, SIGNAL(addFiles(QStringList)),
Chris@326 2692 this, SLOT(hgAddFiles(QStringList)));
Chris@326 2693
Chris@326 2694 connect(m_hgTabs, SIGNAL(removeFiles(QStringList)),
Chris@326 2695 this, SLOT(hgRemoveFiles(QStringList)));
Chris@326 2696
Chris@326 2697 connect(m_hgTabs, SIGNAL(redoFileMerges(QStringList)),
Chris@326 2698 this, SLOT(hgRedoFileMerges(QStringList)));
Chris@326 2699
Chris@326 2700 connect(m_hgTabs, SIGNAL(markFilesResolved(QStringList)),
Chris@326 2701 this, SLOT(hgMarkFilesResolved(QStringList)));
Chris@326 2702
Chris@326 2703 connect(m_hgTabs, SIGNAL(ignoreFiles(QStringList)),
Chris@326 2704 this, SLOT(hgIgnoreFiles(QStringList)));
Chris@326 2705
Chris@326 2706 connect(m_hgTabs, SIGNAL(unIgnoreFiles(QStringList)),
Chris@326 2707 this, SLOT(hgUnIgnoreFiles(QStringList)));
sam@624 2708
sam@624 2709 connect(m_hgTabs, SIGNAL(showIn(QStringList)),
sam@624 2710 this, SLOT(hgShowIn(QStringList)));
Chris@141 2711 }
Chris@141 2712
jtkorhonen@0 2713 void MainWindow::enableDisableActions()
jtkorhonen@0 2714 {
Chris@90 2715 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 2716
Chris@284 2717 QString dirname = QDir(m_workFolderPath).dirName();
Chris@340 2718
Chris@340 2719 if (m_workFolderPath != "") { // dirname of "" is ".", so test path instead
Chris@202 2720 setWindowTitle(tr("EasyMercurial: %1").arg(dirname));
Chris@202 2721 } else {
Chris@202 2722 setWindowTitle(tr("EasyMercurial"));
Chris@202 2723 }
Chris@202 2724
Chris@115 2725 //!!! should also do things like set the status texts for the
Chris@115 2726 //!!! actions appropriately by context
Chris@115 2727
jtkorhonen@0 2728 QDir localRepoDir;
jtkorhonen@0 2729 QDir workFolderDir;
jtkorhonen@0 2730
Chris@284 2731 m_remoteRepoActionsEnabled = true;
Chris@284 2732 if (m_remoteRepoPath.isEmpty()) {
Chris@284 2733 m_remoteRepoActionsEnabled = false;
jtkorhonen@0 2734 }
jtkorhonen@0 2735
Chris@284 2736 m_localRepoActionsEnabled = true;
Chris@284 2737 if (m_workFolderPath.isEmpty()) {
Chris@284 2738 m_localRepoActionsEnabled = false;
jtkorhonen@0 2739 }
jtkorhonen@0 2740
Chris@284 2741 if (m_workFolderPath == "" || !workFolderDir.exists(m_workFolderPath)) {
Chris@284 2742 m_localRepoActionsEnabled = false;
jtkorhonen@0 2743 }
jtkorhonen@0 2744
Chris@284 2745 if (!localRepoDir.exists(m_workFolderPath + "/.hg")) {
Chris@284 2746 m_localRepoActionsEnabled = false;
jtkorhonen@0 2747 }
jtkorhonen@0 2748
Chris@179 2749 bool haveDiff = false;
Chris@179 2750 QSettings settings;
Chris@179 2751 settings.beginGroup("Locations");
Chris@179 2752 if (settings.value("extdiffbinary", "").toString() != "") {
Chris@179 2753 haveDiff = true;
Chris@179 2754 }
Chris@179 2755 settings.endGroup();
Chris@112 2756
Chris@505 2757 m_hgTabs->setHaveMerge(m_currentParents.size() == 2);
Chris@505 2758
Chris@365 2759 m_hgRefreshAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2760 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && haveDiff);
Chris@365 2761 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2762 m_hgAddAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2763 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled);
Chris@425 2764 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2765 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2766 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2767 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled);
Chris@365 2768 m_hgServeAct->setEnabled(m_localRepoActionsEnabled);
Chris@413 2769 m_hgEditIgnoreAct->setEnabled(m_localRepoActionsEnabled);
Chris@273 2770
Chris@284 2771 DEBUG << "m_localRepoActionsEnabled = " << m_localRepoActionsEnabled << endl;
Chris@284 2772 DEBUG << "canCommit = " << m_hgTabs->canCommit() << endl;
Chris@273 2773
Chris@284 2774 m_hgAddAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canAdd());
Chris@284 2775 m_hgRemoveAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRemove());
Chris@284 2776 m_hgCommitAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canCommit());
Chris@284 2777 m_hgRevertAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canRevert());
Chris@284 2778 m_hgFolderDiffAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canDiff());
Chris@425 2779 m_hgIgnoreAct->setEnabled(m_localRepoActionsEnabled && m_hgTabs->canIgnore());
Chris@90 2780
Chris@108 2781 // A default merge makes sense if:
Chris@108 2782 // * there is only one parent (if there are two, we have an uncommitted merge) and
Chris@108 2783 // * there are exactly two heads that have the same branch as the current branch and
Chris@108 2784 // * our parent is one of those heads
Chris@108 2785 //
Chris@108 2786 // A default update makes sense if:
Chris@108 2787 // * there is only one parent and
Chris@108 2788 // * the parent is not one of the current heads
Chris@156 2789
Chris@108 2790 bool canMerge = false;
Chris@108 2791 bool canUpdate = false;
Chris@156 2792 bool haveMerge = false;
Chris@162 2793 bool emptyRepo = false;
Chris@225 2794 bool noWorkingCopy = false;
Chris@235 2795 bool newBranch = false;
Chris@506 2796 bool closedBranch = false;
Chris@506 2797 int currentBranchActiveHeads = 0;
Chris@273 2798
Chris@284 2799 if (m_currentParents.size() == 1) {
Chris@156 2800 bool parentIsHead = false;
Chris@506 2801 bool parentIsActiveHead = false;
Chris@284 2802 Changeset *parent = m_currentParents[0];
Chris@506 2803 foreach (Changeset *head, m_activeHeads) {
Chris@284 2804 if (head->isOnBranch(m_currentBranch)) {
Chris@506 2805 ++currentBranchActiveHeads;
Chris@235 2806 }
Chris@235 2807 if (parent->id() == head->id()) {
Chris@506 2808 parentIsActiveHead = parentIsHead = true;
Chris@108 2809 }
Chris@108 2810 }
Chris@506 2811 if (!parentIsActiveHead) {
Chris@506 2812 foreach (Changeset *head, m_currentHeads) {
Chris@506 2813 if (parent->id() == head->id()) {
Chris@506 2814 parentIsHead = true;
Chris@506 2815 }
Chris@506 2816 }
Chris@506 2817 }
Chris@506 2818 if (currentBranchActiveHeads == 2 && parentIsActiveHead) {
Chris@108 2819 canMerge = true;
Chris@108 2820 }
Chris@506 2821 if (currentBranchActiveHeads == 0 && parentIsActiveHead) {
Chris@235 2822 // Just created a new branch
Chris@235 2823 newBranch = true;
Chris@235 2824 }
Chris@108 2825 if (!parentIsHead) {
Chris@108 2826 canUpdate = true;
Chris@108 2827 DEBUG << "parent id = " << parent->id() << endl;
Chris@108 2828 DEBUG << " head ids "<<endl;
Chris@284 2829 foreach (Changeset *h, m_currentHeads) {
Chris@108 2830 DEBUG << "head id = " << h->id() << endl;
Chris@108 2831 }
Chris@506 2832 } else if (!parentIsActiveHead) {
Chris@506 2833 closedBranch = true;
Chris@108 2834 }
Chris@284 2835 m_justMerged = false;
Chris@284 2836 } else if (m_currentParents.size() == 0) {
Chris@284 2837 if (m_currentHeads.size() == 0) {
Chris@225 2838 // No heads -> empty repo
Chris@225 2839 emptyRepo = true;
Chris@225 2840 } else {
Chris@225 2841 // Heads, but no parents -> no working copy, e.g. we have
Chris@225 2842 // just converted this repo but haven't updated in it yet.
Chris@225 2843 // Uncommon but confusing; probably merits a special case
Chris@225 2844 noWorkingCopy = true;
Chris@225 2845 canUpdate = true;
Chris@225 2846 }
Chris@284 2847 m_justMerged = false;
Chris@156 2848 } else {
Chris@156 2849 haveMerge = true;
Chris@284 2850 m_justMerged = true;
Chris@108 2851 }
Chris@505 2852
Chris@363 2853 m_hgIncomingAct->setEnabled(m_remoteRepoActionsEnabled);
Chris@363 2854 m_hgPullAct->setEnabled(m_remoteRepoActionsEnabled);
Chris@363 2855 // permit push even if no remote yet; we'll ask for one
Chris@363 2856 m_hgPushAct->setEnabled(m_localRepoActionsEnabled && !emptyRepo);
Chris@363 2857
Chris@284 2858 m_hgMergeAct->setEnabled(m_localRepoActionsEnabled &&
Chris@506 2859 (canMerge || m_hgTabs->canResolve()));
Chris@284 2860 m_hgUpdateAct->setEnabled(m_localRepoActionsEnabled &&
Chris@506 2861 (canUpdate && !m_hgTabs->haveChangesToCommit()));
Chris@115 2862
Chris@115 2863 // Set the state field on the file status widget
Chris@115 2864
Chris@115 2865 QString branchText;
Chris@284 2866 if (m_currentBranch == "" || m_currentBranch == "default") {
Chris@115 2867 branchText = tr("the default branch");
Chris@115 2868 } else {
Chris@284 2869 branchText = tr("branch \"%1\"").arg(m_currentBranch);
Chris@115 2870 }
Chris@156 2871
Chris@284 2872 if (m_stateUnknown) {
Chris@284 2873 if (m_workFolderPath == "") {
Chris@287 2874 m_workStatus->setState(tr("No repository open"));
Chris@248 2875 } else {
Chris@287 2876 m_workStatus->setState(tr("(Examining repository)"));
Chris@248 2877 }
Chris@173 2878 } else if (emptyRepo) {
Chris@287 2879 m_workStatus->setState(tr("Nothing committed to this repository yet"));
Chris@225 2880 } else if (noWorkingCopy) {
Chris@287 2881 m_workStatus->setState(tr("No working copy yet: consider updating"));
Chris@162 2882 } else if (canMerge) {
Chris@287 2883 m_workStatus->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
Chris@284 2884 } else if (!m_hgTabs->getAllUnresolvedFiles().empty()) {
Chris@287 2885 m_workStatus->setState(tr("Have unresolved files following merge on %1").arg(branchText));
Chris@156 2886 } else if (haveMerge) {
Chris@287 2887 m_workStatus->setState(tr("Have merged but not yet committed on %1").arg(branchText));
Chris@235 2888 } else if (newBranch) {
Chris@287 2889 m_workStatus->setState(tr("On %1. New branch: has not yet been committed").arg(branchText));
Chris@506 2890 } else if (closedBranch) {
Chris@506 2891 if (canUpdate) {
Chris@506 2892 m_workStatus->setState(tr("On a closed branch. Not at the head of the branch"));
Chris@506 2893 } else {
Chris@506 2894 m_workStatus->setState(tr("At the head of a closed branch"));
Chris@506 2895 }
Chris@156 2896 } else if (canUpdate) {
Chris@284 2897 if (m_hgTabs->haveChangesToCommit()) {
Chris@163 2898 // have uncommitted changes
Chris@287 2899 m_workStatus->setState(tr("On %1. Not at the head of the branch").arg(branchText));
Chris@163 2900 } else {
Chris@163 2901 // no uncommitted changes
Chris@287 2902 m_workStatus->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
Chris@163 2903 }
Chris@506 2904 } else if (currentBranchActiveHeads > 1) {
Chris@506 2905 m_workStatus->setState(tr("At one of %n heads of %1", "", currentBranchActiveHeads).arg(branchText));
Chris@115 2906 } else {
Chris@287 2907 m_workStatus->setState(tr("At the head of %1").arg(branchText));
Chris@115 2908 }
jtkorhonen@0 2909 }
jtkorhonen@0 2910
Chris@359 2911
Chris@506 2912 void MainWindow::updateClosedHeads()
Chris@506 2913 {
Chris@506 2914 m_closedHeadIds.clear();
Chris@506 2915 QSet<QString> activeIds;
Chris@506 2916 foreach (Changeset *cs, m_activeHeads) {
Chris@506 2917 activeIds.insert(cs->id());
Chris@506 2918 }
Chris@506 2919 foreach (Changeset *cs, m_currentHeads) {
Chris@506 2920 if (!activeIds.contains(cs->id())) {
Chris@506 2921 m_closedHeadIds.insert(cs->id());
Chris@506 2922 }
Chris@506 2923 }
Chris@506 2924 m_hgTabs->setClosedHeadIds(m_closedHeadIds);
Chris@506 2925 }
Chris@506 2926
Chris@359 2927 void MainWindow::updateRecentMenu()
Chris@359 2928 {
Chris@359 2929 m_recentMenu->clear();
Chris@359 2930 RecentFiles rf("Recent-local");
Chris@359 2931 QStringList recent = rf.getRecent();
Chris@359 2932 if (recent.empty()) {
Chris@359 2933 QLabel *label = new QLabel(tr("No recent local repositories"));
Chris@359 2934 QWidgetAction *wa = new QWidgetAction(m_recentMenu);
Chris@359 2935 wa->setDefaultWidget(label);
Chris@359 2936 return;
Chris@359 2937 }
Chris@359 2938 foreach (QString r, recent) {
Chris@359 2939 QAction *a = m_recentMenu->addAction(r);
Chris@611 2940 connect(a, SIGNAL(triggered()), this, SLOT(recentMenuActivated()));
Chris@359 2941 }
Chris@359 2942 }
Chris@359 2943
jtkorhonen@0 2944 void MainWindow::createActions()
jtkorhonen@0 2945 {
jtkorhonen@0 2946 //File actions
Chris@365 2947 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("&Open..."), this);
Chris@609 2948 m_openAct->setStatusTip(tr("Open a remote repository or an existing local folder"));
Chris@365 2949 m_openAct->setShortcut(tr("Ctrl+O"));
Chris@365 2950
Chris@609 2951 m_changeRemoteRepoAct = new QAction(tr("Set Push and Pull &Location..."), this);
Chris@609 2952 m_changeRemoteRepoAct->setStatusTip(tr("Set or change the default URL for pull and push actions from this repository"));
Chris@273 2953
Chris@365 2954 m_settingsAct = new QAction(QIcon(":/images/settings.png"), tr("&Settings..."), this);
Chris@365 2955 m_settingsAct->setStatusTip(tr("View and change application settings"));
Chris@273 2956
Chris@343 2957 #ifdef Q_OS_WIN32
Chris@365 2958 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("E&xit"), this);
Chris@343 2959 #else
Chris@365 2960 m_exitAct = new QAction(QIcon(":/images/exit.png"), tr("&Quit"), this);
Chris@343 2961 #endif
Chris@284 2962 m_exitAct->setShortcuts(QKeySequence::Quit);
Chris@365 2963 m_exitAct->setStatusTip(tr("Exit EasyMercurial"));
jtkorhonen@0 2964
jtkorhonen@0 2965 //Repository actions
Chris@544 2966 m_hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("&Re-Read Working Folder"), this);
Chris@365 2967 m_hgRefreshAct->setShortcut(tr("Ctrl+R"));
Chris@284 2968 m_hgRefreshAct->setStatusTip(tr("Refresh the window to show the current state of the working folder"));
Chris@273 2969
Chris@365 2970 m_hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Pre&view Incoming Changes"), this);
Chris@365 2971 m_hgIncomingAct->setIconText(tr("Preview"));
Chris@365 2972 m_hgIncomingAct->setStatusTip(tr("See what changes are available in the remote repository waiting to be pulled"));
Chris@365 2973
Chris@365 2974 m_hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pu&ll from Remote Repository"), this);
Chris@365 2975 m_hgPullAct->setIconText(tr("Pull"));
Chris@365 2976 m_hgPullAct->setShortcut(tr("Ctrl+L"));
Chris@365 2977 m_hgPullAct->setStatusTip(tr("Pull changes from the remote repository to the local repository"));
Chris@365 2978
Chris@365 2979 m_hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Pus&h to Remote Repository"), this);
Chris@365 2980 m_hgPushAct->setIconText(tr("Push"));
Chris@365 2981 m_hgPushAct->setShortcut(tr("Ctrl+H"));
Chris@284 2982 m_hgPushAct->setStatusTip(tr("Push changes from the local repository to the remote repository"));
jtkorhonen@0 2983
jtkorhonen@0 2984 //Workfolder actions
Chris@365 2985 m_hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("&Diff"), this);
Chris@365 2986 m_hgFolderDiffAct->setIconText(tr("Diff"));
Chris@365 2987 m_hgFolderDiffAct->setShortcut(tr("Ctrl+D"));
Chris@284 2988 m_hgFolderDiffAct->setStatusTip(tr("See what has changed in the working folder compared with the last committed state"));
Chris@273 2989
Chris@365 2990 m_hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Re&vert"), this);
Chris@284 2991 m_hgRevertAct->setStatusTip(tr("Throw away your changes and return to the last committed state"));
Chris@273 2992
Chris@365 2993 m_hgAddAct = new QAction(QIcon(":/images/add.png"), tr("&Add Files"), this);
Chris@365 2994 m_hgAddAct->setIconText(tr("Add"));
Chris@365 2995 m_hgAddAct->setShortcut(tr("+"));
Chris@365 2996 m_hgAddAct->setStatusTip(tr("Mark the selected files to be added on the next commit"));
Chris@365 2997
Chris@365 2998 m_hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("&Remove Files"), this);
Chris@365 2999 m_hgRemoveAct->setIconText(tr("Remove"));
Chris@365 3000 m_hgRemoveAct->setShortcut(tr("Del"));
Chris@365 3001 m_hgRemoveAct->setStatusTip(tr("Mark the selected files to be removed from version control on the next commit"));
Chris@365 3002
Chris@425 3003 m_hgIgnoreAct = new QAction(tr("&Ignore Files..."), this);
Chris@425 3004 m_hgIgnoreAct->setStatusTip(tr("Add the selected filenames to the ignored list, of files that should never be tracked in this repository"));
Chris@425 3005
Chris@425 3006 m_hgEditIgnoreAct = new QAction(tr("Edit Ignored List"), this);
Chris@425 3007 m_hgEditIgnoreAct->setStatusTip(tr("Edit the .hgignore file, containing the names of files that should be ignored by Mercurial"));
Chris@425 3008
Chris@365 3009 m_hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("&Update to Branch Head"), this);
Chris@365 3010 m_hgUpdateAct->setIconText(tr("Update"));
Chris@365 3011 m_hgUpdateAct->setShortcut(tr("Ctrl+U"));
Chris@284 3012 m_hgUpdateAct->setStatusTip(tr("Update the working folder to the head of the current repository branch"));
jtkorhonen@0 3013
Chris@365 3014 m_hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("&Commit..."), this);
Chris@365 3015 m_hgCommitAct->setShortcut(tr("Ctrl+Return"));
Chris@284 3016 m_hgCommitAct->setStatusTip(tr("Commit your changes to the local repository"));
Chris@273 3017
Chris@365 3018 m_hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("&Merge"), this);
Chris@365 3019 m_hgMergeAct->setShortcut(tr("Ctrl+M"));
Chris@284 3020 m_hgMergeAct->setStatusTip(tr("Merge the two independent sets of changes in the local repository into the working folder"));
jtkorhonen@0 3021
Chris@425 3022 m_hgServeAct = new QAction(tr("Share Repository"), this);
Chris@425 3023 m_hgServeAct->setStatusTip(tr("Serve local repository temporarily via HTTP for workgroup access"));
jtkorhonen@11 3024
jtkorhonen@0 3025 //Help actions
Chris@494 3026 #ifdef Q_OS_MAC
Chris@494 3027 m_helpAct = new QAction(tr("EasyMercurial Help"), this);
Chris@494 3028 #else
Chris@494 3029 m_helpAct = new QAction(tr("Help Topics"), this);
Chris@494 3030 #endif
Chris@494 3031 m_helpAct->setShortcuts(QKeySequence::HelpContents);
Chris@284 3032 m_aboutAct = new QAction(tr("About EasyMercurial"), this);
Chris@94 3033
Chris@94 3034 // Miscellaneous
Chris@199 3035 QShortcut *clearSelectionsShortcut = new QShortcut(Qt::Key_Escape, this);
Chris@199 3036 connect(clearSelectionsShortcut, SIGNAL(activated()),
Chris@199 3037 this, SLOT(clearSelections()));
jtkorhonen@0 3038 }
jtkorhonen@0 3039
jtkorhonen@0 3040 void MainWindow::createMenus()
jtkorhonen@0 3041 {
Chris@365 3042 m_fileMenu = menuBar()->addMenu(tr("&File"));
Chris@365 3043
Chris@365 3044 m_fileMenu->addAction(m_openAct);
Chris@365 3045 m_recentMenu = m_fileMenu->addMenu(tr("Open Re&cent"));
Chris@365 3046 m_fileMenu->addAction(m_hgRefreshAct);
Chris@365 3047 m_fileMenu->addSeparator();
Chris@425 3048 m_fileMenu->addAction(m_hgServeAct);
Chris@425 3049 m_fileMenu->addSeparator();
Chris@365 3050 m_fileMenu->addAction(m_settingsAct);
Chris@365 3051 m_fileMenu->addSeparator();
Chris@365 3052 m_fileMenu->addAction(m_exitAct);
Chris@365 3053
Chris@365 3054 QMenu *workMenu;
Chris@365 3055 workMenu = menuBar()->addMenu(tr("&Work"));
Chris@365 3056 workMenu->addAction(m_hgFolderDiffAct);
Chris@365 3057 workMenu->addSeparator();
Chris@365 3058 workMenu->addAction(m_hgUpdateAct);
Chris@365 3059 workMenu->addAction(m_hgCommitAct);
Chris@365 3060 workMenu->addAction(m_hgMergeAct);
Chris@365 3061 workMenu->addSeparator();
Chris@365 3062 workMenu->addAction(m_hgAddAct);
Chris@365 3063 workMenu->addAction(m_hgRemoveAct);
Chris@365 3064 workMenu->addSeparator();
Chris@425 3065 workMenu->addAction(m_hgIgnoreAct);
Chris@425 3066 workMenu->addAction(m_hgEditIgnoreAct);
Chris@425 3067 workMenu->addSeparator();
Chris@365 3068 workMenu->addAction(m_hgRevertAct);
Chris@365 3069
Chris@365 3070 QMenu *remoteMenu;
Chris@365 3071 remoteMenu = menuBar()->addMenu(tr("&Remote"));
Chris@365 3072 remoteMenu->addAction(m_hgIncomingAct);
Chris@365 3073 remoteMenu->addSeparator();
Chris@609 3074 remoteMenu->addAction(m_changeRemoteRepoAct);
Chris@365 3075 remoteMenu->addAction(m_hgPullAct);
Chris@365 3076 remoteMenu->addAction(m_hgPushAct);
Chris@273 3077
Chris@378 3078 m_helpMenu = menuBar()->addMenu(tr("&Help"));
Chris@494 3079 m_helpMenu->addAction(m_helpAct);
Chris@284 3080 m_helpMenu->addAction(m_aboutAct);
jtkorhonen@0 3081 }
jtkorhonen@0 3082
jtkorhonen@0 3083 void MainWindow::createToolBars()
jtkorhonen@0 3084 {
Chris@442 3085 int sz = 32;
Chris@442 3086
Chris@645 3087 QString spacerBefore, spacerAfter;
Chris@645 3088
Chris@645 3089 spacerBefore = spacerAfter = " ";
Chris@645 3090
Chris@645 3091 #ifdef Q_OS_MAC
Chris@645 3092 spacerAfter = "";
Chris@645 3093 #endif
Chris@645 3094
Chris@645 3095 #ifdef Q_OS_WIN32
Chris@645 3096 spacerBefore = spacerAfter = " "
Chris@645 3097 #endif
Chris@645 3098
Chris@543 3099 bool spacingReqd = false;
chris@550 3100 QString spacer = "";
Chris@645 3101
Chris@645 3102 m_repoToolBar = addToolBar(tr("Remote"));
Chris@645 3103 m_repoToolBar->setIconSize(QSize(sz, sz));
Chris@645 3104 if (spacerBefore != "") {
Chris@645 3105 m_repoToolBar->addWidget(new QLabel(spacerBefore));
Chris@645 3106 }
Chris@645 3107 m_repoToolBar->addAction(m_openAct);
Chris@645 3108 if (spacerAfter != "") {
Chris@645 3109 m_repoToolBar->addWidget(new QLabel(spacerAfter));
Chris@645 3110 }
Chris@645 3111 m_repoToolBar->addSeparator();
Chris@645 3112 m_repoToolBar->addAction(m_hgIncomingAct);
Chris@645 3113 m_repoToolBar->addAction(m_hgPullAct);
Chris@645 3114 m_repoToolBar->addAction(m_hgPushAct);
Chris@645 3115 m_repoToolBar->setMovable(false);
Chris@273 3116
Chris@594 3117 m_workFolderToolBar = new QToolBar(tr("Work"));
Chris@284 3118 addToolBar(Qt::LeftToolBarArea, m_workFolderToolBar);
Chris@442 3119 m_workFolderToolBar->setIconSize(QSize(sz, sz));
Chris@645 3120
Chris@645 3121 QWidget *w = new QWidget;
Chris@645 3122 w->setFixedHeight(6);
Chris@645 3123 m_workFolderToolBar->addWidget(w);
Chris@645 3124
Chris@284 3125 m_workFolderToolBar->addAction(m_hgFolderDiffAct);
Chris@284 3126 m_workFolderToolBar->addSeparator();
Chris@284 3127 m_workFolderToolBar->addAction(m_hgRevertAct);
Chris@284 3128 m_workFolderToolBar->addAction(m_hgUpdateAct);
Chris@284 3129 m_workFolderToolBar->addAction(m_hgCommitAct);
Chris@284 3130 m_workFolderToolBar->addAction(m_hgMergeAct);
Chris@284 3131 m_workFolderToolBar->addSeparator();
Chris@284 3132 m_workFolderToolBar->addAction(m_hgAddAct);
Chris@284 3133 m_workFolderToolBar->addAction(m_hgRemoveAct);
Chris@365 3134 m_workFolderToolBar->setMovable(false);
Chris@61 3135
Chris@230 3136 updateToolBarStyle();
jtkorhonen@0 3137 }
jtkorhonen@0 3138
Chris@230 3139 void MainWindow::updateToolBarStyle()
Chris@230 3140 {
Chris@230 3141 QSettings settings;
Chris@230 3142 settings.beginGroup("Presentation");
Chris@230 3143 bool showText = settings.value("showiconlabels", true).toBool();
Chris@230 3144 settings.endGroup();
Chris@230 3145
Chris@230 3146 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@230 3147 tb->setToolButtonStyle(showText ?
Chris@230 3148 Qt::ToolButtonTextUnderIcon :
Chris@230 3149 Qt::ToolButtonIconOnly);
Chris@230 3150 }
Chris@230 3151 }
jtkorhonen@0 3152
Chris@287 3153 void MainWindow::updateWorkFolderAndRepoNames()
Chris@287 3154 {
Chris@287 3155 m_hgTabs->setLocalPath(m_workFolderPath);
Chris@287 3156
Chris@287 3157 m_workStatus->setLocalPath(m_workFolderPath);
Chris@287 3158 m_workStatus->setRemoteURL(m_remoteRepoPath);
Chris@287 3159 }
Chris@287 3160
jtkorhonen@0 3161 void MainWindow::createStatusBar()
jtkorhonen@0 3162 {
jtkorhonen@0 3163 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 3164 }
jtkorhonen@0 3165
jtkorhonen@0 3166 void MainWindow::readSettings()
jtkorhonen@0 3167 {
jtkorhonen@0 3168 QDir workFolder;
jtkorhonen@0 3169
Chris@61 3170 QSettings settings;
jtkorhonen@0 3171
Chris@284 3172 m_workFolderPath = settings.value("workfolderpath", "").toString();
Chris@553 3173 if (!workFolder.exists(m_workFolderPath)) {
Chris@284 3174 m_workFolderPath = "";
jtkorhonen@0 3175 }
jtkorhonen@0 3176
jtkorhonen@0 3177 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
Chris@340 3178 QSize size = settings.value("size", QSize(550, 550)).toSize();
Chris@284 3179 m_firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 3180
jtkorhonen@0 3181 resize(size);
jtkorhonen@0 3182 move(pos);
jtkorhonen@0 3183 }
jtkorhonen@0 3184
jtkorhonen@0 3185 void MainWindow::writeSettings()
jtkorhonen@0 3186 {
Chris@61 3187 QSettings settings;
jtkorhonen@0 3188 settings.setValue("pos", pos());
jtkorhonen@0 3189 settings.setValue("size", size());
Chris@284 3190 settings.setValue("remoterepopath", m_remoteRepoPath);
Chris@284 3191 settings.setValue("workfolderpath", m_workFolderPath);
Chris@284 3192 settings.setValue("firststart", m_firstStart);
jtkorhonen@0 3193 }
jtkorhonen@0 3194
Chris@491 3195 void MainWindow::newerVersionAvailable(QString version)
Chris@491 3196 {
Chris@491 3197 QSettings settings;
Chris@491 3198 settings.beginGroup("NewerVersionWarning");
Chris@491 3199 QString tag = QString("version-%1-available-show").arg(version);
Chris@491 3200 if (settings.value(tag, true).toBool()) {
Chris@491 3201 QString title(tr("Newer version available"));
Chris@618 3202 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of EasyMercurial, but version %3 is now available.</p><p>Please see the <a href=\"http://easyhg.org/\">EasyMercurial website</a> for more information.</p>").arg(EASYHG_VERSION).arg(version));
Chris@491 3203 QMessageBox::information(this, title, text);
Chris@491 3204 settings.setValue(tag, false);
Chris@491 3205 }
Chris@491 3206 settings.endGroup();
Chris@491 3207 }
Chris@491 3208
Chris@494 3209 void MainWindow::help()
Chris@494 3210 {
Chris@494 3211 if (!m_helpDialog) {
Chris@494 3212 m_helpDialog = new QDialog;
Chris@494 3213 QGridLayout *layout = new QGridLayout;
Chris@494 3214 m_helpDialog->setLayout(layout);
Chris@498 3215 QPushButton *home = new QPushButton;
Chris@498 3216 home->setIcon(QIcon(":images/home.png"));
Chris@498 3217 layout->addWidget(home, 0, 0);
Chris@498 3218 QPushButton *back = new QPushButton;
Chris@498 3219 back->setIcon(QIcon(":images/back.png"));
Chris@498 3220 layout->addWidget(back, 0, 1);
Chris@498 3221 QPushButton *fwd = new QPushButton;
Chris@498 3222 fwd->setIcon(QIcon(":images/forward.png"));
Chris@498 3223 layout->addWidget(fwd, 0, 2);
Chris@494 3224 QTextBrowser *text = new QTextBrowser;
Chris@494 3225 text->setOpenExternalLinks(true);
Chris@498 3226 layout->addWidget(text, 1, 0, 1, 4);
Chris@494 3227 text->setSource(QUrl("qrc:help/topics.html"));
Chris@494 3228 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@494 3229 connect(bb, SIGNAL(rejected()), m_helpDialog, SLOT(hide()));
Chris@498 3230 connect(text, SIGNAL(backwardAvailable(bool)),
Chris@498 3231 back, SLOT(setEnabled(bool)));
Chris@498 3232 connect(text, SIGNAL(forwardAvailable(bool)),
Chris@498 3233 fwd, SLOT(setEnabled(bool)));
Chris@498 3234 connect(home, SIGNAL(clicked()), text, SLOT(home()));
Chris@498 3235 connect(back, SIGNAL(clicked()), text, SLOT(backward()));
Chris@498 3236 connect(fwd, SIGNAL(clicked()), text, SLOT(forward()));
Chris@498 3237 back->setEnabled(false);
Chris@498 3238 fwd->setEnabled(false);
Chris@498 3239 layout->addWidget(bb, 2, 0, 1, 4);
Chris@498 3240 layout->setColumnStretch(3, 20);
Chris@494 3241 m_helpDialog->resize(450, 500);
Chris@494 3242 }
Chris@494 3243 QTextBrowser *tb = m_helpDialog->findChild<QTextBrowser *>();
Chris@494 3244 if (tb) tb->home();
Chris@494 3245 m_helpDialog->show();
Chris@494 3246 m_helpDialog->raise();
Chris@494 3247 }
Chris@494 3248