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());
108 kernel().bufferview()->update();
111 // Generate the colours requested by each new branch.
112 BranchList & branchlist = params().branchlist();
113 if (branchlist.empty())
116 BranchList::const_iterator it = branchlist.begin();
117 BranchList::const_iterator const end = branchlist.end();
118 for (; it != end; ++it) {
119 string const & current_branch = it->getBranch();
120 Branch const * branch = branchlist.find(current_branch);
121 string x11hexname = branch->getColor();
122 // check that we have a valid color!
123 if (x11hexname.empty() || x11hexname[0] != '#')
124 x11hexname = lcolor.getX11Name(LColor::background);
125 // display the new color
126 string const str = current_branch + ' ' + x11hexname;
127 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
130 // Open insets of selected branches, close deselected ones
131 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "assign branch"));
135 void ControlDocument::setLanguage() const
137 Language const * const newL = bp_->language;
138 if (kernel().buffer().params().language == newL)
141 string const lang_name = newL->lang();
142 kernel().dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
146 bool ControlDocument::loadTextclass(textclass_type tc) const
148 string const name = textclasslist[tc].name();
149 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
151 // Report back whether we were able to change the class.
152 bool const success = textclasslist[tc].loaded();
157 void ControlDocument::saveAsDefault() const
159 dispatch_bufferparams(kernel(), params(), LFUN_SAVE_AS_DEFAULT);
162 } // namespace frontend