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