]> git.lyx.org Git - lyx.git/blob - src/insets/insetcite.C
The BIG UNDO patch. Recodes undo handling for better use inside InsetText.
[lyx.git] / src / insets / insetcite.C
1 /* This file is part of*
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000-2001 The LyX Team.
7  * 
8  * ====================================================== */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "insetcite.h"
17 #include "BufferView.h"
18 #include "LyXView.h"
19 #include "frontends/Dialogs.h"
20 #include "support/lstrings.h"
21
22 InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
23         : InsetCommand(p)
24 {}
25
26 string const InsetCitation::getScreenLabel() const
27 {
28         string keys(getContents());
29
30         // If keys is "too long" then only print out the first few tokens
31         string label;
32         if (contains(keys, ",")) {
33                 // Final comma allows while loop to cover all keys
34                 keys = frontStrip(split(keys, label, ',')) + ",";
35
36                 string::size_type const maxSize = 40;
37                 while (contains( keys, "," )) {
38                         string key;
39                         keys = frontStrip(split(keys, key, ','));
40
41                         string::size_type size = label.size() + 2 + key.size();
42                         if (size >= maxSize) {
43                                 label += ", ...";
44                                 break;
45                         }
46                         label += ", " + key;
47                 }
48         } else {
49                 label = keys;
50         }
51
52         if (!getOptions().empty())
53                 label += ", " + getOptions();
54
55         return "[" + label + "]";
56 }
57
58
59 void InsetCitation::edit(BufferView * bv, int, int, unsigned int)
60 {
61         bv->owner()->getDialogs()->showCitation(this);
62 }
63
64
65 int InsetCitation::ascii(Buffer const *, std::ostream & os, int) const
66 {
67         os << "[" << getContents() << "]";
68         return 0;
69 }