1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlExternal.C
11 * \author Asger Alstrup
13 * \author Angus Leeming, a.leeming@ic.ac.uk
22 #pragma implementation
25 #include "ControlExternal.h"
30 #include "support/filetools.h"
31 #include "frontends/FileDialog.h"
32 #include "lyx_gui_misc.h" // WriteAlert
37 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
38 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
40 d_.showExternal.connect(SigC::slot(this, &ControlExternal::showInset));
44 InsetExternal::Params const ControlExternal::getParams(string const &)
46 return InsetExternal::Params();
49 InsetExternal::Params const
50 ControlExternal::getParams(InsetExternal const & inset)
52 return inset.params();
56 void ControlExternal::applyParamsToInset()
58 inset()->setFromParams(params());
59 lv_.view()->updateInset(inset(), true);
62 void ControlExternal::editExternal()
64 // fill the local, controller's copy of the Params struct with
65 // the contents of the popup's fields.
68 // Create a local copy of the inset and initialise it with this
71 ie.setFromParams(params());
76 void ControlExternal::viewExternal()
81 ie.setFromParams(params());
86 void ControlExternal::updateExternal()
91 ie.setFromParams(params());
96 vector<string> const ControlExternal::getTemplates() const
98 vector<string> result;
100 ExternalTemplateManager::Templates::const_iterator i1, i2;
101 i1 = ExternalTemplateManager::get().getTemplates().begin();
102 i2 = ExternalTemplateManager::get().getTemplates().end();
104 for (; i1 != i2; ++i1) {
105 result.push_back(i1->second.lyxName);
111 int ControlExternal::getTemplateNumber(string const & name) const
115 ExternalTemplateManager::Templates::const_iterator i1, i2;
116 i1 = ExternalTemplateManager::get().getTemplates().begin();
117 i2 = ExternalTemplateManager::get().getTemplates().end();
118 for (; i1 != i2; ++i1) {
119 if (i1->second.lyxName == name)
124 // we can get here if a LyX document has a template not installed
130 ExternalTemplate ControlExternal::getTemplate(int i) const
132 ExternalTemplateManager::Templates::const_iterator i1;
133 i1 = ExternalTemplateManager::get().getTemplates().begin();
134 for (int n = 1; n < i; ++n)
141 string const ControlExternal::Browse(string const & input) const
143 string buf = MakeAbsPath(lv_.buffer()->fileName());
144 string buf2 = OnlyPath(buf);
146 if (!input.empty()) {
147 buf = MakeAbsPath(input, buf2);
150 buf = OnlyPath(lv_.buffer()->fileName());
153 FileDialog fileDlg(&lv_,
154 _("Select external file"),
155 LFUN_SELECT_FILE_SYNC,
156 make_pair(string(_("Document")), string(buf)));
158 /// Determine the template file extension
159 ExternalTemplate const & et = params().templ;
161 string regexp = et.fileRegExp;
165 // FIXME: a temporary hack until the FileDialog interface is updated
172 string const path = (once) ? current_path : buf;
173 FileDialog::Result result = fileDlg.Select(path, regexp, input);
175 if (result.second.empty())
178 string p = result.second;
180 buf = MakeRelPath(p, buf2);
181 current_path = OnlyPath(p);
184 if (contains(p, "#") ||
188 WriteAlert(_("Filename can't contain any "
189 "of these characters:"),
190 // xgettext:no-c-format
191 _("'#', '~', '$' or '%'."));