]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlRef.C
The reference dialog now disconnects from the inset on Apply. Its behaviour
[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 #include <algorithm>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "ControlRef.h"
24 #include "Dialogs.h"
25 #include "LyXView.h"
26 #include "buffer.h"
27 #include "lyxfunc.h"
28 #include "bufferlist.h"
29
30 using SigC::slot;
31 using std::vector;
32 using std::find;
33
34 extern BufferList bufferlist;
35
36 ControlRef::ControlRef(LyXView & lv, Dialogs & d)
37         : ControlCommand(lv, d, LFUN_REF_INSERT)
38 {
39         d_.showRef.connect(slot(this, &ControlRef::showInset));
40         d_.createRef.connect(slot(this, &ControlRef::createInset));
41 }
42
43
44 vector<string> const ControlRef::getLabelList(string const & name) const
45 {
46         Buffer * buffer = bufferlist.getBuffer(name);
47         if (!buffer)
48                 buffer = lv_.buffer();
49         return buffer->getLabelList();
50 }
51
52
53 void ControlRef::gotoRef(string const & ref) const
54 {
55         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_SAVE, "0");
56         lv_.getLyXFunc()->dispatch(LFUN_REF_GOTO, ref);
57 }
58
59
60 void ControlRef::gotoBookmark() const
61 {
62         lv_.getLyXFunc()->dispatch(LFUN_BOOKMARK_GOTO, "0");
63 }
64
65
66 vector<string> const ControlRef::getBufferList() const
67 {
68         return bufferlist.getFileNames();
69 }
70
71
72 int ControlRef::getBufferNum() const
73 {
74         vector<string> buffers = bufferlist.getFileNames();
75         string const name = lv_.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 cit - buffers.begin();
81 }