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