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