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