]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Overhaul the branches code.
[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 using std::string;
36
37
38 ControlInclude::ControlInclude(Dialog & parent)
39         : Dialog::Controller(parent)
40 {}
41
42
43 bool ControlInclude::initialiseParams(string const & data)
44 {
45         InsetIncludeMailer::string2params(data, params_);
46         return true;
47 }
48
49
50 void ControlInclude::clearParams()
51 {
52         params_ = InsetCommandParams();
53 }
54
55
56 void ControlInclude::dispatchParams()
57 {
58         string const lfun = InsetIncludeMailer::params2string(params_);
59         kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
60 }
61
62
63 void ControlInclude::setParams(InsetCommandParams const & params)
64 {
65         params_ = params;
66 }
67
68
69 string const ControlInclude::Browse(string const & in_name, Type in_type)
70 {
71         string const title = _("Select document to include");
72
73         // input TeX, verbatim, or LyX file ?
74         string pattern;
75         switch (in_type) {
76         case INPUT:
77             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
78             break;
79
80         case VERBATIM:
81             pattern = _("*| All files (*)");
82             break;
83
84         case INCLUDE:
85             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
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, pattern, false, dir1);
95 }
96
97
98 void ControlInclude::load(string const & file)
99 {
100         kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
101 }
102
103
104 bool ControlInclude::fileExists(string const & file)
105 {
106         string const fileWithAbsPath
107                 = MakeAbsPath(file,
108                               OnlyPath(kernel().buffer().fileName()));
109
110         if (IsFileReadable(fileWithAbsPath))
111                 return true;
112
113         return false;
114 }