Code

7cbde9e1fd92a2b7f9aa2403c82c58102894ae43
[inkscape.git] / src / ui / dialog / extension-editor.cpp
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"
28 #include "extension/extension.h"
29 #include "extension/db.h"
31 namespace Inkscape {
32 namespace UI {
33 namespace Dialog {
35 /** \brief  Create a new ExtensionEditor dialog
36     \return None
38     This function creates a new extension editor dialog.  The dialog
39     consists of two basic areas.  The left side is a tree widget, which
40     is only used as a list.  And the right side is a notebook of information
41     about the selected extension.  A handler is set up so that when
42     a new extension is selected, the notebooks are changed appropriately.
43 */
44 ExtensionEditor::ExtensionEditor()
45     : Dialog ("dialogs.extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR)
46 {
47  
48     //Main HBox
49     Gtk::HBox* hbox_list_page = Gtk::manage(new Gtk::HBox());
50     hbox_list_page->set_border_width(12);
51     hbox_list_page->set_spacing(12);
52     this->get_vbox()->add(*hbox_list_page);
55     //Pagelist
56     Gtk::Frame* list_frame = Gtk::manage(new Gtk::Frame());
57     Gtk::ScrolledWindow* scrolled_window = Gtk::manage(new Gtk::ScrolledWindow());
58     hbox_list_page->pack_start(*list_frame, false, true, 0);
59     _page_list.set_headers_visible(false);
60     scrolled_window->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
61     scrolled_window->add(_page_list);
62     list_frame->set_shadow_type(Gtk::SHADOW_IN);
63     list_frame->add(*scrolled_window);
64     _page_list_model = Gtk::TreeStore::create(_page_list_columns);
65     _page_list.set_model(_page_list_model);
66     _page_list.append_column("name",_page_list_columns._col_name);
67     Glib::RefPtr<Gtk::TreeSelection> page_list_selection = _page_list.get_selection();
68     page_list_selection->signal_changed().connect(sigc::mem_fun(*this, &ExtensionEditor::on_pagelist_selection_changed));
69     page_list_selection->set_mode(Gtk::SELECTION_BROWSE);
72     //Pages
73     Gtk::VBox* vbox_page = Gtk::manage(new Gtk::VBox());
74     hbox_list_page->pack_start(*vbox_page, true, true, 0);
75     Gtk::Notebook * notebook = Gtk::manage(new Gtk::Notebook());
76     notebook->append_page(_notebook_info, *Gtk::manage(new Gtk::Label(_("Information"))));
77     notebook->append_page(_notebook_help, *Gtk::manage(new Gtk::Label(_("Help"))));
78     notebook->append_page(_notebook_params, *Gtk::manage(new Gtk::Label(_("Parameters"))));
79     vbox_page->pack_start(*notebook, true, true, 0);
81     Inkscape::Extension::db.foreach(dbfunc, this);
83     gchar const * defaultext = prefs_get_string_attribute("dialogs.extensioneditor", "selected-extension");
84     if (defaultext == NULL) defaultext = "org.inkscape.input.svg";
85     this->setExtension(defaultext);
87     show_all_children();
88 }
90 /** \brief  Destroys the extension editor dialog
91     \return None
92 */
93 ExtensionEditor::~ExtensionEditor()
94 {
95 }
97 void
98 ExtensionEditor::setExtension(Glib::ustring extension_id) {
99     _selection_search = extension_id;
100     _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::setExtensionIter));
101     return;
104 bool
105 ExtensionEditor::setExtensionIter(const Gtk::TreeModel::iterator &iter)
107     Gtk::TreeModel::Row row = *iter;
108     if (row[_page_list_columns._col_id] == _selection_search) {
109         _page_list.get_selection()->select(iter);
110         return true;
111     }
112     return false;
115 /** \brief  Called every time a new extention is selected
116     \return None
118     This function is set up to handle the signal for a changed extension
119     from the tree view in the left pane.  It figure out which extension
120     is selected and updates the widgets to have data for that extension.
121 */
122 void
123 ExtensionEditor::on_pagelist_selection_changed (void)
125     Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
126     Gtk::TreeModel::iterator iter = selection->get_selected();
127     if (iter) {
128         // _page_frame.remove();
129         Gtk::TreeModel::Row row = *iter;
130         // _current_page = row[_page_list_columns._col_page];
131         // _page_title.set_markup("<span size='large'><b>" + row[_page_list_columns._col_name] + "</b></span>");
132         // _page_frame.add(*_current_page);
133         // _current_page->show();
134         Glib::ustring id = row[_page_list_columns._col_id];
135         prefs_set_string_attribute("dialogs.extensioneditor", "selected-extension", id.c_str());
136     }
138     return;
141 /** \brief  A function to pass to the iterator in the Extensions Database
142     \param  in_plug  The extension to evaluate
143     \param  in_data  A pointer to the Extension Editor class
144     \return None
146     This function is a static function with the prototype required for
147     the Extension Database's foreach function.  It will get called for
148     every extension in the database, and will then turn around and
149     call the more object oriented function \c add_extension in the
150     ExtensionEditor.
151 */
152 void
153 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
155     ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
156     ee->add_extension(in_plug);
157     return;
160 /** \brief  Adds an extension into the tree model
161     \param  ext  The extension to add
162     \return The iterator representing the location in the tree model
164     This function takes the data out of the extension and puts it
165     into the tree model for the dialog.
166 */
167 Gtk::TreeModel::iterator
168 ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
170     Gtk::TreeModel::iterator iter;
172     iter = _page_list_model->append();
174     Gtk::TreeModel::Row row = *iter;
175     row[_page_list_columns._col_name] = ext->get_name();
176     row[_page_list_columns._col_id] =   ext->get_id();
177     row[_page_list_columns._col_page] = NULL;
179     return iter;
182 } // namespace Dialog
183 } // namespace UI
184 } // namespace Inkscape
186 /*
187   Local Variables:
188   mode:c++
189   c-file-style:"stroustrup"
190   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
191   indent-tabs-mode:nil
192   fill-column:99
193   End:
194 */
195 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :