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
|
|
|
|
* \author Angus Leeming, a.leeming@.ac.uk
|
|
|
|
*/
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <utility>
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "ControlInclude.h"
|
2002-01-16 14:47:58 +00:00
|
|
|
#include "ControlInset.tmpl"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "buffer.h"
|
2002-01-21 10:47:19 +00:00
|
|
|
#include "Alert.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "Dialogs.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-07-25 12:37:43 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "helper_funcs.h"
|
|
|
|
#include "lyxrc.h"
|
2002-01-14 23:31:23 +00:00
|
|
|
#include "support/filetools.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
2001-03-23 17:09:34 +00:00
|
|
|
using SigC::slot;
|
|
|
|
|
|
|
|
ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
|
|
|
|
{
|
|
|
|
d_.showInclude.connect(slot(this, &ControlInclude::showInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlInclude::applyParamsToInset()
|
|
|
|
{
|
|
|
|
inset()->set(params());
|
|
|
|
lv_.view()->updateInset(inset(), true);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
lv_.getLyXFunc()->dispatch(LFUN_CHILDOPEN, file);
|
|
|
|
}
|
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-03-21 21:21:28 +00:00
|
|
|
string const fileWithAbsPath = MakeAbsPath(file, OnlyPath(params().masterFilename_));
|
2002-01-21 10:47:19 +00:00
|
|
|
if (IsFileReadable(fileWithAbsPath))
|
|
|
|
return true;
|
|
|
|
else
|
2002-03-19 09:42:52 +00:00
|
|
|
Alert::alert(_("Specified file doesn't exist !"));
|
2002-01-21 10:47:19 +00:00
|
|
|
return false;
|
|
|
|
}
|