]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormUrl.C
Changed so one can specify a images without extension and so use pdflatex AND
[lyx.git] / src / frontends / kde / FormUrl.C
1 # /*
2  * FormUrl.C
3  * (C) 2000 John Levon
4  * 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()
67 {
68         dialog_->url->setText(params.getContents().c_str());
69         dialog_->urlname->setText(params.getOptions().c_str());
70
71         if (params.getCmdName()=="url") 
72                 dialog_->htmlurl->setChecked(0);
73         else
74                 dialog_->htmlurl->setChecked(1);
75
76         if (readonly) {
77                 dialog_->urlname->setFocusPolicy(QWidget::NoFocus);
78                 dialog_->url->setFocusPolicy(QWidget::NoFocus);
79                 dialog_->buttonOk->hide();
80                 dialog_->buttonCancel->setText(_("Close"));
81                 dialog_->htmlurl->setEnabled(false);
82         } else {
83                 dialog_->urlname->setFocusPolicy(QWidget::StrongFocus);
84                 dialog_->url->setFocusPolicy(QWidget::StrongFocus);
85                 dialog_->url->setFocus();
86                 dialog_->buttonOk->show();
87                 dialog_->buttonCancel->setText(_("Cancel"));
88                 dialog_->htmlurl->setEnabled(true);
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 void FormUrl::show()
115 {
116         if (!dialog_)
117                 dialog_ = new FormUrlDialog(this, 0, _("LyX: Url"), false);
118  
119         if (!dialog_->isVisible()) {
120                 h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide));
121                 u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::update));
122         }
123
124         dialog_->raise();
125         dialog_->setActiveWindow();
126  
127         update();
128         dialog_->show();
129 }
130
131 void FormUrl::close()
132 {
133         h_.disconnect();
134         u_.disconnect();
135         ih_.disconnect();
136         inset_ = 0;
137 }
138  
139 void FormUrl::hide()
140 {
141         dialog_->hide();
142         close();
143 }