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-12-04 18:51:55 +00:00
|
|
|
|
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-12-04 18:51:55 +00:00
|
|
|
#include "graphics/GraphicsCache.h"
|
|
|
|
#include "graphics/GraphicsCacheItem.h"
|
|
|
|
#include "graphics/GraphicsImage.h"
|
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
#include "insets/insetexternal.h"
|
|
|
|
#include "insets/ExternalSupport.h"
|
2003-06-11 14:30:04 +00:00
|
|
|
#include "insets/ExternalTemplate.h"
|
|
|
|
|
2004-11-25 11:08:32 +00:00
|
|
|
#include "support/filefilterlist.h"
|
2003-12-04 18:51:55 +00:00
|
|
|
#include "support/filetools.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2004-01-28 16:21:29 +00:00
|
|
|
using std::advance;
|
2001-03-30 09:51:46 +00:00
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::FileFilterList;
|
2006-04-08 22:31:11 +00:00
|
|
|
using support::makeAbsPath;
|
2004-05-19 15:11:37 +00:00
|
|
|
using support::readBB_from_PSFile;
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
ControlExternal::ControlExternal(Dialog & parent)
|
2003-12-04 18:51:55 +00:00
|
|
|
: Dialog::Controller(parent),
|
|
|
|
bb_changed_(false)
|
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-10-07 20:25:10 +00:00
|
|
|
params_.reset(new InsetExternalParams);
|
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-12-04 18:51:55 +00:00
|
|
|
|
2005-04-26 09:37:52 +00:00
|
|
|
kernel().dispatch(FuncRequest(getLfun(), lfun));
|
2001-03-30 13:47:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-10-07 20:25:10 +00:00
|
|
|
void ControlExternal::setParams(InsetExternalParams const & p)
|
2001-03-30 13:47:39 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_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-10-07 20:25:10 +00:00
|
|
|
InsetExternalParams const & ControlExternal::params() const
|
2003-03-05 11:30:35 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_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-09-09 17:25:35 +00:00
|
|
|
BOOST_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;
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
external::TemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = external::TemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = external::TemplateManager::get().getTemplates().end();
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
for (; i1 != i2; ++i1) {
|
|
|
|
result.push_back(i1->second.lyxName);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ControlExternal::getTemplateNumber(string const & name) const
|
|
|
|
{
|
2003-10-01 10:16:00 +00:00
|
|
|
external::TemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = external::TemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = external::TemplateManager::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 10:16:00 +00:00
|
|
|
external::Template ControlExternal::getTemplate(int i) const
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
2003-10-01 10:16:00 +00:00
|
|
|
external::TemplateManager::Templates::const_iterator i1
|
|
|
|
= external::TemplateManager::get().getTemplates().begin();
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2004-01-28 16:21:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-19 09:11:25 +00:00
|
|
|
string const
|
|
|
|
ControlExternal::getTemplateFilters(string const & template_name) const
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
|
|
|
/// Determine the template file extension
|
2004-01-08 10:59:51 +00:00
|
|
|
external::TemplateManager const & etm =
|
|
|
|
external::TemplateManager::get();
|
2003-10-07 20:25:10 +00:00
|
|
|
external::Template const * const et_ptr =
|
2004-01-08 10:59:51 +00:00
|
|
|
etm.getTemplateByName(template_name);
|
|
|
|
|
2006-04-19 09:11:25 +00:00
|
|
|
if (et_ptr)
|
|
|
|
return et_ptr->fileRegExp;
|
|
|
|
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const ControlExternal::browse(string const & input,
|
|
|
|
string const & template_name) const
|
|
|
|
{
|
|
|
|
string const title = _("Select external file");
|
|
|
|
|
|
|
|
string const bufpath = kernel().bufferFilepath();
|
|
|
|
FileFilterList const filter =
|
|
|
|
FileFilterList(getTemplateFilters(template_name));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2002-01-17 21:00:58 +00:00
|
|
|
std::pair<string, string> dir1(N_("Documents|#o#O"),
|
2004-01-08 10:59:51 +00:00
|
|
|
string(lyxrc.document_path));
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
return browseRelFile(input, bufpath, title, filter, false, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
2003-12-04 18:51:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
string const ControlExternal::readBB(string const & file)
|
|
|
|
{
|
|
|
|
string const abs_file =
|
2006-04-08 22:31:11 +00:00
|
|
|
makeAbsPath(file, kernel().bufferFilepath());
|
2003-12-04 18:51:55 +00:00
|
|
|
|
|
|
|
// try to get it from the file, if possible. Zipped files are
|
|
|
|
// unzipped in the readBB_from_PSFile-Function
|
|
|
|
string const bb = readBB_from_PSFile(abs_file);
|
|
|
|
if (!bb.empty())
|
|
|
|
return bb;
|
|
|
|
|
|
|
|
// we don't, so ask the Graphics Cache if it has loaded the file
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
graphics::Cache & gc = graphics::Cache::get();
|
2003-12-04 18:51:55 +00:00
|
|
|
if (gc.inCache(abs_file)) {
|
2004-05-19 15:11:37 +00:00
|
|
|
graphics::Image const * image = gc.item(abs_file)->image();
|
2003-12-04 18:51:55 +00:00
|
|
|
|
|
|
|
if (image) {
|
|
|
|
width = image->getWidth();
|
|
|
|
height = image->getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
|
2003-12-04 18:51:55 +00:00
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
|
|
|
|
|
|
|
|
namespace external {
|
2003-12-04 18:51:55 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
RotationDataType origins_array[] = {
|
|
|
|
RotationData::DEFAULT,
|
|
|
|
RotationData::TOPLEFT,
|
|
|
|
RotationData::BOTTOMLEFT,
|
|
|
|
RotationData::BASELINELEFT,
|
|
|
|
RotationData::CENTER,
|
|
|
|
RotationData::TOPCENTER,
|
|
|
|
RotationData::BOTTOMCENTER,
|
|
|
|
RotationData::BASELINECENTER,
|
|
|
|
RotationData::TOPRIGHT,
|
|
|
|
RotationData::BOTTOMRIGHT,
|
|
|
|
RotationData::BASELINERIGHT
|
2003-12-04 18:51:55 +00:00
|
|
|
};
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
size_type const origins_array_size =
|
2003-12-04 18:51:55 +00:00
|
|
|
sizeof(origins_array) / sizeof(origins_array[0]);
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
vector<RotationDataType> const
|
2003-12-04 18:51:55 +00:00
|
|
|
origins(origins_array, origins_array + origins_array_size);
|
|
|
|
|
|
|
|
// These are the strings, corresponding to the above, that the GUI should
|
|
|
|
// use. Note that they can/should be translated.
|
|
|
|
char const * const origin_gui_strs[] = {
|
|
|
|
N_("Default"),
|
|
|
|
N_("Top left"), N_("Bottom left"), N_("Baseline left"),
|
|
|
|
N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
|
|
|
|
N_("Top right"), N_("Bottom right"), N_("Baseline right")
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
vector<RotationDataType> const & all_origins()
|
|
|
|
{
|
|
|
|
return origins;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const origin_gui_str(size_type i)
|
|
|
|
{
|
2005-08-07 21:30:21 +00:00
|
|
|
return _(origin_gui_strs[i]);
|
2003-12-04 18:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace external
|
|
|
|
} // namespace lyx
|