annotate mainwindow.cpp @ 361:4cd753e083cc feature_91b

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