2 * \file ControlInclude.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "ControlInclude.h"
16 #include "helper_funcs.h"
21 #include "funcrequest.h"
25 #include "insets/insetinclude.h"
27 #include "support/filefilterlist.h"
28 #include "support/filetools.h"
37 using support::FileFilterList;
38 using support::FileName;
39 using support::isFileReadable;
40 using support::makeAbsPath;
41 using support::onlyPath;
45 ControlInclude::ControlInclude(Dialog & parent)
46 : Dialog::Controller(parent), params_("include")
50 bool ControlInclude::initialiseParams(string const & data)
52 InsetIncludeMailer::string2params(data, params_);
57 void ControlInclude::clearParams()
63 void ControlInclude::dispatchParams()
65 string const lfun = InsetIncludeMailer::params2string(params_);
66 kernel().dispatch(FuncRequest(getLfun(), lfun));
70 void ControlInclude::setParams(InsetCommandParams const & params)
76 docstring const ControlInclude::browse(docstring const & in_name, Type in_type) const
78 docstring const title = _("Select document to include");
80 // input TeX, verbatim, or LyX file ?
81 FileFilterList filters;
85 filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
91 pair<docstring, docstring> dir1(_("Documents|#o#O"),
92 lyx::from_utf8(lyxrc.document_path));
94 docstring const docpath = lyx::from_utf8(onlyPath(kernel().buffer().fileName()));
96 return browseRelFile(in_name, docpath, title,
97 filters, false, dir1);
101 void ControlInclude::load(string const & file)
103 string const ext = support::getExtension(file);
105 kernel().dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file));
107 // tex file or other text file in verbatim mode
108 formats.edit(kernel().buffer(), FileName(file), "text");
112 bool ControlInclude::fileExists(string const & file)
114 FileName const fileWithAbsPath(
115 makeAbsPath(file, onlyPath(kernel().buffer().fileName())));
117 if (isFileReadable(fileWithAbsPath))
123 } // namespace frontend