annotate hgtabwidget.cpp @ 323:adb14d3f780f filelist_right_button_menu

* Trivial change, just checkpointing
author Chris Cannam
date Thu, 10 Mar 2011 15:33:02 +0000
parents 4811eb34e819
children 6e1fdda1dff2
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@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 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>
Chris@50 26
Chris@44 27 #include <iostream>
jtkorhonen@0 28
Chris@96 29 HgTabWidget::HgTabWidget(QWidget *parent,
Chris@95 30 QString workFolderPath) :
Chris@117 31 QTabWidget(parent)
jtkorhonen@0 32 {
Chris@91 33 // Work page
Chris@116 34 m_fileStatusWidget = new FileStatusWidget;
Chris@116 35 m_fileStatusWidget->setLocalPath(workFolderPath);
Chris@116 36 connect(m_fileStatusWidget, SIGNAL(selectionChanged()),
Chris@95 37 this, SIGNAL(selectionChanged()));
Chris@199 38 connect(m_fileStatusWidget, SIGNAL(showAllChanged(bool)),
Chris@199 39 this, SIGNAL(showAllChanged(bool)));
Chris@116 40 addTab(m_fileStatusWidget, tr("My work"));
Chris@88 41
Chris@43 42 // History graph page
Chris@116 43 m_historyWidget = new HistoryWidget;
Chris@116 44 addTab(m_historyWidget, tr("History"));
Chris@141 45
Chris@141 46 connect(m_historyWidget, SIGNAL(commit()),
Chris@141 47 this, SIGNAL(commit()));
Chris@141 48
Chris@141 49 connect(m_historyWidget, SIGNAL(revert()),
Chris@141 50 this, SIGNAL(revert()));
Chris@141 51
Chris@168 52 connect(m_historyWidget, SIGNAL(showSummary()),
Chris@168 53 this, SIGNAL(showSummary()));
Chris@168 54
Chris@311 55 connect(m_historyWidget, SIGNAL(newBranch()),
Chris@311 56 this, SIGNAL(newBranch()));
Chris@311 57
Chris@311 58 connect(m_historyWidget, SIGNAL(noBranch()),
Chris@311 59 this, SIGNAL(noBranch()));
Chris@311 60
Chris@141 61 connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
Chris@141 62 this, SIGNAL(diffWorkingFolder()));
Chris@141 63
Chris@153 64 connect(m_historyWidget, SIGNAL(showWork()),
Chris@153 65 this, SLOT(showWorkTab()));
Chris@153 66
Chris@141 67 connect(m_historyWidget, SIGNAL(updateTo(QString)),
Chris@141 68 this, SIGNAL(updateTo(QString)));
Chris@141 69
Chris@141 70 connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
Chris@141 71 this, SIGNAL(diffToCurrent(QString)));
Chris@141 72
Chris@148 73 connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
Chris@148 74 this, SIGNAL(diffToParent(QString, QString)));
Chris@141 75
Chris@289 76 connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
Chris@289 77 this, SIGNAL(showSummary(Changeset *)));
Chris@288 78
Chris@141 79 connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
Chris@141 80 this, SIGNAL(mergeFrom(QString)));
Chris@141 81
Chris@278 82 connect(m_historyWidget, SIGNAL(newBranch(QString)),
Chris@278 83 this, SIGNAL(newBranch(QString)));
Chris@278 84
Chris@141 85 connect(m_historyWidget, SIGNAL(tag(QString)),
Chris@141 86 this, SIGNAL(tag(QString)));
jtkorhonen@32 87 }
jtkorhonen@32 88
Chris@96 89 void HgTabWidget::clearSelections()
Chris@94 90 {
Chris@116 91 m_fileStatusWidget->clearSelections();
Chris@94 92 }
Chris@94 93
Chris@153 94 void HgTabWidget::setCurrent(QStringList ids, QString branch)
Chris@128 95 {
Chris@172 96 bool showUncommitted = haveChangesToCommit();
Chris@163 97 m_historyWidget->setCurrent(ids, branch, showUncommitted);
Chris@129 98 }
Chris@129 99
Chris@230 100 void HgTabWidget::updateFileStates()
Chris@230 101 {
Chris@230 102 m_fileStatusWidget->updateWidgets();
Chris@230 103 }
Chris@230 104
Chris@154 105 void HgTabWidget::updateHistory()
Chris@154 106 {
Chris@154 107 m_historyWidget->update();
Chris@154 108 }
Chris@154 109
Chris@163 110 bool HgTabWidget::canDiff() const
Chris@163 111 {
Chris@237 112 return canRevert();
Chris@163 113 }
Chris@163 114
Chris@96 115 bool HgTabWidget::canCommit() const
Chris@90 116 {
Chris@237 117 if (!m_fileStatusWidget->haveChangesToCommit()) return false;
Chris@237 118 if (!m_fileStatusWidget->getAllUnresolvedFiles().empty()) return false;
Chris@237 119
Chris@237 120 QStringList addable = m_fileStatusWidget->getSelectedAddableFiles();
Chris@237 121 if (addable.empty()) return true;
Chris@237 122
Chris@237 123 QStringList committable = m_fileStatusWidget->getSelectedCommittableFiles();
Chris@237 124
Chris@237 125 // "Removed" files are both committable and addable; don't return
Chris@237 126 // a false negative if the selection only contains these
Chris@237 127 if (committable == addable) return true;
Chris@237 128 return false;
Chris@90 129 }
jtkorhonen@0 130
Chris@109 131 bool HgTabWidget::canRevert() const
Chris@109 132 {
Chris@237 133 // Not the same as canCommit() -- we can revert (and diff)
Chris@237 134 // unresolved files, but we can't commit them
Chris@237 135 if (!m_fileStatusWidget->haveChangesToCommit() &&
Chris@237 136 m_fileStatusWidget->getAllUnresolvedFiles().empty()) return false;
Chris@237 137
Chris@237 138 // The rest of this logic is as in canCommit though
Chris@237 139
Chris@237 140 QStringList addable = m_fileStatusWidget->getSelectedAddableFiles();
Chris@237 141 if (addable.empty()) return true;
Chris@237 142
Chris@237 143 QStringList committable = m_fileStatusWidget->getSelectedCommittableFiles();
Chris@237 144 if (committable == addable) return true;
Chris@237 145 return false;
Chris@109 146 }
Chris@109 147
Chris@96 148 bool HgTabWidget::canAdd() const
Chris@95 149 {
Chris@204 150 QStringList addable = m_fileStatusWidget->getSelectedAddableFiles();
Chris@204 151 if (addable.empty()) return false;
Chris@204 152
Chris@204 153 QStringList removable = m_fileStatusWidget->getSelectedRemovableFiles();
Chris@204 154 if (!removable.empty()) return false;
Chris@204 155
Chris@204 156 QStringList committable = m_fileStatusWidget->getSelectedCommittableFiles();
Chris@237 157
Chris@204 158 // "Removed" files are both committable and addable; don't return
Chris@237 159 // a false negative if the selection only contains these
Chris@204 160 if (committable == addable || committable.empty()) return true;
Chris@204 161 return false;
Chris@95 162 }
Chris@95 163
Chris@96 164 bool HgTabWidget::canRemove() const
Chris@95 165 {
Chris@116 166 if (m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
Chris@116 167 if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
Chris@95 168 return true;
Chris@95 169 }
Chris@95 170
Chris@163 171 bool HgTabWidget::canResolve() const
Chris@95 172 {
Chris@163 173 return !m_fileStatusWidget->getSelectedUnresolvedFiles().empty();
Chris@95 174 }
Chris@95 175
Chris@172 176 bool HgTabWidget::haveChangesToCommit() const
Chris@172 177 {
Chris@172 178 return m_fileStatusWidget->haveChangesToCommit();
Chris@172 179 }
Chris@172 180
Chris@96 181 QStringList HgTabWidget::getAllSelectedFiles() const
Chris@95 182 {
Chris@116 183 return m_fileStatusWidget->getAllSelectedFiles();
Chris@95 184 }
Chris@95 185
Chris@109 186 QStringList HgTabWidget::getAllCommittableFiles() const
Chris@109 187 {
Chris@116 188 return m_fileStatusWidget->getAllCommittableFiles();
Chris@109 189 }
Chris@109 190
Chris@96 191 QStringList HgTabWidget::getSelectedCommittableFiles() const
Chris@95 192 {
Chris@116 193 return m_fileStatusWidget->getSelectedCommittableFiles();
Chris@95 194 }
Chris@95 195
Chris@109 196 QStringList HgTabWidget::getAllRevertableFiles() const
Chris@109 197 {
Chris@116 198 return m_fileStatusWidget->getAllRevertableFiles();
Chris@109 199 }
Chris@109 200
Chris@109 201 QStringList HgTabWidget::getSelectedRevertableFiles() const
Chris@109 202 {
Chris@116 203 return m_fileStatusWidget->getSelectedRevertableFiles();
Chris@109 204 }
Chris@109 205
Chris@96 206 QStringList HgTabWidget::getSelectedAddableFiles() const
Chris@95 207 {
Chris@116 208 return m_fileStatusWidget->getSelectedAddableFiles();
Chris@95 209 }
Chris@95 210
Chris@109 211 QStringList HgTabWidget::getAllRemovableFiles() const
Chris@109 212 {
Chris@116 213 return m_fileStatusWidget->getAllRemovableFiles();
Chris@109 214 }
Chris@109 215
Chris@96 216 QStringList HgTabWidget::getSelectedRemovableFiles() const
Chris@95 217 {
Chris@116 218 return m_fileStatusWidget->getSelectedRemovableFiles();
Chris@95 219 }
Chris@95 220
Chris@163 221 QStringList HgTabWidget::getAllUnresolvedFiles() const
Chris@163 222 {
Chris@163 223 return m_fileStatusWidget->getAllUnresolvedFiles();
Chris@163 224 }
Chris@163 225
Chris@163 226 QStringList HgTabWidget::getSelectedUnresolvedFiles() const
Chris@163 227 {
Chris@163 228 return m_fileStatusWidget->getSelectedUnresolvedFiles();
Chris@163 229 }
Chris@163 230
Chris@96 231 void HgTabWidget::updateWorkFolderFileList(QString fileList)
jtkorhonen@0 232 {
Chris@116 233 m_fileStates.parseStates(fileList);
Chris@116 234 m_fileStatusWidget->setFileStates(m_fileStates);
jtkorhonen@0 235 }
jtkorhonen@0 236
Chris@120 237 void HgTabWidget::setNewLog(QString hgLogList)
jtkorhonen@0 238 {
Chris@120 239 m_historyWidget->parseNewLog(hgLogList);
Chris@134 240 if (m_historyWidget->haveNewItems()) {
Chris@153 241 showHistoryTab();
Chris@134 242 }
Chris@120 243 }
Chris@120 244
Chris@120 245 void HgTabWidget::addIncrementalLog(QString hgLogList)
Chris@120 246 {
Chris@120 247 m_historyWidget->parseIncrementalLog(hgLogList);
Chris@134 248 if (m_historyWidget->haveNewItems()) {
Chris@153 249 showHistoryTab();
Chris@134 250 }
jtkorhonen@0 251 }
jtkorhonen@0 252
Chris@287 253 void HgTabWidget::setLocalPath(QString workFolderPath)
jtkorhonen@0 254 {
Chris@116 255 m_fileStatusWidget->setLocalPath(workFolderPath);
Chris@106 256 }
Chris@153 257
Chris@153 258 void HgTabWidget::showWorkTab()
Chris@153 259 {
Chris@153 260 setCurrentWidget(m_fileStatusWidget);
Chris@153 261 }
Chris@153 262
Chris@153 263 void HgTabWidget::showHistoryTab()
Chris@153 264 {
Chris@153 265 setCurrentWidget(m_historyWidget);
Chris@153 266 }
Chris@153 267