annotate src/mainwindow.cpp @ 541:0a16db274f2c fswatcher

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