annotate mainwindow.cpp @ 308:7f50c040e13d new-branches-with-status-outside-tabs

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