annotate mainwindow.cpp @ 301:3bb6b63420ad status_outside_tabs

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