]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompareHistory.cpp
Make a string translatable
[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
27
28 using namespace std;
29 using namespace lyx::support;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
36         : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
37
38 {
39         setupUi(this);
40         setModal(Qt::WindowModal);
41
42         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43         connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotCancel()));
44
45         connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
46         connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
47 }
48
49 bool GuiCompareHistory::initialiseParams(std::string const &)
50 {
51         string revstring = lyxview().currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
52         int rev=0;
53
54         string tmp;
55         bool enableBetween = true;
56         // GIT case, hash is long
57         if (revstring.length() > 20) {
58                 enableBetween = false;
59                 rev = numeric_limits<int>::max();
60         } else {
61                 // RCS case
62                 if (!isStrInt(revstring))
63                         revstring = rsplit(revstring, tmp , '.' );
64                 // both SVN & RCS cases
65                 if (isStrInt(revstring))
66                         rev = convert<int>(revstring);
67         }
68
69         // later we can provide comparison between two hashes
70         betweenrevRB->setEnabled(enableBetween);
71
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);
78
79         //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
80         //bc().setOK(okPB);
81         //bc().setCancel(cancelPB);
82         enableControls();
83         return true;
84 }
85
86
87 void GuiCompareHistory::updateContents()
88 {
89         enableControls();
90 }
91
92
93 void GuiCompareHistory::selectRevback()
94 {
95         betweenrevRB->setChecked(false);
96         enableControls();
97 }
98
99
100 void GuiCompareHistory::selectBetweenrev()
101 {
102         revbackRB->setChecked(false);
103         enableControls();
104 }
105
106
107 void GuiCompareHistory::enableControls()
108 {
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);
117 }
118
119
120 void GuiCompareHistory::slotOK()
121 {
122         string param;
123         if (revbackRB->isChecked())
124                 param = "-" + convert<string>(revbackSB->value());
125         else
126                 param = convert<string>(rev1SB->value()) +
127                         + " " + convert<string>(rev2SB->value());
128
129         GuiDialog::slotClose();
130         dispatch(FuncRequest(LFUN_VC_COMPARE, param));
131 }
132
133
134 void GuiCompareHistory::slotCancel()
135 {
136         GuiDialog::slotClose();
137 }
138
139
140 Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
141
142
143 } // namespace frontend
144 } // namespace lyx
145
146
147 #include "moc_GuiCompareHistory.cpp"