2003-02-28 09:49:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Format.h
|
2003-02-28 09:49:49 +00:00
|
|
|
* 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>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
|
|
|
|
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
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & name() const { return name_; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setName(std::string const & v) { name_ = v; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & extension() const { return extension_; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setExtension(std::string const & v) { extension_ = v; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & prettyname() const { return prettyname_; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setPrettyname(std::string const & v) { prettyname_ = v; }
|
2004-04-13 10:36:09 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & shortcut() const { return shortcut_; }
|
2006-05-17 22:13:33 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setShortcut(std::string const & v) { shortcut_ = v; }
|
2006-05-20 12:03:40 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & viewer() const { return viewer_; }
|
2006-10-03 08:34:59 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setViewer(std::string const & v) { viewer_ = v; }
|
|
|
|
///
|
|
|
|
std::string const & editor() const { return editor_; }
|
|
|
|
///
|
|
|
|
void setEditor(std::string const & v) { editor_ = v; }
|
|
|
|
///
|
|
|
|
bool documentFormat() const { return flags_ & document; }
|
|
|
|
///
|
|
|
|
bool vectorFormat() const { return flags_ & vector; }
|
|
|
|
///
|
|
|
|
void setFlags(int v) { flags_ = v; }
|
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;
|
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
Format const & get(FormatList::size_type i) const { return formatlist[i]; }
|
|
|
|
///
|
|
|
|
Format & get(FormatList::size_type i) { 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.
|
|
|
|
*/
|
2006-11-26 21:30:39 +00:00
|
|
|
std::string getFormatFromFile(support::FileName 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,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & prettyname, std::string const & shortcut,
|
|
|
|
std::string const & viewer, std::string const & editor,
|
|
|
|
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
|
|
|
///
|
2009-11-19 23:37:16 +00:00
|
|
|
void setEditor(std::string const & name, std::string const & command);
|
2010-08-30 12:08:10 +00:00
|
|
|
/// Currently used by hyperlink insets
|
2010-08-29 23:04:36 +00:00
|
|
|
bool viewURL(std::string const &url);
|
2010-08-30 12:08:10 +00:00
|
|
|
/// View the given file. Buffer used for DVI's paper orientation.
|
2006-11-26 21:30:39 +00:00
|
|
|
bool view(Buffer const & buffer, support::FileName const & filename,
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & format_name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
bool edit(Buffer const & buffer, support::FileName const & filename,
|
2004-04-13 10:36:09 +00:00
|
|
|
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
|