annotate src/mainwindow.cpp @ 415:6d7dad48b13c ignore

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