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"
24 namespace support { class FileName; }
30 /// Flags for some format properties
33 /// Set if this format is a document format (as opposed to
34 /// e.g. image formats).
35 /// Some formats are both (e.g. pdf), they have this flag set.
37 /// Set if this format can contain vector graphics.
39 /// This format should appear in the File > Export menu
43 Format(std::string const & n, std::string const & e, std::string const & p,
44 std::string const & s, std::string const & v, std::string const & ed,
48 /// Is \p ext a valid filename extension for this format?
49 bool hasExtension(std::string const & ext) const;
50 /// Tell whether this format is a child format.
51 /// Child formats inherit settings like the viewer from their parent.
52 bool isChildFormat() const;
53 /// Name fo the parent format
54 std::string const parentFormat() const;
56 std::string const & name() const { return name_; }
58 void setName(std::string const & v) { name_ = v; }
60 std::string const & extension() const
62 return extension_list_.empty() ? empty_string() : extension_list_[0];
65 std::string const & extensions() const { return extensions_; }
67 void setExtensions(std::string const & v);
69 std::string const & prettyname() const { return prettyname_; }
71 void setPrettyname(std::string const & v) { prettyname_ = v; }
73 std::string const & shortcut() const { return shortcut_; }
75 void setShortcut(std::string const & v) { shortcut_ = v; }
77 std::string const & viewer() const { return viewer_; }
79 void setViewer(std::string const & v) { viewer_ = v; }
81 std::string const & editor() const { return editor_; }
83 void setEditor(std::string const & v) { editor_ = v; }
85 bool documentFormat() const { return flags_ & document; }
87 bool vectorFormat() const { return flags_ & vector; }
89 void setFlags(int v) { flags_ = v; }
91 bool inExportMenu() const { return flags_ & export_menu; }
93 /// Internal name. Needs to be unique.
95 /// Filename extensions, the first one being the default
96 mutable std::vector<std::string> extension_list_;
97 /// All filename extensions
98 std::string extensions_;
99 /// Name presented to the user. Needs to be unique.
100 std::string prettyname_;
101 /// Keyboard shortcut for the View and Export menu.
102 std::string shortcut_;
104 * Viewer for this format. Needs to be in the PATH or an absolute
106 * This format cannot be viewed if \c viewer_ is empty.
107 * If it is \c auto the default viewer of the OS for this format is
111 /// Editor for this format. \sa viewer_.
118 bool operator<(Format const & a, Format const & b);
125 typedef std::vector<Format> FormatList;
127 typedef FormatList::const_iterator const_iterator;
129 Format const & get(FormatList::size_type i) const { return formatlist[i]; }
131 Format & get(FormatList::size_type i) { return formatlist[i]; }
132 /// \returns format named \p name if it exists, otherwise 0
133 Format const * getFormat(std::string const & name) const;
135 * Get the format of \p filename from file contents or, if this
136 * fails, from file extension.
137 * \returns file format if it could be found, otherwise an empty
140 std::string getFormatFromFile(support::FileName const & filename) const;
141 /// Set editor and/or viewer to "auto" for formats that can be
142 /// opened by the OS.
145 int getNumber(std::string const & name) const;
147 void add(std::string const & name);
149 void add(std::string const & name, std::string const & extensions,
150 std::string const & prettyname, std::string const & shortcut,
151 std::string const & viewer, std::string const & editor,
154 void erase(std::string const & name);
158 void setViewer(std::string const & name, std::string const & command);
160 void setEditor(std::string const & name, std::string const & command);
161 /// View the given file. Buffer used for DVI's paper orientation.
162 bool view(Buffer const & buffer, support::FileName const & filename,
163 std::string const & format_name) const;
165 bool edit(Buffer const & buffer, support::FileName const & filename,
166 std::string const & format_name) const;
168 docstring const prettyName(std::string const & name) const;
170 std::string const extension(std::string const & name) const;
172 std::string const extensions(std::string const & name) const;
174 const_iterator begin() const { return formatlist.begin(); }
176 const_iterator end() const { return formatlist.end(); }
178 FormatList::size_type size() const { return formatlist.size(); }
181 FormatList formatlist;
185 std::string flavor2format(OutputParams::FLAVOR flavor);
186 // Not currently used.
187 // OutputParams::FLAVOR format2flavor(std::string fmt);
189 extern Formats formats;
191 extern Formats system_formats;