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