annotate mainwindow.cpp @ 278:f7cdd5b31aed new-branches

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