]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
The "I want this in now" patch.
[lyx.git] / src / insets / insetexternal.h
1 // -*- C++ -*-
2 /**
3  * \file insetexternal.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef INSET_EXTERNAL_H
13 #define INSET_EXTERNAL_H
14
15 #include "insetbutton.h"
16 #include "ExternalTemplate.h"
17 #include "LString.h"
18
19 ///
20 class InsetExternal : public InsetButton {
21 public:
22         /// hold parameters settable from the GUI
23         struct Params {
24                 Params(string const & f = string(),
25                                         string const & p = string(),
26                                         ExternalTemplate const & t = ExternalTemplate())
27                         : filename(f), parameters(p), templ(t) {}
28                 /// the filename
29                 string filename;
30                 /// the parameters of the current choice
31                 string parameters;
32                 /// the current template used
33                 ExternalTemplate templ;
34         };
35
36         InsetExternal();
37         ///
38         virtual ~InsetExternal();
39         ///
40         virtual dispatch_result localDispatch(FuncRequest const & cmd); 
41         /// what appears in the minibuffer when opening
42         virtual string const editMessage() const;
43         ///
44         virtual EDITABLE editable() const { return IS_EDITABLE; }
45         ///
46         virtual void write(Buffer const *, std::ostream &) const;
47         ///
48         virtual void read(Buffer const *, LyXLex & lex);
49
50         /** returns the number of rows (\n's) of generated tex code.
51          fragile == true means, that the inset should take care about
52          fragile commands by adding a \protect before.
53          If the free_spc (freespacing) variable is set, then this inset
54          is in a free-spacing paragraph.
55          */
56         virtual int latex(Buffer const *, std::ostream &,
57                           LatexRunParams const &,
58                           bool free_spc) const;
59         /// write ASCII output to the ostream
60         virtual int ascii(Buffer const *, std::ostream &, int linelen) const;
61         /// write LinuxDoc output to the ostream
62         virtual int linuxdoc(Buffer const *, std::ostream &) const;
63         /// write DocBook output to the ostream
64         virtual int docbook(Buffer const *, std::ostream &, bool mixcont) const;
65
66         /// Updates needed features for this inset.
67         virtual void validate(LaTeXFeatures & features) const;
68
69         /// returns LyX code associated with the inset. Used for TOC, ...)
70         virtual Inset::Code lyxCode() const { return EXTERNAL_CODE; }
71
72         ///
73         virtual Inset * clone(Buffer const &, bool same_id = false) const;
74
75         /// returns the text of the button
76         virtual string const getScreenLabel(Buffer const *) const;
77
78         // The following public members are used from the frontends code
79
80         /// set the parameters from a Params structure
81         virtual void setFromParams(Params const &);
82
83         ///
84         void updateExternal() const;
85
86         /// update the file represented by the template
87         void updateExternal(string const &, Buffer const *) const;
88
89         /// edit file of this template
90         void editExternal() const;
91
92         /// view file of this template
93         void viewExternal() const;
94
95         /// return a copy of our current params
96         Params const & params() const;
97
98         ///
99         void setView(BufferView * bv) { view_ = bv; }
100
101 private:
102         /// Write the output for a specific file format
103         int write(string const & format, Buffer const *,
104                   std::ostream &) const;
105
106         /// Execute this command in the directory of this document
107         void executeCommand(string const & s, Buffer const * buf) const;
108
109         /// Substitute meta-variables in this string
110         string const doSubstitution(Buffer const *, string const & s) const;
111
112         /// our owning view
113         BufferView * view_;
114
115         /// the current params
116         Params params_;
117
118         /// A temp filename
119         string tempname_;
120 };
121
122
123 #include "mailinset.h"
124
125 class InsetExternalMailer : public MailInset {
126 public:
127         ///
128         InsetExternalMailer(InsetExternal & inset);
129         ///
130         virtual InsetBase & inset() const { return inset_; }
131         ///
132         virtual string const & name() const { return name_; }
133         ///
134         virtual string const inset2string() const;
135         ///
136         static void string2params(string const &, InsetExternal::Params &);
137         ///
138         static string const params2string(InsetExternal::Params const &);
139 private:
140         ///
141         static string const name_;
142         ///
143         InsetExternal & inset_;
144 };
145
146 #endif