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@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 */
|
jtkorhonen@0
|
17
|
Chris@96
|
18 #include "hgtabwidget.h"
|
jtkorhonen@0
|
19 #include "common.h"
|
Chris@43
|
20 #include "logparser.h"
|
Chris@43
|
21 #include "changeset.h"
|
Chris@43
|
22 #include "changesetitem.h"
|
Chris@44
|
23 #include "grapher.h"
|
cannam@45
|
24 #include "panner.h"
|
cannam@45
|
25 #include "panned.h"
|
Chris@88
|
26 #include "filestatuswidget.h"
|
Chris@44
|
27
|
Chris@50
|
28 #include <QClipboard>
|
Chris@50
|
29 #include <QContextMenuEvent>
|
Chris@50
|
30 #include <QApplication>
|
Chris@50
|
31
|
Chris@44
|
32 #include <iostream>
|
jtkorhonen@0
|
33
|
Chris@96
|
34 HgTabWidget::HgTabWidget(QWidget *parent,
|
Chris@95
|
35 QString remoteRepo,
|
Chris@95
|
36 QString workFolderPath) :
|
Chris@106
|
37 QTabWidget(parent)
|
jtkorhonen@0
|
38 {
|
Chris@91
|
39 // Work page
|
Chris@88
|
40 fileStatusWidget = new FileStatusWidget;
|
Chris@89
|
41 fileStatusWidget->setLocalPath(workFolderPath);
|
Chris@89
|
42 fileStatusWidget->setRemoteURL(remoteRepo);
|
Chris@95
|
43 connect(fileStatusWidget, SIGNAL(selectionChanged()),
|
Chris@95
|
44 this, SIGNAL(selectionChanged()));
|
Chris@89
|
45 addTab(fileStatusWidget, tr("My work"));
|
Chris@88
|
46
|
Chris@43
|
47 // History graph page
|
cannam@45
|
48 historyGraphPageWidget = new QWidget;
|
cannam@45
|
49 Panned *panned = new Panned;
|
cannam@45
|
50 Panner *panner = new Panner;
|
cannam@45
|
51 historyGraphWidget = panned;
|
cannam@45
|
52 historyGraphPanner = panner;
|
cannam@45
|
53 QGridLayout *layout = new QGridLayout;
|
cannam@45
|
54 layout->addWidget(historyGraphWidget, 0, 0);
|
cannam@45
|
55 layout->addWidget(historyGraphPanner, 0, 1);
|
cannam@45
|
56 panner->setMaximumWidth(80);
|
cannam@45
|
57 panner->connectToPanned(panned);
|
cannam@45
|
58 historyGraphPageWidget->setLayout(layout);
|
Chris@58
|
59 addTab(historyGraphPageWidget, tr("History"));
|
jtkorhonen@32
|
60 }
|
jtkorhonen@32
|
61
|
Chris@96
|
62 void HgTabWidget::clearSelections()
|
Chris@94
|
63 {
|
Chris@94
|
64 fileStatusWidget->clearSelections();
|
Chris@94
|
65 }
|
Chris@94
|
66
|
Chris@96
|
67 bool HgTabWidget::canCommit() const
|
Chris@90
|
68 {
|
Chris@109
|
69 if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
|
Chris@90
|
70 return fileStatusWidget->haveChangesToCommit();
|
Chris@90
|
71 }
|
jtkorhonen@0
|
72
|
Chris@109
|
73 bool HgTabWidget::canRevert() const
|
Chris@109
|
74 {
|
Chris@109
|
75 return fileStatusWidget->haveChangesToCommit() ||
|
Chris@109
|
76 !fileStatusWidget->getSelectedRevertableFiles().empty();
|
Chris@109
|
77 }
|
Chris@109
|
78
|
Chris@96
|
79 bool HgTabWidget::canAdd() const
|
Chris@95
|
80 {
|
Chris@95
|
81 if (fileStatusWidget->getSelectedAddableFiles().empty()) return false;
|
Chris@95
|
82 if (!fileStatusWidget->getSelectedCommittableFiles().empty()) return false;
|
Chris@95
|
83 if (!fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
|
Chris@95
|
84 return true;
|
Chris@95
|
85 }
|
Chris@95
|
86
|
Chris@96
|
87 bool HgTabWidget::canRemove() const
|
Chris@95
|
88 {
|
Chris@95
|
89 if (fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
|
Chris@95
|
90 if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
|
Chris@95
|
91 return true;
|
Chris@95
|
92 }
|
Chris@95
|
93
|
Chris@96
|
94 bool HgTabWidget::canDoDiff() const
|
Chris@95
|
95 {
|
Chris@95
|
96 return canCommit();
|
Chris@95
|
97 }
|
Chris@95
|
98
|
Chris@96
|
99 QStringList HgTabWidget::getAllSelectedFiles() const
|
Chris@95
|
100 {
|
Chris@95
|
101 return fileStatusWidget->getAllSelectedFiles();
|
Chris@95
|
102 }
|
Chris@95
|
103
|
Chris@109
|
104 QStringList HgTabWidget::getAllCommittableFiles() const
|
Chris@109
|
105 {
|
Chris@109
|
106 return fileStatusWidget->getAllCommittableFiles();
|
Chris@109
|
107 }
|
Chris@109
|
108
|
Chris@96
|
109 QStringList HgTabWidget::getSelectedCommittableFiles() const
|
Chris@95
|
110 {
|
Chris@95
|
111 return fileStatusWidget->getSelectedCommittableFiles();
|
Chris@95
|
112 }
|
Chris@95
|
113
|
Chris@109
|
114 QStringList HgTabWidget::getAllRevertableFiles() const
|
Chris@109
|
115 {
|
Chris@109
|
116 return fileStatusWidget->getAllRevertableFiles();
|
Chris@109
|
117 }
|
Chris@109
|
118
|
Chris@109
|
119 QStringList HgTabWidget::getSelectedRevertableFiles() const
|
Chris@109
|
120 {
|
Chris@109
|
121 return fileStatusWidget->getSelectedRevertableFiles();
|
Chris@109
|
122 }
|
Chris@109
|
123
|
Chris@96
|
124 QStringList HgTabWidget::getSelectedAddableFiles() const
|
Chris@95
|
125 {
|
Chris@95
|
126 return fileStatusWidget->getSelectedAddableFiles();
|
Chris@95
|
127 }
|
Chris@95
|
128
|
Chris@109
|
129 QStringList HgTabWidget::getAllRemovableFiles() const
|
Chris@109
|
130 {
|
Chris@109
|
131 return fileStatusWidget->getAllRemovableFiles();
|
Chris@109
|
132 }
|
Chris@109
|
133
|
Chris@96
|
134 QStringList HgTabWidget::getSelectedRemovableFiles() const
|
Chris@95
|
135 {
|
Chris@95
|
136 return fileStatusWidget->getSelectedRemovableFiles();
|
Chris@95
|
137 }
|
Chris@95
|
138
|
Chris@96
|
139 void HgTabWidget::updateWorkFolderFileList(QString fileList)
|
jtkorhonen@0
|
140 {
|
Chris@94
|
141 fileStates.parseStates(fileList);
|
Chris@92
|
142 fileStatusWidget->setFileStates(fileStates);
|
jtkorhonen@0
|
143 }
|
jtkorhonen@0
|
144
|
Chris@96
|
145 void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList)
|
jtkorhonen@0
|
146 {
|
Chris@43
|
147 //!!!
|
cannam@45
|
148 Panned *panned = static_cast<Panned *>(historyGraphWidget);
|
cannam@45
|
149 Panner *panner = static_cast<Panner *>(historyGraphPanner);
|
Chris@43
|
150 QGraphicsScene *scene = new QGraphicsScene();
|
Chris@43
|
151 Changesets csets = parseChangeSets(hgLogList);
|
Chris@44
|
152 if (csets.empty()) return;
|
Chris@53
|
153 Grapher g(scene);
|
Chris@44
|
154 try {
|
Chris@106
|
155 g.layout(csets);
|
Chris@44
|
156 } catch (std::string s) {
|
Chris@106
|
157 std::cerr << "Internal error: Layout failed: " << s << std::endl;
|
Chris@44
|
158 }
|
Chris@87
|
159 QGraphicsScene *oldScene = panned->scene();
|
cannam@45
|
160 panned->setScene(scene);
|
cannam@45
|
161 panner->setScene(scene);
|
Chris@87
|
162 if (oldScene) delete oldScene;
|
Chris@53
|
163 ChangesetItem *tipItem = g.getItemFor(csets[0]);
|
Chris@53
|
164 if (tipItem) tipItem->ensureVisible();
|
Chris@108
|
165 //!!! track lifecycle of those Changesets
|
jtkorhonen@0
|
166 }
|
jtkorhonen@0
|
167
|
Chris@96
|
168 Changesets HgTabWidget::parseChangeSets(QString changeSetsStr)
|
Chris@43
|
169 {
|
Chris@108
|
170 Changesets csets = Changeset::parseChangesets(changeSetsStr);
|
Chris@44
|
171 for (int i = 0; i+1 < csets.size(); ++i) {
|
Chris@106
|
172 Changeset *cs = csets[i];
|
Chris@106
|
173 if (cs->parents().empty()) {
|
Chris@106
|
174 QStringList list;
|
Chris@106
|
175 list.push_back(csets[i+1]->id());
|
Chris@106
|
176 cs->setParents(list);
|
Chris@106
|
177 }
|
Chris@44
|
178 }
|
Chris@43
|
179 return csets;
|
jtkorhonen@0
|
180 }
|
jtkorhonen@0
|
181
|
Chris@96
|
182 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
|
jtkorhonen@0
|
183 {
|
Chris@89
|
184 fileStatusWidget->setLocalPath(workFolderPath);
|
Chris@89
|
185 fileStatusWidget->setRemoteURL(remoteRepoPath);
|
jtkorhonen@0
|
186 }
|
Chris@106
|
187
|
Chris@115
|
188 void HgTabWidget::setState(QString state)
|
Chris@106
|
189 {
|
Chris@115
|
190 fileStatusWidget->setState(state);
|
Chris@106
|
191 }
|