]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlRef.C
ff91fcb361a974d80833aa005c0efe31c02b644e
[features.git] / src / frontends / controllers / ControlRef.C
1 /**
2  * \file ControlRef.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "ControlRef.h"
15 #include "buffer.h"
16 #include "funcrequest.h"
17
18 #include "frontends/Application.h"
19
20 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
21
22 using std::vector;
23 using std::string;
24
25 namespace lyx {
26
27 using support::makeAbsPath;
28 using support::makeDisplayPath;
29
30 namespace frontend {
31
32 ControlRef::ControlRef(Dialog & d)
33         : ControlCommand(d, "ref")
34 {}
35
36
37 vector<string> const ControlRef::getLabelList(string const & name) const
38 {
39         Buffer const & buf = *theApp->bufferList().getBuffer(makeAbsPath(name));
40         vector<string> list;
41         buf.getLabelList(list);
42         return list;
43 }
44
45
46 void ControlRef::gotoRef(string const & ref)
47 {
48         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
49         kernel().dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
50 }
51
52
53 void ControlRef::gotoBookmark()
54 {
55         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
56 }
57
58
59 vector<string> const ControlRef::getBufferList() const
60 {
61         vector<string> buffers = theApp->bufferList().getFileNames();
62         for (vector<string>::iterator it = buffers.begin();
63              it != buffers.end(); ++it) {
64                 *it = lyx::to_utf8(makeDisplayPath(*it));
65         }
66
67         return buffers;
68 }
69
70
71 int ControlRef::getBufferNum() const
72 {
73         vector<string> buffers = theApp->bufferList().getFileNames();
74         string const name = kernel().buffer().fileName();
75         vector<string>::const_iterator cit =
76                 find(buffers.begin(), buffers.end(), name);
77         if (cit == buffers.end())
78                 return 0;
79         return int(cit - buffers.begin());
80 }
81
82 string const ControlRef::getBufferName(int num) const
83 {
84         return theApp->bufferList().getFileNames()[num];
85 }
86
87 } // namespace frontend
88 } // namespace lyx