2 * \file ControlDocument.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "ControlDocument.h"
16 #include "BranchList.h"
18 #include "bufferparams.h"
19 #include "BufferView.h"
20 #include "buffer_funcs.h"
21 #include "funcrequest.h"
24 #include "lyxtextclasslist.h"
28 using std::ostringstream;
34 ControlDocument::ControlDocument(Dialog & parent)
35 : Dialog::Controller(parent)
39 ControlDocument::~ControlDocument()
43 bool ControlDocument::initialiseParams(std::string const &)
45 bp_.reset(new BufferParams);
46 *bp_ = kernel().buffer().params();
51 void ControlDocument::clearParams()
57 BufferParams & ControlDocument::params() const
59 BOOST_ASSERT(bp_.get());
64 LyXTextClass const & ControlDocument::textClass() const
66 return textclasslist[bp_->textclass];
72 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
76 ss << "\\begin_header\n";
78 ss << "\\end_header\n";
79 kernel.dispatch(FuncRequest(lfun, ss.str()));
85 void ControlDocument::dispatchParams()
87 // This must come first so that a language change is correctly noticed
90 // Set the document class.
91 textclass_type const old_class =
92 kernel().buffer().params().textclass;
93 textclass_type const new_class = bp_->textclass;
94 if (new_class != old_class) {
95 string const name = textclasslist[new_class].name();
96 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
99 int const old_secnumdepth = kernel().buffer().params().secnumdepth;
100 int const new_secnumdepth = bp_->secnumdepth;
102 // Apply the BufferParams.
103 dispatch_bufferparams(kernel(), params(), LFUN_BUFFERPARAMS_APPLY);
105 // redo the numbering if necessary
106 if (new_secnumdepth != old_secnumdepth)
107 updateCounters(kernel().buffer());
109 // Generate the colours requested by each new branch.
110 BranchList & branchlist = params().branchlist();
111 if (!branchlist.empty()) {
112 BranchList::const_iterator it = branchlist.begin();
113 BranchList::const_iterator const end = branchlist.end();
114 for (; it != end; ++it) {
115 string const & current_branch = it->getBranch();
116 Branch const * branch = branchlist.find(current_branch);
117 string x11hexname = branch->getColor();
118 // check that we have a valid color!
119 if (x11hexname.empty() || x11hexname[0] != '#')
121 lcolor.getX11Name(LColor::background);
122 // display the new color
123 string const str = current_branch + ' ' + x11hexname;
124 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
127 // Open insets of selected branches, close deselected ones
128 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
131 // update the bufferview
132 kernel().bufferview()->update();
136 void ControlDocument::setLanguage() const
138 Language const * const newL = bp_->language;
139 if (kernel().buffer().params().language == newL)
142 string const lang_name = newL->lang();
143 kernel().dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
147 bool ControlDocument::loadTextclass(textclass_type tc) const
149 string const name = textclasslist[tc].name();
150 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
152 // Report back whether we were able to change the class.
153 bool const success = textclasslist[tc].loaded();
158 void ControlDocument::saveAsDefault() const
160 dispatch_bufferparams(kernel(), params(), LFUN_SAVE_AS_DEFAULT);
163 } // namespace frontend