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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-30 09:51:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlExternal.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
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
#include "insets/ExternalTemplate.h"
|
|
|
|
|
2003-06-04 09:16:29 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
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);
|
2003-08-28 07:41:31 +00:00
|
|
|
InsetExternalMailer::string2params(data, kernel().buffer(), *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-07-23 09:54:21 +00:00
|
|
|
string const lfun = InsetExternalMailer::params2string(params(),
|
2003-08-28 07:41:31 +00:00
|
|
|
kernel().buffer());
|
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-30 23:56:22 +00:00
|
|
|
Assert(params_.get());
|
2003-06-04 09:16:29 +00:00
|
|
|
*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-30 23:56:22 +00:00
|
|
|
Assert(params_.get());
|
2003-06-04 09:16:29 +00:00
|
|
|
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-30 23:56:22 +00:00
|
|
|
Assert(params_.get());
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
dialog().view().apply();
|
2003-07-23 09:07:28 +00:00
|
|
|
string const lfun =
|
2003-08-28 07:41:31 +00:00
|
|
|
InsetExternalMailer::params2string(params(), kernel().buffer());
|
2003-06-11 11:01:34 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
|
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();
|
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
|
|
|
|
{
|
|
|
|
ExternalTemplateManager & etm = ExternalTemplateManager::get();
|
|
|
|
ExternalTemplate const & templ = etm.getTemplateByName(params.templatename);
|
|
|
|
if (templ.lyxName.empty())
|
|
|
|
return 0;
|
|
|
|
return &templ;
|
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-06-11 14:30:04 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
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-07-23 09:07:28 +00:00
|
|
|
string const bufpath = kernel().bufferFilepath();
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
/// Determine the template file extension
|
2003-06-11 14:30:04 +00:00
|
|
|
string pattern = "*";
|
|
|
|
ExternalTemplate const * const et_ptr = getTemplatePtr(params());
|
|
|
|
if (et_ptr)
|
|
|
|
pattern = et_ptr->fileRegExp;
|
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
|
|
|
}
|