annotate mainwindow.cpp @ 122:c3e8342d2de9

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