annotate mainwindow.cpp @ 163:5c262ac73948

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