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