]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
5 new lfuns, move all apply code out of ControlDocument and into the core.
[lyx.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 "bufferlist.h"
17 #include "funcrequest.h"
18
19 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
20
21 using lyx::support::MakeAbsPath;
22 using lyx::support::MakeDisplayPath;
23
24 using std::vector;
25 using std::string;
26
27
28 extern BufferList bufferlist;
29
30
31 ControlRef::ControlRef(Dialog & d)
32         : ControlCommand(d, "ref")
33 {}
34
35
36 vector<string> const ControlRef::getLabelList(string const & name) const
37 {
38         Buffer const & buf = *bufferlist.getBuffer(MakeAbsPath(name));
39         vector<string> list;
40         buf.getLabelList(list);
41         return list;
42 }
43
44
45 void ControlRef::gotoRef(string const & ref)
46 {
47         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"), false);
48         kernel().dispatch(FuncRequest(LFUN_REF_GOTO, ref));
49 }
50
51
52 void ControlRef::gotoBookmark()
53 {
54         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"), false);
55 }
56
57
58 vector<string> const ControlRef::getBufferList() const
59 {
60         vector<string> buffers = bufferlist.getFileNames();
61         for (vector<string>::iterator it = buffers.begin();
62              it != buffers.end(); ++it) {
63                 *it = MakeDisplayPath(*it);
64         }
65
66         return buffers;
67 }
68
69
70 int ControlRef::getBufferNum() const
71 {
72         vector<string> buffers = bufferlist.getFileNames();
73         string const name = kernel().buffer().fileName();
74         vector<string>::const_iterator cit =
75                 find(buffers.begin(), buffers.end(), name);
76         if (cit == buffers.end())
77                 return 0;
78         return int(cit - buffers.begin());
79 }
80
81 string const ControlRef::getBufferName(int num) const
82 {
83         return bufferlist.getFileNames()[num];
84 }