]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBranch.cpp
95c52ac014019160d1a8be879fe56f116b134b3b
[lyx.git] / src / frontends / qt4 / GuiBranch.cpp
1 /**
2  * \file GuiBranch.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiBranch.h"
16
17 #include "qt_helpers.h"
18 #include "BranchList.h"
19
20 #include "Buffer.h"
21 #include "BufferParams.h"
22 #include "BranchList.h"
23 #include "FuncRequest.h"
24
25 #include "insets/InsetBranch.h"
26
27 #include <QPushButton>
28 #include <QCloseEvent>
29
30 using namespace std;
31
32 namespace lyx {
33 namespace frontend {
34
35 GuiBranch::GuiBranch(GuiView & lv)
36         : GuiDialog(lv, "branch", qt_("Branch Settings"))
37 {
38         setupUi(this);
39
40         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
42         connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
43
44         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
45         bc().setOK(okPB);
46         bc().setCancel(closePB);
47 }
48
49
50 void GuiBranch::change_adaptor()
51 {
52         changed();
53 }
54
55
56 void GuiBranch::updateContents()
57 {
58         typedef BranchList::const_iterator const_iterator;
59
60         BranchList const & branchlist = buffer().params().branchlist();
61         docstring const cur_branch = params_.branch;
62
63         branchCO->clear();
64
65         const_iterator const begin = branchlist.begin();
66         const_iterator const end = branchlist.end();
67         int id = 0;
68         int count = 0;
69         for (const_iterator it = begin; it != end; ++it, ++count) {
70                 docstring const & branch = it->getBranch();
71                 branchCO->addItem(toqstr(branch));
72
73                 if (cur_branch == branch)
74                         id = count;
75         }
76         branchCO->setCurrentIndex(id);
77 }
78
79
80 void GuiBranch::applyView()
81 {
82         params_.branch = qstring_to_ucs4(branchCO->currentText());
83 }
84
85
86 bool GuiBranch::initialiseParams(string const & data)
87 {
88         InsetBranchMailer::string2params(data, params_);
89         return true;
90 }
91
92
93 void GuiBranch::clearParams()
94 {
95         params_ = InsetBranchParams();
96 }
97
98
99 void GuiBranch::dispatchParams()
100 {
101         dispatch(FuncRequest(getLfun(), InsetBranchMailer::params2string(params_)));
102 }
103
104
105 Dialog * createGuiBranch(GuiView & lv) { return new GuiBranch(lv); }
106
107
108 } // namespace frontend
109 } // namespace lyx
110
111 #include "GuiBranch_moc.cpp"