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
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-30 09:51:46 +00:00
|
|
|
#include "ControlExternal.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "frontends/FileDialog.h"
|
|
|
|
#include "lyx_gui_misc.h" // WriteAlert
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.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;
|
|
|
|
|
|
|
|
return (*i1).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const ControlExternal::Browse(string const & input) const
|
|
|
|
{
|
|
|
|
string buf = MakeAbsPath(lv_.buffer()->fileName());
|
|
|
|
string buf2 = OnlyPath(buf);
|
|
|
|
|
|
|
|
if (!input.empty()) {
|
|
|
|
buf = MakeAbsPath(input, buf2);
|
|
|
|
buf = OnlyPath(buf);
|
|
|
|
} else {
|
|
|
|
buf = OnlyPath(lv_.buffer()->fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialog fileDlg(&lv_,
|
|
|
|
_("Select external file"),
|
|
|
|
LFUN_SELECT_FILE_SYNC,
|
|
|
|
make_pair(string(_("Document")), string(buf)));
|
|
|
|
|
|
|
|
/// Determine the template file extension
|
|
|
|
ExternalTemplate const & et = params().templ;
|
|
|
|
|
|
|
|
string regexp = et.fileRegExp;
|
|
|
|
if (regexp.empty())
|
|
|
|
regexp = "*";
|
|
|
|
|
|
|
|
// FIXME: a temporary hack until the FileDialog interface is updated
|
|
|
|
regexp += "|";
|
|
|
|
|
2001-06-04 23:57:32 +00:00
|
|
|
static int once;
|
2001-03-30 09:51:46 +00:00
|
|
|
string current_path;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
string const path = (once) ? current_path : buf;
|
|
|
|
FileDialog::Result result = fileDlg.Select(path, regexp, input);
|
|
|
|
|
|
|
|
if (result.second.empty())
|
|
|
|
return string();
|
|
|
|
|
|
|
|
string p = result.second;
|
|
|
|
|
2001-03-30 13:47:39 +00:00
|
|
|
buf = MakeRelPath(p, buf2);
|
|
|
|
current_path = OnlyPath(p);
|
2001-03-30 09:51:46 +00:00
|
|
|
once = 1;
|
|
|
|
|
2001-03-30 13:47:39 +00:00
|
|
|
if (contains(p, "#") ||
|
|
|
|
contains(p, "~") ||
|
|
|
|
contains(p, "$") ||
|
|
|
|
contains(p, "%")) {
|
2001-03-30 09:51:46 +00:00
|
|
|
WriteAlert(_("Filename can't contain any "
|
|
|
|
"of these characters:"),
|
|
|
|
// xgettext:no-c-format
|
|
|
|
_("'#', '~', '$' or '%'."));
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|