annotate mainwindow.cpp @ 199:f16fe0db11f3

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