annotate mainwindow.cpp @ 287:3fbafca196e4 status_outside_tabs

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