2007-08-31 15:42:35 +00:00
|
|
|
/**
|
|
|
|
* \file ControlEmbeddedFiles.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Bo Peng
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlEmbeddedFiles.h"
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "debug.h"
|
2007-08-31 22:02:34 +00:00
|
|
|
#include "Format.h"
|
2007-09-01 04:20:34 +00:00
|
|
|
#include "LyXRC.h"
|
2007-08-31 15:42:35 +00:00
|
|
|
|
2007-09-01 04:20:34 +00:00
|
|
|
#include "frontend_helpers.h"
|
2007-08-31 22:02:34 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2007-09-01 04:20:34 +00:00
|
|
|
|
|
|
|
#include "support/FileFilterList.h"
|
2007-08-31 22:02:34 +00:00
|
|
|
#include "support/convert.h"
|
2007-08-31 15:42:35 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
2007-09-01 04:20:34 +00:00
|
|
|
|
|
|
|
using support::FileFilterList;
|
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
|
2007-09-08 21:16:54 +00:00
|
|
|
: Controller(parent)
|
2007-08-31 15:42:35 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-09-03 04:03:43 +00:00
|
|
|
EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
|
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
return buffer().embeddedFiles();
|
2007-09-03 04:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
bool ControlEmbeddedFiles::initialiseParams(string const &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlEmbeddedFiles::updateEmbeddedFiles()
|
|
|
|
{
|
|
|
|
// copy buffer embeddedFiles to a local copy
|
2007-09-10 22:32:59 +00:00
|
|
|
buffer().embeddedFiles().update();
|
|
|
|
buffer().embeddingChanged();
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
void ControlEmbeddedFiles::dispatchMessage(string const & msg)
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
2007-09-07 16:33:55 +00:00
|
|
|
// FIXME: the right thing to do? QT guys?
|
2007-08-31 15:42:35 +00:00
|
|
|
// lyx view will only be updated if we do something to the main window. :-)
|
2007-09-10 22:32:59 +00:00
|
|
|
dispatch(FuncRequest(LFUN_MESSAGE, msg));
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 15:09:56 +00:00
|
|
|
bool ControlEmbeddedFiles::isReadonly()
|
|
|
|
{
|
|
|
|
return buffer().isReadonly();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 04:56:46 +00:00
|
|
|
void ControlEmbeddedFiles::setEmbedding(bool enable)
|
|
|
|
{
|
|
|
|
if (embeddedFiles().enabled() == enable)
|
|
|
|
return;
|
|
|
|
embeddedFiles().enable(enable);
|
|
|
|
buffer().markDirty();
|
|
|
|
if (enable)
|
|
|
|
dispatchMessage("Stop saving in bundled format.");
|
|
|
|
else
|
|
|
|
dispatchMessage("Save in bundled format.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-08 04:10:43 +00:00
|
|
|
void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
2007-08-31 22:02:34 +00:00
|
|
|
{
|
2007-09-08 04:10:43 +00:00
|
|
|
BOOST_ASSERT(idx < item.refCount());
|
2007-09-10 22:32:59 +00:00
|
|
|
item.saveBookmark(&buffer(), idx);
|
|
|
|
lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
|
2007-08-31 22:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlEmbeddedFiles::view(EmbeddedFile const & item)
|
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
formats.view(buffer(), item, formats.getFormatFromFile(item));
|
2007-08-31 22:02:34 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 04:20:34 +00:00
|
|
|
|
2007-09-11 16:00:16 +00:00
|
|
|
void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
|
2007-09-07 16:33:55 +00:00
|
|
|
{
|
2007-09-13 04:45:49 +00:00
|
|
|
if (item.embedded() == embed)
|
|
|
|
return;
|
2007-09-07 16:33:55 +00:00
|
|
|
item.setEmbed(embed);
|
2007-09-11 16:00:16 +00:00
|
|
|
if (update) {
|
|
|
|
if (embed)
|
|
|
|
item.updateFromExternalFile(&buffer());
|
|
|
|
else
|
|
|
|
item.extract(&buffer());
|
2007-09-12 14:27:47 +00:00
|
|
|
item.updateInsets(&buffer());
|
2007-09-11 16:00:16 +00:00
|
|
|
}
|
2007-09-13 04:45:49 +00:00
|
|
|
if (embed)
|
|
|
|
dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
|
|
|
|
else
|
|
|
|
dispatchMessage("Stop embedding file " + item.outputFilename(buffer().filePath()));
|
|
|
|
buffer().markDirty();
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 05:30:44 +00:00
|
|
|
bool ControlEmbeddedFiles::browseAndAddFile()
|
2007-09-01 04:20:34 +00:00
|
|
|
{
|
|
|
|
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
2007-09-10 22:32:59 +00:00
|
|
|
from_utf8(lyxrc.document_path));
|
2007-09-01 04:20:34 +00:00
|
|
|
FileFilterList const filter(_("All file (*.*)"));
|
2007-09-13 05:30:44 +00:00
|
|
|
docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
|
2007-09-01 04:20:34 +00:00
|
|
|
_("Select a file to embed"),
|
|
|
|
filter, false, dir1);
|
2007-09-13 05:30:44 +00:00
|
|
|
if (!file.empty()) {
|
|
|
|
EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
|
|
|
|
if (embeddedFiles().enabled())
|
|
|
|
ef.updateFromExternalFile(&buffer());
|
|
|
|
buffer().markDirty();
|
|
|
|
dispatchMessage("Add an embedded file" + to_utf8(file));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-09-01 04:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 20:08:16 +00:00
|
|
|
bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
|
|
|
{
|
2007-09-08 04:10:43 +00:00
|
|
|
if (item.embedded())
|
2007-09-10 22:32:59 +00:00
|
|
|
return item.extract(&buffer());
|
2007-09-08 04:10:43 +00:00
|
|
|
else
|
|
|
|
return false;
|
2007-09-01 20:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
|
|
|
{
|
2007-09-08 04:10:43 +00:00
|
|
|
if (item.embedded())
|
2007-09-10 22:32:59 +00:00
|
|
|
return item.updateFromExternalFile(&buffer());
|
2007-09-08 04:10:43 +00:00
|
|
|
else
|
|
|
|
return false;
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|