]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.cpp
ControlRef.cpp: compile fix
[lyx.git] / src / frontends / controllers / ControlRef.cpp
1 /**
2  * \file ControlRef.cpp
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 #include "ControlRef.h"
14
15 #include "Buffer.h"
16 #include "BufferList.h"
17 #include "FuncRequest.h"
18
19 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
20
21 #include <boost/filesystem/operations.hpp>
22
23 using lyx::docstring;
24
25 using std::find;
26 using std::vector;
27 using std::string;
28
29 namespace lyx {
30
31 using support::makeAbsPath;
32 using support::makeDisplayPath;
33
34 namespace frontend {
35
36 ControlRef::ControlRef(Dialog & d)
37         : ControlCommand(d, "ref")
38 {}
39
40
41 vector<docstring> const ControlRef::getLabelList(string const & name) const
42 {
43         Buffer const & buf = *theBufferList().getBuffer(makeAbsPath(name).absFilename());
44         vector<docstring> list;
45         buf.getLabelList(list);
46         return list;
47 }
48
49
50 void ControlRef::gotoRef(string const & ref)
51 {
52         dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
53         dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
54 }
55
56
57 void ControlRef::gotoBookmark()
58 {
59         dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
60 }
61
62
63 vector<string> const ControlRef::getBufferList() const
64 {
65         vector<string> buffers = theBufferList().getFileNames();
66         for (vector<string>::iterator it = buffers.begin();
67              it != buffers.end(); ++it) {
68                 *it = lyx::to_utf8(makeDisplayPath(*it));
69         }
70
71         return buffers;
72 }
73
74
75 int ControlRef::getBufferNum() const
76 {
77         vector<string> buffers = theBufferList().getFileNames();
78         string const name = buffer().fileName();
79         vector<string>::const_iterator cit =
80                 find(buffers.begin(), buffers.end(), name);
81         if (cit == buffers.end())
82                 return 0;
83         return int(cit - buffers.begin());
84 }
85
86 string const ControlRef::getBufferName(int num) const
87 {
88         return theBufferList().getFileNames()[num];
89 }
90
91 } // namespace frontend
92 } // namespace lyx