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
38 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
39 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
41 d_.showExternal.connect(SigC::slot(this, &ControlExternal::showInset));
45 InsetExternal::Params const ControlExternal::getParams(string const &)
47 return InsetExternal::Params();
50 InsetExternal::Params const
51 ControlExternal::getParams(InsetExternal const & inset)
53 return inset.params();
57 void ControlExternal::applyParamsToInset()
59 inset()->setFromParams(params());
60 lv_.view()->updateInset(inset(), true);
63 void ControlExternal::editExternal()
65 // fill the local, controller's copy of the Params struct with
66 // the contents of the dialog's fields.
69 // Create a local copy of the inset and initialise it with this
72 ie.setFromParams(params());
77 void ControlExternal::viewExternal()
82 ie.setFromParams(params());
87 void ControlExternal::updateExternal()
92 ie.setFromParams(params());
97 vector<string> const ControlExternal::getTemplates() const
99 vector<string> result;
101 ExternalTemplateManager::Templates::const_iterator i1, i2;
102 i1 = ExternalTemplateManager::get().getTemplates().begin();
103 i2 = ExternalTemplateManager::get().getTemplates().end();
105 for (; i1 != i2; ++i1) {
106 result.push_back(i1->second.lyxName);
112 int ControlExternal::getTemplateNumber(string const & name) const
116 ExternalTemplateManager::Templates::const_iterator i1, i2;
117 i1 = ExternalTemplateManager::get().getTemplates().begin();
118 i2 = ExternalTemplateManager::get().getTemplates().end();
119 for (; i1 != i2; ++i1) {
120 if (i1->second.lyxName == name)
125 // we can get here if a LyX document has a template not installed
131 ExternalTemplate ControlExternal::getTemplate(int i) const
133 ExternalTemplateManager::Templates::const_iterator i1;
134 i1 = ExternalTemplateManager::get().getTemplates().begin();
135 for (int n = 1; n < i; ++n)
142 string const ControlExternal::Browse(string const & input) const
144 string buf = MakeAbsPath(lv_.buffer()->fileName());
145 string buf2 = OnlyPath(buf);
147 if (!input.empty()) {
148 buf = MakeAbsPath(input, buf2);
151 buf = OnlyPath(lv_.buffer()->fileName());
154 FileDialog fileDlg(&lv_,
155 _("Select external file"),
156 LFUN_SELECT_FILE_SYNC,
157 make_pair(string(_("Document")), string(buf)));
159 /// Determine the template file extension
160 ExternalTemplate const & et = params().templ;
162 string regexp = et.fileRegExp;
166 // FIXME: a temporary hack until the FileDialog interface is updated
173 string const path = (once) ? current_path : buf;
174 FileDialog::Result result = fileDlg.Select(path, regexp, input);
176 if (result.second.empty())
179 string p = result.second;
181 buf = MakeRelPath(p, buf2);
182 current_path = OnlyPath(p);
185 if (contains(p, "#") ||
189 WriteAlert(_("Filename can't contain any "
190 "of these characters:"),
191 // xgettext:no-c-format
192 _("'#', '~', '$' or '%'."));