]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormCitationDialogImpl.C
- Compiles and links again
[lyx.git] / src / frontends / qt2 / FormCitationDialogImpl.C
1 /**
2  * $Id: FormCitationDialogImpl.C,v 1.2 2001/03/26 19:34:45 kalle Exp $
3  */
4
5 #include "FormCitationDialogImpl.h"
6 #include "Dialogs.h"
7 #include "FormCitation.h"
8
9 #include <qlistbox.h>
10 #include <qmultilineedit.h>
11 #undef emit
12
13 #include <algorithm>
14 #include "LyXView.h"
15 #include "buffer.h"
16
17 using std::vector;
18 using std::find;
19
20 // PENDING(kalle) Wire text before and citation style
21
22 /*
23  *  Constructs a FormCitationDialogImpl which is a child of 'parent', with the
24  *  name 'name' and widget flags set to 'f'
25  *
26  *  The dialog will by default be modeless, unless you set 'modal' to
27  *  TRUE to construct a modal dialog.
28  */
29 FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* parent,  const char* name, bool modal, WFlags fl )
30   : FormCitationDialog( parent, name, modal, fl ),
31     form_( form )
32 {
33 }
34
35 /*
36  *  Destroys the object and frees any allocated resources
37  */
38 FormCitationDialogImpl::~FormCitationDialogImpl()
39 {
40     // no need to delete child widgets, Qt does it all for us
41 }
42
43
44
45 // These slots correspond to the XForms input() method.
46 void FormCitationDialogImpl::slotBibSelected( int sel )
47 {
48     insetKeysLB->clearSelection();
49
50     if( sel < 0 || sel > form_->bibkeys.size()-1)
51         return;
52
53     // Put into browser_info the additional info associated with
54     // the selected browser_bib key
55     infoML->clear();
56     infoML->append( form_->bibkeysInfo[sel].c_str() );
57
58     // Highlight the selected browser_bib key in browser_cite if present
59     vector<string>::iterator it =
60         ::find(form_->citekeys.begin(), form_->citekeys.end(), form_->bibkeys[sel]);
61
62     if (it != form_->citekeys.end()) {
63         int n = static_cast<int>(it - form_->citekeys.begin());
64         insetKeysLB->setSelected( n, true );
65     }
66
67     if (!form_->lv_->buffer()->isReadonly()) {
68         if (it != form_->citekeys.end()) {
69             form_->setBibButtons(FormCitation::OFF);
70             form_->setCiteButtons(FormCitation::ON);
71         } else {
72             form_->setBibButtons(FormCitation::ON);
73             form_->setCiteButtons(FormCitation::OFF);
74         }
75     }
76
77 }
78
79
80 void FormCitationDialogImpl::slotInsetSelected( int sel )
81 {
82     if (sel < 0 || sel > form_->citekeys.size() -1 )
83         return;
84
85     if (!form_->lv_->buffer()->isReadonly()) {
86         form_->setBibButtons(FormCitation::OFF);
87         form_->setCiteButtons(FormCitation::ON);
88     }
89
90     // Highlight the selected browser_cite key in browser_bib
91     vector<string>::iterator it =
92         ::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
93
94     if (it != form_->bibkeys.end()) {
95         int n = static_cast<int>(it - form_->bibkeys.begin());
96         bibliographyKeysLB->setSelected( n, true );
97
98         // Put into browser_info the additional info associated with
99         // the selected browser_cite key
100         infoML->clear();
101         infoML->append( form_->bibkeysInfo[n].c_str() );
102     }
103 }
104
105
106 void FormCitationDialogImpl::slotAddClicked()
107 {
108     qDebug( "FormCitationDialogImpl::slotAddClicked()" );
109     int sel = bibliographyKeysLB->currentItem();
110     if (sel < 0 || sel > form_->bibkeys.size() -1 )
111         return;
112
113     qDebug( "sel = %d" );
114     qDebug( "bibkeys.size() = %d", form_->bibkeys.size() );
115
116     // Add the selected browser_bib key to browser_cite
117     insetKeysLB->insertItem( form_->bibkeys[sel].c_str());
118     form_->citekeys.push_back(form_->bibkeys[sel]);
119
120     int n = static_cast<int>(form_->citekeys.size());
121     insetKeysLB->setSelected( n, true );
122
123     form_->setBibButtons(FormCitation::OFF);
124     form_->setCiteButtons(FormCitation::ON);
125 }
126
127
128 void FormCitationDialogImpl::slotDelClicked()
129 {
130     int sel = insetKeysLB->currentItem();
131     if (sel < 0 || sel > form_->citekeys.size()-1)
132         return;
133
134     // Remove the selected key from browser_cite
135     insetKeysLB->removeItem( sel );
136     form_->citekeys.erase(form_->citekeys.begin() + sel);
137
138     form_->setBibButtons(FormCitation::ON);
139     form_->setCiteButtons(FormCitation::OFF);
140 }
141
142
143 void FormCitationDialogImpl::slotUpClicked()
144 {
145     int sel = insetKeysLB->currentItem();
146     if (sel < 1 || sel > form_->citekeys.size()-1)
147         return;
148
149     // Move the selected key up one line
150     vector<string>::iterator it = form_->citekeys.begin() + sel;
151     string tmp = *it;
152
153     insetKeysLB->removeItem( sel );
154     form_->citekeys.erase(it);
155
156     insetKeysLB->insertItem( tmp.c_str(), sel-1 );
157     insetKeysLB->setSelected( sel-1, true );
158     form_->citekeys.insert(it-1, tmp);
159     form_->setCiteButtons(FormCitation::ON);
160 }
161
162
163 void FormCitationDialogImpl::slotDownClicked()
164 {
165     int sel = insetKeysLB->currentItem();
166     if (sel < 0 || sel > form_->citekeys.size()-2)
167         return;
168
169     // Move the selected key down one line
170     vector<string>::iterator it = form_->citekeys.begin() + sel;
171     string tmp = *it;
172
173     insetKeysLB->removeItem( sel );
174     form_->citekeys.erase(it);
175
176     insetKeysLB->insertItem( tmp.c_str(), sel+1 );
177     insetKeysLB->setSelected( sel+1, true );
178     form_->citekeys.insert(it+1, tmp);
179     form_->setCiteButtons(FormCitation::ON);
180 }
181
182
183 void FormCitationDialogImpl::apply_adaptor()
184 {
185     form_->apply();
186 }
187
188
189 void FormCitationDialogImpl::close_adaptor()
190 {
191     form_->close();
192     hide();
193 }