annotate mainwindow.cpp @ 174:4dc802a4d5ae

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