annotate mainwindow.cpp @ 184:1220f26d6f35

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