a92087668916e16ff5bbb5c942cae455d7b4594e
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 "preferences.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 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
88 Glib::ustring defaultext = prefs->getString("dialogs.extensioneditor", "selected-extension");
89 if (defaultext.empty()) defaultext = "org.inkscape.input.svg";
90 this->setExtension(defaultext);
92 show_all_children();
93 }
95 /** \brief Destroys the extension editor dialog
96 \return None
97 */
98 ExtensionEditor::~ExtensionEditor()
99 {
100 }
102 void
103 ExtensionEditor::setExtension(Glib::ustring extension_id) {
104 _selection_search = extension_id;
105 _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::setExtensionIter));
106 return;
107 }
109 bool
110 ExtensionEditor::setExtensionIter(const Gtk::TreeModel::iterator &iter)
111 {
112 Gtk::TreeModel::Row row = *iter;
113 if (row[_page_list_columns._col_id] == _selection_search) {
114 _page_list.get_selection()->select(iter);
115 return true;
116 }
117 return false;
118 }
120 /** \brief Called every time a new extention is selected
121 \return None
123 This function is set up to handle the signal for a changed extension
124 from the tree view in the left pane. It figure out which extension
125 is selected and updates the widgets to have data for that extension.
126 */
127 void
128 ExtensionEditor::on_pagelist_selection_changed (void)
129 {
130 Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
131 Gtk::TreeModel::iterator iter = selection->get_selected();
132 if (iter) {
133 /* Get the row info */
134 Gtk::TreeModel::Row row = *iter;
135 Glib::ustring id = row[_page_list_columns._col_id];
136 Glib::ustring name = row[_page_list_columns._col_name];
138 /* Set the selection in the preferences */
139 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
140 prefs->setString("dialogs.extensioneditor", "selected-extension", id);
142 /* Adjust the dialog's title */
143 gchar title[500];
144 sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_EXTENSIONEDITOR), title);
145 Glib::ustring utitle(title);
146 // set_title(utitle + ": " + name);
148 /* Clear the notbook pages */
149 _notebook_info.remove();
150 _notebook_help.remove();
151 _notebook_params.remove();
153 Inkscape::Extension::Extension * ext = Inkscape::Extension::db.get(id.c_str());
155 /* Make sure we have all the widges */
156 Gtk::Widget * info = NULL;
157 Gtk::Widget * help = NULL;
158 Gtk::Widget * params = NULL;
160 if (ext != NULL) {
161 info = ext->get_info_widget();
162 help = ext->get_help_widget();
163 params = ext->get_params_widget();
164 }
166 /* Place them in the pages */
167 if (info != NULL) {
168 _notebook_info.add(*info);
169 }
170 if (help != NULL) {
171 _notebook_help.add(*help);
172 }
173 if (params != NULL) {
174 _notebook_params.add(*params);
175 }
177 }
179 return;
180 }
182 /** \brief A function to pass to the iterator in the Extensions Database
183 \param in_plug The extension to evaluate
184 \param in_data A pointer to the Extension Editor class
185 \return None
187 This function is a static function with the prototype required for
188 the Extension Database's foreach function. It will get called for
189 every extension in the database, and will then turn around and
190 call the more object oriented function \c add_extension in the
191 ExtensionEditor.
192 */
193 void
194 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
195 {
196 ExtensionEditor * ee = static_cast<ExtensionEditor *>(in_data);
197 ee->add_extension(in_plug);
198 return;
199 }
201 /** \brief Adds an extension into the tree model
202 \param ext The extension to add
203 \return The iterator representing the location in the tree model
205 This function takes the data out of the extension and puts it
206 into the tree model for the dialog.
207 */
208 Gtk::TreeModel::iterator
209 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
210 {
211 Gtk::TreeModel::iterator iter;
213 iter = _page_list_model->append();
215 Gtk::TreeModel::Row row = *iter;
216 row[_page_list_columns._col_name] = ext->get_name();
217 row[_page_list_columns._col_id] = ext->get_id();
219 return iter;
220 }
222 } // namespace Dialog
223 } // namespace UI
224 } // namespace Inkscape
226 /*
227 Local Variables:
228 mode:c++
229 c-file-style:"stroustrup"
230 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
231 indent-tabs-mode:nil
232 fill-column:99
233 End:
234 */
235 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :