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"
22 namespace support { class FileName; }
28 /// Flags for some format properties
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.
35 /// Set if this format can contain vector graphics.
39 Format(std::string const & n, std::string const & e, std::string const & p,
40 std::string const & s, std::string const & v, std::string const & ed,
44 /// Tell whether this format is a child format.
45 /// Child formats inherit settings like the viewer from their parent.
46 bool isChildFormat() const;
47 /// Name fo the parent format
48 std::string const parentFormat() const;
50 std::string const & name() const { return name_; }
52 void setName(std::string const & v) { name_ = v; }
54 std::string const & extension() const { return extension_; }
56 void setExtension(std::string const & v) { extension_ = v; }
58 std::string const & prettyname() const { return prettyname_; }
60 void setPrettyname(std::string const & v) { prettyname_ = v; }
62 std::string const & shortcut() const { return shortcut_; }
64 void setShortcut(std::string const & v) { shortcut_ = v; }
66 std::string const & viewer() const { return viewer_; }
68 void setViewer(std::string const & v) { viewer_ = v; }
70 std::string const & editor() const { return editor_; }
72 void setEditor(std::string const & v) { editor_ = v; }
74 bool documentFormat() const { return flags_ & document; }
76 bool vectorFormat() const { return flags_ & vector; }
78 void setFlags(int v) { flags_ = v; }
80 /// Internal name. Needs to be unique.
82 /// Filename extension
83 std::string extension_;
84 /// Name presented to the user. Needs to be unique.
85 std::string prettyname_;
86 /// Keyboard shortcut for the View and Export menu.
87 std::string shortcut_;
89 * Viewer for this format. Needs to be in the PATH or an absolute
91 * This format cannot be viewed if \c viewer_ is empty.
92 * If it is \c auto the default viewer of the OS for this format is
96 /// Editor for this format. \sa viewer_.
103 bool operator<(Format const & a, Format const & b);
110 typedef std::vector<Format> FormatList;
112 typedef FormatList::const_iterator const_iterator;
114 Format const & get(FormatList::size_type i) const { return formatlist[i]; }
116 Format & get(FormatList::size_type i) { return formatlist[i]; }
117 /// \returns format named \p name if it exists, otherwise 0
118 Format const * getFormat(std::string const & name) const;
120 * Get the format of \p filename from file contents or, if this
121 * fails, from file extension.
122 * \returns file format if it could be found, otherwise an empty
125 std::string getFormatFromFile(support::FileName const & filename) const;
126 /// Set editor and/or viewer to "auto" for formats that can be
127 /// opened by the OS.
130 int getNumber(std::string const & name) const;
132 void add(std::string const & name);
134 void add(std::string const & name, std::string const & extension,
135 std::string const & prettyname, std::string const & shortcut,
136 std::string const & viewer, std::string const & editor,
139 void erase(std::string const & name);
143 void setViewer(std::string const & name, std::string const & command);
145 void setEditor(std::string const & name, std::string const & command);
147 bool view(Buffer const & buffer, support::FileName const & filename,
148 std::string const & format_name) const;
150 bool edit(Buffer const & buffer, support::FileName const & filename,
151 std::string const & format_name) const;
153 docstring const prettyName(std::string const & name) const;
155 std::string const extension(std::string const & name) const;
157 const_iterator begin() const { return formatlist.begin(); }
159 const_iterator end() const { return formatlist.end(); }
161 FormatList::size_type size() const { return formatlist.size(); }
164 FormatList formatlist;
167 extern Formats formats;
169 extern Formats system_formats;