]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlEmbeddedFiles.cpp
Embedding: store inset pointer instead of ParConstIterator to enable more accurate...
[features.git] / src / frontends / controllers / ControlEmbeddedFiles.cpp
1 /**
2  * \file ControlEmbeddedFiles.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Bo Peng
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlEmbeddedFiles.h"
14
15 #include "Buffer.h"
16
17 #include "FuncRequest.h"
18 #include "gettext.h"
19 #include "debug.h"
20 #include "Format.h"
21 #include "LyXRC.h"
22
23 #include "frontend_helpers.h"
24 #include "frontends/LyXView.h"
25
26 #include "support/FileFilterList.h"
27 #include "support/convert.h"
28
29 using std::string;
30
31 namespace lyx {
32
33 using support::FileFilterList;
34
35 namespace frontend {
36
37 ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
38         : Controller(parent)
39 {}
40
41
42 EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
43 {
44         return kernel().buffer().embeddedFiles();
45 }
46
47
48 bool ControlEmbeddedFiles::initialiseParams(string const &)
49 {
50         return true;
51 }
52
53
54 void ControlEmbeddedFiles::updateEmbeddedFiles()
55 {
56         // copy buffer embeddedFiles to a local copy
57         kernel().buffer().embeddedFiles().update();
58         kernel().buffer().embeddingChanged();
59 }
60
61
62 void ControlEmbeddedFiles::dispatchMessage(string const & msg)
63 {
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         kernel().dispatch(FuncRequest(LFUN_MESSAGE, msg));
67 }
68
69
70 void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
71 {
72         BOOST_ASSERT(idx < item.refCount());
73         item.saveBookmark(&kernel().buffer(), idx);
74         kernel().lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
75 }
76
77
78 void ControlEmbeddedFiles::view(EmbeddedFile const & item)
79 {
80         formats.view(kernel().buffer(), item, formats.getFormatFromFile(item));
81 }
82
83
84 void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed)
85 {
86         // FIXME: updateFromExternalFile() or extract() may fail...
87         if (embed)
88                 item.updateFromExternalFile(&kernel().buffer());
89         else
90                 item.extract(&kernel().buffer());
91         item.setEmbed(embed);
92 }
93
94
95 docstring const ControlEmbeddedFiles::browseFile()
96 {
97         std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
98                                   lyx::from_utf8(lyxrc.document_path));
99         FileFilterList const filter(_("All file (*.*)"));
100         return browseRelFile(docstring(), lyx::from_utf8(kernel().bufferFilepath()),
101                              _("Select a file to embed"),
102                              filter, false, dir1);
103 }
104
105
106 bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
107 {
108         if (item.embedded())
109                 return item.extract(&kernel().buffer());
110         else
111                 return false;
112 }
113
114
115 bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
116 {
117         if (item.embedded())
118                 return item.updateFromExternalFile(&kernel().buffer());
119         else
120                 return false;
121 }
122
123 } // namespace frontend
124 } // namespace lyx