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"
17 #include "OutputParams.h"
23 namespace support { class FileName; }
29 /// Flags for some format properties
32 /// Set if this format is a document format (as opposed to
33 /// e.g. image formats).
34 /// Some formats are both (e.g. pdf), they have this flag set.
36 /// Set if this format can contain vector graphics.
38 /// This format should appear in the File > Export menu
40 /// This may be a compressed file but doesn't need decompression
44 Format(std::string const & n, std::string const & e, std::string const & p,
45 std::string const & s, std::string const & v, std::string const & ed,
49 /// Is \p ext a valid filename extension for this format?
50 bool hasExtension(std::string const & ext) const;
51 /// Tell whether this format is a child format.
52 /// Child formats inherit settings like the viewer from their parent.
53 bool isChildFormat() const;
54 /// Name fo the parent format
55 std::string const parentFormat() const;
57 std::string const & name() const { return name_; }
59 void setName(std::string const & v) { name_ = v; }
61 std::string const & extension() const
63 return extension_list_.empty() ? empty_string() : extension_list_[0];
66 std::string const extensions() const;
68 void setExtensions(std::string const & v);
70 std::string const & prettyname() const { return prettyname_; }
72 void setPrettyname(std::string const & v) { prettyname_ = v; }
74 std::string const & shortcut() const { return shortcut_; }
76 void setShortcut(std::string const & v) { shortcut_ = v; }
78 std::string const & viewer() const { return viewer_; }
80 void setViewer(std::string const & v) { viewer_ = v; }
82 std::string const & editor() const { return editor_; }
84 void setEditor(std::string const & v) { editor_ = v; }
86 bool documentFormat() const { return flags_ & document; }
88 bool vectorFormat() const { return flags_ & vector; }
90 void setFlags(int v) { flags_ = v; }
92 bool inExportMenu() const { return flags_ & export_menu; }
94 bool zippedNative() const { return flags_ & zipped_native; }
96 /// Internal name. Needs to be unique.
98 /// Filename extensions, the first one being the default
99 std::vector<std::string> extension_list_;
100 /// Name presented to the user. Needs to be unique.
101 std::string prettyname_;
102 /// Keyboard shortcut for the View and Export menu.
103 std::string shortcut_;
105 * Viewer for this format. Needs to be in the PATH or an absolute
107 * This format cannot be viewed if \c viewer_ is empty.
108 * If it is \c auto the default viewer of the OS for this format is
112 /// Editor for this format. \sa viewer_.
119 bool operator<(Format const & a, Format const & b);
126 typedef std::vector<Format> FormatList;
128 typedef FormatList::const_iterator const_iterator;
130 Format const & get(FormatList::size_type i) const { return formatlist[i]; }
132 Format & get(FormatList::size_type i) { return formatlist[i]; }
133 /// \returns format named \p name if it exists, otherwise 0
134 Format const * getFormat(std::string const & name) const;
136 * Get the format of \p filename from file contents or, if this
137 * fails, from file extension.
138 * \returns file format if it could be found, otherwise an empty
141 std::string getFormatFromFile(support::FileName const & filename) const;
142 /// Finds a format from a file extension. Returns string() if not found.
143 std::string getFormatFromExtension(std::string const & ext) const;
144 /** Returns true if the file referenced by \p filename is zipped and
145 ** needs to be unzipped for being handled
146 ** @note For natively zipped formats, such as dia/odg, this returns false.
148 bool isZippedFile(support::FileName const & filename) const;
149 /// Set editor and/or viewer to "auto" for formats that can be
150 /// opened by the OS.
153 int getNumber(std::string const & name) const;
155 void add(std::string const & name);
157 void add(std::string const & name, std::string const & extensions,
158 std::string const & prettyname, std::string const & shortcut,
159 std::string const & viewer, std::string const & editor,
162 void erase(std::string const & name);
166 void setViewer(std::string const & name, std::string const & command);
168 void setEditor(std::string const & name, std::string const & command);
169 /// View the given file. Buffer used for DVI's paper orientation.
170 bool view(Buffer const & buffer, support::FileName const & filename,
171 std::string const & format_name) const;
173 bool edit(Buffer const & buffer, support::FileName const & filename,
174 std::string const & format_name) const;
176 docstring const prettyName(std::string const & name) const;
178 std::string const extension(std::string const & name) const;
180 std::string const extensions(std::string const & name) const;
182 const_iterator begin() const { return formatlist.begin(); }
184 const_iterator end() const { return formatlist.end(); }
186 FormatList::size_type size() const { return formatlist.size(); }
189 FormatList formatlist;
193 std::string flavor2format(OutputParams::FLAVOR flavor);
194 // Not currently used.
195 // OutputParams::FLAVOR format2flavor(std::string fmt);
197 extern Formats formats;
199 extern Formats system_formats;