]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
the FuncRequest changes
[lyx.git] / src / frontends / controllers / ControlRef.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlRef.C
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlRef.h"
21 #include "lyxfunc.h"
22 #include "bufferlist.h"
23 #include "funcrequest.h"
24
25 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
26
27 using std::vector;
28
29 extern BufferList bufferlist;
30
31
32 ControlRef::ControlRef(LyXView & lv, Dialogs & d)
33         : ControlCommand(lv, d, LFUN_REF_INSERT)
34 {}
35
36
37 vector<string> const ControlRef::getLabelList(string const & name) const
38 {
39         Buffer * buffer = bufferlist.getBuffer(MakeAbsPath(name));
40         if (!buffer)
41                 buffer = lv_.buffer();
42         return buffer->getLabelList();
43 }
44
45
46 void ControlRef::gotoRef(string const & ref) const
47 {
48         lv_.getLyXFunc()->dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"), false);
49         lv_.getLyXFunc()->dispatch(FuncRequest(LFUN_REF_GOTO, ref));
50 }
51
52
53 void ControlRef::gotoBookmark() const
54 {
55         lv_.getLyXFunc()->dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"), false);
56 }
57
58
59 vector<string> const ControlRef::getBufferList() const
60 {
61
62         vector<string> buffers = bufferlist.getFileNames();
63         for (vector<string>::iterator it = buffers.begin();
64              it != buffers.end(); ++it) {
65                 *it = MakeDisplayPath(*it);
66         }
67
68         return buffers;
69 }
70
71
72 int ControlRef::getBufferNum() const
73 {
74         vector<string> buffers = bufferlist.getFileNames();
75         string const name = lv_.buffer()->fileName();
76         vector<string>::const_iterator cit =
77                 find(buffers.begin(), buffers.end(), name);
78         if (cit == buffers.end())
79                 return 0;
80         return int(cit - buffers.begin());
81 }
82
83 string const ControlRef::getBufferName(int num) const
84 {
85         return bufferlist.getFileNames()[num];
86 }