2 * \file GuiCompareHistory.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
12 #include <support/debug.h>
15 #include "GuiCompareHistory.h"
18 #include "BufferView.h"
19 #include "FuncRequest.h"
23 #include "support/convert.h"
24 #include "support/lstrings.h"
26 #include <QDialogButtonBox>
27 #include <QPushButton>
30 using namespace lyx::support;
36 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
37 : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
41 setModal(Qt::WindowModal);
43 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
44 this, SLOT(slotButtonBox(QAbstractButton *)));
46 connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
47 connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
50 bool GuiCompareHistory::initialiseParams(std::string const &)
52 string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
56 bool enableBetween = true;
57 // GIT case, hash is long
58 if (revstring.length() > 20) {
59 enableBetween = false;
60 rev = numeric_limits<int>::max();
63 if (!isStrInt(revstring))
64 revstring = rsplit(revstring, tmp , '.' );
65 // both SVN & RCS cases
66 if (isStrInt(revstring))
67 rev = convert<int>(revstring);
70 // later we can provide comparison between two hashes
71 betweenrevRB->setEnabled(enableBetween);
73 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(rev);
74 rev1SB->setMaximum(rev);
75 rev2SB->setMaximum(rev);
76 revbackSB->setMaximum(rev-1);
77 rev2SB->setValue(rev);
78 rev1SB->setValue(rev-1);
80 //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
82 //bc().setCancel(cancelPB);
88 void GuiCompareHistory::updateContents()
94 void GuiCompareHistory::selectRevback()
96 betweenrevRB->setChecked(false);
101 void GuiCompareHistory::selectBetweenrev()
103 revbackRB->setChecked(false);
108 void GuiCompareHistory::enableControls()
110 bool rb = revbackRB->isChecked();
111 oldL->setEnabled(!rb);
112 newL->setEnabled(!rb);
113 rev1SB->setEnabled(!rb);
114 rev2SB->setEnabled(!rb);
115 rev2SB->setEnabled(!rb);
116 betweenrevRB->setChecked(!rb);
117 revbackSB->setEnabled(rb);
121 void GuiCompareHistory::slotOK()
124 if (revbackRB->isChecked())
125 param = "-" + convert<string>(revbackSB->value());
127 param = convert<string>(rev1SB->value()) +
128 + " " + convert<string>(rev2SB->value());
130 GuiDialog::slotClose();
131 dispatch(FuncRequest(LFUN_VC_COMPARE, param));
135 void GuiCompareHistory::slotCancel()
137 GuiDialog::slotClose();
141 void GuiCompareHistory::slotButtonBox(QAbstractButton * button)
143 switch (buttonBox->standardButton(button)) {
144 case QDialogButtonBox::Ok:
147 case QDialogButtonBox::Cancel:
156 Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
159 } // namespace frontend
163 #include "moc_GuiCompareHistory.cpp"