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