]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
fix crash due to invalidated iterator
[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 std::vector;
22 using std::string;
23
24
25 extern BufferList bufferlist;
26
27 namespace lyx {
28
29 using support::MakeAbsPath;
30 using support::MakeDisplayPath;
31
32 namespace frontend {
33
34 ControlRef::ControlRef(Dialog & d)
35         : ControlCommand(d, "ref")
36 {}
37
38
39 vector<string> const ControlRef::getLabelList(string const & name) const
40 {
41         Buffer const & buf = *bufferlist.getBuffer(MakeAbsPath(name));
42         vector<string> list;
43         buf.getLabelList(list);
44         return list;
45 }
46
47
48 void ControlRef::gotoRef(string const & ref)
49 {
50         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
51         kernel().dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
52 }
53
54
55 void ControlRef::gotoBookmark()
56 {
57         kernel().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
58 }
59
60
61 vector<string> const ControlRef::getBufferList() const
62 {
63         vector<string> buffers = bufferlist.getFileNames();
64         for (vector<string>::iterator it = buffers.begin();
65              it != buffers.end(); ++it) {
66                 *it = MakeDisplayPath(*it);
67         }
68
69         return buffers;
70 }
71
72
73 int ControlRef::getBufferNum() const
74 {
75         vector<string> buffers = bufferlist.getFileNames();
76         string const name = kernel().buffer().fileName();
77         vector<string>::const_iterator cit =
78                 find(buffers.begin(), buffers.end(), name);
79         if (cit == buffers.end())
80                 return 0;
81         return int(cit - buffers.begin());
82 }
83
84 string const ControlRef::getBufferName(int num) const
85 {
86         return bufferlist.getFileNames()[num];
87 }
88
89 } // namespace frontend
90 } // namespace lyx