2001-03-23 17:09:34 +00:00
|
|
|
/**
|
|
|
|
* \file ControlInclude.C
|
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-23 17:09:34 +00:00
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author John Levon
|
2002-10-21 17:38:09 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-23 17:09:34 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include "ControlInclude.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "helper_funcs.h"
|
2003-09-19 10:16:33 +00:00
|
|
|
#include "Kernel.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
#include "buffer.h"
|
2004-09-16 18:03:07 +00:00
|
|
|
#include "format.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "funcrequest.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "lyxrc.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
#include "insets/insetinclude.h"
|
|
|
|
|
2004-11-25 11:08:32 +00:00
|
|
|
#include "support/filefilterlist.h"
|
2002-01-14 23:31:23 +00:00
|
|
|
#include "support/filetools.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
#include <utility>
|
2002-05-29 16:21:03 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::FileFilterList;
|
|
|
|
using support::IsFileReadable;
|
|
|
|
using support::MakeAbsPath;
|
|
|
|
using support::OnlyPath;
|
|
|
|
|
|
|
|
namespace frontend {
|
2001-03-23 17:09:34 +00:00
|
|
|
|
2003-03-05 14:59:37 +00:00
|
|
|
ControlInclude::ControlInclude(Dialog & parent)
|
|
|
|
: Dialog::Controller(parent)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
bool ControlInclude::initialiseParams(string const & data)
|
2003-03-05 14:59:37 +00:00
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
InsetIncludeMailer::string2params(data, params_);
|
2003-03-14 00:20:42 +00:00
|
|
|
return true;
|
2003-03-05 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::clearParams()
|
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
params_ = InsetCommandParams();
|
2003-03-05 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::dispatchParams()
|
2001-03-23 17:09:34 +00:00
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
string const lfun = InsetIncludeMailer::params2string(params_);
|
2003-03-05 14:59:37 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
void ControlInclude::setParams(InsetCommandParams const & params)
|
2003-03-05 14:59:37 +00:00
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
params_ = params;
|
2003-03-05 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
string const ControlInclude::browse(string const & in_name, Type in_type) const
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2002-01-16 22:17:38 +00:00
|
|
|
string const title = _("Select document to include");
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
// input TeX, verbatim, or LyX file ?
|
2004-01-08 10:59:51 +00:00
|
|
|
FileFilterList filters;
|
2001-03-30 09:51:46 +00:00
|
|
|
switch (in_type) {
|
2004-01-08 10:59:51 +00:00
|
|
|
case INCLUDE:
|
2001-03-30 09:51:46 +00:00
|
|
|
case INPUT:
|
2004-01-08 10:59:51 +00:00
|
|
|
filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
|
2001-03-30 09:51:46 +00:00
|
|
|
break;
|
|
|
|
case VERBATIM:
|
|
|
|
break;
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-13 15:01:25 +00:00
|
|
|
pair<string, string> dir1(N_("Documents|#o#O"),
|
|
|
|
string(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
string const docpath = OnlyPath(kernel().buffer().fileName());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
return browseRelFile(in_name, docpath, title,
|
|
|
|
filters, false, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2001-07-25 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::load(string const & file)
|
|
|
|
{
|
2004-11-09 19:08:34 +00:00
|
|
|
string const ext = support::GetExtension(file);
|
|
|
|
if (ext == "lyx")
|
2004-09-16 18:03:07 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
|
|
|
|
else
|
|
|
|
// tex file or other text file in verbatim mode
|
|
|
|
formats.edit(kernel().buffer(), file, "text");
|
2001-07-25 12:37:43 +00:00
|
|
|
}
|
2002-01-21 10:47:19 +00:00
|
|
|
|
|
|
|
|
2002-01-24 15:49:53 +00:00
|
|
|
bool ControlInclude::fileExists(string const & file)
|
2002-01-21 10:47:19 +00:00
|
|
|
{
|
2002-08-07 08:11:41 +00:00
|
|
|
string const fileWithAbsPath
|
2003-09-19 10:16:33 +00:00
|
|
|
= MakeAbsPath(file,
|
|
|
|
OnlyPath(kernel().buffer().fileName()));
|
2002-07-04 09:58:16 +00:00
|
|
|
|
|
|
|
if (IsFileReadable(fileWithAbsPath))
|
|
|
|
return true;
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2002-09-09 17:32:53 +00:00
|
|
|
return false;
|
2002-01-21 10:47:19 +00:00
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|