annotate src/mainwindow.cpp @ 494:41a156d439d0

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