annotate src/hgtabwidget.cpp @ 644:ae67ea0af696

Update copyright dates
author Chris Cannam
date Mon, 07 Jan 2013 10:57:08 +0000
parents 58ac1b197666
children
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 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@644 8 Copyright (c) 2013 Chris Cannam
Chris@644 9 Copyright (c) 2013 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 */
jtkorhonen@0 17
Chris@96 18 #include "hgtabwidget.h"
jtkorhonen@0 19 #include "common.h"
Chris@88 20 #include "filestatuswidget.h"
Chris@116 21 #include "historywidget.h"
Chris@44 22
Chris@50 23 #include <QClipboard>
Chris@50 24 #include <QContextMenuEvent>
Chris@50 25 #include <QApplication>
sam@634 26 #include <QSettings>
Chris@50 27
Chris@44 28 #include <iostream>
jtkorhonen@0 29
Chris@96 30 HgTabWidget::HgTabWidget(QWidget *parent,
Chris@95 31 QString workFolderPath) :
Chris@505 32 QTabWidget(parent),
Chris@505 33 m_haveMerge(false)
jtkorhonen@0 34 {
Chris@326 35 // Work tab
Chris@116 36 m_fileStatusWidget = new FileStatusWidget;
Chris@116 37 m_fileStatusWidget->setLocalPath(workFolderPath);
Chris@326 38
Chris@116 39 connect(m_fileStatusWidget, SIGNAL(selectionChanged()),
Chris@95 40 this, SIGNAL(selectionChanged()));
Chris@326 41
Chris@484 42 connect(m_fileStatusWidget, SIGNAL(showAllChanged()),
Chris@484 43 this, SIGNAL(showAllChanged()));
Chris@326 44
Chris@326 45 connect(m_fileStatusWidget, SIGNAL(annotateFiles(QStringList)),
Chris@326 46 this, SIGNAL(annotateFiles(QStringList)));
Chris@326 47
Chris@326 48 connect(m_fileStatusWidget, SIGNAL(diffFiles(QStringList)),
Chris@326 49 this, SIGNAL(diffFiles(QStringList)));
Chris@326 50
Chris@326 51 connect(m_fileStatusWidget, SIGNAL(commitFiles(QStringList)),
Chris@326 52 this, SIGNAL(commitFiles(QStringList)));
Chris@326 53
Chris@326 54 connect(m_fileStatusWidget, SIGNAL(revertFiles(QStringList)),
Chris@326 55 this, SIGNAL(revertFiles(QStringList)));
Chris@326 56
Chris@361 57 connect(m_fileStatusWidget, SIGNAL(renameFiles(QStringList)),
Chris@361 58 this, SIGNAL(renameFiles(QStringList)));
Chris@361 59
Chris@361 60 connect(m_fileStatusWidget, SIGNAL(copyFiles(QStringList)),
Chris@361 61 this, SIGNAL(copyFiles(QStringList)));
Chris@361 62
Chris@326 63 connect(m_fileStatusWidget, SIGNAL(addFiles(QStringList)),
Chris@326 64 this, SIGNAL(addFiles(QStringList)));
Chris@326 65
Chris@326 66 connect(m_fileStatusWidget, SIGNAL(removeFiles(QStringList)),
Chris@326 67 this, SIGNAL(removeFiles(QStringList)));
Chris@326 68
Chris@326 69 connect(m_fileStatusWidget, SIGNAL(redoFileMerges(QStringList)),
Chris@326 70 this, SIGNAL(redoFileMerges(QStringList)));
Chris@326 71
Chris@326 72 connect(m_fileStatusWidget, SIGNAL(markFilesResolved(QStringList)),
Chris@326 73 this, SIGNAL(markFilesResolved(QStringList)));
Chris@326 74
Chris@326 75 connect(m_fileStatusWidget, SIGNAL(ignoreFiles(QStringList)),
Chris@326 76 this, SIGNAL(ignoreFiles(QStringList)));
Chris@326 77
Chris@326 78 connect(m_fileStatusWidget, SIGNAL(unIgnoreFiles(QStringList)),
Chris@326 79 this, SIGNAL(unIgnoreFiles(QStringList)));
Chris@326 80
sam@624 81 connect(m_fileStatusWidget, SIGNAL(showIn(QStringList)),
sam@624 82 this, SIGNAL(showIn(QStringList)));
sam@624 83
Chris@116 84 addTab(m_fileStatusWidget, tr("My work"));
Chris@88 85
Chris@326 86 // History graph tab
Chris@116 87 m_historyWidget = new HistoryWidget;
Chris@116 88 addTab(m_historyWidget, tr("History"));
Chris@141 89
Chris@141 90 connect(m_historyWidget, SIGNAL(commit()),
Chris@141 91 this, SIGNAL(commit()));
Chris@141 92
Chris@141 93 connect(m_historyWidget, SIGNAL(revert()),
Chris@141 94 this, SIGNAL(revert()));
Chris@141 95
Chris@168 96 connect(m_historyWidget, SIGNAL(showSummary()),
Chris@168 97 this, SIGNAL(showSummary()));
Chris@168 98
Chris@311 99 connect(m_historyWidget, SIGNAL(newBranch()),
Chris@311 100 this, SIGNAL(newBranch()));
Chris@311 101
Chris@311 102 connect(m_historyWidget, SIGNAL(noBranch()),
Chris@311 103 this, SIGNAL(noBranch()));
Chris@311 104
Chris@141 105 connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
Chris@141 106 this, SIGNAL(diffWorkingFolder()));
Chris@141 107
Chris@153 108 connect(m_historyWidget, SIGNAL(showWork()),
Chris@153 109 this, SLOT(showWorkTab()));
Chris@153 110
Chris@141 111 connect(m_historyWidget, SIGNAL(updateTo(QString)),
Chris@141 112 this, SIGNAL(updateTo(QString)));
Chris@141 113
Chris@141 114 connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
Chris@141 115 this, SIGNAL(diffToCurrent(QString)));
Chris@141 116
Chris@148 117 connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
Chris@148 118 this, SIGNAL(diffToParent(QString, QString)));
Chris@141 119
Chris@289 120 connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
Chris@289 121 this, SIGNAL(showSummary(Changeset *)));
Chris@288 122
Chris@141 123 connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
Chris@141 124 this, SIGNAL(mergeFrom(QString)));
Chris@141 125
Chris@278 126 connect(m_historyWidget, SIGNAL(newBranch(QString)),
Chris@278 127 this, SIGNAL(newBranch(QString)));
Chris@278 128
Chris@514 129 connect(m_historyWidget, SIGNAL(closeBranch(QString)),
Chris@514 130 this, SIGNAL(closeBranch(QString)));
Chris@514 131
Chris@141 132 connect(m_historyWidget, SIGNAL(tag(QString)),
Chris@141 133 this, SIGNAL(tag(QString)));
jtkorhonen@32 134 }
jtkorhonen@32 135
Chris@96 136 void HgTabWidget::clearSelections()
Chris@94 137 {
Chris@116 138 m_fileStatusWidget->clearSelections();
Chris@94 139 }
Chris@94 140
Chris@153 141 void HgTabWidget::setCurrent(QStringList ids, QString branch)
Chris@128 142 {
Chris@505 143 m_historyWidget->setCurrent(ids, branch, haveChangesToCommit());
Chris@129 144 }
Chris@129 145
Chris@506 146 void HgTabWidget::setClosedHeadIds(QSet<QString> closed)
Chris@506 147 {
Chris@506 148 m_historyWidget->setClosedHeadIds(closed);
Chris@506 149 }
Chris@506 150
Chris@608 151 void HgTabWidget::clearAll()
Chris@608 152 {
Chris@608 153 m_fileStatusWidget->clearWidgets();
Chris@608 154 m_historyWidget->clear();
Chris@608 155 }
Chris@608 156
Chris@230 157 void HgTabWidget::updateFileStates()
Chris@230 158 {
Chris@230 159 m_fileStatusWidget->updateWidgets();
Chris@230 160 }
Chris@230 161
Chris@154 162 void HgTabWidget::updateHistory()
Chris@154 163 {
Chris@154 164 m_historyWidget->update();
Chris@154 165 }
Chris@154 166
Chris@555 167 void HgTabWidget::setSearchText(QString text)
Chris@555 168 {
Chris@555 169 m_fileStatusWidget->setSearchText(text);
Chris@555 170 m_historyWidget->setSearchText(text);
Chris@555 171 }
Chris@555 172
Chris@163 173 bool HgTabWidget::canDiff() const
Chris@163 174 {
Chris@237 175 return canRevert();
Chris@163 176 }
Chris@163 177
Chris@96 178 bool HgTabWidget::canCommit() const
Chris@90 179 {
Chris@505 180 if (!haveChangesToCommit()) return false;
Chris@505 181 if (!getAllUnresolvedFiles().empty()) return false;
Chris@326 182 return true;
Chris@90 183 }
jtkorhonen@0 184
Chris@109 185 bool HgTabWidget::canRevert() const
Chris@109 186 {
Chris@237 187 // Not the same as canCommit() -- we can revert (and diff)
Chris@237 188 // unresolved files, but we can't commit them
Chris@505 189 if (!haveChangesToCommit() &&
Chris@505 190 getAllUnresolvedFiles().empty()) return false;
Chris@326 191 return true;
Chris@109 192 }
Chris@109 193
Chris@96 194 bool HgTabWidget::canAdd() const
Chris@95 195 {
Chris@327 196 // Permit this only when work tab is visible
Chris@327 197 if (currentIndex() != 0) return false;
Chris@327 198
Chris@505 199 QStringList addable = getSelectedAddableFiles();
Chris@204 200 if (addable.empty()) return false;
Chris@204 201
Chris@505 202 QStringList removable = getSelectedRemovableFiles();
Chris@204 203 if (!removable.empty()) return false;
Chris@204 204
Chris@326 205 return true;
Chris@95 206 }
Chris@95 207
Chris@96 208 bool HgTabWidget::canRemove() const
Chris@95 209 {
Chris@327 210 // Permit this only when work tab is visible
Chris@327 211 if (currentIndex() != 0) return false;
Chris@327 212
Chris@505 213 if (getSelectedRemovableFiles().empty()) return false;
Chris@505 214 if (!getSelectedAddableFiles().empty()) return false;
Chris@95 215 return true;
Chris@95 216 }
Chris@95 217
Chris@163 218 bool HgTabWidget::canResolve() const
Chris@95 219 {
Chris@505 220 return !getAllUnresolvedFiles().empty();
Chris@95 221 }
Chris@95 222
Chris@425 223 bool HgTabWidget::canIgnore() const
Chris@425 224 {
Chris@425 225 return canAdd();
Chris@425 226 }
Chris@425 227
Chris@172 228 bool HgTabWidget::haveChangesToCommit() const
Chris@172 229 {
Chris@505 230 return m_haveMerge || m_fileStatusWidget->haveChangesToCommit();
Chris@172 231 }
Chris@172 232
Chris@109 233 QStringList HgTabWidget::getAllCommittableFiles() const
Chris@109 234 {
Chris@116 235 return m_fileStatusWidget->getAllCommittableFiles();
Chris@109 236 }
Chris@109 237
Chris@109 238 QStringList HgTabWidget::getAllRevertableFiles() const
Chris@109 239 {
Chris@116 240 return m_fileStatusWidget->getAllRevertableFiles();
Chris@109 241 }
Chris@109 242
Chris@96 243 QStringList HgTabWidget::getSelectedAddableFiles() const
Chris@95 244 {
Chris@116 245 return m_fileStatusWidget->getSelectedAddableFiles();
Chris@95 246 }
Chris@95 247
Chris@96 248 QStringList HgTabWidget::getSelectedRemovableFiles() const
Chris@95 249 {
Chris@116 250 return m_fileStatusWidget->getSelectedRemovableFiles();
Chris@95 251 }
Chris@95 252
Chris@163 253 QStringList HgTabWidget::getAllUnresolvedFiles() const
Chris@163 254 {
Chris@163 255 return m_fileStatusWidget->getAllUnresolvedFiles();
Chris@163 256 }
Chris@163 257
Chris@96 258 void HgTabWidget::updateWorkFolderFileList(QString fileList)
jtkorhonen@0 259 {
Chris@116 260 m_fileStates.parseStates(fileList);
Chris@116 261 m_fileStatusWidget->setFileStates(m_fileStates);
jtkorhonen@0 262 }
jtkorhonen@0 263
Chris@505 264 void HgTabWidget::setHaveMerge(bool haveMerge)
Chris@505 265 {
Chris@505 266 if (m_haveMerge != haveMerge) {
Chris@505 267 m_haveMerge = haveMerge;
Chris@505 268 m_historyWidget->setShowUncommitted(haveChangesToCommit());
Chris@505 269 updateHistory();
Chris@505 270 }
Chris@505 271 }
Chris@505 272
Chris@120 273 void HgTabWidget::setNewLog(QString hgLogList)
jtkorhonen@0 274 {
Chris@120 275 m_historyWidget->parseNewLog(hgLogList);
Chris@134 276 if (m_historyWidget->haveNewItems()) {
Chris@153 277 showHistoryTab();
Chris@134 278 }
Chris@120 279 }
Chris@120 280
Chris@120 281 void HgTabWidget::addIncrementalLog(QString hgLogList)
Chris@120 282 {
Chris@120 283 m_historyWidget->parseIncrementalLog(hgLogList);
Chris@134 284 if (m_historyWidget->haveNewItems()) {
sam@634 285 QSettings settings;
sam@634 286 settings.beginGroup("Presentation");
sam@634 287 if (settings.value("showHistoryAutomatically", true).toBool()) {
sam@634 288 showHistoryTab();
sam@634 289 }
Chris@134 290 }
jtkorhonen@0 291 }
jtkorhonen@0 292
Chris@287 293 void HgTabWidget::setLocalPath(QString workFolderPath)
jtkorhonen@0 294 {
Chris@116 295 m_fileStatusWidget->setLocalPath(workFolderPath);
Chris@106 296 }
Chris@153 297
Chris@153 298 void HgTabWidget::showWorkTab()
Chris@153 299 {
Chris@153 300 setCurrentWidget(m_fileStatusWidget);
Chris@153 301 }
Chris@153 302
Chris@153 303 void HgTabWidget::showHistoryTab()
Chris@153 304 {
Chris@153 305 setCurrentWidget(m_historyWidget);
Chris@153 306 }
Chris@153 307
Chris@484 308 bool HgTabWidget::shouldShowAll() const
Chris@484 309 {
Chris@484 310 return m_fileStatusWidget->shouldShowAll();
Chris@484 311 }
Chris@484 312