]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompareHistory.cpp
Make the InsetInfo dialog a bit less esoteric.
[lyx.git] / src / frontends / qt4 / GuiCompareHistory.cpp
1 /**
2  * \file GuiCompareHistory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Pavel Sanda
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <support/debug.h>
13 #include <limits>
14
15 #include "GuiCompareHistory.h"
16
17 #include "Buffer.h"
18 #include "BufferView.h"
19 #include "FuncRequest.h"
20 #include "GuiView.h"
21 #include "LyXVC.h"
22
23 #include "support/convert.h"
24 #include "support/lstrings.h"
25
26 #include <QDialogButtonBox>
27 #include <QPushButton>
28
29 using namespace std;
30 using namespace lyx::support;
31
32 namespace lyx {
33 namespace frontend {
34
35
36 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
37         : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
38
39 {
40         setupUi(this);
41         setModal(Qt::WindowModal);
42
43         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
44                 this, SLOT(slotButtonBox(QAbstractButton *)));
45
46         connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
47         connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
48 }
49
50 bool GuiCompareHistory::initialiseParams(std::string const &)
51 {
52         string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
53         int rev = 0;
54
55         string tmp;
56         bool enableBetween = true;
57         // GIT case, hash is long
58         if (revstring.length() > 20) {
59                 enableBetween = false;
60                 rev = numeric_limits<int>::max();
61         } else {
62                 // RCS case
63                 if (!isStrInt(revstring))
64                         revstring = rsplit(revstring, tmp , '.' );
65                 // both SVN & RCS cases
66                 if (isStrInt(revstring))
67                         rev = convert<int>(revstring);
68         }
69
70         // later we can provide comparison between two hashes
71         betweenrevRB->setEnabled(enableBetween);
72
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);
79
80         //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
81         //bc().setOK(okPB);
82         //bc().setCancel(cancelPB);
83         enableControls();
84         return true;
85 }
86
87
88 void GuiCompareHistory::updateContents()
89 {
90         enableControls();
91 }
92
93
94 void GuiCompareHistory::selectRevback()
95 {
96         betweenrevRB->setChecked(false);
97         enableControls();
98 }
99
100
101 void GuiCompareHistory::selectBetweenrev()
102 {
103         revbackRB->setChecked(false);
104         enableControls();
105 }
106
107
108 void GuiCompareHistory::enableControls()
109 {
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);
118 }
119
120
121 void GuiCompareHistory::slotOK()
122 {
123         string param;
124         if (revbackRB->isChecked())
125                 param = "-" + convert<string>(revbackSB->value());
126         else
127                 param = convert<string>(rev1SB->value()) +
128                         + " " + convert<string>(rev2SB->value());
129
130         GuiDialog::slotClose();
131         dispatch(FuncRequest(LFUN_VC_COMPARE, param));
132 }
133
134
135 void GuiCompareHistory::slotCancel()
136 {
137         GuiDialog::slotClose();
138 }
139
140
141 void GuiCompareHistory::slotButtonBox(QAbstractButton * button)
142 {
143         switch (buttonBox->standardButton(button)) {
144         case QDialogButtonBox::Ok:
145                 slotOK();
146                 break;
147         case QDialogButtonBox::Cancel:
148                 slotCancel();
149                 break;
150         default:
151                 break;
152         }
153 }
154
155
156 Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
157
158
159 } // namespace frontend
160 } // namespace lyx
161
162
163 #include "moc_GuiCompareHistory.cpp"