annotate mainwindow.cpp @ 152:2b997861174b

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