e20ac4592f496416bfff8c4c228e90c5f094abea
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 gchar const * defaultext = prefs_get_string_attribute("dialogs.extensioneditor", "selected-extension");
82 if (defaultext == NULL) defaultext = "org.inkscape.input.svg";
83 this->setExtension(defaultext);
85 show_all_children();
86 }
88 /** \brief Destroys the extension editor dialog
89 \return None
90 */
91 ExtensionEditor::~ExtensionEditor()
92 {
93 }
95 void
96 ExtensionEditor::setExtension(Glib::ustring extension_id) {
97 _selection_search = extension_id;
98 _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::setExtensionIter));
99 return;
100 }
102 bool
103 ExtensionEditor::setExtensionIter(const Gtk::TreeModel::iterator &iter)
104 {
105 Gtk::TreeModel::Row row = *iter;
106 if (row[_page_list_columns._col_id] == _selection_search) {
107 _page_list.get_selection()->select(iter);
108 return true;
109 }
110 return false;
111 }
113 /** \brief Called every time a new extention is selected
114 \return None
116 This function is set up to handle the signal for a changed extension
117 from the tree view in the left pane. It figure out which extension
118 is selected and updates the widgets to have data for that extension.
119 */
120 void
121 ExtensionEditor::on_pagelist_selection_changed (void)
122 {
123 Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
124 Gtk::TreeModel::iterator iter = selection->get_selected();
125 if (iter) {
126 _page_frame.remove();
127 Gtk::TreeModel::Row row = *iter;
128 // _current_page = row[_page_list_columns._col_page];
129 _page_title.set_markup("<span size='large'><b>" + row[_page_list_columns._col_name] + "</b></span>");
130 // _page_frame.add(*_current_page);
131 // _current_page->show();
132 Glib::ustring id = row[_page_list_columns._col_id];
133 prefs_set_string_attribute("dialogs.extensioneditor", "selected-extension", id.c_str());
134 }
136 return;
137 }
139 /** \brief A function to pass to the iterator in the Extensions Database
140 \param in_plug The extension to evaluate
141 \param in_data A pointer to the Extension Editor class
142 \return None
144 This function is a static function with the prototype required for
145 the Extension Database's foreach function. It will get called for
146 every extension in the database, and will then turn around and
147 call the more object oriented function \c add_extension in the
148 ExtensionEditor.
149 */
150 void
151 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
152 {
153 ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
154 ee->add_extension(in_plug);
155 return;
156 }
158 /** \brief Adds an extension into the tree model
159 \param ext The extension to add
160 \return The iterator representing the location in the tree model
162 This function takes the data out of the extension and puts it
163 into the tree model for the dialog.
164 */
165 Gtk::TreeModel::iterator
166 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
167 {
168 Gtk::TreeModel::iterator iter;
170 iter = _page_list_model->append();
172 Gtk::TreeModel::Row row = *iter;
173 row[_page_list_columns._col_name] = ext->get_name();
174 row[_page_list_columns._col_id] = ext->get_id();
175 row[_page_list_columns._col_page] = NULL;
177 return iter;
178 }
180 } // namespace Dialog
181 } // namespace UI
182 } // namespace Inkscape
184 /*
185 Local Variables:
186 mode:c++
187 c-file-style:"stroustrup"
188 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
189 indent-tabs-mode:nil
190 fill-column:99
191 End:
192 */
193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :