annotate src/mainwindow.cpp @ 413:2a19d5706673 ignore

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