annotate mainwindow.cpp @ 108:8ae3b44c0073

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