]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlExternal.C
Nothing but a changed email address (trying to factor my tree in in small steps)
[lyx.git] / src / frontends / controllers / ControlExternal.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlExternal.C
11  * \author Asger Alstrup
12  * \author John Levon, moz@compsoc.man.ac.uk
13  * \author Angus Leeming <leeming@lyx.org>
14  */
15
16 #include <config.h>
17
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include "ControlExternal.h"
23 #include "buffer.h"
24 #include "BufferView.h"
25 #include "gettext.h"
26 #include "helper_funcs.h"
27 #include "lyxrc.h"
28 #include "support/filetools.h"
29
30 #include <vector>
31
32 using std::vector;
33
34 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
35         : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
36 {}
37
38
39 InsetExternal::Params const ControlExternal::getParams(string const &)
40 {
41         return InsetExternal::Params();
42 }
43
44 InsetExternal::Params const
45 ControlExternal::getParams(InsetExternal const & inset)
46 {
47         return inset.params();
48 }
49
50
51 void ControlExternal::applyParamsToInset()
52 {
53         inset()->setFromParams(params());
54         bufferview()->updateInset(inset(), true);
55 }
56
57 void ControlExternal::editExternal()
58 {
59         // fill the local, controller's copy of the Params struct with
60         // the contents of the dialog's fields.
61         view().apply();
62
63         // Create a local copy of the inset and initialise it with this
64         // params struct.
65         boost::scoped_ptr<InsetExternal> ie;
66         ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
67         ie->setFromParams(params());
68
69         ie->editExternal();
70 }
71
72 void ControlExternal::viewExternal()
73 {
74         view().apply();
75
76         boost::scoped_ptr<InsetExternal> ie;
77         ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
78         ie->setFromParams(params());
79
80         ie->viewExternal();
81 }
82
83 void ControlExternal::updateExternal()
84 {
85         view().apply();
86
87         boost::scoped_ptr<InsetExternal> ie;
88         ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
89         ie->setFromParams(params());
90
91         ie->updateExternal();
92 }
93
94 vector<string> const ControlExternal::getTemplates() const
95 {
96         vector<string> result;
97
98         ExternalTemplateManager::Templates::const_iterator i1, i2;
99         i1 = ExternalTemplateManager::get().getTemplates().begin();
100         i2 = ExternalTemplateManager::get().getTemplates().end();
101
102         for (; i1 != i2; ++i1) {
103                 result.push_back(i1->second.lyxName);
104         }
105         return result;
106 }
107
108
109 int ControlExternal::getTemplateNumber(string const & name) const
110 {
111         int i = 0;
112
113         ExternalTemplateManager::Templates::const_iterator i1, i2;
114         i1 = ExternalTemplateManager::get().getTemplates().begin();
115         i2 = ExternalTemplateManager::get().getTemplates().end();
116         for (; i1 != i2; ++i1) {
117                 if (i1->second.lyxName == name)
118                         return i;
119                 ++i;
120         }
121
122         // we can get here if a LyX document has a template not installed
123         // on this machine.
124         return -1;
125 }
126
127
128 ExternalTemplate ControlExternal::getTemplate(int i) const
129 {
130         ExternalTemplateManager::Templates::const_iterator i1;
131         i1 = ExternalTemplateManager::get().getTemplates().begin();
132         for (int n = 1; n < i; ++n)
133                 ++i1;
134
135         return i1->second;
136 }
137
138
139 string const ControlExternal::Browse(string const & input) const
140 {
141         string const title =  _("Select external file");
142
143         string const bufpath = buffer()->filePath();
144
145         /// Determine the template file extension
146         ExternalTemplate const & et = params().templ;
147         string pattern = et.fileRegExp;
148         if (pattern.empty())
149                 pattern = "*";
150
151         // FIXME: a temporary hack until the FileDialog interface is updated
152         pattern += "|";
153
154         std::pair<string, string> dir1(N_("Documents|#o#O"),
155                                   string(lyxrc.document_path));
156
157         return browseRelFile(&lv_, input, bufpath, title, pattern, dir1);
158 }