annotate src/mainwindow.cpp @ 555:a1d210c767ab find

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