annotate mainwindow.cpp @ 306:b280a2dc0512 status_outside_tabs

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