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 "funcrequest.h"
22 #include "lyxtextclasslist.h"
26 using std::ostringstream;
32 ControlDocument::ControlDocument(Dialog & parent)
33 : Dialog::Controller(parent)
37 ControlDocument::~ControlDocument()
41 bool ControlDocument::initialiseParams(std::string const &)
43 bp_.reset(new BufferParams);
44 *bp_ = kernel().buffer().params();
49 void ControlDocument::clearParams()
55 BufferParams & ControlDocument::params() const
57 BOOST_ASSERT(bp_.get());
62 LyXTextClass const & ControlDocument::textClass() const
64 return textclasslist[bp_->textclass];
70 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
75 ss << "\\end_header\n";
76 kernel.dispatch(FuncRequest(lfun, ss.str()));
82 void ControlDocument::dispatchParams()
84 // This must come first so that a language change is correctly noticed
87 // Set the document class.
88 textclass_type const old_class =
89 kernel().buffer().params().textclass;
90 textclass_type const new_class = bp_->textclass;
92 if (new_class != old_class) {
93 string const name = textclasslist[new_class].name();
94 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
97 // Apply the BufferParams.
98 dispatch_bufferparams(kernel(), params(), LFUN_BUFFERPARAMS_APPLY);
100 // Generate the colours requested by each new branch.
101 BranchList & branchlist = params().branchlist();
102 if (branchlist.empty())
105 BranchList::const_iterator it = branchlist.begin();
106 BranchList::const_iterator const end = branchlist.end();
107 for (; it != end; ++it) {
108 string const & current_branch = it->getBranch();
109 Branch const * branch = branchlist.find(current_branch);
110 string x11hexname = branch->getColor();
111 // check that we have a valid color!
112 if (x11hexname.empty() || x11hexname[0] != '#')
113 x11hexname = lcolor.getX11Name(LColor::background);
114 // display the new color
115 string const str = current_branch + ' ' + x11hexname;
116 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
119 // Open insets of selected branches, close deselected ones
120 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "assign branch"));
124 void ControlDocument::setLanguage() const
126 Language const * const newL = bp_->language;
127 if (kernel().buffer().params().language == newL)
130 string const lang_name = newL->lang();
131 kernel().dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
135 bool ControlDocument::loadTextclass(textclass_type tc) const
137 string const name = textclasslist[tc].name();
138 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
140 // Report back whether we were able to change the class.
141 bool const success = textclasslist[tc].loaded();
146 void ControlDocument::saveAsDefault() const
148 dispatch_bufferparams(kernel(), params(), LFUN_SAVE_AS_DEFAULT);
151 } // namespace frontend