]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Really dull and boring header shit
[lyx.git] / src / frontends / controllers / ControlInclude.C
1 /**
2  * \file ControlInclude.C
3  * Read the file COPYING
4  *
5  * \author Alejandro Aguilar Sierra
6  * \author John Levon
7  * \author Angus Leeming 
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "ControlInclude.h"
19
20 #include "helper_funcs.h"
21
22 #include "BufferView.h"
23 #include "funcrequest.h"
24 #include "gettext.h"
25 #include "lyxfunc.h"
26 #include "lyxrc.h"
27
28 #include "frontends/Alert.h"
29
30 #include "support/filetools.h"
31
32 #include <utility>
33
34 using std::pair;
35
36
37 ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
38         : ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
39 {}
40
41
42 void ControlInclude::applyParamsToInset()
43 {
44         inset()->set(params());
45         bufferview()->updateInset(inset(), true);
46 }
47
48
49 string const ControlInclude::Browse(string const & in_name, Type in_type)
50 {
51         string const title = _("Select document to include");
52
53         // input TeX, verbatim, or LyX file ?
54         string pattern;
55         switch (in_type) {
56         case INPUT:
57             pattern = _("*.tex| LaTeX Documents (*.tex)");
58             break;
59
60         case VERBATIM:
61             pattern = _("*| All files ");
62             break;
63
64         case INCLUDE:
65             pattern = _("*.lyx| LyX Documents (*.lyx)");
66             break;
67         }
68
69         pair<string, string> dir1(N_("Documents|#o#O"),
70                                   string(lyxrc.document_path));
71
72         string const docpath = OnlyPath(params().masterFilename_);
73
74         return browseRelFile(&lv_, in_name, docpath, title, pattern, dir1);
75 }
76
77
78 void ControlInclude::load(string const & file)
79 {
80         lyxfunc().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
81 }
82
83
84 bool ControlInclude::fileExists(string const & file)
85 {
86         string const fileWithAbsPath
87                 = MakeAbsPath(file, OnlyPath(params().masterFilename_));
88
89         if (params().noload) {
90
91                 if (prefixIs(file, "../") || prefixIs(file, "/"))
92                         Alert::alert(_("Warning!"),
93                                 _("On some systems, with this options only relative path names"),
94                                 _("inside the master file dir are allowed. You might get a LaTeX error!"));
95         }
96
97         if (IsFileReadable(fileWithAbsPath))
98                 return true;
99         
100         else
101                 Alert::alert(_("Warning!"), _("Specified file doesn't exist"));
102                 return false;
103 }