-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpatchview.cpp
More file actions
187 lines (141 loc) · 4.71 KB
/
Copy pathpatchview.cpp
File metadata and controls
187 lines (141 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Description: patch viewer window
Author: Marco Costalba (C) 2005-2007
Copyright: See COPYING file that comes with this distribution
*/
#include <QScrollBar>
#include "common.h"
#include "git.h"
#include "mainimpl.h"
#include "patchcontent.h"
#include "patchview.h"
PatchView::PatchView(MainImpl* mi, Git* g) : Domain(mi, g, false) {
patchTab = new Ui_TabPatch();
patchTab->setupUi(container);
SCRef ic(QString::fromUtf8(":/icons/resources/plusminus.png"));
patchTab->buttonFilterPatch->setIcon(QIcon(ic));
QButtonGroup* bg = new QButtonGroup(this);
bg->addButton(patchTab->radioButtonParent, DIFF_TO_PARENT);
bg->addButton(patchTab->radioButtonHead, DIFF_TO_HEAD);
bg->addButton(patchTab->radioButtonSha, DIFF_TO_SHA);
connect(bg, SIGNAL(buttonClicked(int)), this, SLOT(button_clicked(int)));
patchTab->textBrowserDesc->setup(this);
patchTab->textEditDiff->setup(this, git);
patchTab->fileList->setup(this, git);
connect(m(), SIGNAL(typeWriterFontChanged()),
patchTab->textEditDiff, SLOT(typeWriterFontChanged()));
connect(m(), SIGNAL(changeFont(const QFont&)),
patchTab->fileList, SLOT(on_changeFont(const QFont&)));
connect(patchTab->lineEditDiff, SIGNAL(returnPressed()),
this, SLOT(lineEditDiff_returnPressed()));
connect(patchTab->fileList, SIGNAL(contextMenu(const QString&, int)),
this, SLOT(on_contextMenu(const QString&, int)));
connect(patchTab->buttonFilterPatch, SIGNAL(clicked()),
this, SLOT(buttonFilterPatch_clicked()));
}
PatchView::~PatchView() {
if (!parent())
return;
clear(); // to cancel any data loading
delete patchTab;
}
void PatchView::clear(bool complete) {
if (complete) {
st.clear();
patchTab->textBrowserDesc->clear();
patchTab->fileList->clear();
}
patchTab->textEditDiff->clear();
}
void PatchView::buttonFilterPatch_clicked() {
QString ic;
PatchContent* pc = patchTab->textEditDiff;
pc->prevFilter = pc->curFilter;
if (pc->curFilter == PatchContent::VIEW_ALL) {
pc->curFilter = PatchContent::VIEW_ADDED;
ic = QString::fromUtf8(":/icons/resources/plusonly.png");
} else if (pc->curFilter == PatchContent::VIEW_ADDED) {
pc->curFilter = PatchContent::VIEW_REMOVED;
ic = QString::fromUtf8(":/icons/resources/minusonly.png");
} else if (pc->curFilter == PatchContent::VIEW_REMOVED) {
pc->curFilter = PatchContent::VIEW_ALL;
ic = QString::fromUtf8(":/icons/resources/plusminus.png");
}
patchTab->buttonFilterPatch->setIcon(QIcon(ic));
patchTab->textEditDiff->refresh();
}
void PatchView::on_contextMenu(const QString& data, int type) {
if (isLinked()) // skip if not linked to main view
Domain::on_contextMenu(data, type);
}
void PatchView::lineEditDiff_returnPressed() {
if (patchTab->lineEditDiff->text().isEmpty())
return;
patchTab->radioButtonSha->setChecked(true); // could be called by code
button_clicked(DIFF_TO_SHA);
}
void PatchView::button_clicked(int diffType) {
QString sha;
switch (diffType) {
case DIFF_TO_PARENT:
break;
case DIFF_TO_HEAD:
sha = "HEAD";
break;
case DIFF_TO_SHA:
sha = patchTab->lineEditDiff->text();
break;
}
if (sha == QGit::ZERO_SHA)
return;
// check for a ref name or an abbreviated form
normalizedSha = (sha.length() != 40 && !sha.isEmpty() ? git->getRefSha(sha) : sha);
if (normalizedSha != st.diffToSha()) { // avoid looping
st.setDiffToSha(normalizedSha); // could be empty
UPDATE();
}
}
void PatchView::on_updateRevDesc() {
SCRef d = m()->getRevisionDesc(st.sha());
patchTab->textBrowserDesc->setHtml(d);
}
void PatchView::updatePatch() {
PatchContent* pc = patchTab->textEditDiff;
pc->clear();
if (normalizedSha != st.diffToSha()) { // note <(null)> != <(empty)>
if (!st.diffToSha().isEmpty()) {
patchTab->lineEditDiff->setText(st.diffToSha());
lineEditDiff_returnPressed();
} else if (!normalizedSha.isEmpty()) {
normalizedSha = "";
// we cannot uncheck radioButtonSha directly
// because "Parent" button will stay off
patchTab->radioButtonParent->toggle();
}
}
pc->update(st); // non blocking
}
bool PatchView::doUpdate(bool force) {
const RevFile* files = NULL;
bool newFiles = false;
if (st.isChanged(StateInfo::SHA) || force) {
if (!isLinked()) {
QString caption(git->getShortLog(st.sha()));
if (caption.length() > 30)
caption = caption.left(30 - 3).trimmed().append("...");
setTabCaption(caption);
}
on_updateRevDesc();
}
if (st.isChanged(StateInfo::ANY & ~StateInfo::FILE_NAME) || force) {
updatePatch();
patchTab->fileList->clear();
files = git->getFiles(st.sha(), st.diffToSha(), st.allMergeFiles());
newFiles = true;
}
// call always to allow a simple refresh
patchTab->fileList->update(files, newFiles);
if (st.isChanged() || force)
patchTab->textEditDiff->centerOnFileHeader(st);
return true;
}