annotate mainwindow.cpp @ 197:2afac743acdf

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