annotate src/mainwindow.cpp @ 493:75ebcacd3f75

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