]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormUrl.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / kde / FormUrl.C
1 /**
2  * \file FormUrl.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #include "Dialogs.h"
12 #include "FormUrl.h"
13 #include "gettext.h"
14 #include "buffer.h"
15 #include "LyXView.h"
16 #include "lyxfunc.h" 
17 #include "urldlg.h"
18
19 FormUrl::FormUrl(LyXView *v, Dialogs *d)
20         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
21 {
22         d->showUrl.connect(slot(this, &FormUrl::showUrl));
23         d->createUrl.connect(slot(this, &FormUrl::createUrl));
24 }
25
26
27 FormUrl::~FormUrl()
28 {
29         delete dialog_;
30 }
31
32
33 void FormUrl::showUrl(InsetCommand * const inset)
34 {
35         // FIXME: when could inset be 0 here ?
36         if (inset == 0)
37                 return;
38
39         inset_ = inset;
40         readonly = lv_->buffer()->isReadonly();
41         ih_ = inset_->hide.connect(slot(this,&FormUrl::hide));
42         params = inset->params();
43         
44         show();
45 }
46
47  
48 void FormUrl::createUrl(string const & arg)
49 {
50         // we could already be showing a URL, clear it out
51         if (inset_)
52                 close();
53  
54         readonly = lv_->buffer()->isReadonly();
55         params.setFromString(arg);
56         show();
57 }
58
59  
60 void FormUrl::update(bool switched)
61 {
62         if (switched) {
63                 hide();
64                 return;
65         }
66
67         dialog_->url->setText(params.getContents().c_str());
68         dialog_->urlname->setText(params.getOptions().c_str());
69
70         if (params.getCmdName() == "url") 
71                 dialog_->htmlurl->setChecked(0);
72         else
73                 dialog_->htmlurl->setChecked(1);
74
75         if (readonly) {
76                 dialog_->urlname->setFocusPolicy(QWidget::NoFocus);
77                 dialog_->url->setFocusPolicy(QWidget::NoFocus);
78                 dialog_->buttonOk->setEnabled(false);
79                 dialog_->buttonCancel->setText(_("&Close"));
80                 dialog_->htmlurl->setEnabled(false);
81         } else {
82                 dialog_->urlname->setFocusPolicy(QWidget::StrongFocus);
83                 dialog_->url->setFocusPolicy(QWidget::StrongFocus);
84                 dialog_->url->setFocus();
85                 dialog_->buttonOk->setEnabled(true);
86                 dialog_->buttonCancel->setText(_("&Cancel"));
87                 dialog_->htmlurl->setEnabled(true);
88         }
89 }
90
91  
92 void FormUrl::apply()
93 {
94         if (readonly)
95                 return;
96
97         params.setContents(dialog_->url->text());
98         params.setOptions(dialog_->urlname->text());
99
100         if (dialog_->htmlurl->isChecked())
101                 params.setCmdName("htmlurl");
102         else
103                 params.setCmdName("url");
104
105         if (inset_ != 0) {
106                 if (params != inset_->params()) {
107                         inset_->setParams(params);
108                         lv_->view()->updateInset(inset_, true);
109                 }
110         } else
111                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
112 }
113
114  
115 void FormUrl::show()
116 {
117         if (!dialog_)
118                 dialog_ = new UrlDialog(this, 0, _("LyX: Url"), false);
119  
120         if (!dialog_->isVisible()) {
121                 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
122                 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
123         }
124
125         dialog_->raise();
126         dialog_->setActiveWindow();
127  
128         update();
129         dialog_->show();
130 }
131
132
133 void FormUrl::close()
134 {
135         h_.disconnect();
136         u_.disconnect();
137         ih_.disconnect();
138         inset_ = 0;
139 }
140
141  
142 void FormUrl::hide()
143 {
144         dialog_->hide();
145         close();
146 }