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