2002-09-05 14:10:50 +00:00
|
|
|
/**
|
2001-03-30 09:51:46 +00:00
|
|
|
* \file ControlExternal.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.
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2001-03-30 09:51:46 +00:00
|
|
|
* \author Asger Alstrup
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-30 09:51:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlExternal.h"
|
2002-08-12 20:17:41 +00:00
|
|
|
#include "buffer.h"
|
2003-03-05 11:30:35 +00:00
|
|
|
#include "funcrequest.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2002-01-16 22:17:38 +00:00
|
|
|
#include "helper_funcs.h"
|
|
|
|
#include "lyxrc.h"
|
2003-06-04 09:16:29 +00:00
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
ControlExternal::ControlExternal(Dialog & parent)
|
|
|
|
: Dialog::Controller(parent)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
bool ControlExternal::initialiseParams(string const & data)
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2003-06-04 09:16:29 +00:00
|
|
|
params_.reset(new InsetExternal::Params);
|
|
|
|
InsetExternalMailer::string2params(data, *params_);
|
2003-03-14 00:20:42 +00:00
|
|
|
return true;
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
void ControlExternal::clearParams()
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2003-06-04 09:16:29 +00:00
|
|
|
params_.reset();
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
void ControlExternal::dispatchParams()
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
string const lfun = InsetExternalMailer::params2string(params());
|
2003-03-05 11:30:35 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
|
2001-03-30 13:47:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
void ControlExternal::setParams(InsetExternal::Params const & p)
|
2001-03-30 13:47:39 +00:00
|
|
|
{
|
2003-06-04 09:16:29 +00:00
|
|
|
lyx::Assert(params_.get());
|
|
|
|
*params_ = p;
|
2003-03-05 11:30:35 +00:00
|
|
|
}
|
2001-03-30 13:47:39 +00:00
|
|
|
|
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
InsetExternal::Params const & ControlExternal::params() const
|
2003-03-05 11:30:35 +00:00
|
|
|
{
|
2003-06-04 09:16:29 +00:00
|
|
|
lyx::Assert(params_.get());
|
|
|
|
return *params_;
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
void ControlExternal::editExternal()
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2003-06-04 09:16:29 +00:00
|
|
|
lyx::Assert(params_.get());
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
dialog().view().apply();
|
2003-06-04 09:16:29 +00:00
|
|
|
InsetExternal inset;
|
|
|
|
inset.setParams(*params_, kernel().buffer()->filePath());
|
|
|
|
inset.cache(kernel().bufferview());
|
|
|
|
inset.editExternal();
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
vector<string> const ControlExternal::getTemplates() const
|
|
|
|
{
|
|
|
|
vector<string> result;
|
|
|
|
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = ExternalTemplateManager::get().getTemplates().end();
|
|
|
|
|
|
|
|
for (; i1 != i2; ++i1) {
|
|
|
|
result.push_back(i1->second.lyxName);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ControlExternal::getTemplateNumber(string const & name) const
|
|
|
|
{
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = ExternalTemplateManager::get().getTemplates().end();
|
2002-10-21 17:38:09 +00:00
|
|
|
for (int i = 0; i1 != i2; ++i1, ++i) {
|
2001-03-30 09:51:46 +00:00
|
|
|
if (i1->second.lyxName == name)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can get here if a LyX document has a template not installed
|
|
|
|
// on this machine.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalTemplate ControlExternal::getTemplate(int i) const
|
|
|
|
{
|
2002-10-21 17:38:09 +00:00
|
|
|
ExternalTemplateManager::Templates::const_iterator i1
|
|
|
|
= ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
|
|
|
|
std::advance(i1, i);
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2001-07-12 11:11:10 +00:00
|
|
|
return i1->second;
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const ControlExternal::Browse(string const & input) const
|
|
|
|
{
|
2002-01-16 22:17:38 +00:00
|
|
|
string const title = _("Select external file");
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
string const bufpath = kernel().buffer()->filePath();
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
/// Determine the template file extension
|
|
|
|
ExternalTemplate const & et = params().templ;
|
2002-01-16 22:17:38 +00:00
|
|
|
string pattern = et.fileRegExp;
|
|
|
|
if (pattern.empty())
|
|
|
|
pattern = "*";
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
// FIXME: a temporary hack until the FileDialog interface is updated
|
2002-11-27 10:30:28 +00:00
|
|
|
pattern += '|';
|
2002-01-16 22:17:38 +00:00
|
|
|
|
2002-01-17 21:00:58 +00:00
|
|
|
std::pair<string, string> dir1(N_("Documents|#o#O"),
|
2002-01-16 22:17:38 +00:00
|
|
|
string(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
return browseRelFile(input, bufpath, title, pattern, false, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|