]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlExternal.C
port the minipage dialog to the new scheme. Various other small changes
[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 "buffer.h"
17 #include "funcrequest.h"
18 #include "gettext.h"
19 #include "helper_funcs.h"
20 #include "lyxrc.h"
21 #include <vector>
22
23 using std::vector;
24
25
26 ControlExternal::ControlExternal(Dialog & parent)
27         : Dialog::Controller(parent)
28 {}
29
30
31 void ControlExternal::initialiseParams(string const & data)
32 {
33         inset_.reset(new InsetExternal);
34         InsetExternal::Params params;
35         InsetExternalMailer::string2params(data, params);
36         inset_->setFromParams(params);
37         inset_->setView(kernel().bufferview());
38 }
39
40
41 void ControlExternal::clearParams()
42 {
43         inset_.reset();
44 }
45
46
47 void ControlExternal::dispatchParams()
48 {
49         string const lfun = InsetExternalMailer::params2string(params());
50         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
51 }
52
53
54 void ControlExternal::setParams(InsetExternal::Params const & p)
55 {
56         inset_->setFromParams(p);
57 }
58
59
60 void ControlExternal::editExternal()
61 {
62         dialog().view().apply();
63         inset_->editExternal();
64 }
65
66
67 void ControlExternal::viewExternal()
68 {
69         dialog().view().apply();
70         inset_->viewExternal();
71 }
72
73
74 void ControlExternal::updateExternal()
75 {
76         dialog().view().apply();
77         inset_->updateExternal();
78 }
79
80
81 vector<string> const ControlExternal::getTemplates() const
82 {
83         vector<string> result;
84
85         ExternalTemplateManager::Templates::const_iterator i1, i2;
86         i1 = ExternalTemplateManager::get().getTemplates().begin();
87         i2 = ExternalTemplateManager::get().getTemplates().end();
88
89         for (; i1 != i2; ++i1) {
90                 result.push_back(i1->second.lyxName);
91         }
92         return result;
93 }
94
95
96 int ControlExternal::getTemplateNumber(string const & name) const
97 {
98         ExternalTemplateManager::Templates::const_iterator i1, i2;
99         i1 = ExternalTemplateManager::get().getTemplates().begin();
100         i2 = ExternalTemplateManager::get().getTemplates().end();
101         for (int i = 0; i1 != i2; ++i1, ++i) {
102                 if (i1->second.lyxName == name)
103                         return i;
104         }
105
106         // we can get here if a LyX document has a template not installed
107         // on this machine.
108         return -1;
109 }
110
111
112 ExternalTemplate ControlExternal::getTemplate(int i) const
113 {
114         ExternalTemplateManager::Templates::const_iterator i1
115                 = ExternalTemplateManager::get().getTemplates().begin();
116
117         std::advance(i1,  i);
118
119         return i1->second;
120 }
121
122
123 string const ControlExternal::Browse(string const & input) const
124 {
125         string const title =  _("Select external file");
126
127         string const bufpath = kernel().buffer()->filePath();
128
129         /// Determine the template file extension
130         ExternalTemplate const & et = params().templ;
131         string pattern = et.fileRegExp;
132         if (pattern.empty())
133                 pattern = "*";
134
135         // FIXME: a temporary hack until the FileDialog interface is updated
136         pattern += '|';
137
138         std::pair<string, string> dir1(N_("Documents|#o#O"),
139                                   string(lyxrc.document_path));
140
141         return browseRelFile(input, bufpath, title, pattern, false, dir1);
142 }