annotate src/mainwindow.cpp @ 520:a17c06f773cd

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