2003-02-28 09:49:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file format.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-28 09:49:49 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#ifndef FORMAT_H
|
|
|
|
#define FORMAT_H
|
2003-02-28 09:49:49 +00:00
|
|
|
|
|
|
|
#include <vector>
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
2003-02-28 09:49:49 +00:00
|
|
|
|
2003-05-23 13:54:09 +00:00
|
|
|
class Buffer;
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
class Format {
|
|
|
|
public:
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
Format(std::string const & n, std::string const & e, std::string const & p,
|
2004-04-13 10:36:09 +00:00
|
|
|
std::string const & s, std::string const & v, std::string const & ed);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
bool dummy() const;
|
|
|
|
///
|
|
|
|
bool isChildFormat() const;
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const parentFormat() const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & name() const {
|
2003-02-28 09:49:49 +00:00
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & extension() const {
|
2003-02-28 09:49:49 +00:00
|
|
|
return extension_;
|
|
|
|
}
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & prettyname() const {
|
2003-02-28 09:49:49 +00:00
|
|
|
return prettyname_;
|
|
|
|
}
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & shortcut() const {
|
2003-02-28 09:49:49 +00:00
|
|
|
return shortcut_;
|
|
|
|
}
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & viewer() const {
|
2003-02-28 09:49:49 +00:00
|
|
|
return viewer_;
|
|
|
|
}
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void setViewer(std::string const & v) {
|
2003-02-28 09:49:49 +00:00
|
|
|
viewer_ = v;
|
|
|
|
}
|
2004-04-13 10:36:09 +00:00
|
|
|
///
|
|
|
|
std::string const & editor() const {
|
|
|
|
return editor_;
|
|
|
|
}
|
2003-02-28 09:49:49 +00:00
|
|
|
private:
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string name_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string extension_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string prettyname_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string shortcut_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string viewer_;
|
2004-04-13 10:36:09 +00:00
|
|
|
///
|
|
|
|
std::string editor_;
|
2003-02-28 09:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(Format const & a, Format const & b);
|
|
|
|
|
|
|
|
///
|
|
|
|
class Formats {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
typedef std::vector<Format> FormatList;
|
|
|
|
///
|
|
|
|
typedef FormatList::const_iterator const_iterator;
|
|
|
|
///
|
|
|
|
Format const & get(FormatList::size_type i) const {
|
|
|
|
return formatlist[i];
|
|
|
|
}
|
2004-10-29 15:47:55 +00:00
|
|
|
/// \returns format named \p name if it exists, otherwise 0
|
2003-10-06 15:43:21 +00:00
|
|
|
Format const * getFormat(std::string const & name) const;
|
2004-11-09 19:08:34 +00:00
|
|
|
/*!
|
|
|
|
* Get the format of \p filename from file contents or, if this
|
|
|
|
* fails, from file extension.
|
|
|
|
* \returns file format if it could be found, otherwise an empty
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
std::string getFormatFromFile(std::string const & filename) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
int getNumber(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void add(std::string const & name);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void add(std::string const & name, std::string const & extension,
|
2006-04-05 23:56:29 +00:00
|
|
|
std::string const & prettyname, std::string const & shortcut,
|
|
|
|
std::string const & viewer, std::string const & editor);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void erase(std::string const & name);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
void sort();
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void setViewer(std::string const & name, std::string const & command);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
bool view(Buffer const & buffer, std::string const & filename,
|
|
|
|
std::string const & format_name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2004-04-13 10:36:09 +00:00
|
|
|
bool edit(Buffer const & buffer, std::string const & filename,
|
|
|
|
std::string const & format_name) const;
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const prettyName(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const extension(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
const_iterator begin() const {
|
|
|
|
return formatlist.begin();
|
|
|
|
}
|
|
|
|
///
|
|
|
|
const_iterator end() const {
|
|
|
|
return formatlist.end();
|
|
|
|
}
|
|
|
|
///
|
|
|
|
FormatList::size_type size() const {
|
|
|
|
return formatlist.size();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
FormatList formatlist;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Formats formats;
|
|
|
|
|
|
|
|
extern Formats system_formats;
|
|
|
|
|
|
|
|
#endif //FORMAT_H
|