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