comparison src/hgtabwidget.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents hgtabwidget.cpp@4cd753e083cc
children ad106f5fe75f
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on HgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "hgtabwidget.h"
19 #include "common.h"
20 #include "filestatuswidget.h"
21 #include "historywidget.h"
22
23 #include <QClipboard>
24 #include <QContextMenuEvent>
25 #include <QApplication>
26
27 #include <iostream>
28
29 HgTabWidget::HgTabWidget(QWidget *parent,
30 QString workFolderPath) :
31 QTabWidget(parent)
32 {
33 // Work tab
34 m_fileStatusWidget = new FileStatusWidget;
35 m_fileStatusWidget->setLocalPath(workFolderPath);
36
37 connect(m_fileStatusWidget, SIGNAL(selectionChanged()),
38 this, SIGNAL(selectionChanged()));
39
40 connect(m_fileStatusWidget, SIGNAL(showAllChanged(bool)),
41 this, SIGNAL(showAllChanged(bool)));
42
43 connect(m_fileStatusWidget, SIGNAL(annotateFiles(QStringList)),
44 this, SIGNAL(annotateFiles(QStringList)));
45
46 connect(m_fileStatusWidget, SIGNAL(diffFiles(QStringList)),
47 this, SIGNAL(diffFiles(QStringList)));
48
49 connect(m_fileStatusWidget, SIGNAL(commitFiles(QStringList)),
50 this, SIGNAL(commitFiles(QStringList)));
51
52 connect(m_fileStatusWidget, SIGNAL(revertFiles(QStringList)),
53 this, SIGNAL(revertFiles(QStringList)));
54
55 connect(m_fileStatusWidget, SIGNAL(renameFiles(QStringList)),
56 this, SIGNAL(renameFiles(QStringList)));
57
58 connect(m_fileStatusWidget, SIGNAL(copyFiles(QStringList)),
59 this, SIGNAL(copyFiles(QStringList)));
60
61 connect(m_fileStatusWidget, SIGNAL(addFiles(QStringList)),
62 this, SIGNAL(addFiles(QStringList)));
63
64 connect(m_fileStatusWidget, SIGNAL(removeFiles(QStringList)),
65 this, SIGNAL(removeFiles(QStringList)));
66
67 connect(m_fileStatusWidget, SIGNAL(redoFileMerges(QStringList)),
68 this, SIGNAL(redoFileMerges(QStringList)));
69
70 connect(m_fileStatusWidget, SIGNAL(markFilesResolved(QStringList)),
71 this, SIGNAL(markFilesResolved(QStringList)));
72
73 connect(m_fileStatusWidget, SIGNAL(ignoreFiles(QStringList)),
74 this, SIGNAL(ignoreFiles(QStringList)));
75
76 connect(m_fileStatusWidget, SIGNAL(unIgnoreFiles(QStringList)),
77 this, SIGNAL(unIgnoreFiles(QStringList)));
78
79 addTab(m_fileStatusWidget, tr("My work"));
80
81 // History graph tab
82 m_historyWidget = new HistoryWidget;
83 addTab(m_historyWidget, tr("History"));
84
85 connect(m_historyWidget, SIGNAL(commit()),
86 this, SIGNAL(commit()));
87
88 connect(m_historyWidget, SIGNAL(revert()),
89 this, SIGNAL(revert()));
90
91 connect(m_historyWidget, SIGNAL(showSummary()),
92 this, SIGNAL(showSummary()));
93
94 connect(m_historyWidget, SIGNAL(newBranch()),
95 this, SIGNAL(newBranch()));
96
97 connect(m_historyWidget, SIGNAL(noBranch()),
98 this, SIGNAL(noBranch()));
99
100 connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
101 this, SIGNAL(diffWorkingFolder()));
102
103 connect(m_historyWidget, SIGNAL(showWork()),
104 this, SLOT(showWorkTab()));
105
106 connect(m_historyWidget, SIGNAL(updateTo(QString)),
107 this, SIGNAL(updateTo(QString)));
108
109 connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
110 this, SIGNAL(diffToCurrent(QString)));
111
112 connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
113 this, SIGNAL(diffToParent(QString, QString)));
114
115 connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
116 this, SIGNAL(showSummary(Changeset *)));
117
118 connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
119 this, SIGNAL(mergeFrom(QString)));
120
121 connect(m_historyWidget, SIGNAL(newBranch(QString)),
122 this, SIGNAL(newBranch(QString)));
123
124 connect(m_historyWidget, SIGNAL(tag(QString)),
125 this, SIGNAL(tag(QString)));
126 }
127
128 void HgTabWidget::clearSelections()
129 {
130 m_fileStatusWidget->clearSelections();
131 }
132
133 void HgTabWidget::setCurrent(QStringList ids, QString branch)
134 {
135 bool showUncommitted = haveChangesToCommit();
136 m_historyWidget->setCurrent(ids, branch, showUncommitted);
137 }
138
139 void HgTabWidget::updateFileStates()
140 {
141 m_fileStatusWidget->updateWidgets();
142 }
143
144 void HgTabWidget::updateHistory()
145 {
146 m_historyWidget->update();
147 }
148
149 bool HgTabWidget::canDiff() const
150 {
151 return canRevert();
152 }
153
154 bool HgTabWidget::canCommit() const
155 {
156 if (!m_fileStatusWidget->haveChangesToCommit()) return false;
157 if (!m_fileStatusWidget->getAllUnresolvedFiles().empty()) return false;
158 return true;
159 }
160
161 bool HgTabWidget::canRevert() const
162 {
163 // Not the same as canCommit() -- we can revert (and diff)
164 // unresolved files, but we can't commit them
165 if (!m_fileStatusWidget->haveChangesToCommit() &&
166 m_fileStatusWidget->getAllUnresolvedFiles().empty()) return false;
167 return true;
168 }
169
170 bool HgTabWidget::canAdd() const
171 {
172 // Permit this only when work tab is visible
173 if (currentIndex() != 0) return false;
174
175 QStringList addable = m_fileStatusWidget->getSelectedAddableFiles();
176 if (addable.empty()) return false;
177
178 QStringList removable = m_fileStatusWidget->getSelectedRemovableFiles();
179 if (!removable.empty()) return false;
180
181 return true;
182 }
183
184 bool HgTabWidget::canRemove() const
185 {
186 // Permit this only when work tab is visible
187 if (currentIndex() != 0) return false;
188
189 if (m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
190 if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
191 return true;
192 }
193
194 bool HgTabWidget::canResolve() const
195 {
196 return !m_fileStatusWidget->getAllUnresolvedFiles().empty();
197 }
198
199 bool HgTabWidget::haveChangesToCommit() const
200 {
201 return m_fileStatusWidget->haveChangesToCommit();
202 }
203
204 QStringList HgTabWidget::getAllCommittableFiles() const
205 {
206 return m_fileStatusWidget->getAllCommittableFiles();
207 }
208
209 QStringList HgTabWidget::getAllRevertableFiles() const
210 {
211 return m_fileStatusWidget->getAllRevertableFiles();
212 }
213
214 QStringList HgTabWidget::getSelectedAddableFiles() const
215 {
216 return m_fileStatusWidget->getSelectedAddableFiles();
217 }
218
219 QStringList HgTabWidget::getSelectedRemovableFiles() const
220 {
221 return m_fileStatusWidget->getSelectedRemovableFiles();
222 }
223
224 QStringList HgTabWidget::getAllUnresolvedFiles() const
225 {
226 return m_fileStatusWidget->getAllUnresolvedFiles();
227 }
228
229 void HgTabWidget::updateWorkFolderFileList(QString fileList)
230 {
231 m_fileStates.parseStates(fileList);
232 m_fileStatusWidget->setFileStates(m_fileStates);
233 }
234
235 void HgTabWidget::setNewLog(QString hgLogList)
236 {
237 m_historyWidget->parseNewLog(hgLogList);
238 if (m_historyWidget->haveNewItems()) {
239 showHistoryTab();
240 }
241 }
242
243 void HgTabWidget::addIncrementalLog(QString hgLogList)
244 {
245 m_historyWidget->parseIncrementalLog(hgLogList);
246 if (m_historyWidget->haveNewItems()) {
247 showHistoryTab();
248 }
249 }
250
251 void HgTabWidget::setLocalPath(QString workFolderPath)
252 {
253 m_fileStatusWidget->setLocalPath(workFolderPath);
254 }
255
256 void HgTabWidget::showWorkTab()
257 {
258 setCurrentWidget(m_fileStatusWidget);
259 }
260
261 void HgTabWidget::showHistoryTab()
262 {
263 setCurrentWidget(m_historyWidget);
264 }
265