2 Description: patch viewer window
4 Author: Marco Costalba (C) 2005-2007
6 Copyright: See COPYING file that comes with this distribution
13 #include "patchcontent.h"
14 #include "patchview.h"
16 PatchView::PatchView(MainImpl
* mi
, Git
* g
) : Domain(mi
, g
, false) {
18 patchTab
= new Ui_TabPatch();
19 patchTab
->setupUi(container
);
20 SCRef
ic(QString::fromUtf8(":/icons/resources/plusminus.png"));
21 patchTab
->buttonFilterPatch
->setIcon(QIcon(ic
));
23 QButtonGroup
* bg
= new QButtonGroup(this);
24 bg
->addButton(patchTab
->radioButtonParent
, DIFF_TO_PARENT
);
25 bg
->addButton(patchTab
->radioButtonHead
, DIFF_TO_HEAD
);
26 bg
->addButton(patchTab
->radioButtonSha
, DIFF_TO_SHA
);
27 connect(bg
, SIGNAL(buttonClicked(int)), this, SLOT(button_clicked(int)));
29 patchTab
->textBrowserDesc
->setup(this);
30 patchTab
->textEditDiff
->setup(this, git
);
31 patchTab
->fileList
->setup(this, git
);
33 connect(m(), SIGNAL(typeWriterFontChanged()),
34 patchTab
->textEditDiff
, SLOT(typeWriterFontChanged()));
36 connect(m(), SIGNAL(changeFont(const QFont
&)),
37 patchTab
->fileList
, SLOT(on_changeFont(const QFont
&)));
39 connect(patchTab
->lineEditDiff
, SIGNAL(returnPressed()),
40 this, SLOT(lineEditDiff_returnPressed()));
42 connect(patchTab
->fileList
, SIGNAL(contextMenu(const QString
&, int)),
43 this, SLOT(on_contextMenu(const QString
&, int)));
45 connect(patchTab
->buttonFilterPatch
, SIGNAL(clicked()),
46 this, SLOT(buttonFilterPatch_clicked()));
49 PatchView::~PatchView() {
54 clear(); // to cancel any data loading
58 void PatchView::clear(bool complete
) {
62 patchTab
->textBrowserDesc
->clear();
63 patchTab
->fileList
->clear();
65 patchTab
->textEditDiff
->clear();
68 void PatchView::buttonFilterPatch_clicked() {
71 PatchContent
* pc
= patchTab
->textEditDiff
;
72 pc
->prevFilter
= pc
->curFilter
;
73 if (pc
->curFilter
== PatchContent::VIEW_ALL
) {
74 pc
->curFilter
= PatchContent::VIEW_ADDED
;
75 ic
= QString::fromUtf8(":/icons/resources/plusonly.png");
77 } else if (pc
->curFilter
== PatchContent::VIEW_ADDED
) {
78 pc
->curFilter
= PatchContent::VIEW_REMOVED
;
79 ic
= QString::fromUtf8(":/icons/resources/minusonly.png");
81 } else if (pc
->curFilter
== PatchContent::VIEW_REMOVED
) {
82 pc
->curFilter
= PatchContent::VIEW_ALL
;
83 ic
= QString::fromUtf8(":/icons/resources/plusminus.png");
85 patchTab
->buttonFilterPatch
->setIcon(QIcon(ic
));
86 patchTab
->textEditDiff
->refresh();
89 void PatchView::on_contextMenu(const QString
& data
, int type
) {
91 if (isLinked()) // skip if not linked to main view
92 Domain::on_contextMenu(data
, type
);
95 void PatchView::lineEditDiff_returnPressed() {
97 if (patchTab
->lineEditDiff
->text().isEmpty())
100 patchTab
->radioButtonSha
->setChecked(true); // could be called by code
101 button_clicked(DIFF_TO_SHA
);
104 void PatchView::button_clicked(int diffType
) {
114 sha
= patchTab
->lineEditDiff
->text();
117 if (sha
== QGit::ZERO_SHA
)
120 // check for a ref name or an abbreviated form
121 normalizedSha
= (sha
.length() != 40 && !sha
.isEmpty() ? git
->getRefSha(sha
) : sha
);
123 if (normalizedSha
!= st
.diffToSha()) { // avoid looping
124 st
.setDiffToSha(normalizedSha
); // could be empty
129 void PatchView::on_updateRevDesc() {
131 SCRef d
= m()->getRevisionDesc(st
.sha());
132 patchTab
->textBrowserDesc
->setHtml(d
);
135 void PatchView::updatePatch() {
137 PatchContent
* pc
= patchTab
->textEditDiff
;
140 if (normalizedSha
!= st
.diffToSha()) { // note <(null)> != <(empty)>
142 if (!st
.diffToSha().isEmpty()) {
143 patchTab
->lineEditDiff
->setText(st
.diffToSha());
144 lineEditDiff_returnPressed();
146 } else if (!normalizedSha
.isEmpty()) {
148 // we cannot uncheck radioButtonSha directly
149 // because "Parent" button will stay off
150 patchTab
->radioButtonParent
->toggle();
153 pc
->update(st
); // non blocking
156 bool PatchView::doUpdate(bool force
) {
158 const RevFile
* files
= NULL
;
159 bool newFiles
= false;
161 if (st
.isChanged(StateInfo::SHA
) || force
) {
164 QString
caption(git
->getShortLog(st
.sha()));
165 if (caption
.length() > 30)
166 caption
= caption
.left(30 - 3).trimmed().append("...");
168 setTabCaption(caption
);
173 if (st
.isChanged(StateInfo::ANY
& ~StateInfo::FILE_NAME
) || force
) {
176 patchTab
->fileList
->clear();
177 files
= git
->getFiles(st
.sha(), st
.diffToSha(), st
.allMergeFiles());
180 // call always to allow a simple refresh
181 patchTab
->fileList
->update(files
, newFiles
);
183 if (st
.isChanged() || force
)
184 patchTab
->textEditDiff
->centerOnFileHeader(st
);