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