]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormCharacter.C
Fix for qt2 citation dialog crash when selecting first key
[lyx.git] / src / frontends / qt2 / FormCharacter.C
1 /**
2  * \file FormCharacter.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven, leuven@fee.uva.nl
7  */
8
9 #include <config.h>
10
11 #include "gettext.h"
12 #include "chardlgimpl.h"
13 #include "FormCharacter.h"
14 #include "bufferview_funcs.h"
15 #include "Dialogs.h"
16 #include "Liason.h"
17 #include "QtLyXView.h"
18 #include "buffer.h"
19 #include "lyxtext.h"
20 #include "language.h"
21 #include "support/lstrings.h"
22
23 using SigC::slot;
24 using Liason::setMinibuffer;
25
26 FormCharacter::FormCharacter(LyXView *v, Dialogs *d)
27         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
28 {
29         // let the dialog be shown
30         // This is a permanent connection so we won't bother
31         // storing a copy because we won't be disconnecting.
32         d->showCharacter.connect(slot(this, &FormCharacter::show));
33         // for LFUN_FREE
34         d->setUserFreeFont.connect(slot(this, &FormCharacter::apply));
35 }
36
37
38 FormCharacter::~FormCharacter()
39 {
40         delete dialog_;
41 }
42
43
44 void FormCharacter::apply()
45 {
46         if (!lv_->view()->available() || !dialog_)
47                 return;
48
49         LyXFont font = dialog_->getChar();
50
51         if (dialog_->langItem()==1)
52                 font.setLanguage(lv_->buffer()->params.language);
53
54         ToggleAndShow(lv_->view(), font, dialog_->toggleAll());
55         lv_->view()->setState();
56         lv_->buffer()->markDirty();
57         setMinibuffer(lv_, _("Character set"));
58 }
59
60 void FormCharacter::show()
61 {
62         if (!dialog_) {
63                 dialog_ = new CharDlgImpl(this, 0, _("Character Options"), false);
64                 // add languages
65                 for (Languages::const_iterator cit = languages.begin();
66                         cit != languages.end(); ++cit) {
67                         const string language = (*cit).second.lang();
68                         dialog_->lang->insertItem( tostr(language).c_str(), -1 );
69                 }
70         }
71
72         if (!dialog_->isVisible()) {
73                 h_ = d_->hideBufferDependent.connect(slot(this, &FormCharacter::hide));
74                 u_ = d_->updateBufferDependent.connect(slot(this, &FormCharacter::update));
75         }
76
77         dialog_->raise();
78         dialog_->setActiveWindow();
79         update();
80         dialog_->show();
81 }
82
83 void FormCharacter::close()
84 {
85         h_.disconnect();
86         u_.disconnect();
87 }
88
89 void FormCharacter::hide()
90 {
91         dialog_->hide();
92         close();
93 }
94
95 void FormCharacter::update(bool)
96 {
97         if (!lv_->view()->available())
98                 return;
99
100         dialog_->setReadOnly(lv_->buffer()->isReadonly());
101 }