annotate src/mainwindow.cpp @ 510:c623ce6b3104

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