annotate src/mainwindow.cpp @ 552:7663c1c19d47

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