]> git.lyx.org Git - lyx.git/blob - src/format.h
85ad850de2dd9cc93930a6c86f6a76b201331b1e
[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 <vector>
16 #include <string>
17
18 class Buffer;
19
20 class Format {
21 public:
22         ///
23         Format(std::string const & n, std::string const & e, std::string const & p,
24                std::string const & s, std::string const & v, std::string const & ed);
25         ///
26         bool dummy() const;
27         ///
28         bool isChildFormat() const;
29         ///
30         std::string const parentFormat() const;
31         ///
32         std::string const & name() const {
33                 return name_;
34         }
35         ///
36         std::string const & extension() const {
37                 return extension_;
38         }
39         ///
40         std::string const & prettyname() const {
41                 return prettyname_;
42         }
43         ///
44         std::string const & shortcut() const {
45                 return shortcut_;
46         }
47         ///
48         std::string const & viewer() const {
49                 return viewer_;
50         }
51         ///
52         void setViewer(std::string const & v) {
53                 viewer_ = v;
54         }
55         ///
56         std::string const & editor() const {
57                 return editor_;
58         }
59         ///
60         void setEditor(std::string const & v) {
61                 editor_ = v;
62         }
63 private:
64         std::string name_;
65         ///
66         std::string extension_;
67         ///
68         std::string prettyname_;
69         ///
70         std::string shortcut_;
71         ///
72         std::string viewer_;
73         ///
74         std::string editor_;
75 };
76
77
78 bool operator<(Format const & a, Format const & b);
79
80 ///
81 class Formats {
82 public:
83         ///
84         typedef std::vector<Format> FormatList;
85         ///
86         typedef FormatList::const_iterator const_iterator;
87         ///
88         Format const & get(FormatList::size_type i) const {
89                 return formatlist[i];
90         }
91         /// \returns format named \p name if it exists, otherwise 0
92         Format const * getFormat(std::string const & name) const;
93         /*!
94          * Get the format of \p filename from file contents or, if this
95          * fails, from file extension.
96          * \returns file format if it could be found, otherwise an empty
97          * string.
98          */
99         std::string getFormatFromFile(std::string const & filename) const;
100         /// Set editor and/or viewer to "auto" for formats that can be
101         /// opened by the OS.
102         void setAutoOpen();
103         ///
104         int getNumber(std::string const & name) const;
105         ///
106         void add(std::string const & name);
107         ///
108         void add(std::string const & name, std::string const & extension,
109                  std::string const & prettyname, std::string const & shortcut,
110                  std::string const & viewer, std::string const & editor);
111         ///
112         void erase(std::string const & name);
113         ///
114         void sort();
115         ///
116         void setViewer(std::string const & name, std::string const & command);
117         ///
118         bool view(Buffer const & buffer, std::string const & filename,
119                   std::string const & format_name) const;
120         ///
121         bool edit(Buffer const & buffer, std::string const & filename,
122                   std::string const & format_name) const;
123         ///
124         std::string const prettyName(std::string const & name) const;
125         ///
126         std::string const extension(std::string const & name) const;
127         ///
128         const_iterator begin() const {
129                 return formatlist.begin();
130         }
131         ///
132         const_iterator end() const {
133                 return formatlist.end();
134         }
135         ///
136         FormatList::size_type size() const {
137                 return formatlist.size();
138         }
139 private:
140         ///
141         FormatList formatlist;
142 };
143
144 extern Formats formats;
145
146 extern Formats system_formats;
147
148 #endif //FORMAT_H