4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "support/docstring.h"
27 /// Flags for some format properties
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.
34 /// Set if this format can contain vector graphics.
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,
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;
49 std::string const & name() const {
53 std::string const & extension() const {
57 std::string const & prettyname() const {
61 std::string const & shortcut() const {
65 std::string const & viewer() const {
69 void setViewer(std::string const & v) {
73 std::string const & editor() const {
77 void setEditor(std::string const & v) {
81 bool documentFormat() const {
82 return flags_ & document;
85 bool vectorFormat() const {
86 return flags_ & vector;
89 /// Internal name. Needs to be unique.
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_;
98 * Viewer for this format. Needs to be in the PATH or an absolute
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
105 /// Editor for this format. \sa viewer_.
112 bool operator<(Format const & a, Format const & b);
119 typedef std::vector<Format> FormatList;
121 typedef FormatList::const_iterator const_iterator;
123 Format const & get(FormatList::size_type i) const {
124 return formatlist[i];
126 /// \returns format named \p name if it exists, otherwise 0
127 Format const * getFormat(std::string const & name) const;
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
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.
139 int getNumber(std::string const & name) const;
141 void add(std::string const & name);
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,
148 void erase(std::string const & name);
152 void setViewer(std::string const & name, std::string const & command);
154 bool view(Buffer const & buffer, std::string const & filename,
155 std::string const & format_name) const;
157 bool edit(Buffer const & buffer, std::string const & filename,
158 std::string const & format_name) const;
160 docstring const prettyName(std::string const & name) const;
162 std::string const extension(std::string const & name) const;
164 const_iterator begin() const { return formatlist.begin(); }
166 const_iterator end() const { return formatlist.end(); }
168 FormatList::size_type size() const { return formatlist.size(); }
171 FormatList formatlist;
174 extern Formats formats;
176 extern Formats system_formats;