2001-03-30 09:51:46 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file ControlExternal.C
|
|
|
|
* \author Asger Alstrup
|
2001-04-11 17:14:20 +00:00
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
2001-03-30 09:51:46 +00:00
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2002-01-16 22:17:38 +00:00
|
|
|
#include "BufferView.h"
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "ControlExternal.h"
|
2002-01-16 14:47:58 +00:00
|
|
|
#include "ControlInset.tmpl"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "LyXView.h"
|
2002-01-16 22:17:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "buffer.h"
|
2001-11-26 10:19:58 +00:00
|
|
|
#include "frontends/Alert.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"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
using std::make_pair;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
|
|
|
|
{
|
|
|
|
d_.showExternal.connect(SigC::slot(this, &ControlExternal::showInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetExternal::Params const ControlExternal::getParams(string const &)
|
|
|
|
{
|
|
|
|
return InsetExternal::Params();
|
|
|
|
}
|
|
|
|
|
|
|
|
InsetExternal::Params const
|
|
|
|
ControlExternal::getParams(InsetExternal const & inset)
|
|
|
|
{
|
|
|
|
return inset.params();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 13:47:39 +00:00
|
|
|
void ControlExternal::applyParamsToInset()
|
2001-03-30 09:51:46 +00:00
|
|
|
{
|
|
|
|
inset()->setFromParams(params());
|
2001-03-30 13:47:39 +00:00
|
|
|
lv_.view()->updateInset(inset(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlExternal::editExternal()
|
|
|
|
{
|
|
|
|
// fill the local, controller's copy of the Params struct with
|
2001-04-03 14:30:58 +00:00
|
|
|
// the contents of the dialog's fields.
|
2001-03-30 13:47:39 +00:00
|
|
|
view().apply();
|
|
|
|
|
|
|
|
// Create a local copy of the inset and initialise it with this
|
|
|
|
// params struct.
|
2001-04-11 17:14:20 +00:00
|
|
|
boost::scoped_ptr<InsetExternal> ie;
|
2001-06-28 10:25:20 +00:00
|
|
|
ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->setFromParams(params());
|
2001-03-30 13:47:39 +00:00
|
|
|
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->editExternal();
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlExternal::viewExternal()
|
|
|
|
{
|
2001-03-30 13:47:39 +00:00
|
|
|
view().apply();
|
|
|
|
|
2001-04-11 17:14:20 +00:00
|
|
|
boost::scoped_ptr<InsetExternal> ie;
|
2001-06-28 10:25:20 +00:00
|
|
|
ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->setFromParams(params());
|
2001-03-30 13:47:39 +00:00
|
|
|
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->viewExternal();
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlExternal::updateExternal()
|
|
|
|
{
|
2001-03-30 13:47:39 +00:00
|
|
|
view().apply();
|
|
|
|
|
2001-04-11 17:14:20 +00:00
|
|
|
boost::scoped_ptr<InsetExternal> ie;
|
2001-06-28 10:25:20 +00:00
|
|
|
ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->setFromParams(params());
|
2001-03-30 13:47:39 +00:00
|
|
|
|
2001-04-11 17:14:20 +00:00
|
|
|
ie->updateExternal();
|
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
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = ExternalTemplateManager::get().getTemplates().end();
|
|
|
|
for (; i1 != i2; ++i1) {
|
|
|
|
if (i1->second.lyxName == name)
|
|
|
|
return i;
|
|
|
|
++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
|
|
|
|
{
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
for (int n = 1; n < i; ++n)
|
|
|
|
++i1;
|
|
|
|
|
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");
|
|
|
|
|
2002-01-14 23:31:23 +00:00
|
|
|
string const bufpath = lv_.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-01-16 22:17:38 +00:00
|
|
|
pattern += "|";
|
|
|
|
|
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
|
|
|
|
2002-01-16 22:17:38 +00:00
|
|
|
return browseRelFile(&lv_, input, bufpath, title, pattern, dir1);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|