]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormUrl.C
Angus's FormInset work; Dekel's languages patch; my reworking of Angus's stuff +...
[lyx.git] / src / frontends / kde / FormUrl.C
1 /*
2  * FormUrl.C
3  * (C) 2000 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6  
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include <config.h>
17
18 #include "Dialogs.h"
19 #include "FormUrl.h"
20 #include "gettext.h"
21 #include "buffer.h"
22 #include "LyXView.h"
23 #include "lyxfunc.h" 
24 #include "formurldialog.h"
25
26 FormUrl::FormUrl(LyXView *v, Dialogs *d)
27         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(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->showUrl.connect(slot(this, &FormUrl::showUrl));
33         d->createUrl.connect(slot(this, &FormUrl::createUrl));
34 }
35
36 FormUrl::~FormUrl()
37 {
38         delete dialog_;
39 }
40
41 void FormUrl::showUrl(InsetCommand * const inset)
42 {
43         // FIXME: when could inset be 0 here ?
44         if (inset==0)
45                 return;
46
47         inset_ = inset;
48         readonly = lv_->buffer()->isReadonly();
49         ih_ = inset_->hide.connect(slot(this,&FormUrl::hide));
50         params = inset->params();
51         
52         show();
53 }
54  
55 void FormUrl::createUrl(string const & arg)
56 {
57         // we could already be showing a URL, clear it out
58         if (inset_)
59                 close();
60  
61         readonly = lv_->buffer()->isReadonly();
62         params.setFromString(arg);
63         show();
64 }
65  
66 void FormUrl::update(bool switched)
67 {
68         if (switched) {
69                 // I suspect a buffer switch should cause hide() here. ARRae
70                 hide();
71                 return;
72         }
73
74         dialog_->url->setText(params.getContents().c_str());
75         dialog_->urlname->setText(params.getOptions().c_str());
76
77         if (params.getCmdName()=="url") 
78                 dialog_->htmlurl->setChecked(0);
79         else
80                 dialog_->htmlurl->setChecked(1);
81
82         if (readonly) {
83                 dialog_->urlname->setFocusPolicy(QWidget::NoFocus);
84                 dialog_->url->setFocusPolicy(QWidget::NoFocus);
85                 dialog_->buttonOk->setEnabled(false);
86                 dialog_->buttonCancel->setText(_("Close"));
87                 dialog_->htmlurl->setEnabled(false);
88         } else {
89                 dialog_->urlname->setFocusPolicy(QWidget::StrongFocus);
90                 dialog_->url->setFocusPolicy(QWidget::StrongFocus);
91                 dialog_->url->setFocus();
92                 dialog_->buttonOk->setEnabled(true);
93                 dialog_->buttonCancel->setText(_("Cancel"));
94                 dialog_->htmlurl->setEnabled(true);
95         }
96 }
97  
98 void FormUrl::apply()
99 {
100         if (readonly)
101                 return;
102
103         params.setContents(dialog_->url->text());
104         params.setOptions(dialog_->urlname->text());
105
106         if (dialog_->htmlurl->isChecked())
107                 params.setCmdName("htmlurl");
108         else
109                 params.setCmdName("url");
110
111         if (inset_ != 0) {
112                 if (params != inset_->params()) {
113                         inset_->setParams(params);
114                         lv_->view()->updateInset(inset_, true);
115                 }
116         } else
117                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
118 }
119  
120 void FormUrl::show()
121 {
122         if (!dialog_)
123                 dialog_ = new FormUrlDialog(this, 0, _("LyX: Url"), false);
124  
125         if (!dialog_->isVisible()) {
126                 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
127                 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
128         }
129
130         dialog_->raise();
131         dialog_->setActiveWindow();
132  
133         update();
134         dialog_->show();
135 }
136
137 void FormUrl::close()
138 {
139         h_.disconnect();
140         u_.disconnect();
141         ih_.disconnect();
142         inset_ = 0;
143 }
144  
145 void FormUrl::hide()
146 {
147         dialog_->hide();
148         close();
149 }