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