2 * \file ControlEmbeddedFiles.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "ControlEmbeddedFiles.h"
17 #include "FuncRequest.h"
23 #include "frontend_helpers.h"
24 #include "frontends/LyXView.h"
26 #include "support/FileFilterList.h"
27 #include "support/convert.h"
33 using support::FileFilterList;
37 ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
42 EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
44 return buffer().embeddedFiles();
48 bool ControlEmbeddedFiles::initialiseParams(string const &)
54 void ControlEmbeddedFiles::updateEmbeddedFiles()
56 // copy buffer embeddedFiles to a local copy
57 buffer().embeddedFiles().update();
58 buffer().embeddingChanged();
62 void ControlEmbeddedFiles::dispatchMessage(string const & msg)
64 // FIXME: the right thing to do? QT guys?
65 // lyx view will only be updated if we do something to the main window. :-)
66 dispatch(FuncRequest(LFUN_MESSAGE, msg));
70 bool ControlEmbeddedFiles::isReadonly()
72 return buffer().isReadonly();
76 void ControlEmbeddedFiles::setEmbedding(bool enable)
78 if (embeddedFiles().enabled() == enable)
80 embeddedFiles().enable(enable);
83 dispatchMessage("Stop saving in bundled format.");
85 dispatchMessage("Save in bundled format.");
89 void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
91 BOOST_ASSERT(idx < item.refCount());
92 item.saveBookmark(&buffer(), idx);
93 lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
97 void ControlEmbeddedFiles::view(EmbeddedFile const & item)
99 formats.view(buffer(), item, formats.getFormatFromFile(item));
103 void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
105 if (item.embedded() == embed)
107 item.setEmbed(embed);
110 item.updateFromExternalFile(&buffer());
112 item.extract(&buffer());
113 item.updateInsets(&buffer());
114 // FIXME: unless we record the type of file item, we will
115 // need to update all possible dialogs (bibtex etc).
116 updateDialog("graphics");
119 dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
121 dispatchMessage("Stop embedding file " + item.outputFilename(buffer().filePath()));
122 buffer().markDirty();
126 bool ControlEmbeddedFiles::browseAndAddFile()
128 std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
129 from_utf8(lyxrc.document_path));
130 FileFilterList const filter(_("All file (*.*)"));
131 docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
132 _("Select a file to embed"),
133 filter, false, dir1);
135 EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
136 if (embeddedFiles().enabled())
137 ef.updateFromExternalFile(&buffer());
138 buffer().markDirty();
139 dispatchMessage("Add an embedded file" + to_utf8(file));
146 bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
149 return item.extract(&buffer());
155 bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
158 return item.updateFromExternalFile(&buffer());
163 } // namespace frontend