]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
Nothing but a changed email address (trying to factor my tree in in small steps)
[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 <leeming@lyx.org>
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 "buffer.h"
23 #include "bufferlist.h"
24 #include "funcrequest.h"
25
26 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
27
28 using std::vector;
29
30 extern BufferList bufferlist;
31
32
33 ControlRef::ControlRef(LyXView & lv, Dialogs & d)
34         : ControlCommand(lv, d, LFUN_REF_INSERT)
35 {}
36
37
38 vector<string> const ControlRef::getLabelList(string const & name) const
39 {
40         Buffer const * buf = bufferlist.getBuffer(MakeAbsPath(name));
41         if (!buf)
42                 buf = buffer();
43         return buf->getLabelList();
44 }
45
46
47 void ControlRef::gotoRef(string const & ref)
48 {
49         lyxfunc().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"), false);
50         lyxfunc().dispatch(FuncRequest(LFUN_REF_GOTO, ref));
51 }
52
53
54 void ControlRef::gotoBookmark()
55 {
56         lyxfunc().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"), false);
57 }
58
59
60 vector<string> const ControlRef::getBufferList() const
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 = 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 }