]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlExternal.C
Re-add the RasterImage template.
[lyx.git] / src / frontends / controllers / ControlExternal.C
1 /**
2  * \file ControlExternal.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author John Levon
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "ControlExternal.h"
16 #include "funcrequest.h"
17 #include "gettext.h"
18 #include "helper_funcs.h"
19 #include "lyxrc.h"
20
21 #include "insets/ExternalTemplate.h"
22
23 using std::vector;
24
25
26 ControlExternal::ControlExternal(Dialog & parent)
27         : Dialog::Controller(parent)
28 {}
29
30
31 bool ControlExternal::initialiseParams(string const & data)
32 {
33         params_.reset(new InsetExternal::Params);
34         InsetExternalMailer::string2params(data, kernel().buffer(), *params_);
35         return true;
36 }
37
38
39 void ControlExternal::clearParams()
40 {
41         params_.reset();
42 }
43
44
45 void ControlExternal::dispatchParams()
46 {
47         string const lfun = InsetExternalMailer::params2string(params(),
48                                                                kernel().buffer());
49         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
50 }
51
52
53 void ControlExternal::setParams(InsetExternal::Params const & p)
54 {
55         BOOST_ASSERT(params_.get());
56         *params_ = p;
57 }
58
59
60 InsetExternal::Params const & ControlExternal::params() const
61 {
62         BOOST_ASSERT(params_.get());
63         return *params_;
64 }
65
66
67 void ControlExternal::editExternal()
68 {
69         BOOST_ASSERT(params_.get());
70
71         dialog().view().apply();
72         string const lfun =
73                 InsetExternalMailer::params2string(params(), kernel().buffer());
74         kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
75 }
76
77
78 vector<string> const ControlExternal::getTemplates() const
79 {
80         vector<string> result;
81
82         ExternalTemplateManager::Templates::const_iterator i1, i2;
83         i1 = ExternalTemplateManager::get().getTemplates().begin();
84         i2 = ExternalTemplateManager::get().getTemplates().end();
85
86         for (; i1 != i2; ++i1) {
87                 result.push_back(i1->second.lyxName);
88         }
89         return result;
90 }
91
92
93 int ControlExternal::getTemplateNumber(string const & name) const
94 {
95         ExternalTemplateManager::Templates::const_iterator i1, i2;
96         i1 = ExternalTemplateManager::get().getTemplates().begin();
97         i2 = ExternalTemplateManager::get().getTemplates().end();
98         for (int i = 0; i1 != i2; ++i1, ++i) {
99                 if (i1->second.lyxName == name)
100                         return i;
101         }
102
103         // we can get here if a LyX document has a template not installed
104         // on this machine.
105         return -1;
106 }
107
108
109 ExternalTemplate ControlExternal::getTemplate(int i) const
110 {
111         ExternalTemplateManager::Templates::const_iterator i1
112                 = ExternalTemplateManager::get().getTemplates().begin();
113
114         std::advance(i1, i);
115
116         return i1->second;
117 }
118
119
120 namespace {
121
122 ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
123 {
124         ExternalTemplateManager const & etm = ExternalTemplateManager::get();
125         return etm.getTemplateByName(params.templatename());
126 }
127
128 } // namespace anon
129
130
131 string const ControlExternal::Browse(string const & input) const
132 {
133         string const title =  _("Select external file");
134
135         string const bufpath = kernel().bufferFilepath();
136
137         /// Determine the template file extension
138         string pattern = "*";
139         ExternalTemplate const * const et_ptr = getTemplatePtr(params());
140         if (et_ptr)
141                 pattern = et_ptr->fileRegExp;
142
143         // FIXME: a temporary hack until the FileDialog interface is updated
144         pattern += '|';
145
146         std::pair<string, string> dir1(N_("Documents|#o#O"),
147                                   string(lyxrc.document_path));
148
149         return browseRelFile(input, bufpath, title, pattern, false, dir1);
150 }