annotate src/mainwindow.cpp @ 418:93cb9005bb6f ignore

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