annotate mainwindow.cpp @ 291:2e34e7ee7baf more_information_dialog

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