2 * \file ControlExternal.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
16 #include "ControlExternal.h"
18 #include "BufferView.h"
20 #include "helper_funcs.h"
22 #include "support/filetools.h"
29 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
30 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
34 InsetExternal::Params const ControlExternal::getParams(string const &)
36 return InsetExternal::Params();
40 InsetExternal::Params const
41 ControlExternal::getParams(InsetExternal const & inset)
43 return inset.params();
47 void ControlExternal::applyParamsToInset()
49 inset()->setFromParams(params());
50 bufferview()->updateInset(inset(), true);
54 void ControlExternal::editExternal()
56 // fill the local, controller's copy of the Params struct with
57 // the contents of the dialog's fields.
60 // Create a local copy of the inset and initialise it with this
62 boost::scoped_ptr<InsetExternal> ie;
63 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
64 ie->setFromParams(params());
70 void ControlExternal::viewExternal()
74 boost::scoped_ptr<InsetExternal> ie;
75 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
76 ie->setFromParams(params());
82 void ControlExternal::updateExternal()
86 boost::scoped_ptr<InsetExternal> ie;
87 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
88 ie->setFromParams(params());
94 vector<string> const ControlExternal::getTemplates() const
96 vector<string> result;
98 ExternalTemplateManager::Templates::const_iterator i1, i2;
99 i1 = ExternalTemplateManager::get().getTemplates().begin();
100 i2 = ExternalTemplateManager::get().getTemplates().end();
102 for (; i1 != i2; ++i1) {
103 result.push_back(i1->second.lyxName);
109 int ControlExternal::getTemplateNumber(string const & name) const
111 ExternalTemplateManager::Templates::const_iterator i1, i2;
112 i1 = ExternalTemplateManager::get().getTemplates().begin();
113 i2 = ExternalTemplateManager::get().getTemplates().end();
114 for (int i = 0; i1 != i2; ++i1, ++i) {
115 if (i1->second.lyxName == name)
119 // we can get here if a LyX document has a template not installed
125 ExternalTemplate ControlExternal::getTemplate(int i) const
127 ExternalTemplateManager::Templates::const_iterator i1
128 = ExternalTemplateManager::get().getTemplates().begin();
136 string const ControlExternal::Browse(string const & input) const
138 string const title = _("Select external file");
140 string const bufpath = buffer()->filePath();
142 /// Determine the template file extension
143 ExternalTemplate const & et = params().templ;
144 string pattern = et.fileRegExp;
148 // FIXME: a temporary hack until the FileDialog interface is updated
151 std::pair<string, string> dir1(N_("Documents|#o#O"),
152 string(lyxrc.document_path));
154 return browseRelFile(input, bufpath, title, pattern, false, dir1);