annotate mainwindow.cpp @ 289:37f67999b661

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