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