]> git.lyx.org Git - lyx.git/blob - src/insets/insetcite.C
3b6304e41f7162f79e6b063cc6569a87affe5e6c
[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 "LyXView.h"
19 #include "BufferView.h"
20 #include "frontends/Dialogs.h"
21 #include "support/lstrings.h"
22
23 InsetCitation::InsetCitation(InsetCommandParams const & p)
24                 : InsetCommand(p)
25 {}
26
27 InsetCitation::~InsetCitation()
28 {
29         hide();
30 }
31
32 string InsetCitation::getScreenLabel() const
33 {
34         string keys(getContents());
35
36         // If keys is "too long" then only print out the first few tokens
37         string label;
38         if( contains( keys, "," ) ) {
39                 // Final comma allows while loop to cover all keys
40                 keys = frontStrip( split( keys, label, ',' ) ) + ",";
41
42                 const int maxSize( 40 );
43                 while( contains( keys, "," ) ) {
44                         string key;
45                         keys = frontStrip( split( keys, key, ',' ) );
46
47                         int size = label.size() + 2 + key.size();
48                         if( size >= maxSize ) {
49                                 label += ", ...";
50                                 break;
51                         }
52                         label += ", " + key;
53                 }
54         } else {
55                 label = keys;
56         }
57
58         if( !getOptions().empty() )
59                 label += ", " + getOptions();
60
61         return '[' + label + ']';
62 }
63
64 void InsetCitation::Edit(BufferView * bv, int, int, unsigned int)
65 {
66         bv->owner()->getDialogs()->showCitation( this );
67 }
68