2001-03-21 13:27:03 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-05 14:10:50 +00:00
|
|
|
/**
|
|
|
|
* \file helper_funcs.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-21 13:27:03 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Angus Leeming
|
2001-03-21 13:27:03 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-21 13:27:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HELPERFUNCS_H
|
|
|
|
#define HELPERFUNCS_H
|
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
#include <boost/bind.hpp>
|
2003-09-07 21:25:37 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
2006-09-28 00:42:47 +00:00
|
|
|
#include <algorithm>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
namespace lyx {
|
2004-05-19 15:11:37 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
namespace support {
|
|
|
|
class FileFilterList;
|
|
|
|
} // namespace support
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace frontend {
|
2004-01-08 10:59:51 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
/** Launch a file dialog and return the chosen file.
|
|
|
|
filename: a suggested filename.
|
|
|
|
title: the title of the dialog.
|
|
|
|
pattern: *.ps etc.
|
|
|
|
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const
|
|
|
|
browseFile(std::string const & filename,
|
|
|
|
std::string const & title,
|
2004-05-19 15:11:37 +00:00
|
|
|
support::FileFilterList const & filters,
|
2002-11-17 08:32:09 +00:00
|
|
|
bool save = false,
|
2003-10-06 15:43:21 +00:00
|
|
|
std::pair<std::string,std::string> const & dir1 =
|
|
|
|
std::make_pair(std::string(), std::string()),
|
|
|
|
std::pair<std::string,std::string> const & dir2 =
|
|
|
|
std::make_pair(std::string(), std::string()));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
|
2004-08-08 15:23:43 +00:00
|
|
|
/** Wrapper around browseFile which tries to provide a filename
|
|
|
|
relative to relpath. If the relative path is of the form "foo.txt"
|
|
|
|
or "bar/foo.txt", then it is returned as relative. OTOH, if it is
|
|
|
|
of the form "../baz/foo.txt", an absolute path is returned. This is
|
|
|
|
intended to be useful for insets which encapsulate files/
|
2002-01-14 23:31:23 +00:00
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const
|
|
|
|
browseRelFile(std::string const & filename,
|
|
|
|
std::string const & refpath,
|
|
|
|
std::string const & title,
|
2004-05-19 15:11:37 +00:00
|
|
|
support::FileFilterList const & filters,
|
2002-11-17 08:32:09 +00:00
|
|
|
bool save = false,
|
2003-10-06 15:43:21 +00:00
|
|
|
std::pair<std::string,std::string> const & dir1 =
|
|
|
|
std::make_pair(std::string(), std::string()),
|
|
|
|
std::pair<std::string,std::string> const & dir2 =
|
|
|
|
std::make_pair(std::string(), std::string()));
|
2002-01-14 23:31:23 +00:00
|
|
|
|
|
|
|
|
2004-08-08 15:23:43 +00:00
|
|
|
/** Wrapper around browseFile which tries to provide a filename
|
|
|
|
* relative to the user or system directory. The dir, name and ext
|
|
|
|
* parameters have the same meaning as in the
|
|
|
|
* lyx::support::LibFileSearch function.
|
|
|
|
*/
|
|
|
|
std::string const
|
|
|
|
browseLibFile(std::string const & dir,
|
|
|
|
std::string const & name,
|
|
|
|
std::string const & ext,
|
|
|
|
std::string const & title,
|
|
|
|
support::FileFilterList const & filters);
|
|
|
|
|
|
|
|
|
2003-01-14 21:51:34 +00:00
|
|
|
/** Launch a file dialog and return the chosen directory.
|
|
|
|
pathname: a suggested pathname.
|
|
|
|
title: the title of the dialog.
|
|
|
|
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const
|
|
|
|
browseDir(std::string const & pathname,
|
|
|
|
std::string const & title,
|
|
|
|
std::pair<std::string,std::string> const & dir1 =
|
|
|
|
std::make_pair(std::string(), std::string()),
|
|
|
|
std::pair<std::string,std::string> const & dir2 =
|
|
|
|
std::make_pair(std::string(), std::string()));
|
2003-01-14 21:51:34 +00:00
|
|
|
|
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
/// Returns a vector of units that can be used to create a valid LaTeX length.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::vector<std::string> const getLatexUnits();
|
2001-10-15 10:28:31 +00:00
|
|
|
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
/** Functions to extract vectors of the first and second elems from a
|
|
|
|
vector<pair<A,B> >
|
|
|
|
*/
|
|
|
|
template<class Pair>
|
2001-08-07 16:23:52 +00:00
|
|
|
std::vector<typename Pair::first_type> const
|
|
|
|
getFirst(std::vector<Pair> const & pr)
|
2001-03-21 13:27:03 +00:00
|
|
|
{
|
2001-08-07 16:23:52 +00:00
|
|
|
std::vector<typename Pair::first_type> tmp(pr.size());
|
2002-02-18 19:13:48 +00:00
|
|
|
std::transform(pr.begin(), pr.end(), tmp.begin(),
|
2004-01-08 10:59:51 +00:00
|
|
|
boost::bind(&Pair::first, _1));
|
2001-03-21 13:27:03 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class Pair>
|
2001-08-07 16:23:52 +00:00
|
|
|
std::vector<typename Pair::second_type> const
|
|
|
|
getSecond(std::vector<Pair> const & pr)
|
2001-03-21 13:27:03 +00:00
|
|
|
{
|
2001-08-07 16:23:52 +00:00
|
|
|
std::vector<typename Pair::second_type> tmp(pr.size());
|
2002-02-18 19:13:48 +00:00
|
|
|
std::transform(pr.begin(), pr.end(), tmp.begin(),
|
2004-01-08 10:59:51 +00:00
|
|
|
boost::bind(&Pair::second, _1));
|
2001-03-21 13:27:03 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
#endif // NOT HELPERFUNCS_H
|