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