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"
29 using namespace lyx::support;
35 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
36 : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
40 setModal(Qt::WindowModal);
42 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43 connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotCancel()));
45 connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
46 connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
49 bool GuiCompareHistory::initialiseParams(std::string const &)
51 string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
55 bool enableBetween = true;
56 // GIT case, hash is long
57 if (revstring.length() > 20) {
58 enableBetween = false;
59 rev = numeric_limits<int>::max();
62 if (!isStrInt(revstring))
63 revstring = rsplit(revstring, tmp , '.' );
64 // both SVN & RCS cases
65 if (isStrInt(revstring))
66 rev = convert<int>(revstring);
69 // later we can provide comparison between two hashes
70 betweenrevRB->setEnabled(enableBetween);
72 okPB->setEnabled(rev);
73 rev1SB->setMaximum(rev);
74 rev2SB->setMaximum(rev);
75 revbackSB->setMaximum(rev-1);
76 rev2SB->setValue(rev);
77 rev1SB->setValue(rev-1);
79 //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
81 //bc().setCancel(cancelPB);
87 void GuiCompareHistory::updateContents()
93 void GuiCompareHistory::selectRevback()
95 betweenrevRB->setChecked(false);
100 void GuiCompareHistory::selectBetweenrev()
102 revbackRB->setChecked(false);
107 void GuiCompareHistory::enableControls()
109 bool rb = revbackRB->isChecked();
110 oldL->setEnabled(!rb);
111 newL->setEnabled(!rb);
112 rev1SB->setEnabled(!rb);
113 rev2SB->setEnabled(!rb);
114 rev2SB->setEnabled(!rb);
115 betweenrevRB->setChecked(!rb);
116 revbackSB->setEnabled(rb);
120 void GuiCompareHistory::slotOK()
123 if (revbackRB->isChecked())
124 param = "-" + convert<string>(revbackSB->value());
126 param = convert<string>(rev1SB->value()) +
127 + " " + convert<string>(rev2SB->value());
129 GuiDialog::slotClose();
130 dispatch(FuncRequest(LFUN_VC_COMPARE, param));
134 void GuiCompareHistory::slotCancel()
136 GuiDialog::slotClose();
140 Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
143 } // namespace frontend
147 #include "moc_GuiCompareHistory.cpp"