]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCompareHistory.cpp
Add decent UI for VC_COMPARE
[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
13 #include "GuiCompareHistory.h"
14
15 #include "Buffer.h"
16 #include "BufferView.h"
17 #include "FuncRequest.h"
18 #include "GuiView.h"
19 #include "LyXVC.h"
20
21 #include "support/convert.h"
22 #include "support/lstrings.h"
23
24
25
26 using namespace std;
27 using namespace lyx::support;
28
29 namespace lyx {
30 namespace frontend {
31
32
33 GuiCompareHistory::GuiCompareHistory(GuiView & lv)
34         : GuiDialog(lv, "comparehistory", qt_("Compare different revisions"))
35
36 {
37         setupUi(this);
38         setModal(Qt::WindowModal);
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotCancel()));
42
43         connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback()));
44         connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev()));
45
46         string revstring = lv.currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File);
47         int rev=0;
48         if (prefixIs(revstring, "r"))
49                 revstring = ltrim(revstring,"r");
50         if (isStrInt(revstring))
51                 rev = convert<int>(revstring);
52
53         okPB->setEnabled(rev);
54         rev1SB->setMaximum(rev);
55         rev2SB->setMaximum(rev);
56         revbackSB->setMaximum(rev);
57         rev2SB->setValue(rev);
58         rev1SB->setValue(rev-1);
59
60         //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
61         //bc().setOK(okPB);
62         //bc().setCancel(cancelPB);
63         enableControls();
64 }
65
66
67 void GuiCompareHistory::updateContents()
68 {
69         enableControls();
70 }
71
72
73 void GuiCompareHistory::selectRevback()
74 {
75         betweenrevRB->setChecked(false);
76         enableControls();
77 }
78
79
80 void GuiCompareHistory::selectBetweenrev()
81 {
82         revbackRB->setChecked(false);
83         enableControls();
84 }
85
86
87 void GuiCompareHistory::enableControls()
88 {
89         bool rb = revbackRB->isChecked();
90         rev1SB->setEnabled(!rb);
91         rev2SB->setEnabled(!rb);
92         betweenrevRB->setChecked(!rb);
93         revbackSB->setEnabled(rb);
94 }
95
96
97 void GuiCompareHistory::slotOK()
98 {
99         string param;
100         if (revbackRB->isChecked())
101                 param = "-" + convert<string>(revbackSB->value());
102         else
103                 param = convert<string>(rev1SB->value()) +
104                         + " " + convert<string>(rev2SB->value());
105
106         GuiDialog::slotClose();
107         dispatch(FuncRequest(LFUN_VC_COMPARE, param));
108 }
109
110
111 void GuiCompareHistory::slotCancel()
112 {
113         GuiDialog::slotClose();
114 }
115
116
117 Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); }
118
119
120 } // namespace frontend
121 } // namespace lyx
122
123
124 #include "moc_GuiCompareHistory.cpp"