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.
13 #include "GuiCompareHistory.h"
16 #include "BufferView.h"
17 #include "FuncRequest.h"
21 #include "support/convert.h"
22 #include "support/debug.h"
23 #include "support/lstrings.h"
25 #include <QDialogButtonBox>
26 #include <QPushButton>
31 using namespace lyx::support;
37 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
38 : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
42 setModal(Qt::WindowModal);
44 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
45 this, SLOT(slotButtonBox(QAbstractButton *)));
47 connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
48 connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
51 bool GuiCompareHistory::initialiseParams(std::string const &)
53 string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
57 bool enableBetween = true;
58 // GIT case, hash is long
59 if (revstring.length() > 20) {
60 enableBetween = false;
61 rev = numeric_limits<int>::max();
64 if (!isStrInt(revstring))
65 revstring = rsplit(revstring, tmp , '.' );
66 // both SVN & RCS cases
67 if (isStrInt(revstring))
68 rev = convert<int>(revstring);
71 // later we can provide comparison between two hashes
72 betweenrevRB->setEnabled(enableBetween);
74 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(rev);
75 rev1SB->setMaximum(rev);
76 rev2SB->setMaximum(rev);
77 revbackSB->setMaximum(rev-1);
78 rev2SB->setValue(rev);
79 rev1SB->setValue(rev-1);
81 //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
83 //bc().setCancel(cancelPB);
89 void GuiCompareHistory::updateContents()
95 void GuiCompareHistory::selectRevback()
97 betweenrevRB->setChecked(false);
102 void GuiCompareHistory::selectBetweenrev()
104 revbackRB->setChecked(false);
109 void GuiCompareHistory::enableControls()
111 bool rb = revbackRB->isChecked();
112 oldL->setEnabled(!rb);
113 newL->setEnabled(!rb);
114 rev1SB->setEnabled(!rb);
115 rev2SB->setEnabled(!rb);
116 rev2SB->setEnabled(!rb);
117 betweenrevRB->setChecked(!rb);
118 revbackSB->setEnabled(rb);
122 void GuiCompareHistory::slotOK()
125 if (revbackRB->isChecked())
126 param = "-" + convert<string>(revbackSB->value());
128 param = convert<string>(rev1SB->value()) +
129 + " " + convert<string>(rev2SB->value());
131 GuiDialog::slotClose();
132 dispatch(FuncRequest(LFUN_VC_COMPARE, param));
136 void GuiCompareHistory::slotCancel()
138 GuiDialog::slotClose();
142 void GuiCompareHistory::slotButtonBox(QAbstractButton * button)
144 switch (buttonBox->standardButton(button)) {
145 case QDialogButtonBox::Ok:
148 case QDialogButtonBox::Cancel:
157 } // namespace frontend
161 #include "moc_GuiCompareHistory.cpp"