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"
25 Format(std::string const & n, std::string const & e, std::string const & p,
26 std::string const & s, std::string const & v, std::string const & ed,
30 /// Tell whether this format is a child format.
31 /// Child formats inherit settings like the viewer from their parent.
32 bool isChildFormat() const;
33 /// Name fo the parent format
34 std::string const parentFormat() const;
36 std::string const & name() const {
40 std::string const & extension() const {
44 std::string const & prettyname() const {
48 std::string const & shortcut() const {
52 std::string const & viewer() const {
56 void setViewer(std::string const & v) {
60 std::string const & editor() const {
64 void setEditor(std::string const & v) {
68 bool documentFormat() const {
72 /// Internal name. Needs to be unique.
74 /// Filename extension
75 std::string extension_;
76 /// Name presented to the user. Needs to be unique.
77 std::string prettyname_;
78 /// Keyboard shortcut for the View and Export menu.
79 std::string shortcut_;
81 * Viewer for this format. Needs to be in the PATH or an absolute
83 * This format cannot be viewed if \c viewer_ is empty.
84 * If it is \c auto the default viewer of the OS for this format is
88 /// Editor for this format. \sa viewer_.
90 /// Is this format a document format? (as opposed to e.g. image formats)
91 /// Some formats are both (e.g. pdf), they have this flag set.
96 bool operator<(Format const & a, Format const & b);
102 typedef std::vector<Format> FormatList;
104 typedef FormatList::const_iterator const_iterator;
106 Format const & get(FormatList::size_type i) const {
107 return formatlist[i];
109 /// \returns format named \p name if it exists, otherwise 0
110 Format const * getFormat(std::string const & name) const;
112 * Get the format of \p filename from file contents or, if this
113 * fails, from file extension.
114 * \returns file format if it could be found, otherwise an empty
117 std::string getFormatFromFile(std::string const & filename) const;
118 /// Set editor and/or viewer to "auto" for formats that can be
119 /// opened by the OS.
122 int getNumber(std::string const & name) const;
124 void add(std::string const & name);
126 void add(std::string const & name, std::string const & extension,
127 std::string const & prettyname, std::string const & shortcut,
128 std::string const & viewer, std::string const & editor,
131 void erase(std::string const & name);
135 void setViewer(std::string const & name, std::string const & command);
137 bool view(Buffer const & buffer, std::string const & filename,
138 std::string const & format_name) const;
140 bool edit(Buffer const & buffer, std::string const & filename,
141 std::string const & format_name) const;
143 lyx::docstring const prettyName(std::string const & name) const;
145 std::string const extension(std::string const & name) const;
147 const_iterator begin() const {
148 return formatlist.begin();
151 const_iterator end() const {
152 return formatlist.end();
155 FormatList::size_type size() const {
156 return formatlist.size();
160 FormatList formatlist;
163 extern Formats formats;
165 extern Formats system_formats;