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 : UI::Widget::Panel ("", "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 _getContents()->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 = NULL;
155 Gtk::Widget * help = NULL;
156 Gtk::Widget * params = NULL;
158 if (ext != NULL) {
159 info = ext->get_info_widget();
160 help = ext->get_help_widget();
161 params = ext->get_params_widget();
162 }
164 /* Place them in the pages */
165 if (info != NULL) {
166 _notebook_info.add(*info);
167 }
168 if (help != NULL) {
169 _notebook_help.add(*help);
170 }
171 if (params != NULL) {
172 _notebook_params.add(*params);
173 }
175 }
177 return;
178 }
180 /** \brief A function to pass to the iterator in the Extensions Database
181 \param in_plug The extension to evaluate
182 \param in_data A pointer to the Extension Editor class
183 \return None
185 This function is a static function with the prototype required for
186 the Extension Database's foreach function. It will get called for
187 every extension in the database, and will then turn around and
188 call the more object oriented function \c add_extension in the
189 ExtensionEditor.
190 */
191 void
192 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
193 {
194 ExtensionEditor * ee = static_cast<ExtensionEditor *>(in_data);
195 ee->add_extension(in_plug);
196 return;
197 }
199 /** \brief Adds an extension into the tree model
200 \param ext The extension to add
201 \return The iterator representing the location in the tree model
203 This function takes the data out of the extension and puts it
204 into the tree model for the dialog.
205 */
206 Gtk::TreeModel::iterator
207 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
208 {
209 Gtk::TreeModel::iterator iter;
211 iter = _page_list_model->append();
213 Gtk::TreeModel::Row row = *iter;
214 row[_page_list_columns._col_name] = ext->get_name();
215 row[_page_list_columns._col_id] = ext->get_id();
217 return iter;
218 }
220 } // namespace Dialog
221 } // namespace UI
222 } // namespace Inkscape
224 /*
225 Local Variables:
226 mode:c++
227 c-file-style:"stroustrup"
228 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
229 indent-tabs-mode:nil
230 fill-column:99
231 End:
232 */
233 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :