]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Convert most of the bibtex machinery to docstring.
[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 "format.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23 #include "lyxrc.h"
24
25 #include "insets/insetinclude.h"
26
27 #include "support/filefilterlist.h"
28 #include "support/filetools.h"
29
30 #include <utility>
31
32 using std::pair;
33 using std::string;
34
35 namespace lyx {
36
37 using support::FileFilterList;
38 using support::FileName;
39 using support::isFileReadable;
40 using support::makeAbsPath;
41 using support::onlyPath;
42
43 namespace frontend {
44
45 ControlInclude::ControlInclude(Dialog & parent)
46         : Dialog::Controller(parent), params_("include")
47 {}
48
49
50 bool ControlInclude::initialiseParams(string const & data)
51 {
52         InsetIncludeMailer::string2params(data, params_);
53         return true;
54 }
55
56
57 void ControlInclude::clearParams()
58 {
59         params_.clear();
60 }
61
62
63 void ControlInclude::dispatchParams()
64 {
65         string const lfun = InsetIncludeMailer::params2string(params_);
66         kernel().dispatch(FuncRequest(getLfun(), lfun));
67 }
68
69
70 void ControlInclude::setParams(InsetCommandParams const & params)
71 {
72         params_ = params;
73 }
74
75
76 docstring const ControlInclude::browse(docstring const & in_name, Type in_type) const
77 {
78         docstring const title = _("Select document to include");
79
80         // input TeX, verbatim, or LyX file ?
81         FileFilterList filters;
82         switch (in_type) {
83         case INCLUDE:
84         case INPUT:
85                 filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
86                 break;
87         case VERBATIM:
88                 break;
89         }
90
91         pair<docstring, docstring> dir1(_("Documents|#o#O"),
92                 lyx::from_utf8(lyxrc.document_path));
93
94         docstring const docpath = lyx::from_utf8(onlyPath(kernel().buffer().fileName()));
95
96         return browseRelFile(in_name, docpath, title,
97                              filters, false, dir1);
98 }
99
100
101 void ControlInclude::load(string const & file)
102 {
103         string const ext = support::getExtension(file);
104         if (ext == "lyx")
105                 kernel().dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file));
106         else
107                 // tex file or other text file in verbatim mode
108                 formats.edit(kernel().buffer(), FileName(file), "text");
109 }
110
111
112 bool ControlInclude::fileExists(string const & file)
113 {
114         string const fileWithAbsPath
115                 = makeAbsPath(file,
116                               onlyPath(kernel().buffer().fileName()));
117
118         if (isFileReadable(FileName(fileWithAbsPath)))
119                 return true;
120
121         return false;
122 }
123
124 } // namespace frontend
125 } // namespace lyx