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