annotate mainwindow.cpp @ 198:4adbd5c9c15d

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