2001-03-23 17:09:34 +00:00
|
|
|
/**
|
|
|
|
* \file ControlInclude.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
2002-08-14 19:19:47 +00:00
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2001-03-23 17:09:34 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include "ControlInclude.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "funcrequest.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "lyxrc.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
|
|
|
#include "frontends/Alert.h"
|
2002-05-29 16:21:03 +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
|
|
|
|
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
|
|
|
|
|
|
|
ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::applyParamsToInset()
|
|
|
|
{
|
|
|
|
inset()->set(params());
|
2002-08-12 20:17:41 +00:00
|
|
|
bufferview()->updateInset(inset(), true);
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
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:
|
|
|
|
pattern = _("*.tex| LaTeX Documents (*.tex)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERBATIM:
|
|
|
|
pattern = _("*| All files ");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INCLUDE:
|
|
|
|
pattern = _("*.lyx| LyX Documents (*.lyx)");
|
|
|
|
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
|
|
|
|
2002-01-14 23:31:23 +00:00
|
|
|
return browseRelFile(&lv_, in_name, docpath, title, pattern, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2001-07-25 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::load(string const & file)
|
|
|
|
{
|
2002-08-12 20:17:41 +00:00
|
|
|
lyxfunc().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
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
if (params().noload) {
|
2002-07-04 09:58:16 +00:00
|
|
|
|
|
|
|
if (prefixIs(file, "../") || prefixIs(file, "/"))
|
|
|
|
Alert::alert(_("Warning!"),
|
|
|
|
_("On some systems, with this options only relative path names"),
|
|
|
|
_("inside the master file dir are allowed. You might get a LaTeX error!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsFileReadable(fileWithAbsPath))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
else
|
2002-08-07 08:11:41 +00:00
|
|
|
Alert::alert(_("Warning!"), _("Specified file doesn't exist"));
|
2002-07-04 09:58:16 +00:00
|
|
|
return false;
|
2002-01-21 10:47:19 +00:00
|
|
|
}
|