]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
5 new lfuns, move all apply code out of ControlDocument and into the core.
[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 #include "support/globbing.h"
28
29 #include <utility>
30
31 using lyx::support::FileFilterList;
32 using lyx::support::IsFileReadable;
33 using lyx::support::MakeAbsPath;
34 using lyx::support::OnlyPath;
35
36 using std::pair;
37 using std::string;
38
39
40 ControlInclude::ControlInclude(Dialog & parent)
41         : Dialog::Controller(parent)
42 {}
43
44
45 bool ControlInclude::initialiseParams(string const & data)
46 {
47         InsetIncludeMailer::string2params(data, params_);
48         return true;
49 }
50
51
52 void ControlInclude::clearParams()
53 {
54         params_ = InsetCommandParams();
55 }
56
57
58 void ControlInclude::dispatchParams()
59 {
60         string const lfun = InsetIncludeMailer::params2string(params_);
61         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
62 }
63
64
65 void ControlInclude::setParams(InsetCommandParams const & params)
66 {
67         params_ = params;
68 }
69
70
71 string const ControlInclude::browse(string const & in_name, Type in_type) const
72 {
73         string const title = _("Select document to include");
74
75         // input TeX, verbatim, or LyX file ?
76         FileFilterList filters;
77         switch (in_type) {
78         case INCLUDE:
79         case INPUT:
80             filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
81             break;
82         case VERBATIM:
83             break;
84         }
85
86         pair<string, string> dir1(N_("Documents|#o#O"),
87                                   string(lyxrc.document_path));
88
89         string const docpath = OnlyPath(kernel().buffer().fileName());
90
91         return browseRelFile(in_name, docpath, title,
92                              filters, false, dir1);
93 }
94
95
96 void ControlInclude::load(string const & file)
97 {
98         kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
99 }
100
101
102 bool ControlInclude::fileExists(string const & file)
103 {
104         string const fileWithAbsPath
105                 = MakeAbsPath(file,
106                               OnlyPath(kernel().buffer().fileName()));
107
108         if (IsFileReadable(fileWithAbsPath))
109                 return true;
110
111         return false;
112 }