]> git.lyx.org Git - lyx.git/blob - src/format.h
hopefully fix tex2lyx linking.
[lyx.git] / src / format.h
1 // -*- C++ -*-
2 /**
3  * \file format.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef FORMAT_H
13 #define FORMAT_H
14
15 #include "support/docstring.h"
16
17 #include <vector>
18 #include <string>
19
20
21 namespace lyx {
22
23 class Buffer;
24
25 class Format {
26 public:
27         /// Flags for some format properties
28         enum Flags {
29                 none = 0,
30                 /// Set if this format is a document format (as opposed to
31                 /// e.g. image formats).
32                 /// Some formats are both (e.g. pdf), they have this flag set.
33                 document = 1,
34                 /// Set if this format can contain vector graphics.
35                 vector = 2,
36         };
37         ///
38         Format(std::string const & n, std::string const & e, std::string const & p,
39                std::string const & s, std::string const & v, std::string const & ed,
40                int);
41         ///
42         bool dummy() const;
43         /// Tell whether this format is a child format.
44         /// Child formats inherit settings like the viewer from their parent.
45         bool isChildFormat() const;
46         /// Name fo the parent format
47         std::string const parentFormat() const;
48         ///
49         std::string const & name() const {
50                 return name_;
51         }
52         ///
53         std::string const & extension() const {
54                 return extension_;
55         }
56         ///
57         std::string const & prettyname() const {
58                 return prettyname_;
59         }
60         ///
61         std::string const & shortcut() const {
62                 return shortcut_;
63         }
64         ///
65         std::string const & viewer() const {
66                 return viewer_;
67         }
68         ///
69         void setViewer(std::string const & v) {
70                 viewer_ = v;
71         }
72         ///
73         std::string const & editor() const {
74                 return editor_;
75         }
76         ///
77         void setEditor(std::string const & v) {
78                 editor_ = v;
79         }
80         ///
81         bool documentFormat() const {
82                 return flags_ & document;
83         }
84         ///
85         bool vectorFormat() const {
86                 return flags_ & vector;
87         }
88 private:
89         /// Internal name. Needs to be unique.
90         std::string name_;
91         /// Filename extension
92         std::string extension_;
93         /// Name presented to the user. Needs to be unique.
94         std::string prettyname_;
95         /// Keyboard shortcut for the View and Export menu.
96         std::string shortcut_;
97         /*!
98          * Viewer for this format. Needs to be in the PATH or an absolute
99          * filename.
100          * This format cannot be viewed if \c viewer_ is empty.
101          * If it is \c auto the default viewer of the OS for this format is
102          * used.
103          */
104         std::string viewer_;
105         /// Editor for this format. \sa viewer_.
106         std::string editor_;
107         ///
108         int flags_;
109 };
110
111
112 bool operator<(Format const & a, Format const & b);
113
114
115 ///
116 class Formats {
117 public:
118         ///
119         typedef std::vector<Format> FormatList;
120         ///
121         typedef FormatList::const_iterator const_iterator;
122         ///
123         Format const & get(FormatList::size_type i) const {
124                 return formatlist[i];
125         }
126         /// \returns format named \p name if it exists, otherwise 0
127         Format const * getFormat(std::string const & name) const;
128         /*!
129          * Get the format of \p filename from file contents or, if this
130          * fails, from file extension.
131          * \returns file format if it could be found, otherwise an empty
132          * string.
133          */
134         std::string getFormatFromFile(std::string const & filename) const;
135         /// Set editor and/or viewer to "auto" for formats that can be
136         /// opened by the OS.
137         void setAutoOpen();
138         ///
139         int getNumber(std::string const & name) const;
140         ///
141         void add(std::string const & name);
142         ///
143         void add(std::string const & name, std::string const & extension,
144                  std::string const & prettyname, std::string const & shortcut,
145                  std::string const & viewer, std::string const & editor,
146                  int flags);
147         ///
148         void erase(std::string const & name);
149         ///
150         void sort();
151         ///
152         void setViewer(std::string const & name, std::string const & command);
153         ///
154         bool view(Buffer const & buffer, std::string const & filename,
155                   std::string const & format_name) const;
156         ///
157         bool edit(Buffer const & buffer, std::string const & filename,
158                   std::string const & format_name) const;
159         ///
160         docstring const prettyName(std::string const & name) const;
161         ///
162         std::string const extension(std::string const & name) const;
163         ///
164         const_iterator begin() const { return formatlist.begin(); }
165         ///
166         const_iterator end() const { return formatlist.end(); }
167         ///
168         FormatList::size_type size() const { return formatlist.size(); }
169 private:
170         ///
171         FormatList formatlist;
172 };
173
174 extern Formats formats;
175
176 extern Formats system_formats;
177
178
179 } // namespace lyx
180
181 #endif //FORMAT_H