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