annotate src/mainwindow.cpp @ 419:69b2338c06e1 ignore

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