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