ed9d020c7b6ed0270a4e9b6763b37259d5a4a917
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 /* Make sure we have all the widges */
152 Gtk::Widget * info;
153 info = row[_page_list_columns._col_info];
154 if (info == NULL) {
155 info = Inkscape::Extension::db.get(id.c_str())->get_info_widget();
156 row[_page_list_columns._col_info] = info;
157 //info->ref();
158 }
160 Gtk::Widget * help;
161 help = row[_page_list_columns._col_help];
162 if (help == NULL) {
163 help = Inkscape::Extension::db.get(id.c_str())->get_help_widget();
164 row[_page_list_columns._col_help] = help;
165 //help->ref();
166 }
168 Gtk::Widget * params;
169 params = row[_page_list_columns._col_params];
170 if (params == NULL) {
171 params = Inkscape::Extension::db.get(id.c_str())->get_params_widget();
172 row[_page_list_columns._col_params] = params;
173 //params->ref();
174 }
176 /* Place them in the pages */
177 if (info != NULL) {
178 _notebook_info.add(*info);
179 }
180 if (help != NULL) {
181 _notebook_help.add(*help);
182 }
183 if (params != NULL) {
184 _notebook_params.add(*params);
185 }
187 }
189 return;
190 }
192 /** \brief A function to pass to the iterator in the Extensions Database
193 \param in_plug The extension to evaluate
194 \param in_data A pointer to the Extension Editor class
195 \return None
197 This function is a static function with the prototype required for
198 the Extension Database's foreach function. It will get called for
199 every extension in the database, and will then turn around and
200 call the more object oriented function \c add_extension in the
201 ExtensionEditor.
202 */
203 void
204 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
205 {
206 ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
207 ee->add_extension(in_plug);
208 return;
209 }
211 /** \brief Adds an extension into the tree model
212 \param ext The extension to add
213 \return The iterator representing the location in the tree model
215 This function takes the data out of the extension and puts it
216 into the tree model for the dialog.
217 */
218 Gtk::TreeModel::iterator
219 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
220 {
221 Gtk::TreeModel::iterator iter;
223 iter = _page_list_model->append();
225 Gtk::TreeModel::Row row = *iter;
226 row[_page_list_columns._col_name] = ext->get_name();
227 row[_page_list_columns._col_id] = ext->get_id();
228 row[_page_list_columns._col_info] = NULL;
229 row[_page_list_columns._col_help] = NULL;
230 row[_page_list_columns._col_params] = NULL;
232 return iter;
233 }
235 } // namespace Dialog
236 } // namespace UI
237 } // namespace Inkscape
239 /*
240 Local Variables:
241 mode:c++
242 c-file-style:"stroustrup"
243 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
244 indent-tabs-mode:nil
245 fill-column:99
246 End:
247 */
248 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :