]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
Create a grfx::Loader class and so move large chunks of code out of
[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
24 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
25
26 using std::vector;
27
28 extern BufferList bufferlist;
29
30
31 ControlRef::ControlRef(LyXView & lv, Dialogs & d)
32         : ControlCommand(lv, d, LFUN_REF_INSERT)
33 {}
34
35
36 vector<string> const ControlRef::getLabelList(string const & name) const
37 {
38         Buffer * buffer = bufferlist.getBuffer(MakeAbsPath(name));
39         if (!buffer)
40                 buffer = lv_.buffer();
41         return buffer->getLabelList();
42 }
43
44
45 void ControlRef::gotoRef(string const & ref) const
46 {
47         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_SAVE, "0");
48         lv_.getLyXFunc()->dispatch(LFUN_REF_GOTO, ref);
49 }
50
51
52 void ControlRef::gotoBookmark() const
53 {
54         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_GOTO, "0");
55 }
56
57
58 vector<string> const ControlRef::getBufferList() const
59 {
60
61         vector<string> buffers = bufferlist.getFileNames();
62         for (vector<string>::iterator it = buffers.begin();
63              it != buffers.end(); ++it) {
64                 *it = MakeDisplayPath(*it);
65         }
66
67         return buffers;
68 }
69
70
71 int ControlRef::getBufferNum() const
72 {
73         vector<string> buffers = bufferlist.getFileNames();
74         string const name = lv_.buffer()->fileName();
75         vector<string>::const_iterator cit =
76                 find(buffers.begin(), buffers.end(), name);
77         if (cit == buffers.end())
78                 return 0;
79         return int(cit - buffers.begin());
80 }
81
82 string const ControlRef::getBufferName(int num) const
83 {
84         return bufferlist.getFileNames()[num];
85 }