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