annotate mainwindow.cpp @ 362:73fb5ef55744

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