]> git.lyx.org Git - lyx.git/blob - src/format.h
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / format.h
1 // -*- C++ -*-
2 /**
3  * \file format.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef FORMAT_H
13 #define FORMAT_H
14
15 #include "support/docstring.h"
16
17 #include <vector>
18 #include <string>
19
20 class Buffer;
21
22 class Format {
23 public:
24         ///
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,
27                bool ex);
28         ///
29         bool dummy() const;
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;
35         ///
36         std::string const & name() const {
37                 return name_;
38         }
39         ///
40         std::string const & extension() const {
41                 return extension_;
42         }
43         ///
44         std::string const & prettyname() const {
45                 return prettyname_;
46         }
47         ///
48         std::string const & shortcut() const {
49                 return shortcut_;
50         }
51         ///
52         std::string const & viewer() const {
53                 return viewer_;
54         }
55         ///
56         void setViewer(std::string const & v) {
57                 viewer_ = v;
58         }
59         ///
60         std::string const & editor() const {
61                 return editor_;
62         }
63         ///
64         void setEditor(std::string const & v) {
65                 editor_ = v;
66         }
67         ///
68         bool documentFormat() const {
69                 return document_;
70         }
71 private:
72         /// Internal name. Needs to be unique.
73         std::string name_;
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_;
80         /*!
81          * Viewer for this format. Needs to be in the PATH or an absolute
82          * filename.
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
85          * used.
86          */
87         std::string viewer_;
88         /// Editor for this format. \sa viewer_.
89         std::string editor_;
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.
92         bool document_;
93 };
94
95
96 bool operator<(Format const & a, Format const & b);
97
98 ///
99 class Formats {
100 public:
101         ///
102         typedef std::vector<Format> FormatList;
103         ///
104         typedef FormatList::const_iterator const_iterator;
105         ///
106         Format const & get(FormatList::size_type i) const {
107                 return formatlist[i];
108         }
109         /// \returns format named \p name if it exists, otherwise 0
110         Format const * getFormat(std::string const & name) const;
111         /*!
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
115          * string.
116          */
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.
120         void setAutoOpen();
121         ///
122         int getNumber(std::string const & name) const;
123         ///
124         void add(std::string const & name);
125         ///
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,
129                  bool document);
130         ///
131         void erase(std::string const & name);
132         ///
133         void sort();
134         ///
135         void setViewer(std::string const & name, std::string const & command);
136         ///
137         bool view(Buffer const & buffer, std::string const & filename,
138                   std::string const & format_name) const;
139         ///
140         bool edit(Buffer const & buffer, std::string const & filename,
141                   std::string const & format_name) const;
142         ///
143         lyx::docstring const prettyName(std::string const & name) const;
144         ///
145         std::string const extension(std::string const & name) const;
146         ///
147         const_iterator begin() const {
148                 return formatlist.begin();
149         }
150         ///
151         const_iterator end() const {
152                 return formatlist.end();
153         }
154         ///
155         FormatList::size_type size() const {
156                 return formatlist.size();
157         }
158 private:
159         ///
160         FormatList formatlist;
161 };
162
163 extern Formats formats;
164
165 extern Formats system_formats;
166
167 #endif //FORMAT_H