]> git.lyx.org Git - lyx.git/blob - src/insets/insetexternal.h
Collapse all those LFUN_XYZ_APPLY to a single LFUN_INSET_APPLY.
[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 #include <boost/signals/signal0.hpp>
21
22 ///
23 class InsetExternal : public InsetButton {
24 public:
25         /// hold parameters settable from the GUI
26         struct Params {
27                 Params(string const & f = string(),
28                                         string const & p = string(),
29                                         ExternalTemplate const & t = ExternalTemplate())
30                         : filename(f), parameters(p), templ(t) {}
31                 /// the filename
32                 string filename;
33                 /// the parameters of the current choice
34                 string parameters;
35                 /// the current template used
36                 ExternalTemplate templ;
37         };
38
39         InsetExternal();
40         ///
41         virtual ~InsetExternal();
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 params() const;
101
102         /// hide connection
103         boost::signal0<void> hideDialog;
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 bool operator==(InsetExternal::Params const &, InsetExternal::Params const &);
128 ///
129 bool operator!=(InsetExternal::Params const &, InsetExternal::Params const &);
130
131 #endif