]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBranch.cpp
Introducing TextClassPtr.h to minimize header dependencies.
[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 std::string;
31 using std::vector;
32
33 namespace lyx {
34 namespace frontend {
35
36 GuiBranch::GuiBranch(LyXView & lv)
37         : GuiDialog(lv, "branch")
38 {
39         setupUi(this);
40         setViewTitle(_("Branch Settings"));
41
42         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44         connect(branchCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
45
46         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
47         bc().setOK(okPB);
48         bc().setCancel(closePB);
49 }
50
51
52 void GuiBranch::closeEvent(QCloseEvent * e)
53 {
54         slotClose();
55         e->accept();
56 }
57
58
59 void GuiBranch::change_adaptor()
60 {
61         changed();
62 }
63
64
65 void GuiBranch::updateContents()
66 {
67         typedef BranchList::const_iterator const_iterator;
68
69         BranchList const & branchlist = buffer().params().branchlist();
70         docstring const cur_branch = params_.branch;
71
72         branchCO->clear();
73
74         const_iterator const begin = branchlist.begin();
75         const_iterator const end = branchlist.end();
76         int id = 0;
77         int count = 0;
78         for (const_iterator it = begin; it != end; ++it, ++count) {
79                 docstring const & branch = it->getBranch();
80                 branchCO->addItem(toqstr(branch));
81
82                 if (cur_branch == branch)
83                         id = count;
84         }
85         branchCO->setCurrentIndex(id);
86 }
87
88
89 void GuiBranch::applyView()
90 {
91         params_.branch = qstring_to_ucs4(branchCO->currentText());
92 }
93
94
95 bool GuiBranch::initialiseParams(string const & data)
96 {
97         InsetBranchMailer::string2params(data, params_);
98         return true;
99 }
100
101
102 void GuiBranch::clearParams()
103 {
104         params_ = InsetBranchParams();
105 }
106
107
108 void GuiBranch::dispatchParams()
109 {
110         dispatch(FuncRequest(getLfun(), InsetBranchMailer::params2string(params_)));
111 }
112
113
114 Dialog * createGuiBranch(LyXView & lv) { return new GuiBranch(lv); }
115
116
117 } // namespace frontend
118 } // namespace lyx
119
120 #include "GuiBranch_moc.cpp"