annotate mainwindow.cpp @ 90:b43355c2473a

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