]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GInclude.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / gtk / GInclude.C
1 /**
2  * \file GInclude.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GInclude.h"
22 #include "ControlInclude.h"
23 #include "ghelpers.h"
24
25 #include <libglademm.h>
26
27 using std::string;
28 using std::vector;
29
30 namespace lyx {
31 namespace frontend {
32
33 GInclude::GInclude(Dialog & parent)
34         : GViewCB<ControlInclude, GViewGladeB>(parent, lyx::to_utf8(_("Child Document")), false)
35 {}
36
37
38 void GInclude::doBuild()
39 {
40         string const gladeName = findGladeFile("include");
41         xml_ = Gnome::Glade::Xml::create(gladeName);
42
43         Gtk::Button * button;
44         xml_->get_widget("Cancel", button);
45         setCancel(button);
46         xml_->get_widget("Ok", button);
47         setOK(button);
48
49         xml_->get_widget("Browse", button);
50         button->signal_clicked().connect(
51                 sigc::mem_fun(*this, &GInclude::onBrowseClicked));
52
53         xml_->get_widget("Open", openbutton_);
54         openbutton_->signal_clicked().connect(
55                 sigc::mem_fun(*this, &GInclude::onOpenClicked));
56
57         xml_->get_widget("Include", includeradio_);
58         xml_->get_widget("Input", inputradio_);
59         xml_->get_widget("Verbatim", verbatimradio_);
60         xml_->get_widget("File", fileentry_);
61         xml_->get_widget("MarkSpaces", markspacescheck_);
62         xml_->get_widget("Preview", previewcheck_);
63
64         inputradio_->signal_toggled().connect(
65                 sigc::mem_fun(*this, &GInclude::onTypeToggled));
66         includeradio_->signal_toggled().connect(
67                 sigc::mem_fun(*this, &GInclude::onTypeToggled));
68         verbatimradio_->signal_toggled().connect(
69                 sigc::mem_fun(*this, &GInclude::onTypeToggled));
70 }
71
72
73 void GInclude::update()
74 {
75         string const filename = controller().params().getContents();
76         fileentry_->set_text(filename);
77
78         string const cmdname = controller().params().getCmdName();
79
80         bool const inputCommand = (cmdname == "input" || cmdname.empty());
81         bool const includeCommand = cmdname == "include";
82         bool const verbatimStarCommand = cmdname == "verbatiminput*";
83         bool const verbatimCommand = cmdname == "verbatiminput";
84
85         bool const preview = static_cast<bool>((controller().params().preview()));
86
87         previewcheck_->set_sensitive(inputCommand);
88         previewcheck_->set_active(inputCommand ? preview : false);
89
90         if (inputCommand)
91                 inputradio_->set_active(true);
92
93         if (includeCommand)
94                 includeradio_->set_active(true);
95
96         if (verbatimCommand || verbatimStarCommand) {
97                 verbatimradio_->set_active(true);
98                 markspacescheck_->set_active(verbatimStarCommand);
99                 markspacescheck_->set_sensitive(true);
100                 openbutton_->set_sensitive(false);
101         } else {
102                 markspacescheck_->set_active(false);
103                 markspacescheck_->set_sensitive(false);
104                 openbutton_->set_sensitive(true);
105         }
106
107         bc().valid();
108 }
109
110
111 void GInclude::apply()
112 {
113         InsetCommandParams params = controller().params();
114
115         params.preview(previewcheck_->get_active());
116         params.setContents(fileentry_->get_text());
117
118         if (includeradio_->get_active())
119                 params.setCmdName("include");
120         else if (inputradio_->get_active())
121                 params.setCmdName("input");
122         else
123                 if (markspacescheck_->get_active())
124                         params.setCmdName("verbatiminput*");
125                 else
126                         params.setCmdName("verbatiminput");
127
128         controller().setParams(params);
129 }
130
131
132 void GInclude::onTypeToggled()
133 {
134         previewcheck_->set_sensitive(inputradio_->get_active());
135         markspacescheck_->set_sensitive(verbatimradio_->get_active());
136         openbutton_->set_sensitive(!verbatimradio_->get_active());
137 }
138
139
140 void GInclude::onBrowseClicked()
141 {
142         ControlInclude::Type type;
143         if (includeradio_->get_active())
144                 type = ControlInclude::INCLUDE;
145         else if (inputradio_->get_active())
146                 type = ControlInclude::INPUT;
147         else
148                 type = ControlInclude::VERBATIM;
149
150         fileentry_->set_text(controller().browse(fileentry_->get_text(), type));
151 }
152
153
154 void GInclude::onOpenClicked()
155 {
156         string const in_name = fileentry_->get_text();
157         if (!in_name.empty() && controller().fileExists(in_name)) {
158                 dialog().OKButton();
159                 controller().load(in_name);
160         }
161 }
162
163
164 } // namespace frontend
165 } // namespace lyx