annotate mainwindow.cpp @ 326:6e1fdda1dff2 filelist_right_button_menu

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