annotate mainwindow.cpp @ 177:bb89bcd8986b

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