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
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
#include "support/docstring.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
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2003-05-23 13:54:09 +00:00
|
|
|
class Buffer;
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
class Format {
|
|
|
|
public:
|
2006-10-03 08:34:59 +00:00
|
|
|
/// Flags for some format properties
|
|
|
|
enum Flags {
|
|
|
|
none = 0,
|
|
|
|
/// Set if this format is a document format (as opposed to
|
|
|
|
/// e.g. image formats).
|
|
|
|
/// Some formats are both (e.g. pdf), they have this flag set.
|
|
|
|
document = 1,
|
|
|
|
/// Set if this format can contain vector graphics.
|
|
|
|
vector = 2,
|
|
|
|
};
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
Format(std::string const & n, std::string const & e, std::string const & p,
|
2006-05-20 12:03:40 +00:00
|
|
|
std::string const & s, std::string const & v, std::string const & ed,
|
2006-10-03 08:34:59 +00:00
|
|
|
int);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
bool dummy() const;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Tell whether this format is a child format.
|
|
|
|
/// Child formats inherit settings like the viewer from their parent.
|
2003-02-28 09:49:49 +00:00
|
|
|
bool isChildFormat() const;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Name fo the parent format
|
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_;
|
|
|
|
}
|
2006-05-17 22:13:33 +00:00
|
|
|
///
|
|
|
|
void setEditor(std::string const & v) {
|
|
|
|
editor_ = v;
|
|
|
|
}
|
2006-05-20 12:03:40 +00:00
|
|
|
///
|
|
|
|
bool documentFormat() const {
|
2006-10-03 08:34:59 +00:00
|
|
|
return flags_ & document;
|
|
|
|
}
|
|
|
|
///
|
|
|
|
bool vectorFormat() const {
|
|
|
|
return flags_ & vector;
|
2006-05-20 12:03:40 +00:00
|
|
|
}
|
2003-02-28 09:49:49 +00:00
|
|
|
private:
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Internal name. Needs to be unique.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string name_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Filename extension
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string extension_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Name presented to the user. Needs to be unique.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string prettyname_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Keyboard shortcut for the View and Export menu.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string shortcut_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/*!
|
|
|
|
* Viewer for this format. Needs to be in the PATH or an absolute
|
|
|
|
* filename.
|
|
|
|
* This format cannot be viewed if \c viewer_ is empty.
|
|
|
|
* If it is \c auto the default viewer of the OS for this format is
|
|
|
|
* used.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string viewer_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Editor for this format. \sa viewer_.
|
2004-04-13 10:36:09 +00:00
|
|
|
std::string editor_;
|
2006-10-03 08:34:59 +00:00
|
|
|
///
|
|
|
|
int flags_;
|
2003-02-28 09:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(Format const & a, Format const & b);
|
|
|
|
|
2006-10-03 08:34:59 +00:00
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
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;
|
2006-05-17 22:13:33 +00:00
|
|
|
/// Set editor and/or viewer to "auto" for formats that can be
|
|
|
|
/// opened by the OS.
|
|
|
|
void setAutoOpen();
|
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-05-20 12:03:40 +00:00
|
|
|
std::string const & prettyname, std::string const & shortcut,
|
|
|
|
std::string const & viewer, std::string const & editor,
|
2006-10-03 08:34:59 +00:00
|
|
|
int flags);
|
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;
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring 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
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
const_iterator begin() const { return formatlist.begin(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
const_iterator end() const { return formatlist.end(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
FormatList::size_type size() const { return formatlist.size(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
FormatList formatlist;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Formats formats;
|
|
|
|
|
|
|
|
extern Formats system_formats;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#endif //FORMAT_H
|