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 #pragma implementation
19 #include "ControlExternal.h"
21 #include "BufferView.h"
23 #include "helper_funcs.h"
25 #include "support/filetools.h"
31 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
32 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
36 InsetExternal::Params const ControlExternal::getParams(string const &)
38 return InsetExternal::Params();
41 InsetExternal::Params const
42 ControlExternal::getParams(InsetExternal const & inset)
44 return inset.params();
48 void ControlExternal::applyParamsToInset()
50 inset()->setFromParams(params());
51 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());
69 void ControlExternal::viewExternal()
73 boost::scoped_ptr<InsetExternal> ie;
74 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
75 ie->setFromParams(params());
80 void ControlExternal::updateExternal()
84 boost::scoped_ptr<InsetExternal> ie;
85 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
86 ie->setFromParams(params());
91 vector<string> const ControlExternal::getTemplates() const
93 vector<string> result;
95 ExternalTemplateManager::Templates::const_iterator i1, i2;
96 i1 = ExternalTemplateManager::get().getTemplates().begin();
97 i2 = ExternalTemplateManager::get().getTemplates().end();
99 for (; i1 != i2; ++i1) {
100 result.push_back(i1->second.lyxName);
106 int ControlExternal::getTemplateNumber(string const & name) const
110 ExternalTemplateManager::Templates::const_iterator i1, i2;
111 i1 = ExternalTemplateManager::get().getTemplates().begin();
112 i2 = ExternalTemplateManager::get().getTemplates().end();
113 for (; i1 != i2; ++i1) {
114 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 i1 = ExternalTemplateManager::get().getTemplates().begin();
129 for (int n = 1; n < i; ++n)
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(&lv_, input, bufpath, title, pattern, dir1);