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"
|
|
|
|
|
|
|
|
#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
|
|
|
|
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
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::pair;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
InsetInclude::Params params;
|
|
|
|
InsetIncludeMailer::string2params(data, params);
|
|
|
|
inset_.reset(new InsetInclude(params));
|
2003-03-14 00:20:42 +00:00
|
|
|
return true;
|
2003-03-05 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::clearParams()
|
|
|
|
{
|
|
|
|
inset_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::dispatchParams()
|
2001-03-23 17:09:34 +00:00
|
|
|
{
|
2003-03-05 14:59:37 +00:00
|
|
|
InsetInclude::Params p = params();
|
2003-03-07 14:08:10 +00:00
|
|
|
string const lfun = InsetIncludeMailer::params2string(p);
|
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-03-05 14:59:37 +00:00
|
|
|
void ControlInclude::setParams(InsetInclude::Params const & params)
|
|
|
|
{
|
|
|
|
inset_->set(params);
|
|
|
|
}
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
string const ControlInclude::Browse(string const & in_name, Type in_type)
|
|
|
|
{
|
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 ?
|
2002-03-21 21:21:28 +00:00
|
|
|
string pattern;
|
2001-03-30 09:51:46 +00:00
|
|
|
switch (in_type) {
|
|
|
|
case INPUT:
|
2002-11-14 20:39:16 +00:00
|
|
|
pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
|
2001-03-30 09:51:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VERBATIM:
|
2002-11-14 20:39:16 +00:00
|
|
|
pattern = _("*| All files (*)");
|
2001-03-30 09:51:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case INCLUDE:
|
2002-11-14 20:39:16 +00:00
|
|
|
pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
|
2001-03-30 09:51:46 +00:00
|
|
|
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
|
|
|
|
2002-01-14 23:31:23 +00:00
|
|
|
string const docpath = OnlyPath(params().masterFilename_);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
return browseRelFile(in_name, docpath, title, pattern, false, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2001-07-25 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::load(string const & file)
|
|
|
|
{
|
2003-03-05 14:59:37 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
|
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
|
|
|
|
= MakeAbsPath(file, OnlyPath(params().masterFilename_));
|
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
|
|
|
}
|