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