annotate mainwindow.cpp @ 112:4bd17f36d059

* Make diff binary a settings property; some tidying
author Chris Cannam
date Fri, 26 Nov 2010 17:02:55 +0000
parents 1721c580c10e
children 5fc7b4fc77a8
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
jtkorhonen@0 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@98 6 Based on hgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
Chris@50 17
jtkorhonen@0 18 #include <QStringList>
jtkorhonen@0 19 #include <QDir>
jtkorhonen@24 20 #include <QNetworkInterface>
jtkorhonen@17 21 #include <QHostAddress>
jtkorhonen@17 22 #include <QHostInfo>
jtkorhonen@34 23 #include <QDesktopServices>
Chris@50 24 #include <QStatusBar>
Chris@50 25 #include <QMessageBox>
Chris@50 26 #include <QMenuBar>
Chris@50 27 #include <QApplication>
Chris@50 28 #include <QToolBar>
Chris@61 29 #include <QToolButton>
Chris@50 30 #include <QSettings>
Chris@90 31 #include <QInputDialog>
jtkorhonen@0 32
Chris@53 33 #include "mainwindow.h"
Chris@69 34 #include "multichoicedialog.h"
Chris@64 35 #include "startupdialog.h"
Chris@53 36 #include "colourset.h"
Chris@62 37 #include "debug.h"
Chris@74 38 #include "logparser.h"
Chris@103 39 #include "confirmcommentdialog.h"
Chris@53 40
jtkorhonen@0 41
jtkorhonen@0 42 MainWindow::MainWindow()
jtkorhonen@0 43 {
jtkorhonen@0 44 QString wndTitle;
jtkorhonen@0 45
Chris@90 46 fsWatcher = 0;
Chris@90 47
jtkorhonen@0 48 createActions();
jtkorhonen@0 49 createMenus();
jtkorhonen@0 50 createToolBars();
jtkorhonen@0 51 createStatusBar();
jtkorhonen@0 52
jtkorhonen@0 53 runner = new HgRunner(this);
Chris@109 54 connect(runner, SIGNAL(commandCompleted(HgAction, QString)),
Chris@109 55 this, SLOT(commandCompleted(HgAction, QString)));
Chris@109 56 connect(runner, SIGNAL(commandFailed(HgAction, QString)),
Chris@109 57 this, SLOT(commandFailed(HgAction, QString)));
jtkorhonen@0 58 statusBar()->addPermanentWidget(runner);
jtkorhonen@0 59
Chris@61 60 setWindowTitle(tr("EasyMercurial"));
jtkorhonen@0 61
jtkorhonen@0 62 remoteRepoPath = "";
jtkorhonen@0 63 workFolderPath = "";
jtkorhonen@0 64
jtkorhonen@0 65 readSettings();
jtkorhonen@0 66
Chris@109 67 // tabPage = 0;
jtkorhonen@33 68 justMerged = false;
Chris@98 69 hgTabs = new HgTabWidget((QWidget *) this, remoteRepoPath, workFolderPath);
Chris@98 70 setCentralWidget(hgTabs);
jtkorhonen@0 71
Chris@98 72 connect(hgTabs, SIGNAL(selectionChanged()),
Chris@95 73 this, SLOT(enableDisableActions()));
Chris@95 74
jtkorhonen@0 75 setUnifiedTitleAndToolBarOnMac(true);
jtkorhonen@0 76 connectActions();
jtkorhonen@0 77 enableDisableActions();
jtkorhonen@0 78
Chris@64 79 if (firstStart) {
Chris@64 80 startupDialog();
jtkorhonen@0 81 }
jtkorhonen@0 82
Chris@112 83 findDiffBinaryName();
Chris@112 84
Chris@64 85 ColourSet *cs = ColourSet::instance();
Chris@64 86 cs->clearDefaultNames();
Chris@64 87 cs->addDefaultName("");
Chris@64 88 cs->addDefaultName(getUserInfo());
Chris@62 89
Chris@72 90 if (workFolderPath == "") {
Chris@72 91 open();
Chris@72 92 }
Chris@72 93
Chris@109 94 hgQueryPaths();
jtkorhonen@0 95 }
jtkorhonen@0 96
jtkorhonen@0 97
jtkorhonen@0 98 void MainWindow::closeEvent(QCloseEvent *)
jtkorhonen@0 99 {
jtkorhonen@0 100 writeSettings();
Chris@90 101 delete fsWatcher;
jtkorhonen@0 102 }
jtkorhonen@0 103
jtkorhonen@0 104
Chris@64 105 QString MainWindow::getUserInfo() const
Chris@64 106 {
Chris@64 107 QSettings settings;
Chris@64 108 settings.beginGroup("User Information");
Chris@64 109 QString name = settings.value("name", getUserRealName()).toString();
Chris@64 110 QString email = settings.value("email", "").toString();
Chris@64 111
Chris@64 112 QString identifier;
Chris@64 113
Chris@64 114 if (email != "") {
Chris@64 115 identifier = QString("%1 <%2>").arg(name).arg(email);
Chris@64 116 } else {
Chris@64 117 identifier = name;
Chris@64 118 }
Chris@64 119
Chris@64 120 return identifier;
Chris@64 121 }
Chris@64 122
jtkorhonen@0 123 void MainWindow::about()
jtkorhonen@0 124 {
Chris@97 125 QMessageBox::about(this, tr("About EasyMercurial"),
Chris@97 126 tr("<qt><h2>About EasyMercurial</h2>"
Chris@97 127 "<p>EasyMercurial is a simple user interface for the "
Chris@97 128 "Mercurial version control system.</p>"
Chris@98 129 "<p>EasyMercurial is based on hgExplorer by "
Chris@97 130 "Jari Korhonen, with thanks.<br>EasyMercurial development carried out by "
Chris@97 131 "Chris Cannam for soundsoftware.ac.uk at the Centre for Digital Music, Queen Mary, University of London."
Chris@97 132 "<ul><li>Copyright &copy; 2010 Jari Korhonen</li>"
Chris@97 133 "<li>Copyright &copy; 2010 Chris Cannam</li>"
Chris@97 134 "<li>Copyright &copy; 2010 Queen Mary, University of London</li>"
Chris@97 135 "</ul>"
Chris@97 136 "<p> This program is free software; you can redistribute it and/or "
Chris@97 137 "modify it under the terms of the GNU General Public License as "
Chris@97 138 "published by the Free Software Foundation; either version 2 of the "
Chris@97 139 "License, or (at your option) any later version. See the file "
Chris@97 140 "COPYING included with this distribution for more information."));
jtkorhonen@0 141 }
jtkorhonen@0 142
Chris@94 143 void MainWindow::clearSelections()
Chris@94 144 {
Chris@98 145 hgTabs->clearSelections();
Chris@94 146 }
jtkorhonen@0 147
jtkorhonen@0 148 void MainWindow::hgStat()
jtkorhonen@0 149 {
Chris@109 150 QStringList params;
Chris@109 151 params << "stat" << "-ardum";
Chris@109 152 runner->requestAction(HgAction(ACT_STAT, workFolderPath, params));
jtkorhonen@0 153 }
jtkorhonen@0 154
Chris@109 155 void MainWindow::hgQueryPaths()
Chris@74 156 {
Chris@109 157 QStringList params;
Chris@109 158 params << "paths";
Chris@109 159 runner->requestAction(HgAction(ACT_QUERY_PATHS, workFolderPath, params));
Chris@74 160 }
Chris@74 161
Chris@109 162 void MainWindow::hgQueryBranch()
Chris@106 163 {
Chris@109 164 QStringList params;
Chris@109 165 params << "branch";
Chris@109 166 runner->requestAction(HgAction(ACT_QUERY_BRANCH, workFolderPath, params));
Chris@106 167 }
Chris@106 168
Chris@109 169 void MainWindow::hgQueryHeads()
jtkorhonen@0 170 {
Chris@109 171 QStringList params;
Chris@109 172 params << "heads";
Chris@109 173 // on empty repos, "hg heads" will fail -- we don't care about that.
Chris@109 174 runner->requestAction(HgAction(ACT_QUERY_HEADS, workFolderPath, params));
jtkorhonen@0 175 }
jtkorhonen@0 176
jtkorhonen@0 177 void MainWindow::hgLog()
jtkorhonen@0 178 {
Chris@90 179 //!!! This needs to be incremental, except when we pull or set new repo
Chris@109 180 QStringList params;
Chris@109 181 params << "log";
Chris@109 182 params << "--template";
Chris@109 183 params << "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tag}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n";
Chris@109 184
Chris@109 185 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
Chris@109 186 }
Chris@109 187
Chris@109 188
Chris@109 189 void MainWindow::hgQueryParents()
Chris@109 190 {
Chris@109 191 QStringList params;
Chris@109 192 params << "parents";
Chris@109 193 runner->requestAction(HgAction(ACT_QUERY_PARENTS, workFolderPath, params));
Chris@109 194 }
Chris@109 195
Chris@109 196 void MainWindow::hgAnnotate()
Chris@109 197 {
Chris@109 198 QStringList params;
Chris@109 199 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
Chris@109 200
Chris@109 201 if (!currentFile.isEmpty())
jtkorhonen@0 202 {
Chris@109 203 params << "annotate" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 204
Chris@109 205 runner->requestAction(HgAction(ACT_ANNOTATE, workFolderPath, params));
jtkorhonen@0 206 }
jtkorhonen@0 207 }
jtkorhonen@0 208
Chris@109 209 void MainWindow::hgResolveMark()
Chris@109 210 {
Chris@109 211 QStringList params;
Chris@109 212 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
jtkorhonen@0 213
Chris@109 214 if (!currentFile.isEmpty())
jtkorhonen@0 215 {
Chris@109 216 params << "resolve" << "--mark" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@0 217
Chris@109 218 runner->requestAction(HgAction(ACT_RESOLVE_MARK, workFolderPath, params));
jtkorhonen@0 219 }
jtkorhonen@0 220 }
jtkorhonen@0 221
Chris@109 222 void MainWindow::hgResolveList()
Chris@109 223 {
Chris@109 224 QStringList params;
jtkorhonen@0 225
Chris@109 226 params << "resolve" << "--list";
Chris@109 227 runner->requestAction(HgAction(ACT_RESOLVE_LIST, workFolderPath, params));
Chris@109 228 }
Chris@109 229
Chris@109 230 void MainWindow::hgAdd()
jtkorhonen@0 231 {
Chris@109 232 QStringList params;
jtkorhonen@0 233
Chris@109 234 // hgExplorer permitted adding "all" files -- I'm not sure
Chris@109 235 // that one is a good idea, let's require the user to select
jtkorhonen@0 236
Chris@109 237 QStringList files = hgTabs->getSelectedAddableFiles();
Chris@109 238
Chris@109 239 if (!files.empty()) {
Chris@109 240 params << "add" << "--" << files;
Chris@109 241 runner->requestAction(HgAction(ACT_ADD, workFolderPath, params));
jtkorhonen@0 242 }
jtkorhonen@0 243 }
jtkorhonen@0 244
jtkorhonen@0 245
Chris@98 246 void MainWindow::hgRemove()
Chris@98 247 {
Chris@109 248 QStringList params;
Chris@98 249
Chris@109 250 QStringList files = hgTabs->getSelectedRemovableFiles();
Chris@98 251
Chris@109 252 //!!! todo: confirmation dialog (with file list in it) (or do we
Chris@109 253 // need that? all it does is move the files to the removed
Chris@109 254 // list... doesn't it?)
Chris@98 255
Chris@109 256 if (!files.empty()) {
Chris@109 257 params << "remove" << "--after" << "--force" << "--" << files;
Chris@109 258 runner->requestAction(HgAction(ACT_REMOVE, workFolderPath, params));
Chris@109 259 }
Chris@98 260
Chris@91 261 /*!!!
Chris@98 262 QString currentFile;//!!! = hgTabs -> getCurrentFileListLine();
Chris@98 263
Chris@98 264 if (!currentFile.isEmpty())
jtkorhonen@5 265 {
Chris@98 266 if (QMessageBox::Ok == QMessageBox::warning(this, "Remove file", "Really remove file " + currentFile.mid(2) + "?",
Chris@98 267 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel))
Chris@98 268 {
Chris@98 269 params << "remove" << "--after" << "--force" << "--" << currentFile.mid(2); //Jump over status marker characters (e.g "M ")
jtkorhonen@17 270
Chris@98 271 runner -> startHgCommand(workFolderPath, params);
Chris@98 272 runningAction = ACT_REMOVE;
jtkorhonen@17 273 }
jtkorhonen@5 274 }
Chris@98 275 */
jtkorhonen@0 276 }
jtkorhonen@0 277
jtkorhonen@0 278 void MainWindow::hgCommit()
jtkorhonen@0 279 {
Chris@109 280 QStringList params;
Chris@109 281 QString comment;
Chris@94 282
Chris@109 283 QStringList files = hgTabs->getSelectedCommittableFiles();
Chris@109 284 if (files.empty()) files = hgTabs->getAllCommittableFiles();
Chris@103 285
Chris@109 286 if (ConfirmCommentDialog::confirmAndGetLongComment
Chris@109 287 (this,
Chris@109 288 tr("Commit files"),
Chris@112 289 tr("<h3>Commit files</h3><p>You are about to commit the following files:"),
Chris@112 290 tr("<h3>Commit files</h3><p>You are about to commit %1 files."),
Chris@109 291 files,
Chris@109 292 comment)) {
Chris@103 293
Chris@109 294 if ((justMerged == false) && //!!! review usage of justMerged, and how it interacts with asynchronous request queue
Chris@109 295 !files.empty()) {
Chris@109 296 // User wants to commit selected file(s) (and this is not merge commit, which would fail if we selected files)
Chris@109 297 params << "commit" << "--message" << comment << "--user" << getUserInfo() << "--" << files;
Chris@109 298 } else {
Chris@109 299 // Commit all changes
Chris@109 300 params << "commit" << "--message" << comment << "--user" << getUserInfo();
jtkorhonen@0 301 }
Chris@109 302
Chris@109 303 runner->requestAction(HgAction(ACT_COMMIT, workFolderPath, params));
jtkorhonen@0 304 }
jtkorhonen@0 305 }
jtkorhonen@0 306
jtkorhonen@34 307 QString MainWindow::filterTag(QString tag)
jtkorhonen@34 308 {
jtkorhonen@34 309 for(int i = 0; i < tag.size(); i++)
jtkorhonen@34 310 {
jtkorhonen@34 311 if (tag[i].isLower() || tag[i].isUpper() || tag[i].isDigit() || (tag[i] == QChar('.')))
jtkorhonen@34 312 {
jtkorhonen@34 313 //ok
jtkorhonen@34 314 }
jtkorhonen@34 315 else
jtkorhonen@34 316 {
jtkorhonen@34 317 tag[i] = QChar('_');
jtkorhonen@34 318 }
jtkorhonen@34 319 }
jtkorhonen@34 320 return tag;
jtkorhonen@34 321 }
jtkorhonen@34 322
jtkorhonen@34 323
jtkorhonen@34 324 void MainWindow::hgTag()
jtkorhonen@34 325 {
Chris@109 326 QStringList params;
Chris@109 327 QString tag;
jtkorhonen@34 328
Chris@109 329 if (ConfirmCommentDialog::confirmAndGetShortComment
Chris@109 330 (this,
Chris@109 331 tr("Tag"),
Chris@109 332 tr("Enter tag:"),
Chris@109 333 tag)) {
Chris@109 334 if (!tag.isEmpty()) //!!! do something better if it is empty
Chris@109 335 {
Chris@109 336 params << "tag" << "--user" << getUserInfo() << filterTag(tag);
Chris@109 337
Chris@109 338 runner->requestAction(HgAction(ACT_TAG, workFolderPath, params));
jtkorhonen@34 339 }
jtkorhonen@34 340 }
jtkorhonen@34 341 }
jtkorhonen@34 342
jtkorhonen@34 343
jtkorhonen@34 344 void MainWindow::hgIgnore()
jtkorhonen@34 345 {
Chris@109 346 QString hgIgnorePath;
Chris@109 347 QStringList params;
Chris@109 348 QString editorName;
Chris@109 349
Chris@109 350 hgIgnorePath = workFolderPath;
Chris@109 351 hgIgnorePath += ".hgignore";
Chris@109 352
Chris@109 353 params << hgIgnorePath;
Chris@112 354
Chris@112 355 //!!!
Chris@112 356 #ifdef Q_OS_LINUX
Chris@112 357
Chris@109 358 editorName = "gedit";
Chris@112 359
Chris@112 360 #else
Chris@112 361
Chris@109 362 editorName = """C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe""";
Chris@112 363
Chris@112 364 #endif
jtkorhonen@34 365
Chris@109 366 HgAction action(ACT_HG_IGNORE, workFolderPath, params);
Chris@109 367 action.executable = editorName;
jtkorhonen@34 368
Chris@109 369 runner->requestAction(action);
jtkorhonen@34 370 }
jtkorhonen@34 371
Chris@112 372 void MainWindow::findDiffBinaryName()
Chris@112 373 {
Chris@112 374 QSettings settings;
Chris@112 375 QString diff = settings.value("extdiffbinary", "").toString();
Chris@112 376 if (diff == "") {
Chris@112 377 QStringList bases;
Chris@112 378 bases << "opendiff" << "kompare" << "kdiff3" << "meld";
Chris@112 379 bool found = false;
Chris@112 380 foreach (QString base, bases) {
Chris@112 381 diff = findExecutable(base);
Chris@112 382 if (diff != base) {
Chris@112 383 found = true;
Chris@112 384 break;
Chris@112 385 }
Chris@112 386 }
Chris@112 387 if (found) {
Chris@112 388 settings.setValue("extdiffbinary", diff);
Chris@112 389 } else {
Chris@112 390 diff = "";
Chris@112 391 }
Chris@112 392 }
Chris@112 393 diffBinaryName = diff;
Chris@112 394 }
jtkorhonen@34 395
jtkorhonen@0 396 void MainWindow::hgFileDiff()
jtkorhonen@0 397 {
jtkorhonen@0 398 QStringList params;
Chris@91 399 /*!!!
Chris@98 400 QString currentFile = hgTabs -> getCurrentFileListLine();
jtkorhonen@0 401
jtkorhonen@0 402 if (!currentFile.isEmpty())
jtkorhonen@0 403 {
jtkorhonen@0 404 //Diff parent file against working folder file
mg@41 405 params << "kdiff3" << "--" << currentFile.mid(2);
Chris@62 406 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 407 runningAction = ACT_FILEDIFF;
jtkorhonen@0 408 }
Chris@91 409 */
jtkorhonen@0 410 }
jtkorhonen@0 411
jtkorhonen@0 412
jtkorhonen@0 413 void MainWindow::hgFolderDiff()
jtkorhonen@0 414 {
Chris@112 415 if (diffBinaryName == "") return;
Chris@112 416
Chris@109 417 QStringList params;
jtkorhonen@0 418
Chris@112 419 // Diff parent against working folder (folder diff)
Chris@112 420
Chris@109 421 params << "--config" << "extensions.extdiff=" << "extdiff" << "-p";
Chris@112 422 params << diffBinaryName;
Chris@109 423
Chris@109 424 runner->requestAction(HgAction(ACT_FOLDERDIFF, workFolderPath, params));
jtkorhonen@0 425 }
jtkorhonen@0 426
jtkorhonen@0 427
jtkorhonen@0 428 void MainWindow::hgChgSetDiff()
jtkorhonen@0 429 {
jtkorhonen@0 430 QStringList params;
jtkorhonen@0 431
jtkorhonen@0 432 //Diff 2 history log versions against each other
jtkorhonen@0 433 QString revA;
jtkorhonen@0 434 QString revB;
Chris@91 435 /*!!!
Chris@98 436 hgTabs -> getHistoryDiffRevisions(revA, revB);
jtkorhonen@0 437
jtkorhonen@0 438 if ((!revA.isEmpty()) && (!revB.isEmpty()))
jtkorhonen@0 439 {
jtkorhonen@0 440 params << "kdiff3" << "--rev" << revA << "--rev" << revB;
Chris@62 441 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 442 runningAction = ACT_CHGSETDIFF;
jtkorhonen@0 443 }
jtkorhonen@0 444 else
jtkorhonen@0 445 {
jtkorhonen@0 446 QMessageBox::information(this, tr("Changeset diff"), tr("Please select two changesets from history list or heads list first."));
jtkorhonen@0 447 }
Chris@91 448 */
jtkorhonen@0 449 }
jtkorhonen@0 450
jtkorhonen@0 451
jtkorhonen@0 452
jtkorhonen@0 453 void MainWindow::hgUpdate()
jtkorhonen@0 454 {
Chris@109 455 QStringList params;
jtkorhonen@0 456
Chris@109 457 params << "update";
Chris@109 458
Chris@109 459 runner->requestAction(HgAction(ACT_UPDATE, workFolderPath, params));
jtkorhonen@0 460 }
jtkorhonen@0 461
jtkorhonen@0 462
jtkorhonen@0 463 void MainWindow::hgUpdateToRev()
jtkorhonen@0 464 {
jtkorhonen@0 465 QStringList params;
jtkorhonen@0 466 QString rev;
Chris@91 467 /*!!!
Chris@98 468 hgTabs -> getUpdateToRevRevision(rev);
jtkorhonen@0 469
Chris@98 470 hgTabs -> setCurrentIndex(WORKTAB);
jtkorhonen@0 471 enableDisableActions();
jtkorhonen@0 472
jtkorhonen@0 473 params << "update" << "--rev" << rev << "--clean";
jtkorhonen@0 474
Chris@62 475 runner -> startHgCommand(workFolderPath, params);
jtkorhonen@0 476
jtkorhonen@0 477 runningAction = ACT_UPDATE;
Chris@91 478 */
Chris@109 479
jtkorhonen@0 480 }
jtkorhonen@0 481
jtkorhonen@0 482
jtkorhonen@0 483 void MainWindow::hgRevert()
jtkorhonen@0 484 {
Chris@109 485 QStringList params;
Chris@109 486 QString comment;
Chris@98 487
Chris@109 488 QStringList files = hgTabs->getSelectedRevertableFiles();
Chris@109 489 if (files.empty()) files = hgTabs->getAllRevertableFiles();
Chris@109 490
Chris@109 491 if (ConfirmCommentDialog::confirmDangerousFilesAction
Chris@109 492 (this,
Chris@109 493 tr("Revert files"),
Chris@112 494 tr("<h3>Revert files</h3><p>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@112 495 tr("<h3>Revert files</h3><p>You are about to <b>revert</b> %1 files.<br><br>This will <b>throw away any changes</b> that you have made to these files but have not committed."),
Chris@109 496 files)) {
Chris@109 497
Chris@98 498 if (files.empty()) {
Chris@98 499 params << "revert" << "--no-backup";
Chris@98 500 } else {
Chris@98 501 params << "revert" << "--no-backup" << "--" << files;
Chris@98 502 }
Chris@109 503
Chris@109 504 runner->requestAction(HgAction(ACT_REVERT, workFolderPath, params));
jtkorhonen@0 505 }
jtkorhonen@0 506 }
jtkorhonen@0 507
jtkorhonen@33 508 void MainWindow::hgRetryMerge()
jtkorhonen@33 509 {
Chris@109 510 QStringList params;
jtkorhonen@33 511
Chris@109 512 params << "resolve" << "--all";
Chris@109 513 runner->requestAction(HgAction(ACT_RETRY_MERGE, workFolderPath, params));
jtkorhonen@33 514 }
jtkorhonen@33 515
jtkorhonen@33 516
jtkorhonen@0 517 void MainWindow::hgMerge()
jtkorhonen@0 518 {
Chris@109 519 QStringList params;
jtkorhonen@0 520
Chris@109 521 params << "merge";
Chris@109 522
Chris@109 523 runner->requestAction(HgAction(ACT_MERGE, workFolderPath, params));
jtkorhonen@0 524 }
jtkorhonen@0 525
jtkorhonen@0 526
jtkorhonen@0 527 void MainWindow::hgCloneFromRemote()
jtkorhonen@0 528 {
Chris@109 529 QStringList params;
jtkorhonen@0 530
Chris@109 531 if (!QDir(workFolderPath).exists()) {
Chris@109 532 if (!QDir().mkpath(workFolderPath)) {
Chris@109 533 DEBUG << "hgCloneFromRemote: Failed to create target path "
Chris@109 534 << workFolderPath << endl;
Chris@109 535 //!!! report error
Chris@109 536 return;
Chris@104 537 }
Chris@109 538 }
Chris@104 539
Chris@109 540 params << "clone" << remoteRepoPath << workFolderPath;
Chris@109 541
Chris@109 542 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
jtkorhonen@0 543
Chris@109 544 runner->requestAction(HgAction(ACT_CLONEFROMREMOTE, workFolderPath, params));
jtkorhonen@0 545 }
jtkorhonen@0 546
jtkorhonen@0 547 void MainWindow::hgInit()
jtkorhonen@0 548 {
Chris@109 549 QStringList params;
jtkorhonen@0 550
Chris@109 551 params << "init";
Chris@109 552 params << workFolderPath;
jtkorhonen@0 553
Chris@109 554 runner->requestAction(HgAction(ACT_INIT, workFolderPath, params));
jtkorhonen@0 555 }
jtkorhonen@0 556
jtkorhonen@0 557 void MainWindow::hgIncoming()
jtkorhonen@0 558 {
Chris@109 559 QStringList params;
jtkorhonen@0 560
Chris@109 561 params << "incoming" << "--newest-first" << remoteRepoPath;
jtkorhonen@0 562
Chris@109 563 runner->requestAction(HgAction(ACT_INCOMING, workFolderPath, params));
jtkorhonen@0 564 }
jtkorhonen@0 565
jtkorhonen@0 566
jtkorhonen@0 567 void MainWindow::hgPull()
jtkorhonen@0 568 {
Chris@109 569 QStringList params;
jtkorhonen@0 570
Chris@109 571 params << "pull" << remoteRepoPath;
jtkorhonen@0 572
Chris@109 573 runner->requestAction(HgAction(ACT_PULL, workFolderPath, params));
jtkorhonen@0 574 }
jtkorhonen@0 575
jtkorhonen@0 576
jtkorhonen@0 577 void MainWindow::hgPush()
jtkorhonen@0 578 {
Chris@109 579 QStringList params;
jtkorhonen@0 580
Chris@109 581 params << "push" << remoteRepoPath;
jtkorhonen@0 582
Chris@109 583 runner->requestAction(HgAction(ACT_PUSH, workFolderPath, params));
jtkorhonen@0 584 }
jtkorhonen@0 585
jtkorhonen@28 586 QString MainWindow::listAllUpIpV4Addresses()
jtkorhonen@26 587 {
jtkorhonen@28 588 QString ret;
jtkorhonen@26 589 QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
jtkorhonen@26 590
jtkorhonen@26 591 for (int i = 0; i < ifaces.count(); i++)
jtkorhonen@26 592 {
jtkorhonen@26 593 QNetworkInterface iface = ifaces.at(i);
jtkorhonen@26 594
jtkorhonen@26 595 if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
jtkorhonen@26 596 {
jtkorhonen@26 597 for (int j=0; j<iface.addressEntries().count(); j++)
jtkorhonen@26 598 {
jtkorhonen@28 599 QHostAddress tmp = iface.addressEntries().at(j).ip();
jtkorhonen@28 600 if (QAbstractSocket::IPv4Protocol == tmp.protocol())
jtkorhonen@24 601 {
jtkorhonen@28 602 if (!ret.isEmpty())
jtkorhonen@28 603 {
jtkorhonen@28 604 ret += " ";
jtkorhonen@28 605 }
jtkorhonen@28 606 ret += tmp.toString();
jtkorhonen@24 607 }
jtkorhonen@24 608 }
jtkorhonen@22 609 }
jtkorhonen@17 610 }
jtkorhonen@28 611 return ret;
jtkorhonen@28 612 }
jtkorhonen@17 613
jtkorhonen@17 614
jtkorhonen@11 615 void MainWindow::hgServe()
jtkorhonen@11 616 {
Chris@109 617 QStringList params;
Chris@109 618 QString msg;
jtkorhonen@11 619
Chris@109 620 QString addrs = listAllUpIpV4Addresses();
Chris@109 621 QTextStream(&msg) << "Server running on address(es) (" << addrs << "), port 8000";
Chris@109 622 params << "serve";
jtkorhonen@11 623
Chris@109 624 runner->requestAction(HgAction(ACT_SERVE, workFolderPath, params));
Chris@109 625
Chris@109 626 QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
Chris@109 627 //!!! runner -> killCurrentCommand();
jtkorhonen@11 628 }
jtkorhonen@11 629
Chris@64 630 void MainWindow::startupDialog()
Chris@64 631 {
Chris@64 632 StartupDialog *dlg = new StartupDialog(this);
Chris@65 633 if (dlg->exec()) firstStart = false;
Chris@64 634 }
jtkorhonen@11 635
Chris@69 636 void MainWindow::open()
Chris@69 637 {
Chris@86 638 bool done = false;
Chris@69 639
Chris@86 640 while (!done) {
Chris@69 641
Chris@86 642 MultiChoiceDialog *d = new MultiChoiceDialog
Chris@86 643 (tr("Open Repository"),
Chris@86 644 tr("<qt><big>What would you like to open?</big></qt>"),
Chris@86 645 this);
Chris@69 646
Chris@86 647 d->addChoice("remote",
Chris@86 648 tr("<qt><center><img src=\":images/browser-64.png\"><br>Remote repository</center></qt>"),
Chris@86 649 tr("Open a remote Mercurial repository, by cloning from its URL into a local folder."),
Chris@86 650 MultiChoiceDialog::UrlToDirectoryArg);
Chris@69 651
Chris@86 652 d->addChoice("local",
Chris@86 653 tr("<qt><center><img src=\":images/hglogo-64.png\"><br>Local repository</center></qt>"),
Chris@86 654 tr("Open an existing local Mercurial repository."),
Chris@86 655 MultiChoiceDialog::DirectoryArg);
Chris@69 656
Chris@86 657 d->addChoice("init",
Chris@86 658 tr("<qt><center><img src=\":images/hdd_unmount-64.png\"><br>File folder</center></qt>"),
Chris@86 659 tr("Open a local folder, by creating a Mercurial repository in it."),
Chris@86 660 MultiChoiceDialog::DirectoryArg);
Chris@79 661
Chris@86 662 d->setCurrentChoice("local");
Chris@86 663
Chris@86 664 if (d->exec() == QDialog::Accepted) {
Chris@86 665
Chris@86 666 QString choice = d->getCurrentChoice();
Chris@86 667 QString arg = d->getArgument().trimmed();
Chris@86 668
Chris@86 669 bool result = false;
Chris@86 670
Chris@86 671 if (choice == "local") {
Chris@86 672 result = openLocal(arg);
Chris@86 673 } else if (choice == "remote") {
Chris@86 674 result = openRemote(arg, d->getAdditionalArgument().trimmed());
Chris@86 675 } else if (choice == "init") {
Chris@86 676 result = openInit(arg);
Chris@86 677 }
Chris@86 678
Chris@86 679 if (result) {
Chris@86 680 enableDisableActions();
Chris@109 681 hgQueryPaths();
Chris@91 682 done = true;
Chris@91 683 }
Chris@86 684
Chris@86 685 } else {
Chris@86 686
Chris@86 687 // cancelled
Chris@86 688 done = true;
Chris@69 689 }
Chris@79 690
Chris@86 691 delete d;
Chris@69 692 }
Chris@69 693 }
Chris@69 694
Chris@79 695 bool MainWindow::complainAboutFilePath(QString arg)
Chris@79 696 {
Chris@79 697 QMessageBox::critical
Chris@79 698 (this, tr("File chosen"),
Chris@84 699 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 700 return false;
Chris@79 701 }
Chris@79 702
Chris@79 703 bool MainWindow::complainAboutUnknownFolder(QString arg)
Chris@79 704 {
Chris@79 705 QMessageBox::critical
Chris@79 706 (this, tr("Folder does not exist"),
Chris@84 707 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 708 return false;
Chris@84 709 }
Chris@84 710
Chris@84 711 bool MainWindow::complainAboutInitInRepo(QString arg)
Chris@84 712 {
Chris@84 713 QMessageBox::critical
Chris@84 714 (this, tr("Path is in existing repository"),
Chris@84 715 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 716 return false;
Chris@84 717 }
Chris@84 718
Chris@84 719 bool MainWindow::complainAboutInitFile(QString arg)
Chris@84 720 {
Chris@84 721 QMessageBox::critical
Chris@84 722 (this, tr("Path is a file"),
Chris@84 723 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 724 return false;
Chris@84 725 }
Chris@84 726
Chris@84 727 bool MainWindow::complainAboutCloneToExisting(QString arg)
Chris@84 728 {
Chris@84 729 QMessageBox::critical
Chris@84 730 (this, tr("Path is in existing repository"),
Chris@84 731 tr("<qt><b>Local path is in an existing repository</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This path is already inside an existing repository.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@84 732 return false;
Chris@84 733 }
Chris@84 734
Chris@84 735 bool MainWindow::complainAboutCloneToFile(QString arg)
Chris@84 736 {
Chris@84 737 QMessageBox::critical
Chris@84 738 (this, tr("Path is a file"),
Chris@84 739 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 740 return false;
Chris@84 741 }
Chris@84 742
Chris@84 743 bool MainWindow::complainAboutCloneToExistingFolder(QString arg)
Chris@84 744 {
Chris@84 745 QMessageBox::critical
Chris@84 746 (this, tr("Folder exists"),
Chris@84 747 tr("<qt><b>Local folder already exists</b><br><br>You asked to open a remote repository by cloning it to the local path \"%1\".<br>This is the path of an existing folder.<br>Please provide a new folder name for the local repository.</qt>").arg(xmlEncode(arg)));
Chris@79 748 return false;
Chris@79 749 }
Chris@79 750
Chris@79 751 bool MainWindow::askToOpenParentRepo(QString arg, QString parent)
Chris@79 752 {
Chris@79 753 return (QMessageBox::question
Chris@84 754 (this, tr("Path is inside a repository"),
Chris@86 755 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 756 .arg(xmlEncode(arg)).arg(xmlEncode(parent)),
Chris@79 757 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 758 QMessageBox::Ok)
Chris@79 759 == QMessageBox::Ok);
Chris@79 760 }
Chris@79 761
Chris@79 762 bool MainWindow::askToInitExisting(QString arg)
Chris@79 763 {
Chris@79 764 return (QMessageBox::question
Chris@84 765 (this, tr("Folder has no repository"),
Chris@84 766 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 767 .arg(xmlEncode(arg)),
Chris@79 768 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 769 QMessageBox::Ok)
Chris@79 770 == QMessageBox::Ok);
Chris@79 771 }
Chris@79 772
Chris@79 773 bool MainWindow::askToInitNew(QString arg)
Chris@79 774 {
Chris@79 775 return (QMessageBox::question
Chris@84 776 (this, tr("Folder does not exist"),
Chris@84 777 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 778 .arg(xmlEncode(arg)),
Chris@84 779 QMessageBox::Ok | QMessageBox::Cancel,
Chris@84 780 QMessageBox::Ok)
Chris@84 781 == QMessageBox::Ok);
Chris@84 782 }
Chris@84 783
Chris@84 784 bool MainWindow::askToOpenInsteadOfInit(QString arg)
Chris@84 785 {
Chris@84 786 return (QMessageBox::question
Chris@84 787 (this, tr("Repository exists"),
Chris@84 788 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 789 .arg(xmlEncode(arg)),
Chris@79 790 QMessageBox::Ok | QMessageBox::Cancel,
Chris@79 791 QMessageBox::Ok)
Chris@79 792 == QMessageBox::Ok);
Chris@79 793 }
Chris@79 794
Chris@79 795 bool MainWindow::openLocal(QString local)
Chris@79 796 {
Chris@79 797 DEBUG << "open " << local << endl;
Chris@79 798
Chris@79 799 FolderStatus status = getFolderStatus(local);
Chris@79 800 QString containing = getContainingRepoFolder(local);
Chris@79 801
Chris@79 802 switch (status) {
Chris@79 803
Chris@79 804 case FolderHasRepo:
Chris@79 805 // fine
Chris@79 806 break;
Chris@79 807
Chris@79 808 case FolderExists:
Chris@79 809 if (containing != "") {
Chris@79 810 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 811 local = containing;
Chris@79 812 } else {
Chris@86 813 //!!! No -- this is likely to happen far more by accident
Chris@86 814 // than because the user actually wanted to init something.
Chris@86 815 // Don't ask, just politely reject.
Chris@79 816 if (!askToInitExisting(local)) return false;
Chris@79 817 return openInit(local);
Chris@79 818 }
Chris@79 819 break;
Chris@79 820
Chris@79 821 case FolderParentExists:
Chris@79 822 if (containing != "") {
Chris@79 823 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 824 local = containing;
Chris@79 825 } else {
Chris@79 826 if (!askToInitNew(local)) return false;
Chris@79 827 return openInit(local);
Chris@79 828 }
Chris@79 829 break;
Chris@79 830
Chris@79 831 case FolderUnknown:
Chris@84 832 if (containing != "") {
Chris@84 833 if (!askToOpenParentRepo(local, containing)) return false;
Chris@84 834 local = containing;
Chris@84 835 } else {
Chris@84 836 return complainAboutUnknownFolder(local);
Chris@84 837 }
Chris@84 838 break;
Chris@79 839
Chris@79 840 case FolderIsFile:
Chris@79 841 return complainAboutFilePath(local);
Chris@79 842 }
Chris@79 843
Chris@79 844 workFolderPath = local;
Chris@79 845 remoteRepoPath = "";
Chris@79 846 return true;
Chris@79 847 }
Chris@79 848
Chris@79 849 bool MainWindow::openRemote(QString remote, QString local)
Chris@79 850 {
Chris@79 851 DEBUG << "clone " << remote << " to " << local << endl;
Chris@84 852
Chris@84 853 FolderStatus status = getFolderStatus(local);
Chris@84 854 QString containing = getContainingRepoFolder(local);
Chris@84 855
Chris@84 856 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 857
Chris@84 858 if (status == FolderHasRepo || containing != "") {
Chris@84 859 return complainAboutCloneToExisting(local);
Chris@84 860 }
Chris@84 861
Chris@84 862 if (status == FolderIsFile) {
Chris@84 863 return complainAboutCloneToFile(local);
Chris@84 864 }
Chris@84 865
Chris@84 866 if (status == FolderUnknown) {
Chris@84 867 return complainAboutUnknownFolder(local);
Chris@84 868 }
Chris@84 869
Chris@84 870 if (status == FolderExists) {
Chris@84 871 //!!! we can do better than this surely?
Chris@84 872 return complainAboutCloneToExistingFolder(local);
Chris@84 873 }
Chris@84 874
Chris@84 875 workFolderPath = local;
Chris@84 876 remoteRepoPath = remote;
Chris@84 877 hgCloneFromRemote();
Chris@84 878
Chris@79 879 return true;
Chris@79 880 }
Chris@79 881
Chris@84 882 bool MainWindow::openInit(QString local)
Chris@79 883 {
Chris@84 884 DEBUG << "openInit " << local << endl;
Chris@84 885
Chris@84 886 FolderStatus status = getFolderStatus(local);
Chris@84 887 QString containing = getContainingRepoFolder(local);
Chris@84 888
Chris@84 889 DEBUG << "status = " << status << ", containing = " << containing << endl;
Chris@84 890
Chris@84 891 if (status == FolderHasRepo) {
Chris@84 892 if (!askToOpenInsteadOfInit(local)) return false;
Chris@84 893 }
Chris@84 894
Chris@84 895 if (containing != "") {
Chris@84 896 return complainAboutInitInRepo(local);
Chris@84 897 }
Chris@84 898
Chris@84 899 if (status == FolderIsFile) {
Chris@84 900 return complainAboutInitFile(local);
Chris@84 901 }
Chris@84 902
Chris@84 903 if (status == FolderUnknown) {
Chris@84 904 return complainAboutUnknownFolder(local);
Chris@84 905 }
Chris@84 906
Chris@84 907 workFolderPath = local;
Chris@84 908 remoteRepoPath = "";
Chris@84 909 hgInit();
Chris@79 910 return true;
Chris@79 911 }
Chris@79 912
jtkorhonen@0 913 void MainWindow::settings()
jtkorhonen@0 914 {
Chris@69 915 /*!!!
jtkorhonen@0 916 SettingsDialog *settingsDlg = new SettingsDialog(this);
jtkorhonen@0 917 settingsDlg->setModal(true);
jtkorhonen@0 918 settingsDlg->exec();
Chris@98 919 hgTabs -> clearLists();
jtkorhonen@0 920 enableDisableActions();
jtkorhonen@0 921 hgStat();
Chris@69 922 */
jtkorhonen@0 923 }
jtkorhonen@0 924
jtkorhonen@2 925 #define STDOUT_NEEDS_BIG_WINDOW 512
jtkorhonen@2 926 #define SMALL_WND_W 500
jtkorhonen@2 927 #define SMALL_WND_H 300
jtkorhonen@2 928
jtkorhonen@2 929 #define BIG_WND_W 1024
jtkorhonen@2 930 #define BIG_WND_H 768
jtkorhonen@2 931
jtkorhonen@2 932
jtkorhonen@2 933 void MainWindow::presentLongStdoutToUser(QString stdo)
jtkorhonen@0 934 {
jtkorhonen@2 935 if (!stdo.isEmpty())
jtkorhonen@2 936 {
jtkorhonen@2 937 QDialog dlg;
jtkorhonen@0 938
jtkorhonen@2 939 if (stdo.length() > STDOUT_NEEDS_BIG_WINDOW)
jtkorhonen@2 940 {
jtkorhonen@2 941 dlg.setMinimumWidth(BIG_WND_W);
jtkorhonen@2 942 dlg.setMinimumHeight(BIG_WND_H);
jtkorhonen@2 943 }
jtkorhonen@2 944 else
jtkorhonen@2 945 {
jtkorhonen@2 946 dlg.setMinimumWidth(SMALL_WND_W);
jtkorhonen@2 947 dlg.setMinimumHeight(SMALL_WND_H);
jtkorhonen@2 948 }
jtkorhonen@0 949
jtkorhonen@2 950 QVBoxLayout *box = new QVBoxLayout;
jtkorhonen@2 951 QListWidget *list = new QListWidget;
jtkorhonen@2 952 list-> addItems(stdo.split("\n"));
jtkorhonen@2 953 QPushButton *btn = new QPushButton(tr("Ok"));
jtkorhonen@2 954 connect(btn, SIGNAL(clicked()), &dlg, SLOT(accept()));
jtkorhonen@0 955
jtkorhonen@2 956 box -> addWidget(list);
jtkorhonen@2 957 box -> addWidget(btn);
jtkorhonen@2 958 dlg.setLayout(box);
jtkorhonen@2 959
jtkorhonen@2 960 dlg.exec();
jtkorhonen@2 961 }
jtkorhonen@2 962 else
jtkorhonen@2 963 {
Chris@98 964 QMessageBox::information(this, tr("EasyMercurial"), tr("Mercurial command did not return any output."));
jtkorhonen@2 965 }
jtkorhonen@0 966 }
jtkorhonen@0 967
Chris@90 968 void MainWindow::updateFileSystemWatcher()
Chris@90 969 {
Chris@90 970 //!!! this needs to be incremental when something changes
Chris@90 971
Chris@90 972 delete fsWatcher;
Chris@90 973 fsWatcher = new QFileSystemWatcher();
Chris@90 974 std::deque<QString> pending;
Chris@90 975 pending.push_back(workFolderPath);
Chris@90 976 while (!pending.empty()) {
Chris@90 977 QString path = pending.front();
Chris@90 978 pending.pop_front();
Chris@90 979 fsWatcher->addPath(path);
Chris@90 980 DEBUG << "Added to file system watcher: " << path << endl;
Chris@90 981 QDir d(path);
Chris@90 982 if (d.exists()) {
Chris@90 983 d.setFilter(QDir::Files | QDir::Dirs |
Chris@90 984 QDir::NoDotAndDotDot | QDir::Readable);
Chris@90 985 foreach (QString entry, d.entryList()) {
Chris@90 986 if (entry == ".hg") continue;
Chris@90 987 QString entryPath = d.absoluteFilePath(entry);
Chris@90 988 pending.push_back(entryPath);
Chris@90 989 }
Chris@90 990 }
Chris@90 991 }
Chris@90 992 connect(fsWatcher, SIGNAL(directoryChanged(QString)),
Chris@90 993 this, SLOT(fsDirectoryChanged(QString)));
Chris@90 994 connect(fsWatcher, SIGNAL(fileChanged(QString)),
Chris@90 995 this, SLOT(fsFileChanged(QString)));
Chris@90 996 }
Chris@90 997
Chris@90 998 void MainWindow::fsDirectoryChanged(QString)
Chris@90 999 {
Chris@90 1000 //!!! should just queue one of these!
Chris@90 1001 hgStat();
Chris@90 1002 }
Chris@90 1003
Chris@90 1004 void MainWindow::fsFileChanged(QString)
Chris@90 1005 {
Chris@90 1006 //!!! should just queue one of these!
Chris@90 1007 hgStat();
Chris@90 1008 }
Chris@90 1009
Chris@109 1010 void MainWindow::commandFailed(HgAction action, QString stderr)
Chris@62 1011 {
Chris@62 1012 DEBUG << "MainWindow::commandFailed" << endl;
Chris@109 1013 // runner -> hideProgBar();
Chris@74 1014
Chris@79 1015 //!!! N.B hg incoming returns 1 even if successful, if there were no changes
Chris@62 1016 }
Chris@62 1017
Chris@109 1018 void MainWindow::commandCompleted(HgAction completedAction, QString output)
jtkorhonen@0 1019 {
jtkorhonen@0 1020 bool shouldHgStat = false;
jtkorhonen@0 1021
Chris@109 1022 HGACTIONS action = completedAction.action;
Chris@109 1023
Chris@109 1024 if (action == ACT_NONE) return;
Chris@109 1025
Chris@109 1026 switch(action) {
Chris@109 1027
Chris@109 1028 case ACT_QUERY_PATHS:
jtkorhonen@0 1029 {
Chris@109 1030 DEBUG << "stdout is " << output << endl;
Chris@109 1031 LogParser lp(output, "=");
Chris@109 1032 LogList ll = lp.parse();
Chris@109 1033 DEBUG << ll.size() << " results" << endl;
Chris@109 1034 if (!ll.empty()) {
Chris@109 1035 remoteRepoPath = lp.parse()[0]["default"].trimmed();
Chris@109 1036 DEBUG << "Set remote path to " << remoteRepoPath << endl;
Chris@109 1037 }
Chris@109 1038 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1039 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1040 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
Chris@109 1041 enableDisableActions();
Chris@109 1042 break;
Chris@109 1043 }
jtkorhonen@0 1044
Chris@109 1045 case ACT_QUERY_BRANCH:
Chris@109 1046 currentBranch = output.trimmed();
Chris@109 1047 hgTabs->setBranch(currentBranch);
Chris@109 1048 break;
jtkorhonen@0 1049
Chris@109 1050 case ACT_STAT:
Chris@109 1051 hgTabs -> updateWorkFolderFileList(output);
Chris@109 1052 updateFileSystemWatcher();
Chris@109 1053 break;
Chris@109 1054
Chris@109 1055 case ACT_INCOMING:
Chris@109 1056 case ACT_ANNOTATE:
Chris@109 1057 case ACT_RESOLVE_LIST:
Chris@109 1058 case ACT_RESOLVE_MARK:
Chris@109 1059 presentLongStdoutToUser(output);
Chris@109 1060 shouldHgStat = true;
Chris@109 1061 break;
Chris@109 1062
Chris@109 1063 case ACT_PULL:
Chris@109 1064 QMessageBox::information(this, "Pull", output);
Chris@109 1065 shouldHgStat = true;
Chris@109 1066 break;
Chris@109 1067
Chris@109 1068 case ACT_PUSH:
Chris@109 1069 QMessageBox::information(this, "Push", output);
Chris@109 1070 shouldHgStat = true;
Chris@109 1071 break;
Chris@109 1072
Chris@109 1073 case ACT_INIT:
Chris@109 1074 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
Chris@109 1075 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1076 enableDisableActions();
Chris@109 1077 shouldHgStat = true;
Chris@109 1078 break;
Chris@109 1079
Chris@109 1080 case ACT_CLONEFROMREMOTE:
Chris@109 1081 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
Chris@109 1082 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
Chris@109 1083 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
Chris@109 1084 QMessageBox::information(this, "Clone", output);
Chris@109 1085 enableDisableActions();
Chris@109 1086 shouldHgStat = true;
Chris@109 1087 break;
Chris@109 1088
Chris@109 1089 case ACT_LOG:
Chris@109 1090 hgTabs -> updateLocalRepoHgLogList(output);
Chris@109 1091 break;
Chris@109 1092
Chris@109 1093 case ACT_QUERY_PARENTS:
Chris@109 1094 foreach (Changeset *cs, currentParents) delete cs;
Chris@109 1095 currentParents = Changeset::parseChangesets(output);
Chris@109 1096 break;
Chris@109 1097
Chris@109 1098 case ACT_QUERY_HEADS:
Chris@109 1099 foreach (Changeset *cs, currentHeads) delete cs;
Chris@109 1100 currentHeads = Changeset::parseChangesets(output);
Chris@109 1101 break;
Chris@109 1102
Chris@109 1103 case ACT_REMOVE:
Chris@109 1104 case ACT_ADD:
Chris@109 1105 case ACT_COMMIT:
Chris@109 1106 case ACT_FILEDIFF:
Chris@109 1107 case ACT_FOLDERDIFF:
Chris@109 1108 case ACT_CHGSETDIFF:
Chris@109 1109 case ACT_REVERT:
Chris@109 1110 case ACT_SERVE:
Chris@109 1111 case ACT_TAG:
Chris@109 1112 case ACT_HG_IGNORE:
Chris@109 1113 shouldHgStat = true;
Chris@109 1114 break;
Chris@109 1115
Chris@109 1116 case ACT_UPDATE:
Chris@109 1117 QMessageBox::information(this, tr("Update"), output);
Chris@109 1118 shouldHgStat = true;
Chris@109 1119 break;
Chris@109 1120
Chris@109 1121 case ACT_MERGE:
Chris@109 1122 QMessageBox::information(this, tr("Merge"), output);
Chris@109 1123 shouldHgStat = true;
Chris@109 1124 justMerged = true;
Chris@109 1125 break;
Chris@109 1126
Chris@109 1127 case ACT_RETRY_MERGE:
Chris@109 1128 QMessageBox::information(this, tr("Merge retry"), tr("Merge retry successful."));
Chris@109 1129 shouldHgStat = true;
Chris@109 1130 justMerged = true;
Chris@109 1131 break;
Chris@109 1132
Chris@109 1133 default:
Chris@109 1134 break;
Chris@109 1135 }
Chris@108 1136
Chris@109 1137 enableDisableActions();
Chris@74 1138
Chris@109 1139 // Typical sequence goes paths -> branch -> stat -> heads -> parents -> log
Chris@109 1140 if (action == ACT_QUERY_PATHS) {
Chris@109 1141 hgQueryBranch();
Chris@109 1142 } else if (action == ACT_QUERY_BRANCH) {
Chris@109 1143 hgStat();
Chris@109 1144 } else if (action == ACT_STAT) {
Chris@109 1145 hgQueryHeads();
Chris@109 1146 } else if (action == ACT_QUERY_HEADS) {
Chris@109 1147 hgQueryParents();
Chris@109 1148 } else if (action == ACT_QUERY_PARENTS) {
Chris@109 1149 hgLog();
Chris@109 1150 } else
Chris@109 1151 /* Move to commandFailed
Chris@109 1152 if ((runningAction == ACT_MERGE) && (exitCode != 0))
jtkorhonen@37 1153 {
Chris@106 1154 // If we had a failed merge, offer to retry
jtkorhonen@37 1155 if (QMessageBox::Ok == QMessageBox::information(this, tr("Retry merge ?"), tr("Merge attempt failed. retry ?"), QMessageBox::Ok | QMessageBox::Cancel))
jtkorhonen@37 1156 {
jtkorhonen@37 1157 runningAction = ACT_NONE;
jtkorhonen@37 1158 hgRetryMerge();
jtkorhonen@37 1159 }
jtkorhonen@37 1160 else
jtkorhonen@37 1161 {
jtkorhonen@37 1162 runningAction = ACT_NONE;
jtkorhonen@37 1163 hgStat();
jtkorhonen@37 1164 }
jtkorhonen@37 1165 }
jtkorhonen@0 1166 else
jtkorhonen@0 1167 {
Chris@109 1168 */
Chris@109 1169 if (shouldHgStat) {
Chris@109 1170 hgQueryPaths();
jtkorhonen@0 1171 }
jtkorhonen@0 1172 }
jtkorhonen@0 1173
jtkorhonen@0 1174 void MainWindow::connectActions()
jtkorhonen@0 1175 {
jtkorhonen@0 1176 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
jtkorhonen@0 1177 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
jtkorhonen@0 1178 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
jtkorhonen@0 1179
Chris@109 1180 connect(hgStatAct, SIGNAL(triggered()), this, SLOT(hgQueryPaths()));
jtkorhonen@0 1181 connect(hgRemoveAct, SIGNAL(triggered()), this, SLOT(hgRemove()));
jtkorhonen@0 1182 connect(hgAddAct, SIGNAL(triggered()), this, SLOT(hgAdd()));
jtkorhonen@0 1183 connect(hgCommitAct, SIGNAL(triggered()), this, SLOT(hgCommit()));
jtkorhonen@0 1184 connect(hgFileDiffAct, SIGNAL(triggered()), this, SLOT(hgFileDiff()));
jtkorhonen@0 1185 connect(hgFolderDiffAct, SIGNAL(triggered()), this, SLOT(hgFolderDiff()));
jtkorhonen@0 1186 connect(hgChgSetDiffAct, SIGNAL(triggered()), this, SLOT(hgChgSetDiff()));
jtkorhonen@0 1187 connect(hgUpdateAct, SIGNAL(triggered()), this, SLOT(hgUpdate()));
jtkorhonen@0 1188 connect(hgRevertAct, SIGNAL(triggered()), this, SLOT(hgRevert()));
jtkorhonen@0 1189 connect(hgMergeAct, SIGNAL(triggered()), this, SLOT(hgMerge()));
jtkorhonen@33 1190 connect(hgRetryMergeAct, SIGNAL(triggered()), this, SLOT(hgRetryMerge()));
jtkorhonen@34 1191 connect(hgTagAct, SIGNAL(triggered()), this, SLOT(hgTag()));
jtkorhonen@34 1192 connect(hgIgnoreAct, SIGNAL(triggered()), this, SLOT(hgIgnore()));
jtkorhonen@0 1193
jtkorhonen@0 1194 connect(settingsAct, SIGNAL(triggered()), this, SLOT(settings()));
Chris@69 1195 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
jtkorhonen@0 1196
jtkorhonen@0 1197 connect(hgInitAct, SIGNAL(triggered()), this, SLOT(hgInit()));
jtkorhonen@0 1198 connect(hgCloneFromRemoteAct, SIGNAL(triggered()), this, SLOT(hgCloneFromRemote()));
jtkorhonen@0 1199 connect(hgIncomingAct, SIGNAL(triggered()), this, SLOT(hgIncoming()));
jtkorhonen@0 1200 connect(hgPullAct, SIGNAL(triggered()), this, SLOT(hgPull()));
jtkorhonen@0 1201 connect(hgPushAct, SIGNAL(triggered()), this, SLOT(hgPush()));
jtkorhonen@0 1202
Chris@109 1203 // connect(hgTabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
jtkorhonen@0 1204
jtkorhonen@0 1205 connect(hgUpdateToRevAct, SIGNAL(triggered()), this, SLOT(hgUpdateToRev()));
jtkorhonen@0 1206 connect(hgAnnotateAct, SIGNAL(triggered()), this, SLOT(hgAnnotate()));
jtkorhonen@0 1207 connect(hgResolveListAct, SIGNAL(triggered()), this, SLOT(hgResolveList()));
jtkorhonen@0 1208 connect(hgResolveMarkAct, SIGNAL(triggered()), this, SLOT(hgResolveMark()));
jtkorhonen@11 1209 connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
Chris@94 1210 connect(clearSelectionsAct, SIGNAL(triggered()), this, SLOT(clearSelections()));
jtkorhonen@0 1211 }
Chris@109 1212 /*!!!
jtkorhonen@0 1213 void MainWindow::tabChanged(int currTab)
jtkorhonen@0 1214 {
jtkorhonen@0 1215 tabPage = currTab;
jtkorhonen@32 1216
jtkorhonen@0 1217 }
Chris@109 1218 */
jtkorhonen@0 1219 void MainWindow::enableDisableActions()
jtkorhonen@0 1220 {
Chris@90 1221 DEBUG << "MainWindow::enableDisableActions" << endl;
Chris@90 1222
jtkorhonen@0 1223 QDir localRepoDir;
jtkorhonen@0 1224 QDir workFolderDir;
jtkorhonen@0 1225 bool workFolderExist;
jtkorhonen@0 1226 bool localRepoExist;
jtkorhonen@0 1227
jtkorhonen@0 1228 remoteRepoActionsEnabled = true;
Chris@90 1229 if (remoteRepoPath.isEmpty()) {
jtkorhonen@0 1230 remoteRepoActionsEnabled = false;
jtkorhonen@0 1231 }
jtkorhonen@0 1232
jtkorhonen@0 1233 localRepoActionsEnabled = true;
Chris@90 1234 if (workFolderPath.isEmpty()) {
jtkorhonen@0 1235 localRepoActionsEnabled = false;
jtkorhonen@0 1236 workFolderExist = false;
jtkorhonen@0 1237 }
jtkorhonen@0 1238
Chris@90 1239 if (!workFolderDir.exists(workFolderPath)) {
jtkorhonen@0 1240 localRepoActionsEnabled = false;
jtkorhonen@0 1241 workFolderExist = false;
Chris@90 1242 } else {
jtkorhonen@0 1243 workFolderExist = true;
jtkorhonen@0 1244 }
jtkorhonen@0 1245
Chris@112 1246 if (!localRepoDir.exists(workFolderPath + "/.hg")) {
jtkorhonen@0 1247 localRepoActionsEnabled = false;
jtkorhonen@0 1248 localRepoExist = false;
jtkorhonen@0 1249 }
jtkorhonen@0 1250
jtkorhonen@0 1251 hgCloneFromRemoteAct -> setEnabled(remoteRepoActionsEnabled);
jtkorhonen@0 1252 hgIncomingAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1253 hgPullAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
jtkorhonen@0 1254 hgPushAct -> setEnabled(remoteRepoActionsEnabled && remoteRepoActionsEnabled);
Chris@73 1255 /*
jtkorhonen@0 1256 if (tabPage != WORKTAB)
jtkorhonen@0 1257 {
jtkorhonen@0 1258 localRepoActionsEnabled = false;
jtkorhonen@0 1259 }
Chris@73 1260 */
Chris@112 1261 bool haveDiff = (diffBinaryName != "");
Chris@112 1262
jtkorhonen@0 1263 hgInitAct -> setEnabled((localRepoExist == false) && (workFolderExist==true));
jtkorhonen@0 1264 hgStatAct -> setEnabled(localRepoActionsEnabled);
Chris@112 1265 hgFileDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
Chris@112 1266 hgFolderDiffAct -> setEnabled(localRepoActionsEnabled && haveDiff);
jtkorhonen@0 1267 hgRevertAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1268 hgAddAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1269 hgRemoveAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1270 hgUpdateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1271 hgCommitAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1272 hgMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@33 1273 hgRetryMergeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1274 hgResolveListAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1275 hgResolveMarkAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@2 1276 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@11 1277 hgServeAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1278 hgTagAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@34 1279 hgIgnoreAct -> setEnabled(localRepoActionsEnabled);
jtkorhonen@0 1280
Chris@98 1281 //!!!hgTabs -> enableDisableOtherTabs(tabPage);
jtkorhonen@0 1282
Chris@90 1283 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
Chris@98 1284 DEBUG << "canCommit = " << hgTabs->canCommit() << endl;
Chris@90 1285
Chris@90 1286 //!!! new stuff:
Chris@98 1287 hgAddAct->setEnabled(localRepoActionsEnabled && hgTabs->canAdd());
Chris@98 1288 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
Chris@98 1289 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
Chris@98 1290 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
Chris@98 1291 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDoDiff());
Chris@90 1292
Chris@108 1293 // A default merge makes sense if:
Chris@108 1294 // * there is only one parent (if there are two, we have an uncommitted merge) and
Chris@108 1295 // * there are exactly two heads that have the same branch as the current branch and
Chris@108 1296 // * our parent is one of those heads
Chris@108 1297 //
Chris@108 1298 // A default update makes sense if:
Chris@108 1299 // * there is only one parent and
Chris@108 1300 // * the parent is not one of the current heads
Chris@108 1301 //!!! test this
Chris@108 1302 bool canMerge = false;
Chris@108 1303 bool canUpdate = false;
Chris@108 1304 if (currentParents.size() == 1) {
Chris@108 1305 Changeset *parent = currentParents[0];
Chris@108 1306 int currentBranchHeads = 0;
Chris@108 1307 bool parentIsHead = false;
Chris@108 1308 foreach (Changeset *head, currentHeads) {
Chris@108 1309 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
Chris@108 1310 if (head->isOnBranch(currentBranch)) {
Chris@108 1311 ++currentBranchHeads;
Chris@108 1312 if (parent->id() == head->id()) {
Chris@108 1313 parentIsHead = true;
Chris@108 1314 }
Chris@108 1315 }
Chris@108 1316 }
Chris@108 1317 if (currentBranchHeads == 2 && parentIsHead) {
Chris@108 1318 canMerge = true;
Chris@108 1319 }
Chris@108 1320 if (!parentIsHead) {
Chris@108 1321 canUpdate = true;
Chris@108 1322 DEBUG << "parent id = " << parent->id() << endl;
Chris@108 1323 DEBUG << " head ids "<<endl;
Chris@108 1324 foreach (Changeset *h, currentHeads) {
Chris@108 1325 DEBUG << "head id = " << h->id() << endl;
Chris@108 1326 }
Chris@108 1327 }
Chris@108 1328 }
Chris@108 1329 hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge);
Chris@108 1330 hgUpdateAct->setEnabled(localRepoActionsEnabled && canUpdate);
jtkorhonen@0 1331 }
jtkorhonen@0 1332
jtkorhonen@0 1333 void MainWindow::createActions()
jtkorhonen@0 1334 {
jtkorhonen@0 1335 //File actions
jtkorhonen@0 1336 hgInitAct = new QAction(tr("Init local repository"), this);
jtkorhonen@0 1337 hgInitAct->setStatusTip(tr("Create an empty local repository in selected folder"));
jtkorhonen@0 1338
jtkorhonen@0 1339 hgCloneFromRemoteAct = new QAction(tr("Clone from remote"), this);
jtkorhonen@0 1340 hgCloneFromRemoteAct->setStatusTip(tr("Clone from remote repository into local repository in selected folder"));
jtkorhonen@0 1341
Chris@69 1342 openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
Chris@69 1343 openAct -> setStatusTip(tr("Open repository"));
Chris@69 1344 openAct -> setIconVisibleInMenu(true);
Chris@69 1345
jtkorhonen@0 1346 settingsAct = new QAction(QIcon(":/images/settings.png"), tr("Settings..."), this);
jtkorhonen@0 1347 settingsAct -> setStatusTip(tr("View and change application settings"));
jtkorhonen@0 1348 settingsAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1349
jtkorhonen@0 1350 exitAct = new QAction(QIcon(":/images/exit.png"), tr("Exit"), this);
jtkorhonen@0 1351 exitAct->setShortcuts(QKeySequence::Quit);
jtkorhonen@0 1352 exitAct->setStatusTip(tr("Exit application"));
jtkorhonen@0 1353 exitAct -> setIconVisibleInMenu(true);
jtkorhonen@0 1354
jtkorhonen@0 1355 //Repository actions
Chris@61 1356 hgStatAct = new QAction(QIcon(":/images/status.png"), tr("Refresh"), this);
Chris@61 1357 hgStatAct->setStatusTip(tr("Refresh (info of) status of workfolder files"));
Chris@61 1358
Chris@61 1359 hgIncomingAct = new QAction(QIcon(":/images/incoming.png"), tr("Preview"), this);
jtkorhonen@0 1360 hgIncomingAct -> setStatusTip(tr("View info of changesets incoming to us from remote repository (on pull operation)"));
jtkorhonen@0 1361
Chris@61 1362 hgPullAct = new QAction(QIcon(":/images/pull.png"), tr("Pull"), this);
jtkorhonen@0 1363 hgPullAct -> setStatusTip(tr("Pull changesets from remote repository to local repository"));
jtkorhonen@0 1364
Chris@61 1365 hgPushAct = new QAction(QIcon(":/images/push.png"), tr("Push"), this);
jtkorhonen@0 1366 hgPushAct->setStatusTip(tr("Push local changesets to remote repository"));
jtkorhonen@0 1367
jtkorhonen@0 1368 //Workfolder actions
Chris@61 1369 hgFileDiffAct = new QAction(QIcon(":/images/diff.png"), tr("Diff"), this);
jtkorhonen@0 1370 hgFileDiffAct->setStatusTip(tr("Filediff: View differences between selected working folder file and local repository file"));
jtkorhonen@0 1371
Chris@99 1372 hgFolderDiffAct = new QAction(QIcon(":/images/folderdiff.png"), tr("Diff"), this);
jtkorhonen@0 1373 hgFolderDiffAct->setStatusTip(tr("Folderdiff: View all differences between working folder files and local repository files"));
jtkorhonen@0 1374
jtkorhonen@0 1375 hgChgSetDiffAct = new QAction(QIcon(":/images/chgsetdiff.png"), tr("View changesetdiff"), this);
jtkorhonen@0 1376 hgChgSetDiffAct->setStatusTip(tr("Change set diff: View differences between all files of 2 repository changesets"));
jtkorhonen@0 1377
Chris@61 1378 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Revert"), this);
jtkorhonen@0 1379 hgRevertAct->setStatusTip(tr("Undo selected working folder file changes (return to local repository version)"));
jtkorhonen@0 1380
Chris@61 1381 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add"), this);
jtkorhonen@17 1382 hgAddAct -> setStatusTip(tr("Add working folder file(s) (selected or all yet untracked) to local repository (on next commit)"));
jtkorhonen@0 1383
Chris@61 1384 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove"), this);
jtkorhonen@0 1385 hgRemoveAct -> setStatusTip(tr("Remove selected working folder file from local repository (on next commit)"));
jtkorhonen@0 1386
Chris@61 1387 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update"), this);
jtkorhonen@0 1388 hgUpdateAct->setStatusTip(tr("Update working folder from local repository"));
jtkorhonen@0 1389
Chris@61 1390 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit"), this);
jtkorhonen@20 1391 hgCommitAct->setStatusTip(tr("Save selected file(s) or all changed files in working folder (and all subfolders) to local repository"));
jtkorhonen@0 1392
jtkorhonen@0 1393 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
jtkorhonen@0 1394 hgMergeAct->setStatusTip(tr("Merge two local repository changesets to working folder"));
jtkorhonen@0 1395
jtkorhonen@0 1396 //Advanced actions
jtkorhonen@0 1397 hgUpdateToRevAct = new QAction(tr("Update to revision"), this);
jtkorhonen@0 1398 hgUpdateToRevAct -> setStatusTip(tr("Update working folder to version selected from history list"));
jtkorhonen@0 1399
jtkorhonen@0 1400 hgAnnotateAct = new QAction(tr("Annotate"), this);
jtkorhonen@0 1401 hgAnnotateAct -> setStatusTip(tr("Show line-by-line version information for selected file"));
jtkorhonen@0 1402
jtkorhonen@0 1403 hgResolveListAct = new QAction(tr("Resolve (list)"), this);
jtkorhonen@0 1404 hgResolveListAct -> setStatusTip(tr("Resolve (list): Show list of files needing merge"));
jtkorhonen@0 1405
jtkorhonen@0 1406 hgResolveMarkAct = new QAction(tr("Resolve (mark)"), this);
jtkorhonen@0 1407 hgResolveMarkAct -> setStatusTip(tr("Resolve (mark): Mark selected file status as resolved"));
jtkorhonen@0 1408
jtkorhonen@33 1409 hgRetryMergeAct = new QAction(tr("Retry merge"), this);
jtkorhonen@33 1410 hgRetryMergeAct -> setStatusTip(tr("Retry merge after failed merge attempt."));
jtkorhonen@33 1411
jtkorhonen@34 1412 hgTagAct = new QAction(tr("Tag revision"), this);
jtkorhonen@34 1413 hgTagAct -> setStatusTip(tr("Give decsriptive name (tag) to current workfolder parent revision."));
jtkorhonen@34 1414
jtkorhonen@34 1415 hgIgnoreAct = new QAction(tr("Edit .hgignore"), this);
jtkorhonen@34 1416 hgIgnoreAct -> setStatusTip(tr("Edit .hgignore file (file contains names of files that should be ignored by mercurial)"));
jtkorhonen@34 1417
jtkorhonen@11 1418 hgServeAct = new QAction(tr("Serve (via http)"), this);
jtkorhonen@11 1419 hgServeAct -> setStatusTip(tr("Serve local repository via http for workgroup access"));
jtkorhonen@11 1420
jtkorhonen@0 1421 //Help actions
jtkorhonen@0 1422 aboutAct = new QAction(tr("About"), this);
jtkorhonen@0 1423 aboutAct->setStatusTip(tr("Show the application's About box"));
jtkorhonen@0 1424
jtkorhonen@0 1425 aboutQtAct = new QAction(tr("About Qt"), this);
jtkorhonen@0 1426 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
Chris@94 1427
Chris@94 1428 // Miscellaneous
Chris@94 1429 clearSelectionsAct = new QAction(tr("Clear selections"), this);
Chris@94 1430 clearSelectionsAct->setShortcut(Qt::Key_Escape);
jtkorhonen@0 1431 }
jtkorhonen@0 1432
jtkorhonen@0 1433 void MainWindow::createMenus()
jtkorhonen@0 1434 {
jtkorhonen@0 1435 fileMenu = menuBar()->addMenu(tr("File"));
jtkorhonen@0 1436 fileMenu -> addAction(hgInitAct);
jtkorhonen@0 1437 fileMenu -> addAction(hgCloneFromRemoteAct);
Chris@94 1438 fileMenu->addAction(clearSelectionsAct); //!!! can't live here!
jtkorhonen@0 1439 fileMenu -> addSeparator();
Chris@69 1440 fileMenu -> addAction(openAct);
jtkorhonen@0 1441 fileMenu -> addAction(settingsAct);
jtkorhonen@0 1442 fileMenu -> addSeparator();
jtkorhonen@0 1443 fileMenu -> addAction(exitAct);
jtkorhonen@0 1444
jtkorhonen@0 1445 advancedMenu = menuBar()->addMenu(tr("Advanced"));
jtkorhonen@0 1446 advancedMenu -> addAction(hgUpdateToRevAct);
jtkorhonen@0 1447 advancedMenu -> addSeparator();
jtkorhonen@0 1448 advancedMenu -> addAction(hgAnnotateAct);
jtkorhonen@0 1449 advancedMenu -> addSeparator();
jtkorhonen@33 1450 advancedMenu -> addAction(hgRetryMergeAct);
jtkorhonen@0 1451 advancedMenu -> addAction(hgResolveListAct);
jtkorhonen@0 1452 advancedMenu -> addAction(hgResolveMarkAct);
jtkorhonen@11 1453 advancedMenu -> addSeparator();
jtkorhonen@34 1454 advancedMenu -> addAction(hgTagAct);
jtkorhonen@34 1455 advancedMenu -> addSeparator();
jtkorhonen@34 1456 advancedMenu -> addAction(hgIgnoreAct);
jtkorhonen@34 1457 advancedMenu -> addSeparator();
jtkorhonen@11 1458 advancedMenu -> addAction(hgServeAct);
jtkorhonen@0 1459
jtkorhonen@0 1460 helpMenu = menuBar()->addMenu(tr("Help"));
jtkorhonen@0 1461 helpMenu->addAction(aboutAct);
jtkorhonen@0 1462 helpMenu->addAction(aboutQtAct);
jtkorhonen@0 1463 }
jtkorhonen@0 1464
jtkorhonen@0 1465 void MainWindow::createToolBars()
jtkorhonen@0 1466 {
jtkorhonen@0 1467 fileToolBar = addToolBar(tr("File"));
jtkorhonen@0 1468 fileToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@69 1469 fileToolBar -> addAction(openAct);
Chris@43 1470 fileToolBar -> addAction(hgStatAct);
jtkorhonen@0 1471 fileToolBar -> addSeparator();
Chris@61 1472 // fileToolBar -> addAction(hgChgSetDiffAct);
jtkorhonen@0 1473 fileToolBar -> setMovable(false);
jtkorhonen@0 1474
jtkorhonen@0 1475 repoToolBar = addToolBar(tr(REPOMENU_TITLE));
jtkorhonen@0 1476 repoToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
jtkorhonen@0 1477 repoToolBar->addAction(hgIncomingAct);
jtkorhonen@0 1478 repoToolBar->addAction(hgPullAct);
jtkorhonen@0 1479 repoToolBar->addAction(hgPushAct);
jtkorhonen@0 1480 repoToolBar -> setMovable(false);
jtkorhonen@0 1481
jtkorhonen@0 1482 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
jtkorhonen@0 1483 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
jtkorhonen@0 1484 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
Chris@61 1485 // workFolderToolBar->addSeparator();
Chris@95 1486 // workFolderToolBar->addAction(hgFileDiffAct);
Chris@95 1487 workFolderToolBar->addAction(hgFolderDiffAct);
jtkorhonen@0 1488 workFolderToolBar->addSeparator();
jtkorhonen@0 1489 workFolderToolBar->addAction(hgRevertAct);
jtkorhonen@0 1490 workFolderToolBar->addAction(hgUpdateAct);
jtkorhonen@0 1491 workFolderToolBar->addAction(hgCommitAct);
jtkorhonen@0 1492 workFolderToolBar->addAction(hgMergeAct);
jtkorhonen@0 1493 workFolderToolBar->addSeparator();
jtkorhonen@0 1494 workFolderToolBar->addAction(hgAddAct);
jtkorhonen@0 1495 workFolderToolBar->addAction(hgRemoveAct);
jtkorhonen@0 1496 workFolderToolBar -> setMovable(false);
Chris@61 1497
Chris@61 1498 foreach (QToolButton *tb, findChildren<QToolButton *>()) {
Chris@61 1499 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
Chris@61 1500 }
jtkorhonen@0 1501 }
jtkorhonen@0 1502
jtkorhonen@0 1503
jtkorhonen@0 1504 void MainWindow::createStatusBar()
jtkorhonen@0 1505 {
jtkorhonen@0 1506 statusBar()->showMessage(tr("Ready"));
jtkorhonen@0 1507 }
jtkorhonen@0 1508
Chris@69 1509
Chris@69 1510 //!!! review these:
Chris@69 1511
jtkorhonen@0 1512 void MainWindow::readSettings()
jtkorhonen@0 1513 {
jtkorhonen@0 1514 QDir workFolder;
jtkorhonen@0 1515
Chris@61 1516 QSettings settings;
jtkorhonen@0 1517
jtkorhonen@30 1518 remoteRepoPath = settings.value("remoterepopath", "").toString();
jtkorhonen@0 1519 workFolderPath = settings.value("workfolderpath", "").toString();
jtkorhonen@0 1520 if (!workFolder.exists(workFolderPath))
jtkorhonen@0 1521 {
jtkorhonen@0 1522 workFolderPath = "";
jtkorhonen@0 1523 }
jtkorhonen@0 1524
jtkorhonen@0 1525 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
jtkorhonen@0 1526 QSize size = settings.value("size", QSize(400, 400)).toSize();
jtkorhonen@0 1527 firstStart = settings.value("firststart", QVariant(true)).toBool();
jtkorhonen@0 1528
Chris@109 1529 //!!! initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
jtkorhonen@0 1530 resize(size);
jtkorhonen@0 1531 move(pos);
jtkorhonen@0 1532 }
jtkorhonen@0 1533
jtkorhonen@17 1534
jtkorhonen@0 1535 void MainWindow::writeSettings()
jtkorhonen@0 1536 {
Chris@61 1537 QSettings settings;
jtkorhonen@0 1538 settings.setValue("pos", pos());
jtkorhonen@0 1539 settings.setValue("size", size());
jtkorhonen@0 1540 settings.setValue("remoterepopath", remoteRepoPath);
jtkorhonen@0 1541 settings.setValue("workfolderpath", workFolderPath);
jtkorhonen@0 1542 settings.setValue("firststart", firstStart);
Chris@98 1543 //!!!settings.setValue("viewFileTypes", hgTabs -> getFileTypesBits());
jtkorhonen@0 1544 }
jtkorhonen@0 1545
jtkorhonen@0 1546
jtkorhonen@0 1547
jtkorhonen@0 1548