annotate src/mainwindow.cpp @ 553:9c8147c9f245

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