annotate src/mainwindow.cpp @ 490:cd3dd285d0ff

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