]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInclude.C
Compilation fix.
[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
25 #include "support/filetools.h"
26
27 #include <utility>
28
29 using std::pair;
30
31
32 ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
33         : ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
34 {}
35
36
37 void ControlInclude::applyParamsToInset()
38 {
39         inset()->set(params());
40         lv_.view()->updateInset(inset(), true);
41 }
42
43
44 string const ControlInclude::Browse(string const & in_name, Type in_type)
45 {
46         string const title = _("Select document to include");
47
48         // input TeX, verbatim, or LyX file ?
49         string pattern;
50         switch (in_type) {
51         case INPUT:
52             pattern = _("*.tex| LaTeX Documents (*.tex)");
53             break;
54
55         case VERBATIM:
56             pattern = _("*| All files ");
57             break;
58
59         case INCLUDE:
60             pattern = _("*.lyx| LyX Documents (*.lyx)");
61             break;
62         }
63
64         pair<string, string> dir1(N_("Documents|#o#O"),
65                                   string(lyxrc.document_path));
66
67         string const docpath = OnlyPath(params().masterFilename_);
68
69         return browseRelFile(&lv_, in_name, docpath, title, pattern, dir1);
70 }
71
72
73 void ControlInclude::load(string const & file)
74 {
75         lv_.getLyXFunc()->dispatch(LFUN_CHILDOPEN, file);
76 }
77
78
79 bool ControlInclude::fileExists(string const & file)
80 {
81         string const fileWithAbsPath = MakeAbsPath(file, OnlyPath(params().masterFilename_));
82
83         if (params().noload){
84
85                 if (prefixIs(file, "../") || prefixIs(file, "/"))
86                         Alert::alert(_("Warning!"),
87                                 _("On some systems, with this options only relative path names"),
88                                 _("inside the master file dir are allowed. You might get a LaTeX error!"));
89         }
90
91         if (IsFileReadable(fileWithAbsPath))
92                 return true;
93         
94         else
95                 Alert::alert(_("Warning!"),
96                         _("Specified file doesn't exist"));
97                 return false;
98 }