]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlEmbeddedFiles.cpp
6d051b10225edaa697811d0f8679ceb46ec6b3d5
[lyx.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         : Dialog::Controller(parent), embedded_files(NULL)
39 {}
40
41
42 bool ControlEmbeddedFiles::initialiseParams(string const &)
43 {
44         return true;
45 }
46
47
48 void ControlEmbeddedFiles::updateEmbeddedFiles()
49 {
50         // copy buffer embeddedFiles to a local copy
51         kernel().buffer().embeddedFiles().update();
52         embedded_files = &kernel().buffer().embeddedFiles();
53 }
54
55
56 void ControlEmbeddedFiles::dispatchParams()
57 {
58         // lyx view will only be updated if we do something to the main window. :-)
59         kernel().dispatch(FuncRequest(LFUN_MESSAGE, message_));
60 }
61
62
63 void ControlEmbeddedFiles::goTo(EmbeddedFile const & item)
64 {
65         int id = item.parID();
66         if (id != 0) {
67                 string const tmp = convert<string>(item.parID());
68                 kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
69         }
70 }
71
72
73 void ControlEmbeddedFiles::view(EmbeddedFile const & item)
74 {
75         formats.view(kernel().buffer(), item, formats.getFormatFromFile(item));
76 }
77
78
79 docstring const ControlEmbeddedFiles::browseFile()
80 {
81         std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
82                                   lyx::from_utf8(lyxrc.document_path));
83         FileFilterList const filter(_("All file (*.*)"));
84         return browseRelFile(docstring(), lyx::from_utf8(kernel().bufferFilepath()),
85                              _("Select a file to embed"),
86                              filter, false, dir1);
87 }
88
89
90 } // namespace frontend
91 } // namespace lyx