49f8c92dcbc401f4fde2cab449fedac1ddc76126
1 /**
2 * \brief Extension editor dialog
3 *
4 * Authors:
5 * Bryce W. Harrington <bryce@bryceharrington.org>
6 * Ted Gould <ted@gould.cx>
7 *
8 * Copyright (C) 2004-2006 Authors
9 *
10 * Released under GNU GPL. Read the file 'COPYING' for more information.
11 */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
17 #include <glibmm/i18n.h>
19 #include <gtkmm/frame.h>
20 #include <gtkmm/scrolledwindow.h>
21 #include <gtkmm/alignment.h>
22 #include <gtkmm/notebook.h>
24 #include "extension-editor.h"
25 #include "verbs.h"
26 #include "prefs-utils.h"
27 #include "interface.h"
29 #include "extension/extension.h"
30 #include "extension/db.h"
32 namespace Inkscape {
33 namespace UI {
34 namespace Dialog {
36 /** \brief Create a new ExtensionEditor dialog
37 \return None
39 This function creates a new extension editor dialog. The dialog
40 consists of two basic areas. The left side is a tree widget, which
41 is only used as a list. And the right side is a notebook of information
42 about the selected extension. A handler is set up so that when
43 a new extension is selected, the notebooks are changed appropriately.
44 */
45 ExtensionEditor::ExtensionEditor()
46 : Dialog ("dialogs.extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR)
47 {
48 _notebook_info.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
49 _notebook_help.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
50 _notebook_params.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
52 //Main HBox
53 Gtk::HBox* hbox_list_page = Gtk::manage(new Gtk::HBox());
54 hbox_list_page->set_border_width(12);
55 hbox_list_page->set_spacing(12);
56 this->get_vbox()->add(*hbox_list_page);
59 //Pagelist
60 Gtk::Frame* list_frame = Gtk::manage(new Gtk::Frame());
61 Gtk::ScrolledWindow* scrolled_window = Gtk::manage(new Gtk::ScrolledWindow());
62 hbox_list_page->pack_start(*list_frame, false, true, 0);
63 _page_list.set_headers_visible(false);
64 scrolled_window->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
65 scrolled_window->add(_page_list);
66 list_frame->set_shadow_type(Gtk::SHADOW_IN);
67 list_frame->add(*scrolled_window);
68 _page_list_model = Gtk::TreeStore::create(_page_list_columns);
69 _page_list.set_model(_page_list_model);
70 _page_list.append_column("name",_page_list_columns._col_name);
71 Glib::RefPtr<Gtk::TreeSelection> page_list_selection = _page_list.get_selection();
72 page_list_selection->signal_changed().connect(sigc::mem_fun(*this, &ExtensionEditor::on_pagelist_selection_changed));
73 page_list_selection->set_mode(Gtk::SELECTION_BROWSE);
76 //Pages
77 Gtk::VBox* vbox_page = Gtk::manage(new Gtk::VBox());
78 hbox_list_page->pack_start(*vbox_page, true, true, 0);
79 Gtk::Notebook * notebook = Gtk::manage(new Gtk::Notebook());
80 notebook->append_page(_notebook_info, *Gtk::manage(new Gtk::Label(_("Information"))));
81 notebook->append_page(_notebook_help, *Gtk::manage(new Gtk::Label(_("Help"))));
82 notebook->append_page(_notebook_params, *Gtk::manage(new Gtk::Label(_("Parameters"))));
83 vbox_page->pack_start(*notebook, true, true, 0);
85 Inkscape::Extension::db.foreach(dbfunc, this);
87 gchar const * defaultext = prefs_get_string_attribute("dialogs.extensioneditor", "selected-extension");
88 if (defaultext == NULL) defaultext = "org.inkscape.input.svg";
89 this->setExtension(defaultext);
91 show_all_children();
92 }
94 /** \brief Destroys the extension editor dialog
95 \return None
96 */
97 ExtensionEditor::~ExtensionEditor()
98 {
99 }
101 void
102 ExtensionEditor::setExtension(Glib::ustring extension_id) {
103 _selection_search = extension_id;
104 _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::setExtensionIter));
105 return;
106 }
108 bool
109 ExtensionEditor::setExtensionIter(const Gtk::TreeModel::iterator &iter)
110 {
111 Gtk::TreeModel::Row row = *iter;
112 if (row[_page_list_columns._col_id] == _selection_search) {
113 _page_list.get_selection()->select(iter);
114 return true;
115 }
116 return false;
117 }
119 /** \brief Called every time a new extention is selected
120 \return None
122 This function is set up to handle the signal for a changed extension
123 from the tree view in the left pane. It figure out which extension
124 is selected and updates the widgets to have data for that extension.
125 */
126 void
127 ExtensionEditor::on_pagelist_selection_changed (void)
128 {
129 Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
130 Gtk::TreeModel::iterator iter = selection->get_selected();
131 if (iter) {
132 /* Get the row info */
133 Gtk::TreeModel::Row row = *iter;
134 Glib::ustring id = row[_page_list_columns._col_id];
135 Glib::ustring name = row[_page_list_columns._col_name];
137 /* Set the selection in the preferences */
138 prefs_set_string_attribute("dialogs.extensioneditor", "selected-extension", id.c_str());
140 /* Adjust the dialog's title */
141 gchar title[500];
142 sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_EXTENSIONEDITOR), title);
143 Glib::ustring utitle(title);
144 set_title(utitle + ": " + name);
146 /* Clear the notbook pages */
147 _notebook_info.remove();
148 _notebook_help.remove();
149 _notebook_params.remove();
151 Inkscape::Extension::Extension * ext = Inkscape::Extension::db.get(id.c_str());
153 /* Make sure we have all the widges */
154 Gtk::Widget * info;
155 info = row[_page_list_columns._col_info];
156 if (info == NULL) {
157 if (ext != NULL) {
158 info = ext->get_info_widget();
159 row[_page_list_columns._col_info] = info;
160 info->reference();
161 }
162 } else {
163 info->unparent();
164 }
166 Gtk::Widget * help;
167 help = row[_page_list_columns._col_help];
168 if (help == NULL) {
169 if (ext != NULL) {
170 help = ext->get_help_widget();
171 row[_page_list_columns._col_help] = help;
172 help->reference();
173 }
174 } else {
175 help->unparent();
176 }
178 Gtk::Widget * params;
179 params = row[_page_list_columns._col_params];
180 if (params == NULL) {
181 if (ext != NULL) {
182 params = ext->get_params_widget();
183 row[_page_list_columns._col_params] = params;
184 params->reference();
185 }
186 } else {
187 params->unparent();
188 }
190 /* Place them in the pages */
191 if (info != NULL) {
192 _notebook_info.add(*info);
193 }
194 if (help != NULL) {
195 _notebook_help.add(*help);
196 }
197 if (params != NULL) {
198 _notebook_params.add(*params);
199 }
201 }
203 return;
204 }
206 /** \brief A function to pass to the iterator in the Extensions Database
207 \param in_plug The extension to evaluate
208 \param in_data A pointer to the Extension Editor class
209 \return None
211 This function is a static function with the prototype required for
212 the Extension Database's foreach function. It will get called for
213 every extension in the database, and will then turn around and
214 call the more object oriented function \c add_extension in the
215 ExtensionEditor.
216 */
217 void
218 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
219 {
220 ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
221 ee->add_extension(in_plug);
222 return;
223 }
225 /** \brief Adds an extension into the tree model
226 \param ext The extension to add
227 \return The iterator representing the location in the tree model
229 This function takes the data out of the extension and puts it
230 into the tree model for the dialog.
231 */
232 Gtk::TreeModel::iterator
233 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
234 {
235 Gtk::TreeModel::iterator iter;
237 iter = _page_list_model->append();
239 Gtk::TreeModel::Row row = *iter;
240 row[_page_list_columns._col_name] = ext->get_name();
241 row[_page_list_columns._col_id] = ext->get_id();
242 row[_page_list_columns._col_info] = NULL;
243 row[_page_list_columns._col_help] = NULL;
244 row[_page_list_columns._col_params] = NULL;
246 return iter;
247 }
249 } // namespace Dialog
250 } // namespace UI
251 } // namespace Inkscape
253 /*
254 Local Variables:
255 mode:c++
256 c-file-style:"stroustrup"
257 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
258 indent-tabs-mode:nil
259 fill-column:99
260 End:
261 */
262 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :