]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
Switch from SigC signals to boost::signals
[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 "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "Dialogs.h"
24 #include "buffer.h"
25 #include "lyxfunc.h"
26 #include "bufferlist.h"
27 #include "debug.h"
28
29 #include "frontends/LyXView.h"
30
31 #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
32
33 #include <boost/bind.hpp>
34
35 #include <algorithm>
36
37 using std::vector;
38 using std::find;
39
40 extern BufferList bufferlist;
41
42 ControlRef::ControlRef(LyXView & lv, Dialogs & d)
43         : ControlCommand(lv, d, LFUN_REF_INSERT)
44 {
45         d_.showRef = boost::bind(&ControlRef::showInset, this, _1);
46         d_.createRef = boost::bind(&ControlRef::createInset, this, _1);
47 }
48
49
50 vector<string> const ControlRef::getLabelList(string const & name) const
51 {
52         Buffer * buffer = bufferlist.getBuffer(MakeAbsPath(name));
53         if (!buffer)
54                 buffer = lv_.buffer();
55         return buffer->getLabelList();
56 }
57
58
59 void ControlRef::gotoRef(string const & ref) const
60 {
61         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_SAVE, "0");
62         lv_.getLyXFunc()->dispatch(LFUN_REF_GOTO, ref);
63 }
64
65
66 void ControlRef::gotoBookmark() const
67 {
68         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_GOTO, "0");
69 }
70
71
72 vector<string> const ControlRef::getBufferList() const
73 {
74
75         vector<string> buffers = bufferlist.getFileNames();
76         for (vector<string>::iterator it = buffers.begin();
77              it != buffers.end(); ++it) {
78                 *it = MakeDisplayPath(*it);
79         }
80
81         return buffers;
82 }
83
84
85 int ControlRef::getBufferNum() const
86 {
87         vector<string> buffers = bufferlist.getFileNames();
88         string const name = lv_.buffer()->fileName();
89         vector<string>::const_iterator cit =
90                 find(buffers.begin(), buffers.end(), name);
91         if (cit == buffers.end())
92                 return 0;
93         return int(cit - buffers.begin());
94 }
95
96 string const ControlRef::getBufferName(int num) const
97 {
98         return bufferlist.getFileNames()[num];
99 }