annotate mainwindow.cpp @ 95:d1be9712818a

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