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"
24 #include "support/std_sstream.h"
26 using std::ostringstream;
30 ControlDocument::ControlDocument(Dialog & parent)
31 : Dialog::Controller(parent)
35 ControlDocument::~ControlDocument()
39 bool ControlDocument::initialiseParams(std::string const &)
41 bp_.reset(new BufferParams);
42 *bp_ = kernel().buffer().params();
47 void ControlDocument::clearParams()
53 BufferParams & ControlDocument::params() const
55 BOOST_ASSERT(bp_.get());
60 LyXTextClass const & ControlDocument::textClass() const
62 return textclasslist[bp_->textclass];
68 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
73 ss << "\\end_header\n";
74 kernel.dispatch(FuncRequest(lfun, ss.str()));
80 void ControlDocument::dispatchParams()
82 // This must come first so that a language change is correctly noticed
85 // Set the document class.
86 lyx::textclass_type const old_class =
87 kernel().buffer().params().textclass;
88 lyx::textclass_type const new_class = bp_->textclass;
90 if (new_class != old_class) {
91 string const name = textclasslist[new_class].name();
92 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
95 // Apply the BufferParams.
96 dispatch_bufferparams(kernel(), params(), LFUN_BUFFERPARAMS_APPLY);
98 // Generate the colours requested by each new branch.
99 BranchList & branchlist = params().branchlist();
100 if (branchlist.empty())
103 BranchList::const_iterator it = branchlist.begin();
104 BranchList::const_iterator const end = branchlist.end();
105 for (; it != end; ++it) {
106 string const & current_branch = it->getBranch();
107 Branch const * branch = branchlist.find(current_branch);
108 string x11hexname = branch->getColor();
109 // check that we have a valid color!
110 if (x11hexname.empty() || x11hexname[0] != '#')
111 x11hexname = lcolor.getX11Name(LColor::background);
112 // display the new color
113 string const str = current_branch + ' ' + x11hexname;
114 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
117 // Open insets of selected branches, close deselected ones
118 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "assign branch"));
122 void ControlDocument::setLanguage() const
124 Language const * const newL = bp_->language;
125 if (kernel().buffer().params().language == newL)
128 string const lang_name = newL->lang();
129 kernel().dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
133 bool ControlDocument::loadTextclass(lyx::textclass_type tc) const
135 string const name = textclasslist[tc].name();
136 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
138 // Report back whether we were able to change the class.
139 bool const success = textclasslist[tc].loaded();
144 void ControlDocument::saveAsDefault() const
146 dispatch_bufferparams(kernel(), params(), LFUN_SAVE_AS_DEFAULT);