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 <gtkmm/frame.h>
18 #include <gtkmm/scrolledwindow.h>
19 #include <gtkmm/alignment.h>
21 #include "extension-editor.h"
22 #include "verbs.h"
23 #include "prefs-utils.h"
25 #include "extension/extension.h"
26 #include "extension/db.h"
28 namespace Inkscape {
29 namespace UI {
30 namespace Dialog {
32 /** \brief Create a new ExtensionEditor dialog
33 \return None
35 This function creates a new extension editor dialog. The dialog
36 consists of two basic areas. The left side is a tree widget, which
37 is only used as a list. And the right side is a notebook of information
38 about the selected extension. A handler is set up so that when
39 a new extension is selected, the notebooks are changed appropriately.
40 */
41 ExtensionEditor::ExtensionEditor()
42 : Dialog ("dialogs.extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR)
43 {
45 //Main HBox
46 Gtk::HBox* hbox_list_page = Gtk::manage(new Gtk::HBox());
47 hbox_list_page->set_border_width(12);
48 hbox_list_page->set_spacing(12);
49 this->get_vbox()->add(*hbox_list_page);
52 //Pagelist
53 Gtk::Frame* list_frame = Gtk::manage(new Gtk::Frame());
54 Gtk::ScrolledWindow* scrolled_window = Gtk::manage(new Gtk::ScrolledWindow());
55 hbox_list_page->pack_start(*list_frame, false, true, 0);
56 _page_list.set_headers_visible(false);
57 scrolled_window->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
58 scrolled_window->add(_page_list);
59 list_frame->set_shadow_type(Gtk::SHADOW_IN);
60 list_frame->add(*scrolled_window);
61 _page_list_model = Gtk::TreeStore::create(_page_list_columns);
62 _page_list.set_model(_page_list_model);
63 _page_list.append_column("name",_page_list_columns._col_name);
64 Glib::RefPtr<Gtk::TreeSelection> page_list_selection = _page_list.get_selection();
65 page_list_selection->signal_changed().connect(sigc::mem_fun(*this, &ExtensionEditor::on_pagelist_selection_changed));
66 page_list_selection->set_mode(Gtk::SELECTION_BROWSE);
69 //Pages
70 Gtk::VBox* vbox_page = Gtk::manage(new Gtk::VBox());
71 Gtk::Frame* title_frame = Gtk::manage(new Gtk::Frame());
72 hbox_list_page->pack_start(*vbox_page, true, true, 0);
73 title_frame->add(_page_title);
74 vbox_page->pack_start(*title_frame, false, false, 0);
75 vbox_page->pack_start(_page_frame, true, true, 0);
76 _page_frame.set_shadow_type(Gtk::SHADOW_IN);
77 title_frame->set_shadow_type(Gtk::SHADOW_IN);
79 Inkscape::Extension::db.foreach(dbfunc, this);
81 _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::defaultExtension));
83 show_all_children();
84 }
86 /** \brief Destroys the extension editor dialog
87 \return None
88 */
89 ExtensionEditor::~ExtensionEditor()
90 {
91 }
93 bool
94 ExtensionEditor::defaultExtension(const Gtk::TreeModel::iterator &iter)
95 {
96 Glib::ustring desired = "org.inkscape.input.svg";
97 Gtk::TreeModel::Row row = *iter;
98 if (row[_page_list_columns._col_id] == desired) {
99 _page_list.get_selection()->select(iter);
100 return true;
101 }
102 return false;
103 }
105 /** \brief Called every time a new extention is selected
106 \return None
108 This function is set up to handle the signal for a changed extension
109 from the tree view in the left pane. It figure out which extension
110 is selected and updates the widgets to have data for that extension.
111 */
112 void
113 ExtensionEditor::on_pagelist_selection_changed (void)
114 {
115 Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
116 Gtk::TreeModel::iterator iter = selection->get_selected();
117 if (iter) {
118 _page_frame.remove();
119 Gtk::TreeModel::Row row = *iter;
120 // _current_page = row[_page_list_columns._col_page];
121 // prefs_set_string_attribute("dialogs.extensioneditor", "selected", row[_page_list_columns._col_id].c_str());
122 _page_title.set_markup("<span size='large'><b>" + row[_page_list_columns._col_name] + "</b></span>");
123 // _page_frame.add(*_current_page);
124 // _current_page->show();
125 }
127 return;
128 }
130 /** \brief A function to pass to the iterator in the Extensions Database
131 \param in_plug The extension to evaluate
132 \param in_data A pointer to the Extension Editor class
133 \return None
135 This function is a static function with the prototype required for
136 the Extension Database's foreach function. It will get called for
137 every extension in the database, and will then turn around and
138 call the more object oriented function \c add_extension in the
139 ExtensionEditor.
140 */
141 void
142 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
143 {
144 ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
145 ee->add_extension(in_plug);
146 return;
147 }
149 /** \brief Adds an extension into the tree model
150 \param ext The extension to add
151 \return The iterator representing the location in the tree model
153 This function takes the data out of the extension and puts it
154 into the tree model for the dialog.
155 */
156 Gtk::TreeModel::iterator
157 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
158 {
159 Gtk::TreeModel::iterator iter;
161 iter = _page_list_model->append();
163 Gtk::TreeModel::Row row = *iter;
164 row[_page_list_columns._col_name] = ext->get_name();
165 row[_page_list_columns._col_id] = ext->get_id();
166 row[_page_list_columns._col_page] = NULL;
168 return iter;
169 }
171 } // namespace Dialog
172 } // namespace UI
173 } // namespace Inkscape
175 /*
176 Local Variables:
177 mode:c++
178 c-file-style:"stroustrup"
179 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
180 indent-tabs-mode:nil
181 fill-column:99
182 End:
183 */
184 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :