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