]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiBranch.cpp
Make string-widget combination more l7n friendly
[lyx.git] / src / frontends / qt / 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
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "BranchList.h"
22
23 #include "insets/InsetBranch.h"
24
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27
28 #include <QPushButton>
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36 GuiBranch::GuiBranch(QWidget * parent) : InsetParamsWidget(parent)
37 {
38         setupUi(this);
39         connect(branchCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
40         connect(invertedCB, SIGNAL(clicked()), this, SIGNAL(changed()));
41 }
42
43
44 void GuiBranch::paramsToDialog(Inset const * inset)
45 {
46         InsetBranch const * ib = static_cast<InsetBranch const *>(inset);
47         Buffer const & buf = ib->buffer();
48         BranchList const & branchlist = buf.params().branchlist();
49         docstring const cur_branch = ib->branch();
50
51         branchCO->clear();
52         int id = 0;
53         int count = 0;
54         for (Branch const & it : branchlist) {
55                 docstring const & branch = it.branch();
56                 branchCO->addItem(toqstr(branch), toqstr(branch));
57                 if (cur_branch == branch)
58                         id = count;
59                 ++count;
60         }
61         // Add branches from master
62         Buffer const * masterBuf = buf.masterBuffer();
63         if (masterBuf != &buf) {
64                 BranchList const & masterBranchlist = masterBuf->params().branchlist();
65                 for (Branch const & it : masterBranchlist) {
66                         docstring const & branch = it.branch();
67                         if (!branchlist.find(branch)) {
68                                 branchCO->addItem(
69                                         toqstr(bformat(_("%1$s[[branch]] (%2$s)[[master]]"),
70                                                    branch, _("master"))),
71                                         toqstr(branch));
72                                 if (cur_branch == branch)
73                                         id = count;
74                                 ++count;
75                         }
76                 }
77         }
78         branchCO->setCurrentIndex(id);
79         invertedCB->setChecked(ib->params().inverted);
80 }
81
82
83 docstring GuiBranch::dialogToParams() const
84 {
85         docstring branch = qstring_to_ucs4(branchCO->itemData(branchCO->currentIndex()).toString());
86         InsetBranchParams params(branch, invertedCB->isChecked());
87         return from_utf8(InsetBranch::params2string(params));
88 }
89
90
91 bool GuiBranch::checkWidgets(bool readonly) const
92 {
93         branchCO->setEnabled(!readonly);
94         invertedCB->setEnabled(!readonly);
95         return InsetParamsWidget::checkWidgets();
96 }
97
98
99 } // namespace frontend
100 } // namespace lyx
101
102 #include "moc_GuiBranch.cpp"