]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Re-add the RasterImage template.
[lyx.git] / src / frontends / controllers / ControlInclude.C
1 /**
2  * \file ControlInclude.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
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 "ControlInclude.h"
16 #include "helper_funcs.h"
17 #include "Kernel.h"
18
19 #include "buffer.h"
20 #include "funcrequest.h"
21 #include "gettext.h"
22 #include "lyxrc.h"
23
24 #include "insets/insetinclude.h"
25
26 #include "support/filetools.h"
27
28 #include <utility>
29
30 using lyx::support::IsFileReadable;
31 using lyx::support::MakeAbsPath;
32 using lyx::support::OnlyPath;
33
34 using std::pair;
35
36
37 ControlInclude::ControlInclude(Dialog & parent)
38         : Dialog::Controller(parent)
39 {}
40
41
42 bool ControlInclude::initialiseParams(string const & data)
43 {
44         InsetIncludeMailer::string2params(data, params_);
45         return true;
46 }
47
48
49 void ControlInclude::clearParams()
50 {
51         params_ = InsetCommandParams();
52 }
53
54
55 void ControlInclude::dispatchParams()
56 {
57         string const lfun = InsetIncludeMailer::params2string(params_);
58         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
59 }
60
61
62 void ControlInclude::setParams(InsetCommandParams const & params)
63 {
64         params_ = params;
65 }
66
67
68 string const ControlInclude::Browse(string const & in_name, Type in_type)
69 {
70         string const title = _("Select document to include");
71
72         // input TeX, verbatim, or LyX file ?
73         string pattern;
74         switch (in_type) {
75         case INPUT:
76             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
77             break;
78
79         case VERBATIM:
80             pattern = _("*| All files (*)");
81             break;
82
83         case INCLUDE:
84             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
85             break;
86         }
87
88         pair<string, string> dir1(N_("Documents|#o#O"),
89                                   string(lyxrc.document_path));
90
91         string const docpath = OnlyPath(kernel().buffer().fileName());
92
93         return browseRelFile(in_name, docpath, title, pattern, false, dir1);
94 }
95
96
97 void ControlInclude::load(string const & file)
98 {
99         kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
100 }
101
102
103 bool ControlInclude::fileExists(string const & file)
104 {
105         string const fileWithAbsPath
106                 = MakeAbsPath(file,
107                               OnlyPath(kernel().buffer().fileName()));
108
109         if (IsFileReadable(fileWithAbsPath))
110                 return true;
111
112         return false;
113 }