]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiBranch.cpp
Fix a crash following the input of an invalid paragraph separation value in the docum...
[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::closeEvent(QCloseEvent * e)
51 {
52         slotClose();
53         e->accept();
54 }
55
56
57 void GuiBranch::change_adaptor()
58 {
59         changed();
60 }
61
62
63 void GuiBranch::updateContents()
64 {
65         typedef BranchList::const_iterator const_iterator;
66
67         BranchList const & branchlist = buffer().params().branchlist();
68         docstring const cur_branch = params_.branch;
69
70         branchCO->clear();
71
72         const_iterator const begin = branchlist.begin();
73         const_iterator const end = branchlist.end();
74         int id = 0;
75         int count = 0;
76         for (const_iterator it = begin; it != end; ++it, ++count) {
77                 docstring const & branch = it->getBranch();
78                 branchCO->addItem(toqstr(branch));
79
80                 if (cur_branch == branch)
81                         id = count;
82         }
83         branchCO->setCurrentIndex(id);
84 }
85
86
87 void GuiBranch::applyView()
88 {
89         params_.branch = qstring_to_ucs4(branchCO->currentText());
90 }
91
92
93 bool GuiBranch::initialiseParams(string const & data)
94 {
95         InsetBranchMailer::string2params(data, params_);
96         return true;
97 }
98
99
100 void GuiBranch::clearParams()
101 {
102         params_ = InsetBranchParams();
103 }
104
105
106 void GuiBranch::dispatchParams()
107 {
108         dispatch(FuncRequest(getLfun(), InsetBranchMailer::params2string(params_)));
109 }
110
111
112 Dialog * createGuiBranch(GuiView & lv) { return new GuiBranch(lv); }
113
114
115 } // namespace frontend
116 } // namespace lyx
117
118 #include "GuiBranch_moc.cpp"