annotate mainwindow.cpp @ 137:a4044b4b3e35

* Include closed branches in heads check (see comment)
author Chris Cannam
date Tue, 30 Nov 2010 13:51:27 +0000
parents aaeab914f2a3
children e6c6b88d19b9
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>
jtkorhonen@0 33
Chris@53 34 #include "mainwindow.h"
Chris@69 35 #include "multichoicedialog.h"
Chris@64 36 #include "startupdialog.h"
Chris@53 37 #include "colourset.h"
Chris@62 38 #include "debug.h"
Chris@74 39 #include "logparser.h"
Chris@103 40 #include "confirmcommentdialog.h"
Chris@125 41 #include "incomingdialog.h"
Chris@53 42
jtkorhonen@0 43
jtkorhonen@0 44 MainWindow::MainWindow()
jtkorhonen@0 45 {
jtkorhonen@0 46 QString wndTitle;
jtkorhonen@0 47
Chris@90 48 fsWatcher = 0;
Chris@133 49 commitsSincePush = 0;
Chris@90 50
jtkorhonen@0 51 createActions();
jtkorhonen@0 52 createMenus();
jtkorhonen@0 53 createToolBars();
jtkorhonen@0 54 createStatusBar();
jtkorhonen@0 55
jtkorhonen@0 56 runner = new HgRunner(this);
Chris@109 57 connect(runner, SIGNAL(commandCompleted(HgAction, QString)),
Chris@109 58 this, SLOT(commandCompleted(HgAction, QString)));
Chris@109 59 connect(runner, SIGNAL(commandFailed(HgAction, QString)),
Chris@109 60 this, SLOT(commandFailed(HgAction, QString)));
jtkorhonen@0 61 statusBar()->addPermanentWidget(runner);
jtkorhonen@0 62
Chris@61 63 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 64
jtkorhonen@0 65 remoteRepoPath = "";
jtkorhonen@0 66 workFolderPath = "";
jtkorhonen@0 67
jtkorhonen@0 68 readSettings();
jtkorhonen@0 69
jtkorhonen@33 70 justMerged = false;
Chris@98 71 hgTabs = new HgTabWidget((QWidget *) this, remoteRepoPath, workFolderPath);
Chris@98 72 setCentralWidget(hgTabs);
jtkorhonen@0 73
Chris@98 74 connect(hgTabs, SIGNAL(selectionChanged()),
Chris@95 75 this, SLOT(enableDisableActions()));
Chris@95 76
jtkorhonen@0 77 setUnifiedTitleAndToolBarOnMac(true);
jtkorhonen@0 78 connectActions();
Chris@120 79 clearState();
jtkorhonen@0 80 enableDisableActions();
jtkorhonen@0 81
Chris@64 82 if (firstStart) {
Chris@64 83 startupDialog();
jtkorhonen@0 84 }
jtkorhonen@0 85
Chris@112 86 findDiffBinaryName();
Chris@112 87
Chris@64 88 ColourSet *cs = ColourSet::instance();
Chris@64 89 cs->clearDefaultNames();
Chris@64 90 cs->addDefaultName("");
Chris@64 91 cs->addDefaultName(getUserInfo());
Chris@62 92
Chris@72 93 if (workFolderPath == "") {
Chris@72 94 open();
Chris@72 95 }
Chris@72 96
Chris@109 97 hgQueryPaths();
jtkorhonen@0 98 }
jtkorhonen@0 99
jtkorhonen@0 100
jtkorhonen@0 101 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 102 {
jtkorhonen@0 103 writeSettings();
Chris@90 104 delete fsWatcher;
jtkorhonen@0 105 }
jtkorhonen@0 106
jtkorhonen@0 107
Chris@64 108 QString MainWindow::getUserInfo() const
Chris@64 109 {
Chris@64 110 QSettings settings;
Chris@64 111 settings.beginGroup("User Information");
Chris@64 112 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 113 QString email = settings.value("email", "").toString();
Chris@64 114
Chris@64 115 QString identifier;
Chris@64 116
Chris@64 117 if (email != "") {
Chris@64 118 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 119 } else {
Chris@64 120 identifier = name;
Chris@64 121 }
Chris@64 122
Chris@64 123 return identifier;
Chris@64 124 }
Chris@64 125
jtkorhonen@0 126 void MainWindow::about()
jtkorhonen@0 127 {
Chris@97 128 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@97 129 tr("<qt><h2>About EasyMercurial</h2>"
Chris@97 130 "<p>EasyMercurial is a simple user interface for the "
Chris@97 131 "Mercurial version control system.</p>"
Chris@98 132 "<p>EasyMercurial is based on hgExplorer by "
Chris@97 133 "Jari Korhonen, with thanks.<br>EasyMercurial development carried out by "
Chris@97 134 "Chris Cannam for soundsoftware.ac.uk at the Centre for Digital Music, Queen Mary, University of London."
Chris@97 135 "<ul><li>Copyright &copy; 2010 Jari Korhonen</li>"
Chris@97 136 "<li>Copyright &copy; 2010 Chris Cannam</li>"
Chris@97 137 "<li>Copyright &copy; 2010 Queen Mary, University of London</li>"
Chris@97 138 "</ul>"
Chris@97 139 "<p> This program is free software; you can redistribute it and/or "
Chris@97 140 "modify it under the terms of the GNU General Public License as "
Chris@97 141 "published by the Free Software Foundation; either version 2 of the "
Chris@97 142 "License, or (at your option) any later version. See the file "
Chris@97 143 "COPYING included with this distribution for more information."));
jtkorhonen@0 144 }
jtkorhonen@0 145
Chris@94 146 void MainWindow::clearSelections()
Chris@94 147 {
Chris@98 148 hgTabs->clearSelections();
Chris@94 149 }
jtkorhonen@0 150
Chris@120 151 void MainWindow::hgRefresh()
Chris@120 152 {
Chris@120 153 clearState();
Chris@120 154 hgQueryPaths();
Chris@120 155 }
Chris@120 156
jtkorhonen@0 157 void MainWindow::hgStat()
jtkorhonen@0 158 {
Chris@109 159 QStringList params;
Chris@109 160 params << "stat" << "-ardum";
Chris@109 161 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params));
jtkorhonen@0 162 }
jtkorhonen@0 163
Chris@109 164 void MainWindow::hgQueryPaths()
Chris@74 165 {
Chris@109 166 QStringList params;
Chris@109 167 params << "paths";
Chris@109 168 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params));
Chris@74 169 }
Chris@74 170
Chris@109 171 void MainWindow::hgQueryBranch()
Chris@106 172 {
Chris@109 173 QStringList params;
Chris@109 174 params << "branch";
Chris@109 175 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params));
Chris@106 176 }
Chris@106 177
Chris@109 178 void MainWindow::hgQueryHeads()
jtkorhonen@0 179 {
Chris@109 180 QStringList params;
Chris@137 181 // On empty repos, "hg heads" will fail -- we don't care about
Chris@137 182 // that. Use --closed option so as to include closed branches;
Chris@137 183 // otherwise we'll be stuck if the user updates into one, and our
Chris@137 184 // incremental log will end up with spurious stuff in it because
Chris@137 185 // we won't be pruning at the ends of closed branches
Chris@137 186 params << "heads" << "--closed";
Chris@109 187 runner->requestAction(HgAction(ACT_QUERY_HEADS, workFolderPath, params));
jtkorhonen@0 188 }
jtkorhonen@0 189
jtkorhonen@0 190 void MainWindow::hgLog()
jtkorhonen@0 191 {
Chris@109 192 QStringList params;
Chris@109 193 params << "log";
Chris@109 194 params << "--template";
Chris@125 195 params << Changeset::getLogTemplate();
Chris@109 196
Chris@109 197 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
Chris@109 198 }
Chris@109 199
Chris@120 200 void MainWindow::hgLogIncremental()
Chris@120 201 {
Chris@120 202 QStringList params;
Chris@120 203 params << "log";
Chris@120 204
Chris@120 205 foreach (Changeset *head, currentHeads) {
Chris@120 206 int n = head->number();
Chris@120 207 params << "--prune" << QString("%1").arg(n);
Chris@120 208 }
Chris@120 209
Chris@120 210 params << "--template";
Chris@125 211 params << Changeset::getLogTemplate();
Chris@120 212
Chris@120 213 runner->requestAction(HgAction(ACT_LOG_INCREMENTAL, workFolderPath, params));
Chris@120 214 }
Chris@109 215
Chris@109 216 void MainWindow::hgQueryParents()
Chris@109 217 {
Chris@109 218 QStringList params;
Chris@109 219 params << "parents";
Chris@109 220 runner->requestAction(HgAction(ACT_QUERY_PARENTS, workFolderPath, params));
Chris@109 221 }
Chris@109 222
Chris@109 223 void MainWindow::hgAnnotate()
Chris@109 224 {
Chris@109 225 QStringList params;
Chris@109 226 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
Chris@109 227
Chris@109 228 if (!currentFile.isEmpty())
jtkorhonen@0 229 {
Chris@109 230 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 231
Chris@109 232 runner->requestAction(HgAction(ACT_ANNOTATE, workFolderPath, params));
jtkorhonen@0 233 }
jtkorhonen@0 234 }
jtkorhonen@0 235
Chris@109 236 void MainWindow::hgResolveMark()
Chris@109 237 {
Chris@109 238 QStringList params;
Chris@109 239 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
jtkorhonen@0 240
Chris@109 241 if (!currentFile.isEmpty())
jtkorhonen@0 242 {
Chris@109 243 params << "resolve" << "--mark" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 244
Chris@109 245 runner->requestAction(HgAction(ACT_RESOLVE_MARK, workFolderPath, params));
jtkorhonen@0 246 }
jtkorhonen@0 247 }
jtkorhonen@0 248
Chris@109 249 void MainWindow::hgResolveList()
Chris@109 250 {
Chris@109 251 QStringList params;
jtkorhonen@0 252
Chris@109 253 params << "resolve" << "--list";
Chris@109 254 runner->requestAction(HgAction(ACT_RESOLVE_LIST, workFolderPath, params));
Chris@109 255 }
Chris@109 256
Chris@109 257 void MainWindow::hgAdd()
jtkorhonen@0 258 {
Chris@109 259 QStringList params;
jtkorhonen@0 260
Chris@109 261 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@109 262 // that one is a good idea, let's require the user to select
jtkorhonen@0 263
Chris@109 264 QStringList files = hgTabs->getSelectedAddableFiles();
Chris@109 265
Chris@109 266 if (!files.empty()) {
Chris@109 267 params << "add" << "--" << files;
Chris@109 268 runner->requestAction(HgAction(ACT_ADD, workFolderPath, params));
jtkorhonen@0 269 }
jtkorhonen@0 270 }
jtkorhonen@0 271
jtkorhonen@0 272
Chris@98 273 void MainWindow::hgRemove()
Chris@98 274 {
Chris@109 275 QStringList params;
Chris@98 276
Chris@109 277 QStringList files = hgTabs->getSelectedRemovableFiles();
Chris@98 278
Chris@109 279 //!!! todo: confirmation dialog (with file list in it) (or do we
Chris@109 280 // need that? all it does is move the files to the removed
Chris@109 281 // list... doesn't it?)
Chris@98 282
Chris@109 283 if (!files.empty()) {
Chris@109 284 params << "remove" << "--after" << "--force" << "--" << files;
Chris@109 285 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params));
Chris@109 286 }
Chris@98 287
Chris@91 288 /*!!!
Chris@98 289 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
Chris@98 290
Chris@98 291 if (!currentFile.isEmpty())
jtkorhonen@5 292 {
Chris@98 293 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?",
Chris@98 294 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel))
Chris@98 295 {
Chris@98 296 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@17 297
Chris@98 298 runner -> startHgCommand(workFolderPath, params);
Chris@98 299 runningAction = ACT_REMOVE;
jtkorhonen@17 300 }
jtkorhonen@5 301 }
Chris@98 302 */
jtkorhonen@0 303 }
jtkorhonen@0 304
jtkorhonen@0 305 void MainWindow::hgCommit()
jtkorhonen@0 306 {
Chris@109 307 QStringList params;
Chris@109 308 QString comment;
Chris@94 309
Chris@109 310 QStringList files = hgTabs->getSelectedCommittableFiles();
Chris@127 311 QStringList reportFiles = files;
Chris@127 312 if (reportFiles.empty()) reportFiles = hgTabs->getAllCommittableFiles();
Chris@103 313
Chris@109 314 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@109 315 (this,
Chris@109 316 tr("Commit files"),
Chris@112 317 tr("<h3>Commit files</h3><p>You are about to commit the following files:"),
Chris@112 318 tr("<h3>Commit files</h3><p>You are about to commit %1 files."),
Chris@127 319 reportFiles,
Chris@109 320 comment)) {
Chris@103 321
Chris@109 322 if ((justMerged == false) && //!!! review usage of justMerged, and how it interacts with asynchronous request queue
Chris@109 323 !files.empty()) {
Chris@109 324 // User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files)
Chris@109 325 params << "commit" << "--message" << comment << "--user" << getUserInfo() << "--" << files;
Chris@109 326 } else {
Chris@109 327 // Commit all changes
Chris@109 328 params << "commit" << "--message" << comment << "--user" << getUserInfo();
jtkorhonen@0 329 }
Chris@109 330
Chris@109 331 runner->requestAction(HgAction(ACT_COMMIT, workFolderPath, params));
jtkorhonen@0 332 }
jtkorhonen@0 333 }
jtkorhonen@0 334
jtkorhonen@34 335 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 336 {
jtkorhonen@34 337 for(int i = 0; i < tag.size(); i++)
jtkorhonen@34 338 {
jtkorhonen@34 339 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
jtkorhonen@34 340 {
jtkorhonen@34 341 //ok
jtkorhonen@34 342 }
jtkorhonen@34 343 else
jtkorhonen@34 344 {
jtkorhonen@34 345 tag[i] = QChar('_');
jtkorhonen@34 346 }
jtkorhonen@34 347 }
jtkorhonen@34 348 return tag;
jtkorhonen@34 349 }
jtkorhonen@34 350
jtkorhonen@34 351
jtkorhonen@34 352 void MainWindow::hgTag()
jtkorhonen@34 353 {
Chris@109 354 QStringList params;
Chris@109 355 QString tag;
jtkorhonen@34 356
Chris@109 357 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@109 358 (this,
Chris@109 359 tr("Tag"),
Chris@109 360 tr("Enter tag:"),
Chris@109 361 tag)) {
Chris@109 362 if (!tag.isEmpty()) //!!! do something better if it is empty
Chris@109 363 {
Chris@109 364 params << "tag" << "--user" << getUserInfo() << filterTag(tag);
Chris@109 365
Chris@109 366 runner->requestAction(HgAction(ACT_TAG, workFolderPath, params));
jtkorhonen@34 367 }
jtkorhonen@34 368 }
jtkorhonen@34 369 }
jtkorhonen@34 370
jtkorhonen@34 371
jtkorhonen@34 372 void MainWindow::hgIgnore()
jtkorhonen@34 373 {
Chris@109 374 QString hgIgnorePath;
Chris@109 375 QStringList params;
Chris@109 376 QString editorName;
Chris@109 377
Chris@109 378 hgIgnorePath = workFolderPath;
Chris@109 379 hgIgnorePath += ".hgignore";
Chris@109 380
Chris@109 381 params << hgIgnorePath;
Chris@112 382
Chris@112 383 //!!!
Chris@112 384 #ifdef Q_OS_LINUX
Chris@112 385
Chris@109 386 editorName = "gedit";
Chris@112 387
Chris@112 388 #else
Chris@112 389
Chris@109 390 editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe""";
Chris@112 391
Chris@112 392 #endif
jtkorhonen@34 393
Chris@109 394 HgAction action(ACT_HG_IGNORE, workFolderPath, params);
Chris@109 395 action.executable = editorName;
jtkorhonen@34 396
Chris@109 397 runner->requestAction(action);
jtkorhonen@34 398 }
jtkorhonen@34 399
Chris@112 400 void MainWindow::findDiffBinaryName()
Chris@112 401 {
Chris@112 402 QSettings settings;
Chris@112 403 QString diff = settings.value("extdiffbinary", "").toString();
Chris@112 404 if (diff == "") {
Chris@112 405 QStringList bases;
Chris@112 406 bases << "opendiff" << "kompare" << "kdiff3" << "meld";
Chris@112 407 bool found = false;
Chris@112 408 foreach (QString base, bases) {
Chris@112 409 diff = findExecutable(base);
Chris@112 410 if (diff != base) {
Chris@112 411 found = true;
Chris@112 412 break;
Chris@112 413 }
Chris@112 414 }
Chris@112 415 if (found) {
Chris@112 416 settings.setValue("extdiffbinary", diff);
Chris@112 417 } else {
Chris@112 418 diff = "";
Chris@112 419 }
Chris@112 420 }
Chris@112 421 diffBinaryName = diff;
Chris@112 422 }
jtkorhonen@34 423
jtkorhonen@0 424 void MainWindow::hgFileDiff()
jtkorhonen@0 425 {
jtkorhonen@0 426 QStringList params;
Chris@91 427 /*!!!
Chris@98 428 QString currentFile = hgTabs -> getCurrentFileListLine();
jtkorhonen@0 429
jtkorhonen@0 430 if (!currentFile.isEmpty())
jtkorhonen@0 431 {
jtkorhonen@0 432 //Diff parent file against working folder file
mg@41 433 params << "kdiff3" << "--" << currentFile.mid(2);
Chris@62 434 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 435 runningAction = ACT_FILEDIFF;
jtkorhonen@0 436 }
Chris@91 437 */
jtkorhonen@0 438 }
jtkorhonen@0 439
jtkorhonen@0 440
jtkorhonen@0 441 void MainWindow::hgFolderDiff()
jtkorhonen@0 442 {
Chris@112 443 if (diffBinaryName == "") return;
Chris@112 444
Chris@109 445 QStringList params;
jtkorhonen@0 446
Chris@112 447 // Diff parent against working folder (folder diff)
Chris@112 448
Chris@109 449 params << "--config" << "extensions.extdiff=" << "extdiff" << "-p";
Chris@112 450 params << diffBinaryName;
Chris@109 451
Chris@109 452 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
jtkorhonen@0 453 }
jtkorhonen@0 454
jtkorhonen@0 455
jtkorhonen@0 456 void MainWindow::hgChgSetDiff()
jtkorhonen@0 457 {
jtkorhonen@0 458 QStringList params;
jtkorhonen@0 459
jtkorhonen@0 460 //Diff 2 history log versions against each other
jtkorhonen@0 461 QString revA;
jtkorhonen@0 462 QString revB;
Chris@91 463 /*!!!
Chris@98 464 hgTabs -> getHistoryDiffRevisions(revA, revB);
jtkorhonen@0 465
jtkorhonen@0 466 if ((!revA.isEmpty()) && (!revB.isEmpty()))
jtkorhonen@0 467 {
jtkorhonen@0 468 params << "kdiff3" << "--rev" << revA << "--rev" << revB;
Chris@62 469 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 470 runningAction = ACT_CHGSETDIFF;
jtkorhonen@0 471 }
jtkorhonen@0 472 else
jtkorhonen@0 473 {
jtkorhonen@0 474 QMessageBox::information(this, tr("Changeset diff"), tr("Please select two changesets from history list or heads list first."));
jtkorhonen@0 475 }
Chris@91 476 */
jtkorhonen@0 477 }
jtkorhonen@0 478
jtkorhonen@0 479
jtkorhonen@0 480
jtkorhonen@0 481 void MainWindow::hgUpdate()
jtkorhonen@0 482 {
Chris@109 483 QStringList params;
jtkorhonen@0 484
Chris@109 485 params << "update";
Chris@109 486
Chris@109 487 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
jtkorhonen@0 488 }
jtkorhonen@0 489
jtkorhonen@0 490
jtkorhonen@0 491 void MainWindow::hgUpdateToRev()
jtkorhonen@0 492 {
jtkorhonen@0 493 QStringList params;
jtkorhonen@0 494 QString rev;
Chris@91 495 /*!!!
Chris@98 496 hgTabs -> getUpdateToRevRevision(rev);
jtkorhonen@0 497
Chris@98 498 hgTabs -> setCurrentIndex(WORKTAB);
jtkorhonen@0 499 enableDisableActions();
jtkorhonen@0 500
jtkorhonen@0 501 params << "update" << "--rev" << rev << "--clean";
jtkorhonen@0 502
Chris@62 503 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 504
jtkorhonen@0 505 runningAction = ACT_UPDATE;
Chris@91 506 */
Chris@109 507
jtkorhonen@0 508 }
jtkorhonen@0 509
jtkorhonen@0 510
jtkorhonen@0 511 void MainWindow::hgRevert()
jtkorhonen@0 512 {
Chris@109 513 QStringList params;
Chris@109 514 QString comment;
Chris@98 515
Chris@109 516 QStringList files = hgTabs->getSelectedRevertableFiles();
Chris@109 517 if (files.empty()) files = hgTabs->getAllRevertableFiles();
Chris@109 518
Chris@109 519 if (ConfirmCommentDialog::confirmDangerousFilesAction
Chris@109 520 (this,
Chris@109 521 tr("Revert files"),
Chris@127 522 tr("<h3>Revert files</h3><p>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@112 523 tr("<h3>Revert files</h3><p>You are about to <b>revert</b> %1 files.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."),
Chris@109 524 files)) {
Chris@109 525
Chris@98 526 if (files.empty()) {
Chris@98 527 params << "revert" << "--no-backup";
Chris@98 528 } else {
Chris@98 529 params << "revert" << "--no-backup" << "--" << files;
Chris@98 530 }
Chris@109 531
Chris@109 532 runner->requestAction(HgAction(ACT_REVERT, workFolderPath, params));
jtkorhonen@0 533 }
jtkorhonen@0 534 }
jtkorhonen@0 535
jtkorhonen@33 536 void MainWindow::hgRetryMerge()
jtkorhonen@33 537 {
Chris@109 538 QStringList params;
jtkorhonen@33 539
Chris@109 540 params << "resolve" << "--all";
Chris@109 541 runner->requestAction(HgAction(ACT_RETRY_MERGE, workFolderPath, params));
jtkorhonen@33 542 }
jtkorhonen@33 543
jtkorhonen@33 544
jtkorhonen@0 545 void MainWindow::hgMerge()
jtkorhonen@0 546 {
Chris@109 547 QStringList params;
jtkorhonen@0 548
Chris@109 549 params << "merge";
Chris@109 550
Chris@109 551 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
jtkorhonen@0 552 }
jtkorhonen@0 553
jtkorhonen@0 554
jtkorhonen@0 555 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 556 {
Chris@109 557 QStringList params;
jtkorhonen@0 558
Chris@109 559 if (!QDir(workFolderPath).exists()) {
Chris@109 560 if (!QDir().mkpath(workFolderPath)) {
Chris@109 561 DEBUG << "hgCloneFromRemote: Failed to create target path "
Chris@109 562 << workFolderPath << endl;
Chris@109 563 //!!! report error
Chris@109 564 return;
Chris@104 565 }
Chris@109 566 }
Chris@104 567
Chris@109 568 params << "clone" << remoteRepoPath << workFolderPath;
Chris@109 569
Chris@109 570 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@113 571 hgTabs->updateWorkFolderFileList("");
jtkorhonen@0 572
Chris@109 573 runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, workFolderPath, params));
jtkorhonen@0 574 }
jtkorhonen@0 575
jtkorhonen@0 576 void MainWindow::hgInit()
jtkorhonen@0 577 {
Chris@109 578 QStringList params;
jtkorhonen@0 579
Chris@109 580 params << "init";
Chris@109 581 params << workFolderPath;
jtkorhonen@0 582
Chris@109 583 runner->requestAction(HgAction(ACT_INIT, workFolderPath, params));
jtkorhonen@0 584 }
jtkorhonen@0 585
jtkorhonen@0 586 void MainWindow::hgIncoming()
jtkorhonen@0 587 {
Chris@109 588 QStringList params;
jtkorhonen@0 589
Chris@109 590 params << "incoming" << "--newest-first" << remoteRepoPath;
Chris@125 591 params << "--template" << Changeset::getLogTemplate();
jtkorhonen@0 592
Chris@109 593 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params));
jtkorhonen@0 594 }
jtkorhonen@0 595
jtkorhonen@0 596 void MainWindow::hgPull()
jtkorhonen@0 597 {
Chris@126 598 if (QMessageBox::question
Chris@126 599 (this, tr("Confirm pull"),
Chris@126 600 format3(tr("Confirm pull from remote repository"),
Chris@126 601 tr("You are about to pull from the following remote repository:"),
Chris@126 602 remoteRepoPath),
Chris@126 603 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
jtkorhonen@0 604
Chris@126 605 QStringList params;
Chris@126 606 params << "pull" << remoteRepoPath;
Chris@126 607 runner->requestAction(HgAction(ACT_PULL, workFolderPath, params));
Chris@126 608 }
jtkorhonen@0 609 }
jtkorhonen@0 610
jtkorhonen@0 611 void MainWindow::hgPush()
jtkorhonen@0 612 {
Chris@126 613 if (QMessageBox::question
Chris@126 614 (this, tr("Confirm push"),
Chris@126 615 format3(tr("Confirm push to remote repository"),
Chris@126 616 tr("You are about to push to the following remote repository:"),
Chris@126 617 remoteRepoPath),
Chris@126 618 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
jtkorhonen@0 619
Chris@126 620 QStringList params;
Chris@126 621 params << "push" << remoteRepoPath;
Chris@126 622 runner->requestAction(HgAction(ACT_PUSH, workFolderPath, params));
Chris@126 623 }
jtkorhonen@0 624 }
jtkorhonen@0 625
jtkorhonen@28 626 QString MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 627 {
jtkorhonen@28 628 QString ret;
jtkorhonen@26 629 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 630
jtkorhonen@26 631 for (int i = 0; i < ifaces.count(); i++)
jtkorhonen@26 632 {
jtkorhonen@26 633 QNetworkInterface iface = ifaces.at(i);
jtkorhonen@26 634
jtkorhonen@26 635 if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
jtkorhonen@26 636 {
jtkorhonen@26 637 for (int j=0; j<iface.addressEntries().count(); j++)
jtkorhonen@26 638 {
jtkorhonen@28 639 QHostAddress tmp = iface.addressEntries().at(j).ip();
jtkorhonen@28 640 if (QAbstractSocket::IPv4Protocol == tmp.protocol())
jtkorhonen@24 641 {
jtkorhonen@28 642 if (!ret.isEmpty())
jtkorhonen@28 643 {
jtkorhonen@28 644 ret += " ";
jtkorhonen@28 645 }
jtkorhonen@28 646 ret += tmp.toString();
jtkorhonen@24 647 }
jtkorhonen@24 648 }
jtkorhonen@22 649 }
jtkorhonen@17 650 }
jtkorhonen@28 651 return ret;
jtkorhonen@28 652 }
jtkorhonen@17 653
Chris@120 654 void MainWindow::clearState()
Chris@120 655 {
Chris@120 656 foreach (Changeset *cs, currentParents) delete cs;
Chris@120 657 currentParents.clear();
Chris@120 658 foreach (Changeset *cs, currentHeads) delete cs;
Chris@120 659 currentHeads.clear();
Chris@120 660 currentBranch = "";
Chris@120 661 needNewLog = true;
Chris@120 662 }
jtkorhonen@17 663
jtkorhonen@11 664 void MainWindow::hgServe()
jtkorhonen@11 665 {
Chris@109 666 QStringList params;
Chris@109 667 QString msg;
jtkorhonen@11 668
Chris@109 669 QString addrs = listAllUpIpV4Addresses();
Chris@109 670 QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000";
Chris@109 671 params << "serve";
jtkorhonen@11 672
Chris@109 673 runner->requestAction(HgAction(ACT_SERVE, workFolderPath, params));
Chris@109 674
Chris@109 675 QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
Chris@109 676 //!!! runner -> killCurrentCommand();
jtkorhonen@11 677 }
jtkorhonen@11 678
Chris@64 679 void MainWindow::startupDialog()
Chris@64 680 {
Chris@64 681 StartupDialog *dlg = new StartupDialog(this);
Chris@65 682 if (dlg->exec()) firstStart = false;
Chris@64 683 }
jtkorhonen@11 684
Chris@69 685 void MainWindow::open()
Chris@69 686 {
Chris@86 687 bool done = false;
Chris@69 688
Chris@86 689 while (!done) {
Chris@69 690
Chris@86 691 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 692 (tr("Open Repository"),
Chris@86 693 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 694 this);
Chris@69 695
Chris@86 696 d->addChoice("remote",
Chris@86 697 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@86 698 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@86 699 MultiChoiceDialog::UrlToDirectoryArg);
Chris@69 700
Chris@86 701 d->addChoice("local",
Chris@86 702 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@86 703 tr("Open an existing local Mercurial repository."),
Chris@86 704 MultiChoiceDialog::DirectoryArg);
Chris@69 705
Chris@86 706 d->addChoice("init",
Chris@86 707 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@86 708 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@86 709 MultiChoiceDialog::DirectoryArg);
Chris@79 710
Chris@86 711 d->setCurrentChoice("local");
Chris@86 712
Chris@86 713 if (d->exec() == QDialog::Accepted) {
Chris@86 714
Chris@86 715 QString choice = d->getCurrentChoice();
Chris@86 716 QString arg = d->getArgument().trimmed();
Chris@86 717
Chris@86 718 bool result = false;
Chris@86 719
Chris@86 720 if (choice == "local") {
Chris@86 721 result = openLocal(arg);
Chris@86 722 } else if (choice == "remote") {
Chris@86 723 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 724 } else if (choice == "init") {
Chris@86 725 result = openInit(arg);
Chris@86 726 }
Chris@86 727
Chris@86 728 if (result) {
Chris@86 729 enableDisableActions();
Chris@120 730 clearState();
Chris@109 731 hgQueryPaths();
Chris@91 732 done = true;
Chris@91 733 }
Chris@86 734
Chris@86 735 } else {
Chris@86 736
Chris@86 737 // cancelled
Chris@86 738 done = true;
Chris@69 739 }
Chris@79 740
Chris@86 741 delete d;
Chris@69 742 }
Chris@69 743 }
Chris@69 744
Chris@79 745 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 746 {
Chris@79 747 QMessageBox::critical
Chris@79 748 (this, tr("File chosen"),
Chris@84 749 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 750 return false;
Chris@79 751 }
Chris@79 752
Chris@79 753 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 754 {
Chris@79 755 QMessageBox::critical
Chris@79 756 (this, tr("Folder does not exist"),
Chris@84 757 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 758 return false;
Chris@84 759 }
Chris@84 760
Chris@84 761 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 762 {
Chris@84 763 QMessageBox::critical
Chris@84 764 (this, tr("Path is in existing repository"),
Chris@84 765 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 766 return false;
Chris@84 767 }
Chris@84 768
Chris@84 769 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 770 {
Chris@84 771 QMessageBox::critical
Chris@84 772 (this, tr("Path is a file"),
Chris@84 773 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 774 return false;
Chris@84 775 }
Chris@84 776
Chris@84 777 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 778 {
Chris@84 779 QMessageBox::critical
Chris@84 780 (this, tr("Path is in existing repository"),
Chris@84 781 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 782 return false;
Chris@84 783 }
Chris@84 784
Chris@84 785 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 786 {
Chris@84 787 QMessageBox::critical
Chris@84 788 (this, tr("Path is a file"),
Chris@84 789 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 790 return false;
Chris@84 791 }
Chris@84 792
Chris@84 793 bool MainWindow::complainAboutCloneToExistingFolder(QString arg)
Chris@84 794 {
Chris@84 795 QMessageBox::critical
Chris@84 796 (this, tr("Folder exists"),
Chris@84 797 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 798 return false;
Chris@79 799 }
Chris@79 800
Chris@79 801 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 802 {
Chris@79 803 return (QMessageBox::question
Chris@84 804 (this, tr("Path is inside a repository"),
Chris@86 805 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 806 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 807 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 808 QMessageBox::Ok)
Chris@79 809 == QMessageBox::Ok);
Chris@79 810 }
Chris@79 811
Chris@79 812 bool MainWindow::askToInitExisting(QString arg)
Chris@79 813 {
Chris@79 814 return (QMessageBox::question
Chris@84 815 (this, tr("Folder has no repository"),
Chris@84 816 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 817 .arg(xmlEncode(arg)),
Chris@79 818 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 819 QMessageBox::Ok)
Chris@79 820 == QMessageBox::Ok);
Chris@79 821 }
Chris@79 822
Chris@79 823 bool MainWindow::askToInitNew(QString arg)
Chris@79 824 {
Chris@79 825 return (QMessageBox::question
Chris@84 826 (this, tr("Folder does not exist"),
Chris@84 827 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 828 .arg(xmlEncode(arg)),
Chris@84 829 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 830 QMessageBox::Ok)
Chris@84 831 == QMessageBox::Ok);
Chris@84 832 }
Chris@84 833
Chris@84 834 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 835 {
Chris@84 836 return (QMessageBox::question
Chris@84 837 (this, tr("Repository exists"),
Chris@84 838 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 839 .arg(xmlEncode(arg)),
Chris@79 840 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 841 QMessageBox::Ok)
Chris@79 842 == QMessageBox::Ok);
Chris@79 843 }
Chris@79 844
Chris@79 845 bool MainWindow::openLocal(QString local)
Chris@79 846 {
Chris@79 847 DEBUG << "open " << local << endl;
Chris@79 848
Chris@79 849 FolderStatus status = getFolderStatus(local);
Chris@79 850 QString containing = getContainingRepoFolder(local);
Chris@79 851
Chris@79 852 switch (status) {
Chris@79 853
Chris@79 854 case FolderHasRepo:
Chris@79 855 // fine
Chris@79 856 break;
Chris@79 857
Chris@79 858 case FolderExists:
Chris@79 859 if (containing != "") {
Chris@79 860 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 861 local = containing;
Chris@79 862 } else {
Chris@86 863 //!!! No -- this is likely to happen far more by accident
Chris@86 864 // than because the user actually wanted to init something.
Chris@86 865 // Don't ask, just politely reject.
Chris@79 866 if (!askToInitExisting(local)) return false;
Chris@79 867 return openInit(local);
Chris@79 868 }
Chris@79 869 break;
Chris@79 870
Chris@79 871 case FolderParentExists:
Chris@79 872 if (containing != "") {
Chris@79 873 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 874 local = containing;
Chris@79 875 } else {
Chris@79 876 if (!askToInitNew(local)) return false;
Chris@79 877 return openInit(local);
Chris@79 878 }
Chris@79 879 break;
Chris@79 880
Chris@79 881 case FolderUnknown:
Chris@84 882 if (containing != "") {
Chris@84 883 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 884 local = containing;
Chris@84 885 } else {
Chris@84 886 return complainAboutUnknownFolder(local);
Chris@84 887 }
Chris@84 888 break;
Chris@79 889
Chris@79 890 case FolderIsFile:
Chris@79 891 return complainAboutFilePath(local);
Chris@79 892 }
Chris@79 893
Chris@79 894 workFolderPath = local;
Chris@79 895 remoteRepoPath = "";
Chris@79 896 return true;
Chris@79 897 }
Chris@79 898
Chris@79 899 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 900 {
Chris@79 901 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 902
Chris@84 903 FolderStatus status = getFolderStatus(local);
Chris@84 904 QString containing = getContainingRepoFolder(local);
Chris@84 905
Chris@84 906 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 907
Chris@84 908 if (status == FolderHasRepo || containing != "") {
Chris@84 909 return complainAboutCloneToExisting(local);
Chris@84 910 }
Chris@84 911
Chris@84 912 if (status == FolderIsFile) {
Chris@84 913 return complainAboutCloneToFile(local);
Chris@84 914 }
Chris@84 915
Chris@84 916 if (status == FolderUnknown) {
Chris@84 917 return complainAboutUnknownFolder(local);
Chris@84 918 }
Chris@84 919
Chris@84 920 if (status == FolderExists) {
Chris@84 921 //!!! we can do better than this surely?
Chris@84 922 return complainAboutCloneToExistingFolder(local);
Chris@84 923 }
Chris@84 924
Chris@84 925 workFolderPath = local;
Chris@84 926 remoteRepoPath = remote;
Chris@84 927 hgCloneFromRemote();
Chris@84 928
Chris@79 929 return true;
Chris@79 930 }
Chris@79 931
Chris@84 932 bool MainWindow::openInit(QString local)
Chris@79 933 {
Chris@84 934 DEBUG << "openInit " << local << endl;
Chris@84 935
Chris@84 936 FolderStatus status = getFolderStatus(local);
Chris@84 937 QString containing = getContainingRepoFolder(local);
Chris@84 938
Chris@84 939 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 940
Chris@84 941 if (status == FolderHasRepo) {
Chris@84 942 if (!askToOpenInsteadOfInit(local)) return false;
Chris@84 943 }
Chris@84 944
Chris@84 945 if (containing != "") {
Chris@84 946 return complainAboutInitInRepo(local);
Chris@84 947 }
Chris@84 948
Chris@84 949 if (status == FolderIsFile) {
Chris@84 950 return complainAboutInitFile(local);
Chris@84 951 }
Chris@84 952
Chris@84 953 if (status == FolderUnknown) {
Chris@84 954 return complainAboutUnknownFolder(local);
Chris@84 955 }
Chris@84 956
Chris@84 957 workFolderPath = local;
Chris@84 958 remoteRepoPath = "";
Chris@84 959 hgInit();
Chris@79 960 return true;
Chris@79 961 }
Chris@79 962
jtkorhonen@0 963 void MainWindow::settings()
jtkorhonen@0 964 {
Chris@69 965 /*!!!
jtkorhonen@0 966 SettingsDialog *settingsDlg = new SettingsDialog(this);
jtkorhonen@0 967 settingsDlg->setModal(true);
jtkorhonen@0 968 settingsDlg->exec();
Chris@98 969 hgTabs -> clearLists();
jtkorhonen@0 970 enableDisableActions();
jtkorhonen@0 971 hgStat();
Chris@69 972 */
jtkorhonen@0 973 }
jtkorhonen@0 974
jtkorhonen@2 975 #define STDOUT_NEEDS_BIG_WINDOW 512
jtkorhonen@2 976 #define SMALL_WND_W 500
jtkorhonen@2 977 #define SMALL_WND_H 300
jtkorhonen@2 978
jtkorhonen@2 979 #define BIG_WND_W 1024
jtkorhonen@2 980 #define BIG_WND_H 768
jtkorhonen@2 981
jtkorhonen@2 982
jtkorhonen@2 983 void MainWindow::presentLongStdoutToUser(QString stdo)
jtkorhonen@0 984 {
jtkorhonen@2 985 if (!stdo.isEmpty())
jtkorhonen@2 986 {
jtkorhonen@2 987 QDialog dlg;
jtkorhonen@0 988
jtkorhonen@2 989 if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW)
jtkorhonen@2 990 {
jtkorhonen@2 991 dlg.setMinimumWidth(BIG_WND_W);
jtkorhonen@2 992 dlg.setMinimumHeight(BIG_WND_H);
jtkorhonen@2 993 }
jtkorhonen@2 994 else
jtkorhonen@2 995 {
jtkorhonen@2 996 dlg.setMinimumWidth(SMALL_WND_W);
jtkorhonen@2 997 dlg.setMinimumHeight(SMALL_WND_H);
jtkorhonen@2 998 }
jtkorhonen@0 999
jtkorhonen@2 1000 QVBoxLayout *box = new QVBoxLayout;
jtkorhonen@2 1001 QListWidget *list = new QListWidget;
jtkorhonen@2 1002 list-> addItems(stdo.split("\n"));
jtkorhonen@2 1003 QPushButton *btn = new QPushButton(tr("Ok"));
jtkorhonen@2 1004 connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept()));
jtkorhonen@0 1005
jtkorhonen@2 1006 box -> addWidget(list);
jtkorhonen@2 1007 box -> addWidget(btn);
jtkorhonen@2 1008 dlg.setLayout(box);
jtkorhonen@2 1009
jtkorhonen@2 1010 dlg.exec();
jtkorhonen@2 1011 }
jtkorhonen@2 1012 else
jtkorhonen@2 1013 {
Chris@98 1014 QMessageBox::information(this, tr("EasyMercurial"), tr("Mercurial command did not return any output."));
jtkorhonen@2 1015 }
jtkorhonen@0 1016 }
jtkorhonen@0 1017
Chris@90 1018 void MainWindow::updateFileSystemWatcher()
Chris@90 1019 {
Chris@90 1020 delete fsWatcher;
Chris@90 1021 fsWatcher = new QFileSystemWatcher();
Chris@90 1022 std::deque<QString> pending;
Chris@90 1023 pending.push_back(workFolderPath);
Chris@90 1024 while (!pending.empty()) {
Chris@90 1025 QString path = pending.front();
Chris@90 1026 pending.pop_front();
Chris@90 1027 fsWatcher->addPath(path);
Chris@90 1028 DEBUG << "Added to file system watcher: " << path << endl;
Chris@90 1029 QDir d(path);
Chris@90 1030 if (d.exists()) {
Chris@115 1031 d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable);
Chris@90 1032 foreach (QString entry, d.entryList()) {
Chris@90 1033 if (entry == ".hg") continue;
Chris@90 1034 QString entryPath = d.absoluteFilePath(entry);
Chris@90 1035 pending.push_back(entryPath);
Chris@90 1036 }
Chris@90 1037 }
Chris@90 1038 }
Chris@90 1039 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
Chris@90 1040 this, SLOT(fsDirectoryChanged(QString)));
Chris@90 1041 connect(fsWatcher, SIGNAL(fileChanged(QString)),
Chris@90 1042 this, SLOT(fsFileChanged(QString)));
Chris@90 1043 }
Chris@90 1044
Chris@122 1045 void MainWindow::fsDirectoryChanged(QString d)
Chris@90 1046 {
Chris@122 1047 DEBUG << "MainWindow::fsDirectoryChanged " << d << endl;
Chris@90 1048 hgStat();
Chris@90 1049 }
Chris@90 1050
Chris@122 1051 void MainWindow::fsFileChanged(QString f)
Chris@90 1052 {
Chris@122 1053 DEBUG << "MainWindow::fsFileChanged " << f << endl;
Chris@90 1054 hgStat();
Chris@90 1055 }
Chris@90 1056
Chris@125 1057 QString MainWindow::format3(QString head, QString intro, QString code)
Chris@125 1058 {
Chris@125 1059 if (intro == "") {
Chris@125 1060 return QString("<qt><h3>%1</h3><code>%2</code>")
Chris@125 1061 .arg(head).arg(xmlEncode(code).replace("\n", "<br>"));
Chris@126 1062 } else if (code == "") {
Chris@126 1063 return QString("<qt><h3>%1</h3><p>%2</p>")
Chris@126 1064 .arg(head).arg(intro);
Chris@125 1065 } else {
Chris@125 1066 return QString("<qt><h3>%1</h3><p>%2</p><code>%3</code>")
Chris@125 1067 .arg(head).arg(intro).arg(xmlEncode(code).replace("\n", "<br>"));
Chris@125 1068 }
Chris@125 1069 }
Chris@125 1070
Chris@120 1071 void MainWindow::showIncoming(QString output)
Chris@120 1072 {
Chris@120 1073 runner->hide();
Chris@125 1074 IncomingDialog *d = new IncomingDialog(this, output);
Chris@125 1075 d->exec();
Chris@125 1076 delete d;
Chris@125 1077 }
Chris@125 1078
Chris@125 1079 int MainWindow::extractChangeCount(QString text)
Chris@125 1080 {
Chris@125 1081 QRegExp re("added (\\d+) ch\\w+ with (\\d+) ch\\w+ to (\\d+) f\\w+");
Chris@125 1082 if (re.indexIn(text) >= 0) {
Chris@125 1083 return re.cap(1).toInt();
Chris@125 1084 } else if (text.contains("no changes")) {
Chris@125 1085 return 0;
Chris@125 1086 } else {
Chris@125 1087 return -1; // unknown
Chris@125 1088 }
Chris@120 1089 }
Chris@120 1090
Chris@120 1091 void MainWindow::showPushResult(QString output)
Chris@120 1092 {
Chris@125 1093 QString report;
Chris@125 1094 int n = extractChangeCount(output);
Chris@125 1095 if (n > 0) {
Chris@125 1096 report = tr("Pushed %n changeset(s)", "", n);
Chris@125 1097 } else if (n == 0) {
Chris@125 1098 report = tr("No changes to push");
Chris@125 1099 } else {
Chris@125 1100 report = tr("Push complete");
Chris@125 1101 }
Chris@125 1102 report = format3(report, tr("The push command output was:"), output);
Chris@120 1103 runner->hide();
Chris@125 1104 QMessageBox::information(this, "Push complete", report);
Chris@120 1105 }
Chris@120 1106
Chris@120 1107 void MainWindow::showPullResult(QString output)
Chris@120 1108 {
Chris@125 1109 QString report;
Chris@125 1110 int n = extractChangeCount(output);
Chris@125 1111 if (n > 0) {
Chris@125 1112 report = tr("Pulled %n changeset(s)", "", n);
Chris@125 1113 } else if (n == 0) {
Chris@125 1114 report = tr("No changes to pull");
Chris@125 1115 } else {
Chris@125 1116 report = tr("Pull complete");
Chris@125 1117 }
Chris@125 1118 report = format3(report, tr("The pull command output was:"), output);
Chris@120 1119 runner->hide();
Chris@125 1120
Chris@125 1121 //!!! and something about updating
Chris@125 1122
Chris@125 1123 QMessageBox::information(this, "Pull complete", report);
Chris@120 1124 }
Chris@120 1125
Chris@109 1126 void MainWindow::commandFailed(HgAction action, QString stderr)
Chris@62 1127 {
Chris@62 1128 DEBUG << "MainWindow::commandFailed" << endl;
Chris@74 1129
Chris@113 1130 // Some commands we just have to ignore bad return values from:
Chris@113 1131
Chris@113 1132 switch(action.action) {
Chris@113 1133 case ACT_NONE:
Chris@113 1134 // uh huh
Chris@113 1135 return;
Chris@113 1136 case ACT_INCOMING:
Chris@113 1137 // returns non-zero code if the check was successful but there
Chris@113 1138 // are no changes pending
Chris@125 1139 if (stderr.trimmed() == "") showIncoming("");
Chris@113 1140 return;
Chris@113 1141 case ACT_FOLDERDIFF:
Chris@113 1142 case ACT_FILEDIFF:
Chris@113 1143 case ACT_CHGSETDIFF:
Chris@113 1144 // external program, unlikely to be anything useful in stderr
Chris@113 1145 // and some return with failure codes when something as basic
Chris@113 1146 // as the user closing the window via the wm happens
Chris@113 1147 return;
Chris@113 1148
Chris@113 1149 default:
Chris@114 1150 break;
Chris@113 1151 }
Chris@113 1152
Chris@113 1153 QString command = action.executable;
Chris@113 1154 if (command == "") command = "hg";
Chris@113 1155 foreach (QString arg, action.params) {
Chris@113 1156 command += " " + arg;
Chris@113 1157 }
Chris@113 1158
Chris@113 1159 QString message = tr("<qt><h3>Command failed</h3>"
Chris@113 1160 "<p>The following command failed:</p>"
Chris@113 1161 "<code>%1</code>"
Chris@113 1162 "%2</qt>")
Chris@113 1163 .arg(command)
Chris@113 1164 .arg((stderr.trimmed() != "") ?
Chris@113 1165 tr("<p>Its output said:</p><code>%1</code>")
Chris@113 1166 .arg(xmlEncode(stderr.left(800))
Chris@113 1167 .replace("\n", "<br>"))
Chris@113 1168 : "");
Chris@113 1169
Chris@113 1170 QMessageBox::warning(this, tr("Command failed"), message);
Chris@62 1171 }
Chris@62 1172
Chris@109 1173 void MainWindow::commandCompleted(HgAction completedAction, QString output)
jtkorhonen@0 1174 {
jtkorhonen@0 1175 bool shouldHgStat = false;
jtkorhonen@0 1176
Chris@109 1177 HGACTIONS action = completedAction.action;
Chris@109 1178
Chris@109 1179 if (action == ACT_NONE) return;
Chris@109 1180
Chris@109 1181 switch(action) {
Chris@109 1182
Chris@109 1183 case ACT_QUERY_PATHS:
jtkorhonen@0 1184 {
Chris@109 1185 DEBUG << "stdout is " << output << endl;
Chris@109 1186 LogParser lp(output, "=");
Chris@109 1187 LogList ll = lp.parse();
Chris@109 1188 DEBUG << ll.size() << " results" << endl;
Chris@109 1189 if (!ll.empty()) {
Chris@109 1190 remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@109 1191 DEBUG << "Set remote path to " << remoteRepoPath << endl;
Chris@109 1192 }
Chris@109 1193 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1194 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1195 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@109 1196 break;
Chris@109 1197 }
jtkorhonen@0 1198
Chris@109 1199 case ACT_QUERY_BRANCH:
Chris@109 1200 currentBranch = output.trimmed();
Chris@109 1201 break;
jtkorhonen@0 1202
Chris@109 1203 case ACT_STAT:
Chris@113 1204 hgTabs->updateWorkFolderFileList(output);
Chris@109 1205 updateFileSystemWatcher();
Chris@109 1206 break;
Chris@109 1207
Chris@109 1208 case ACT_INCOMING:
Chris@120 1209 showIncoming(output);
Chris@120 1210 break;
Chris@120 1211
Chris@109 1212 case ACT_ANNOTATE:
Chris@109 1213 case ACT_RESOLVE_LIST:
Chris@109 1214 case ACT_RESOLVE_MARK:
Chris@109 1215 presentLongStdoutToUser(output);
Chris@109 1216 shouldHgStat = true;
Chris@109 1217 break;
Chris@109 1218
Chris@109 1219 case ACT_PULL:
Chris@120 1220 showPullResult(output);
Chris@109 1221 shouldHgStat = true;
Chris@109 1222 break;
Chris@109 1223
Chris@109 1224 case ACT_PUSH:
Chris@120 1225 showPushResult(output);
Chris@109 1226 break;
Chris@109 1227
Chris@109 1228 case ACT_INIT:
Chris@109 1229 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
Chris@109 1230 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1231 enableDisableActions();
Chris@109 1232 shouldHgStat = true;
Chris@109 1233 break;
Chris@109 1234
Chris@109 1235 case ACT_CLONEFROMREMOTE:
Chris@109 1236 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1237 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1238 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
Chris@109 1239 QMessageBox::information(this, "Clone", output);
Chris@109 1240 enableDisableActions();
Chris@109 1241 shouldHgStat = true;
Chris@109 1242 break;
Chris@109 1243
Chris@109 1244 case ACT_LOG:
Chris@120 1245 hgTabs->setNewLog(output);
Chris@120 1246 needNewLog = false;
Chris@120 1247 break;
Chris@120 1248
Chris@120 1249 case ACT_LOG_INCREMENTAL:
Chris@120 1250 hgTabs->addIncrementalLog(output);
Chris@109 1251 break;
Chris@109 1252
Chris@109 1253 case ACT_QUERY_PARENTS:
Chris@109 1254 foreach (Changeset *cs, currentParents) delete cs;
Chris@109 1255 currentParents = Changeset::parseChangesets(output);
Chris@109 1256 break;
Chris@109 1257
Chris@109 1258 case ACT_QUERY_HEADS:
Chris@109 1259 foreach (Changeset *cs, currentHeads) delete cs;
Chris@109 1260 currentHeads = Changeset::parseChangesets(output);
Chris@109 1261 break;
Chris@130 1262
Chris@130 1263 case ACT_COMMIT:
Chris@130 1264 hgTabs->clearSelections();
Chris@130 1265 shouldHgStat = true;
Chris@130 1266 needNewLog = true; // naive incremental log will give us a duplicate tip tag
Chris@130 1267 break;
Chris@109 1268
Chris@109 1269 case ACT_REMOVE:
Chris@109 1270 case ACT_ADD:
Chris@116 1271 case ACT_REVERT:
Chris@116 1272 hgTabs->clearSelections();
Chris@116 1273 shouldHgStat = true;
Chris@116 1274 break;
Chris@116 1275
Chris@109 1276 case ACT_FILEDIFF:
Chris@109 1277 case ACT_FOLDERDIFF:
Chris@109 1278 case ACT_CHGSETDIFF:
Chris@109 1279 case ACT_SERVE:
Chris@109 1280 case ACT_TAG:
Chris@109 1281 case ACT_HG_IGNORE:
Chris@109 1282 shouldHgStat = true;
Chris@109 1283 break;
Chris@109 1284
Chris@109 1285 case ACT_UPDATE:
Chris@109 1286 QMessageBox::information(this, tr("Update"), output);
Chris@109 1287 shouldHgStat = true;
Chris@109 1288 break;
Chris@109 1289
Chris@109 1290 case ACT_MERGE:
Chris@109 1291 QMessageBox::information(this, tr("Merge"), output);
Chris@109 1292 shouldHgStat = true;
Chris@109 1293 justMerged = true;
Chris@109 1294 break;
Chris@109 1295
Chris@109 1296 case ACT_RETRY_MERGE:
Chris@109 1297 QMessageBox::information(this, tr("Merge retry"), tr("Merge retry successful."));
Chris@109 1298 shouldHgStat = true;
Chris@109 1299 justMerged = true;
Chris@109 1300 break;
Chris@109 1301
Chris@109 1302 default:
Chris@109 1303 break;
Chris@109 1304 }
Chris@108 1305
Chris@109 1306 enableDisableActions();
Chris@74 1307
Chris@121 1308 // Sequence when no full log required:
Chris@121 1309 // paths -> branch -> stat -> incremental-log -> heads -> parents
Chris@121 1310 // Sequence when full log required:
Chris@121 1311 // paths -> branch -> stat -> heads -> parents -> log
Chris@109 1312 if (action == ACT_QUERY_PATHS) {
Chris@109 1313 hgQueryBranch();
Chris@109 1314 } else if (action == ACT_QUERY_BRANCH) {
Chris@109 1315 hgStat();
Chris@109 1316 } else if (action == ACT_STAT) {
Chris@121 1317 if (!needNewLog) {
Chris@121 1318 hgLogIncremental();
Chris@121 1319 } else {
Chris@121 1320 hgQueryHeads();
Chris@121 1321 }
Chris@121 1322 } else if (action == ACT_LOG_INCREMENTAL) {
Chris@109 1323 hgQueryHeads();
Chris@109 1324 } else if (action == ACT_QUERY_HEADS) {
Chris@109 1325 hgQueryParents();
Chris@109 1326 } else if (action == ACT_QUERY_PARENTS) {
Chris@120 1327 if (needNewLog) {
Chris@120 1328 hgLog();
Chris@120 1329 }
Chris@109 1330 } else
Chris@109 1331 /* Move to commandFailed
Chris@109 1332 if ((runningAction == ACT_MERGE) && (exitCode != 0))
jtkorhonen@37 1333 {
Chris@106 1334 // If we had a failed merge, offer to retry
jtkorhonen@37 1335 if (QMessageBox::Ok == QMessageBox::information(this, tr("Retry merge ?"), tr("Merge attempt failed. retry ?"), QMessageBox::Ok | QMessageBox::Cancel))
jtkorhonen@37 1336 {
jtkorhonen@37 1337 runningAction = ACT_NONE;
jtkorhonen@37 1338 hgRetryMerge();
jtkorhonen@37 1339 }
jtkorhonen@37 1340 else
jtkorhonen@37 1341 {
jtkorhonen@37 1342 runningAction = ACT_NONE;
jtkorhonen@37 1343 hgStat();
jtkorhonen@37 1344 }
jtkorhonen@37 1345 }
jtkorhonen@0 1346 else
jtkorhonen@0 1347 {
Chris@109 1348 */
Chris@109 1349 if (shouldHgStat) {
Chris@109 1350 hgQueryPaths();
jtkorhonen@0 1351 }
jtkorhonen@0 1352 }
jtkorhonen@0 1353
jtkorhonen@0 1354 void MainWindow::connectActions()
jtkorhonen@0 1355 {
jtkorhonen@0 1356 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
jtkorhonen@0 1357 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
jtkorhonen@0 1358 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
jtkorhonen@0 1359
Chris@120 1360 connect(hgRefreshAct, SIGNAL(triggered()), this, SLOT(hgRefresh()));
jtkorhonen@0 1361 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
jtkorhonen@0 1362 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
jtkorhonen@0 1363 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
jtkorhonen@0 1364 connect(hgFileDiffAct, SIGNAL(triggered()), this, SLOT(hgFileDiff()));
jtkorhonen@0 1365 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
jtkorhonen@0 1366 connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff()));
jtkorhonen@0 1367 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
jtkorhonen@0 1368 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
jtkorhonen@0 1369 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
jtkorhonen@33 1370 connect(hgRetryMergeAct, SIGNAL(triggered()), this, SLOT(hgRetryMerge()));
jtkorhonen@34 1371 connect(hgTagAct, SIGNAL(triggered()), this, SLOT(hgTag()));
jtkorhonen@34 1372 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
jtkorhonen@0 1373
jtkorhonen@0 1374 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@69 1375 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
jtkorhonen@0 1376
jtkorhonen@0 1377 connect(hgInitAct, SIGNAL(triggered()), this, SLOT(hgInit()));
jtkorhonen@0 1378 connect(hgCloneFromRemoteAct, SIGNAL(triggered()), this, SLOT(hgCloneFromRemote()));
jtkorhonen@0 1379 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
jtkorhonen@0 1380 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
jtkorhonen@0 1381 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
jtkorhonen@0 1382
Chris@109 1383 // connect(hgTabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
jtkorhonen@0 1384
jtkorhonen@0 1385 connect(hgUpdateToRevAct, SIGNAL(triggered()), this, SLOT(hgUpdateToRev()));
jtkorhonen@0 1386 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
jtkorhonen@0 1387 connect(hgResolveListAct, SIGNAL(triggered()), this, SLOT(hgResolveList()));
jtkorhonen@0 1388 connect(hgResolveMarkAct, SIGNAL(triggered()), this, SLOT(hgResolveMark()));
jtkorhonen@11 1389 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
Chris@94 1390 connect(clearSelectionsAct, SIGNAL(triggered()), this, SLOT(clearSelections()));
jtkorhonen@0 1391 }
Chris@109 1392 /*!!!
jtkorhonen@0 1393 void MainWindow::tabChanged(int currTab)
jtkorhonen@0 1394 {
jtkorhonen@0 1395 tabPage = currTab;
jtkorhonen@32 1396
jtkorhonen@0 1397 }
Chris@109 1398 */
jtkorhonen@0 1399 void MainWindow::enableDisableActions()
jtkorhonen@0 1400 {
Chris@90 1401 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 1402
Chris@115 1403 //!!! should also do things like set the status texts for the
Chris@115 1404 //!!! actions appropriately by context
Chris@115 1405
jtkorhonen@0 1406 QDir localRepoDir;
jtkorhonen@0 1407 QDir workFolderDir;
jtkorhonen@0 1408 bool workFolderExist;
jtkorhonen@0 1409 bool localRepoExist;
jtkorhonen@0 1410
jtkorhonen@0 1411 remoteRepoActionsEnabled = true;
Chris@90 1412 if (remoteRepoPath.isEmpty()) {
jtkorhonen@0 1413 remoteRepoActionsEnabled = false;
jtkorhonen@0 1414 }
jtkorhonen@0 1415
jtkorhonen@0 1416 localRepoActionsEnabled = true;
Chris@90 1417 if (workFolderPath.isEmpty()) {
jtkorhonen@0 1418 localRepoActionsEnabled = false;
jtkorhonen@0 1419 workFolderExist = false;
jtkorhonen@0 1420 }
jtkorhonen@0 1421
Chris@90 1422 if (!workFolderDir.exists(workFolderPath)) {
jtkorhonen@0 1423 localRepoActionsEnabled = false;
jtkorhonen@0 1424 workFolderExist = false;
Chris@90 1425 } else {
jtkorhonen@0 1426 workFolderExist = true;
jtkorhonen@0 1427 }
jtkorhonen@0 1428
Chris@112 1429 if (!localRepoDir.exists(workFolderPath + "/.hg")) {
jtkorhonen@0 1430 localRepoActionsEnabled = false;
jtkorhonen@0 1431 localRepoExist = false;
jtkorhonen@0 1432 }
jtkorhonen@0 1433
jtkorhonen@0 1434 hgCloneFromRemoteAct -> setEnabled(remoteRepoActionsEnabled);
jtkorhonen@0 1435 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1436 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1437 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
Chris@73 1438 /*
jtkorhonen@0 1439 if (tabPage != WORKTAB)
jtkorhonen@0 1440 {
jtkorhonen@0 1441 localRepoActionsEnabled = false;
jtkorhonen@0 1442 }
Chris@73 1443 */
Chris@112 1444 bool haveDiff = (diffBinaryName != "");
Chris@112 1445
jtkorhonen@0 1446 hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true));
Chris@120 1447 hgRefreshAct -> setEnabled(localRepoActionsEnabled);
Chris@112 1448 hgFileDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
Chris@112 1449 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
jtkorhonen@0 1450 hgRevertAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1451 hgAddAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1452 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1453 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1454 hgCommitAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1455 hgMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@33 1456 hgRetryMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1457 hgResolveListAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1458 hgResolveMarkAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1459 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@11 1460 hgServeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1461 hgTagAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1462 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1463
Chris@98 1464 //!!!hgTabs -> enableDisableOtherTabs(tabPage);
jtkorhonen@0 1465
Chris@90 1466 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
Chris@98 1467 DEBUG << "canCommit = " << hgTabs->canCommit() << endl;
Chris@90 1468
Chris@90 1469 //!!! new stuff:
Chris@98 1470 hgAddAct->setEnabled(localRepoActionsEnabled && hgTabs->canAdd());
Chris@98 1471 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
Chris@98 1472 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
Chris@98 1473 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
Chris@98 1474 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDoDiff());
Chris@90 1475
Chris@108 1476 // A default merge makes sense if:
Chris@108 1477 // * there is only one parent (if there are two, we have an uncommitted merge) and
Chris@108 1478 // * there are exactly two heads that have the same branch as the current branch and
Chris@108 1479 // * our parent is one of those heads
Chris@108 1480 //
Chris@108 1481 // A default update makes sense if:
Chris@108 1482 // * there is only one parent and
Chris@108 1483 // * the parent is not one of the current heads
Chris@108 1484 //!!! test this
Chris@108 1485 bool canMerge = false;
Chris@108 1486 bool canUpdate = false;
Chris@108 1487 if (currentParents.size() == 1) {
Chris@108 1488 Changeset *parent = currentParents[0];
Chris@108 1489 int currentBranchHeads = 0;
Chris@108 1490 bool parentIsHead = false;
Chris@108 1491 foreach (Changeset *head, currentHeads) {
Chris@108 1492 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
Chris@108 1493 if (head->isOnBranch(currentBranch)) {
Chris@108 1494 ++currentBranchHeads;
Chris@108 1495 if (parent->id() == head->id()) {
Chris@108 1496 parentIsHead = true;
Chris@108 1497 }
Chris@108 1498 }
Chris@108 1499 }
Chris@108 1500 if (currentBranchHeads == 2 && parentIsHead) {
Chris@108 1501 canMerge = true;
Chris@108 1502 }
Chris@108 1503 if (!parentIsHead) {
Chris@108 1504 canUpdate = true;
Chris@108 1505 DEBUG << "parent id = " << parent->id() << endl;
Chris@108 1506 DEBUG << " head ids "<<endl;
Chris@108 1507 foreach (Changeset *h, currentHeads) {
Chris@108 1508 DEBUG << "head id = " << h->id() << endl;
Chris@108 1509 }
Chris@108 1510 }
Chris@108 1511 }
Chris@108 1512 hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge);
Chris@108 1513 hgUpdateAct->setEnabled(localRepoActionsEnabled && canUpdate);
Chris@115 1514
Chris@129 1515 QStringList ids;
Chris@129 1516 foreach (Changeset *cs, currentParents) ids.push_back(cs->id());
Chris@129 1517 hgTabs->setCurrent(ids);
Chris@129 1518 hgTabs->showUncommittedChanges(hgTabs->canCommit());
Chris@129 1519
Chris@115 1520 // Set the state field on the file status widget
Chris@115 1521
Chris@115 1522 QString branchText;
Chris@115 1523 if (currentBranch == "" || currentBranch == "default") {
Chris@115 1524 branchText = tr("the default branch");
Chris@115 1525 } else {
Chris@115 1526 branchText = tr("branch \"%1\"").arg(currentBranch);
Chris@115 1527 }
Chris@115 1528 if (canUpdate) {
Chris@115 1529 hgTabs->setState(tr("On %1. Not at the head of the branch: consider updating").arg(branchText));
Chris@115 1530 } else if (canMerge) {
Chris@115 1531 hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
Chris@115 1532 } else {
Chris@115 1533 hgTabs->setState(tr("At the head of %1").arg(branchText));
Chris@115 1534 }
jtkorhonen@0 1535 }
jtkorhonen@0 1536
jtkorhonen@0 1537 void MainWindow::createActions()
jtkorhonen@0 1538 {
jtkorhonen@0 1539 //File actions
jtkorhonen@0 1540 hgInitAct = new QAction(tr("Init local repository"), this);
jtkorhonen@0 1541 hgInitAct->setStatusTip(tr("Create an empty local repository in selected folder"));
jtkorhonen@0 1542
jtkorhonen@0 1543 hgCloneFromRemoteAct = new QAction(tr("Clone from remote"), this);
jtkorhonen@0 1544 hgCloneFromRemoteAct->setStatusTip(tr("Clone from remote repository into local repository in selected folder"));
jtkorhonen@0 1545
Chris@69 1546 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
Chris@69 1547 openAct -> setStatusTip(tr("Open repository"));
Chris@69 1548 openAct -> setIconVisibleInMenu(true);
Chris@69 1549
jtkorhonen@0 1550 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
jtkorhonen@0 1551 settingsAct -> setStatusTip(tr("View and change application settings"));
jtkorhonen@0 1552 settingsAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1553
jtkorhonen@0 1554 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Exit"), this);
jtkorhonen@0 1555 exitAct->setShortcuts(QKeySequence::Quit);
jtkorhonen@0 1556 exitAct->setStatusTip(tr("Exit application"));
jtkorhonen@0 1557 exitAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1558
jtkorhonen@0 1559 //Repository actions
Chris@120 1560 hgRefreshAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
Chris@120 1561 hgRefreshAct->setStatusTip(tr("Refresh (info of) status of workfolder files"));
Chris@61 1562
Chris@61 1563 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
jtkorhonen@0 1564 hgIncomingAct -> setStatusTip(tr("View info of changesets incoming to us from remote repository (on pull operation)"));
jtkorhonen@0 1565
Chris@61 1566 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
jtkorhonen@0 1567 hgPullAct -> setStatusTip(tr("Pull changesets from remote repository to local repository"));
jtkorhonen@0 1568
Chris@61 1569 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
jtkorhonen@0 1570 hgPushAct->setStatusTip(tr("Push local changesets to remote repository"));
jtkorhonen@0 1571
jtkorhonen@0 1572 //Workfolder actions
Chris@61 1573 hgFileDiffAct = new QAction(QIcon(":/images/diff.png"), tr("Diff"), this);
jtkorhonen@0 1574 hgFileDiffAct->setStatusTip(tr("Filediff: View differences between selected working folder file and local repository file"));
jtkorhonen@0 1575
Chris@99 1576 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
jtkorhonen@0 1577 hgFolderDiffAct->setStatusTip(tr("Folderdiff: View all differences between working folder files and local repository files"));
jtkorhonen@0 1578
jtkorhonen@0 1579 hgChgSetDiffAct = new QAction(QIcon(":/images/chgsetdiff.png"), tr("View changesetdiff"), this);
jtkorhonen@0 1580 hgChgSetDiffAct->setStatusTip(tr("Change set diff: View differences between all files of 2 repository changesets"));
jtkorhonen@0 1581
Chris@61 1582 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
jtkorhonen@0 1583 hgRevertAct->setStatusTip(tr("Undo selected working folder file changes (return to local repository version)"));
jtkorhonen@0 1584
Chris@61 1585 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
jtkorhonen@17 1586 hgAddAct -> setStatusTip(tr("Add working folder file(s) (selected or all yet untracked) to local repository (on next commit)"));
jtkorhonen@0 1587
Chris@61 1588 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
jtkorhonen@0 1589 hgRemoveAct -> setStatusTip(tr("Remove selected working folder file from local repository (on next commit)"));
jtkorhonen@0 1590
Chris@61 1591 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
jtkorhonen@0 1592 hgUpdateAct->setStatusTip(tr("Update working folder from local repository"));
jtkorhonen@0 1593
Chris@61 1594 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
jtkorhonen@20 1595 hgCommitAct->setStatusTip(tr("Save selected file(s) or all changed files in working folder (and all subfolders) to local repository"));
jtkorhonen@0 1596
jtkorhonen@0 1597 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
jtkorhonen@0 1598 hgMergeAct->setStatusTip(tr("Merge two local repository changesets to working folder"));
jtkorhonen@0 1599
jtkorhonen@0 1600 //Advanced actions
jtkorhonen@0 1601 hgUpdateToRevAct = new QAction(tr("Update to revision"), this);
jtkorhonen@0 1602 hgUpdateToRevAct -> setStatusTip(tr("Update working folder to version selected from history list"));
jtkorhonen@0 1603
jtkorhonen@0 1604 hgAnnotateAct = new QAction(tr("Annotate"), this);
jtkorhonen@0 1605 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
jtkorhonen@0 1606
jtkorhonen@0 1607 hgResolveListAct = new QAction(tr("Resolve (list)"), this);
jtkorhonen@0 1608 hgResolveListAct -> setStatusTip(tr("Resolve (list): Show list of files needing merge"));
jtkorhonen@0 1609
jtkorhonen@0 1610 hgResolveMarkAct = new QAction(tr("Resolve (mark)"), this);
jtkorhonen@0 1611 hgResolveMarkAct -> setStatusTip(tr("Resolve (mark): Mark selected file status as resolved"));
jtkorhonen@0 1612
jtkorhonen@33 1613 hgRetryMergeAct = new QAction(tr("Retry merge"), this);
jtkorhonen@33 1614 hgRetryMergeAct -> setStatusTip(tr("Retry merge after failed merge attempt."));
jtkorhonen@33 1615
jtkorhonen@34 1616 hgTagAct = new QAction(tr("Tag revision"), this);
jtkorhonen@34 1617 hgTagAct -> setStatusTip(tr("Give decsriptive name (tag) to current workfolder parent revision."));
jtkorhonen@34 1618
jtkorhonen@34 1619 hgIgnoreAct = new QAction(tr("Edit .hgignore"), this);
jtkorhonen@34 1620 hgIgnoreAct -> setStatusTip(tr("Edit .hgignore file (file contains names of files that should be ignored by mercurial)"));
jtkorhonen@34 1621
jtkorhonen@11 1622 hgServeAct = new QAction(tr("Serve (via http)"), this);
jtkorhonen@11 1623 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
jtkorhonen@11 1624
jtkorhonen@0 1625 //Help actions
jtkorhonen@0 1626 aboutAct = new QAction(tr("About"), this);
jtkorhonen@0 1627 aboutAct->setStatusTip(tr("Show the application's About box"));
jtkorhonen@0 1628
jtkorhonen@0 1629 aboutQtAct = new QAction(tr("About Qt"), this);
jtkorhonen@0 1630 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
Chris@94 1631
Chris@94 1632 // Miscellaneous
Chris@94 1633 clearSelectionsAct = new QAction(tr("Clear selections"), this);
Chris@94 1634 clearSelectionsAct->setShortcut(Qt::Key_Escape);
jtkorhonen@0 1635 }
jtkorhonen@0 1636
jtkorhonen@0 1637 void MainWindow::createMenus()
jtkorhonen@0 1638 {
jtkorhonen@0 1639 fileMenu = menuBar()->addMenu(tr("File"));
Chris@131 1640 /* fileMenu -> addAction(hgInitAct);
jtkorhonen@0 1641 fileMenu -> addAction(hgCloneFromRemoteAct);
Chris@94 1642 fileMenu->addAction(clearSelectionsAct); //!!! can't live here!
jtkorhonen@0 1643 fileMenu -> addSeparator();
Chris@131 1644 */
Chris@69 1645 fileMenu -> addAction(openAct);
jtkorhonen@0 1646 fileMenu -> addAction(settingsAct);
jtkorhonen@0 1647 fileMenu -> addSeparator();
jtkorhonen@0 1648 fileMenu -> addAction(exitAct);
jtkorhonen@0 1649
jtkorhonen@0 1650 advancedMenu = menuBar()->addMenu(tr("Advanced"));
Chris@131 1651 /*
jtkorhonen@0 1652 advancedMenu -> addAction(hgUpdateToRevAct);
jtkorhonen@0 1653 advancedMenu -> addSeparator();
jtkorhonen@0 1654 advancedMenu -> addAction(hgAnnotateAct);
jtkorhonen@0 1655 advancedMenu -> addSeparator();
jtkorhonen@33 1656 advancedMenu -> addAction(hgRetryMergeAct);
jtkorhonen@0 1657 advancedMenu -> addAction(hgResolveListAct);
jtkorhonen@0 1658 advancedMenu -> addAction(hgResolveMarkAct);
jtkorhonen@11 1659 advancedMenu -> addSeparator();
jtkorhonen@34 1660 advancedMenu -> addAction(hgTagAct);
jtkorhonen@34 1661 advancedMenu -> addSeparator();
Chris@131 1662 */
jtkorhonen@34 1663 advancedMenu -> addAction(hgIgnoreAct);
jtkorhonen@34 1664 advancedMenu -> addSeparator();
jtkorhonen@11 1665 advancedMenu -> addAction(hgServeAct);
jtkorhonen@0 1666
jtkorhonen@0 1667 helpMenu = menuBar()->addMenu(tr("Help"));
jtkorhonen@0 1668 helpMenu->addAction(aboutAct);
Chris@128 1669 //!!! helpMenu->addAction(aboutQtAct);
jtkorhonen@0 1670 }
jtkorhonen@0 1671
jtkorhonen@0 1672 void MainWindow::createToolBars()
jtkorhonen@0 1673 {
jtkorhonen@0 1674 fileToolBar = addToolBar(tr("File"));
jtkorhonen@0 1675 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@69 1676 fileToolBar -> addAction(openAct);
Chris@120 1677 fileToolBar -> addAction(hgRefreshAct);
jtkorhonen@0 1678 fileToolBar -> addSeparator();
Chris@61 1679 // fileToolBar -> addAction(hgChgSetDiffAct);
jtkorhonen@0 1680 fileToolBar -> setMovable(false);
jtkorhonen@0 1681
jtkorhonen@0 1682 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
jtkorhonen@0 1683 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
jtkorhonen@0 1684 repoToolBar->addAction(hgIncomingAct);
jtkorhonen@0 1685 repoToolBar->addAction(hgPullAct);
jtkorhonen@0 1686 repoToolBar->addAction(hgPushAct);
jtkorhonen@0 1687 repoToolBar -> setMovable(false);
jtkorhonen@0 1688
jtkorhonen@0 1689 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
jtkorhonen@0 1690 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
jtkorhonen@0 1691 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@61 1692 // workFolderToolBar->addSeparator();
Chris@95 1693 // workFolderToolBar->addAction(hgFileDiffAct);
Chris@95 1694 workFolderToolBar->addAction(hgFolderDiffAct);
jtkorhonen@0 1695 workFolderToolBar->addSeparator();
jtkorhonen@0 1696 workFolderToolBar->addAction(hgRevertAct);
jtkorhonen@0 1697 workFolderToolBar->addAction(hgUpdateAct);
jtkorhonen@0 1698 workFolderToolBar->addAction(hgCommitAct);
jtkorhonen@0 1699 workFolderToolBar->addAction(hgMergeAct);
jtkorhonen@0 1700 workFolderToolBar->addSeparator();
jtkorhonen@0 1701 workFolderToolBar->addAction(hgAddAct);
jtkorhonen@0 1702 workFolderToolBar->addAction(hgRemoveAct);
jtkorhonen@0 1703 workFolderToolBar -> setMovable(false);
Chris@61 1704
Chris@61 1705 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@61 1706 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Chris@61 1707 }
jtkorhonen@0 1708 }
jtkorhonen@0 1709
jtkorhonen@0 1710
jtkorhonen@0 1711 void MainWindow::createStatusBar()
jtkorhonen@0 1712 {
jtkorhonen@0 1713 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 1714 }
jtkorhonen@0 1715
Chris@69 1716
Chris@69 1717 //!!! review these:
Chris@69 1718
jtkorhonen@0 1719 void MainWindow::readSettings()
jtkorhonen@0 1720 {
jtkorhonen@0 1721 QDir workFolder;
jtkorhonen@0 1722
Chris@61 1723 QSettings settings;
jtkorhonen@0 1724
jtkorhonen@30 1725 remoteRepoPath = settings.value("remoterepopath", "").toString();
jtkorhonen@0 1726 workFolderPath = settings.value("workfolderpath", "").toString();
jtkorhonen@0 1727 if (!workFolder.exists(workFolderPath))
jtkorhonen@0 1728 {
jtkorhonen@0 1729 workFolderPath = "";
jtkorhonen@0 1730 }
jtkorhonen@0 1731
jtkorhonen@0 1732 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
jtkorhonen@0 1733 QSize size = settings.value("size", QSize(400, 400)).toSize();
jtkorhonen@0 1734 firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 1735
Chris@109 1736 //!!! initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
jtkorhonen@0 1737 resize(size);
jtkorhonen@0 1738 move(pos);
jtkorhonen@0 1739 }
jtkorhonen@0 1740
jtkorhonen@17 1741
jtkorhonen@0 1742 void MainWindow::writeSettings()
jtkorhonen@0 1743 {
Chris@61 1744 QSettings settings;
jtkorhonen@0 1745 settings.setValue("pos", pos());
jtkorhonen@0 1746 settings.setValue("size", size());
jtkorhonen@0 1747 settings.setValue("remoterepopath", remoteRepoPath);
jtkorhonen@0 1748 settings.setValue("workfolderpath", workFolderPath);
jtkorhonen@0 1749 settings.setValue("firststart", firstStart);
Chris@98 1750 //!!!settings.setValue("viewFileTypes", hgTabs -> getFileTypesBits());
jtkorhonen@0 1751 }
jtkorhonen@0 1752
jtkorhonen@0 1753
jtkorhonen@0 1754
jtkorhonen@0 1755