]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Small clean-up.
[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
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "lyxrc.h"
21
22 #include "support/filetools.h"
23
24 #include <utility>
25
26 using lyx::support::IsFileReadable;
27 using lyx::support::MakeAbsPath;
28 using lyx::support::OnlyPath;
29
30 using std::pair;
31
32
33 ControlInclude::ControlInclude(Dialog & parent)
34         : Dialog::Controller(parent)
35 {}
36
37
38 bool ControlInclude::initialiseParams(string const & data)
39 {
40         InsetInclude::Params params;
41         InsetIncludeMailer::string2params(data, params);
42         inset_.reset(new InsetInclude(params));
43         return true;
44 }
45
46
47 void ControlInclude::clearParams()
48 {
49         inset_.reset();
50 }
51
52
53 void ControlInclude::dispatchParams()
54 {
55         InsetInclude::Params p = params();
56         string const lfun = InsetIncludeMailer::params2string(p);
57         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
58 }
59
60
61 void ControlInclude::setParams(InsetInclude::Params const & params)
62 {
63         inset_->set(params);
64 }
65
66 string const ControlInclude::Browse(string const & in_name, Type in_type)
67 {
68         string const title = _("Select document to include");
69
70         // input TeX, verbatim, or LyX file ?
71         string pattern;
72         switch (in_type) {
73         case INPUT:
74             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
75             break;
76
77         case VERBATIM:
78             pattern = _("*| All files (*)");
79             break;
80
81         case INCLUDE:
82             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
83             break;
84         }
85
86         pair<string, string> dir1(N_("Documents|#o#O"),
87                                   string(lyxrc.document_path));
88
89         string const docpath = OnlyPath(params().masterFilename_);
90
91         return browseRelFile(in_name, docpath, title, pattern, false, dir1);
92 }
93
94
95 void ControlInclude::load(string const & file)
96 {
97         kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
98 }
99
100
101 bool ControlInclude::fileExists(string const & file)
102 {
103         string const fileWithAbsPath
104                 = MakeAbsPath(file, OnlyPath(params().masterFilename_));
105
106         if (IsFileReadable(fileWithAbsPath))
107                 return true;
108
109         return false;
110 }