]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
The file dialog browser doesn't need a LyXView...
[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
16 #include "ControlInclude.h"
17
18 #include "helper_funcs.h"
19
20 #include "BufferView.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23 #include "lyxfunc.h"
24 #include "lyxrc.h"
25
26 #include "frontends/Alert.h"
27
28 #include "support/filetools.h"
29
30 #include <utility>
31
32 using std::pair;
33
34
35 ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
36         : ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
37 {}
38
39
40 void ControlInclude::applyParamsToInset()
41 {
42         inset()->set(params());
43         bufferview()->updateInset(inset(), true);
44 }
45
46
47 string const ControlInclude::Browse(string const & in_name, Type in_type)
48 {
49         string const title = _("Select document to include");
50
51         // input TeX, verbatim, or LyX file ?
52         string pattern;
53         switch (in_type) {
54         case INPUT:
55             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
56             break;
57
58         case VERBATIM:
59             pattern = _("*| All files (*)");
60             break;
61
62         case INCLUDE:
63             pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
64             break;
65         }
66
67         pair<string, string> dir1(N_("Documents|#o#O"),
68                                   string(lyxrc.document_path));
69
70         string const docpath = OnlyPath(params().masterFilename_);
71
72         return browseRelFile(in_name, docpath, title, pattern, false, dir1);
73 }
74
75
76 void ControlInclude::load(string const & file)
77 {
78         lyxfunc().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
79 }
80
81
82 bool ControlInclude::fileExists(string const & file)
83 {
84         string const fileWithAbsPath
85                 = MakeAbsPath(file, OnlyPath(params().masterFilename_));
86
87         if (IsFileReadable(fileWithAbsPath))
88                 return true;
89
90         return false;
91 }