annotate src/mainwindow.cpp @ 424:d4da9c0809ac

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