index aca41f6f6717488338e7a5cc6a0a1dd0e4285909..d26e05f0795b00f1938c467250fc8bc84b9072b2 100644 (file)
/**
- * \brief Extension editor
+ * \brief Extension editor dialog
*
* Authors:
* Bryce W. Harrington <bryce@bryceharrington.org>
# include <config.h>
#endif
+#include <glibmm/i18n.h>
+
#include <gtkmm/frame.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/alignment.h>
+#include <gtkmm/notebook.h>
#include "extension-editor.h"
#include "verbs.h"
+#include "prefs-utils.h"
+#include "interface.h"
+
+#include "extension/extension.h"
+#include "extension/db.h"
namespace Inkscape {
namespace UI {
namespace Dialog {
+/** \brief Create a new ExtensionEditor dialog
+ \return None
+
+ This function creates a new extension editor dialog. The dialog
+ consists of two basic areas. The left side is a tree widget, which
+ is only used as a list. And the right side is a notebook of information
+ about the selected extension. A handler is set up so that when
+ a new extension is selected, the notebooks are changed appropriately.
+*/
ExtensionEditor::ExtensionEditor()
- : Dialog ("dialogs.extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR)
+ : UI::Widget::Panel ("", "dialogs.extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR)
{
+ _notebook_info.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ _notebook_help.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ _notebook_params.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
//Main HBox
Gtk::HBox* hbox_list_page = Gtk::manage(new Gtk::HBox());
hbox_list_page->set_border_width(12);
hbox_list_page->set_spacing(12);
- this->get_vbox()->add(*hbox_list_page);
+ _getContents()->add(*hbox_list_page);
//Pagelist
//Pages
Gtk::VBox* vbox_page = Gtk::manage(new Gtk::VBox());
- Gtk::Frame* title_frame = Gtk::manage(new Gtk::Frame());
hbox_list_page->pack_start(*vbox_page, true, true, 0);
- title_frame->add(_page_title);
- vbox_page->pack_start(*title_frame, false, false, 0);
- vbox_page->pack_start(_page_frame, true, true, 0);
- _page_frame.set_shadow_type(Gtk::SHADOW_IN);
- title_frame->set_shadow_type(Gtk::SHADOW_IN);
+ Gtk::Notebook * notebook = Gtk::manage(new Gtk::Notebook());
+ notebook->append_page(_notebook_info, *Gtk::manage(new Gtk::Label(_("Information"))));
+ notebook->append_page(_notebook_help, *Gtk::manage(new Gtk::Label(_("Help"))));
+ notebook->append_page(_notebook_params, *Gtk::manage(new Gtk::Label(_("Parameters"))));
+ vbox_page->pack_start(*notebook, true, true, 0);
+
+ Inkscape::Extension::db.foreach(dbfunc, this);
+ gchar const * defaultext = prefs_get_string_attribute("dialogs.extensioneditor", "selected-extension");
+ if (defaultext == NULL) defaultext = "org.inkscape.input.svg";
+ this->setExtension(defaultext);
show_all_children();
}
+/** \brief Destroys the extension editor dialog
+ \return None
+*/
ExtensionEditor::~ExtensionEditor()
{
}
+void
+ExtensionEditor::setExtension(Glib::ustring extension_id) {
+ _selection_search = extension_id;
+ _page_list_model->foreach_iter(sigc::mem_fun(*this, &ExtensionEditor::setExtensionIter));
+ return;
+}
+
+bool
+ExtensionEditor::setExtensionIter(const Gtk::TreeModel::iterator &iter)
+{
+ Gtk::TreeModel::Row row = *iter;
+ if (row[_page_list_columns._col_id] == _selection_search) {
+ _page_list.get_selection()->select(iter);
+ return true;
+ }
+ return false;
+}
+
+/** \brief Called every time a new extention is selected
+ \return None
+
+ This function is set up to handle the signal for a changed extension
+ from the tree view in the left pane. It figure out which extension
+ is selected and updates the widgets to have data for that extension.
+*/
+void
+ExtensionEditor::on_pagelist_selection_changed (void)
+{
+ Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
+ Gtk::TreeModel::iterator iter = selection->get_selected();
+ if (iter) {
+ /* Get the row info */
+ Gtk::TreeModel::Row row = *iter;
+ Glib::ustring id = row[_page_list_columns._col_id];
+ Glib::ustring name = row[_page_list_columns._col_name];
+
+ /* Set the selection in the preferences */
+ prefs_set_string_attribute("dialogs.extensioneditor", "selected-extension", id.c_str());
+
+ /* Adjust the dialog's title */
+ gchar title[500];
+ sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_EXTENSIONEDITOR), title);
+ Glib::ustring utitle(title);
+ // set_title(utitle + ": " + name);
+
+ /* Clear the notbook pages */
+ _notebook_info.remove();
+ _notebook_help.remove();
+ _notebook_params.remove();
+
+ Inkscape::Extension::Extension * ext = Inkscape::Extension::db.get(id.c_str());
+
+ /* Make sure we have all the widges */
+ Gtk::Widget * info = NULL;
+ Gtk::Widget * help = NULL;
+ Gtk::Widget * params = NULL;
+
+ if (ext != NULL) {
+ info = ext->get_info_widget();
+ help = ext->get_help_widget();
+ params = ext->get_params_widget();
+ }
+
+ /* Place them in the pages */
+ if (info != NULL) {
+ _notebook_info.add(*info);
+ }
+ if (help != NULL) {
+ _notebook_help.add(*help);
+ }
+ if (params != NULL) {
+ _notebook_params.add(*params);
+ }
+
+ }
+
+ return;
+}
+
+/** \brief A function to pass to the iterator in the Extensions Database
+ \param in_plug The extension to evaluate
+ \param in_data A pointer to the Extension Editor class
+ \return None
+
+ This function is a static function with the prototype required for
+ the Extension Database's foreach function. It will get called for
+ every extension in the database, and will then turn around and
+ call the more object oriented function \c add_extension in the
+ ExtensionEditor.
+*/
+void
+ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
+{
+ ExtensionEditor * ee = static_cast<ExtensionEditor *>(in_data);
+ ee->add_extension(in_plug);
+ return;
+}
+
+/** \brief Adds an extension into the tree model
+ \param ext The extension to add
+ \return The iterator representing the location in the tree model
+
+ This function takes the data out of the extension and puts it
+ into the tree model for the dialog.
+*/
+Gtk::TreeModel::iterator
+ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
+{
+ Gtk::TreeModel::iterator iter;
+
+ iter = _page_list_model->append();
+
+ Gtk::TreeModel::Row row = *iter;
+ row[_page_list_columns._col_name] = ext->get_name();
+ row[_page_list_columns._col_id] = ext->get_id();
+
+ return iter;
+}
+
} // namespace Dialog
} // namespace UI
} // namespace Inkscape