Code

noop: rename a local var
[inkscape.git] / src / ui / dialog / extension-editor.cpp
index fb8284e630d665d2048f4322699dfd2b42829818..c2f3426fd26bef2a6df9220d9d99704cba13e88d 100644 (file)
@@ -1,7 +1,7 @@
-/**
- * \brief Extension editor dialog
- *
- * Authors:
+/** @file
+ * @brief Extension editor dialog
+ */
+/* Authors:
  *   Bryce W. Harrington <bryce@bryceharrington.org>
  *   Ted Gould <ted@gould.cx>
  *
 # 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 "preferences.h"
+#include "interface.h"
 
 #include "extension/extension.h"
 #include "extension/db.h"
@@ -39,14 +43,17 @@ namespace Dialog {
     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
@@ -68,15 +75,19 @@ ExtensionEditor::ExtensionEditor()
 
     //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);
+    
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    Glib::ustring defaultext = prefs->getString("/dialogs/extensioneditor/selected-extension");
+    if (defaultext.empty()) defaultext = "org.inkscape.input.svg";
+    this->setExtension(defaultext);
 
     show_all_children();
 }
@@ -88,6 +99,24 @@ 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
 
@@ -101,13 +130,50 @@ ExtensionEditor::on_pagelist_selection_changed (void)
     Glib::RefPtr<Gtk::TreeSelection> selection = _page_list.get_selection();
     Gtk::TreeModel::iterator iter = selection->get_selected();
     if (iter) {
-        _page_frame.remove();
+        /* Get the row info */
         Gtk::TreeModel::Row row = *iter;
-        // _current_page = row[_page_list_columns._col_page];
-        // prefs_set_string_attribute("dialogs.extensioneditor", "selected", row[_page_list_columns._col_id].c_str());
-        _page_title.set_markup("<span size='large'><b>" + row[_page_list_columns._col_name] + "</b></span>");
-        // _page_frame.add(*_current_page);
-        // _current_page->show();
+        Glib::ustring id = row[_page_list_columns._col_id];
+        Glib::ustring name = row[_page_list_columns._col_name];
+
+        /* Set the selection in the preferences */
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        prefs->setString("/dialogs/extensioneditor/selected-extension", id);
+
+        /* 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;
@@ -127,7 +193,7 @@ ExtensionEditor::on_pagelist_selection_changed (void)
 void
 ExtensionEditor::dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data)
 {
-    ExtensionEditor * ee = reinterpret_cast<ExtensionEditor *>(in_data);
+    ExtensionEditor * ee = static_cast<ExtensionEditor *>(in_data);
     ee->add_extension(in_plug);
     return;
 }
@@ -149,7 +215,6 @@ ExtensionEditor::add_extension (Inkscape::Extension::Extension * ext)
     Gtk::TreeModel::Row row = *iter;
     row[_page_list_columns._col_name] = ext->get_name();
     row[_page_list_columns._col_id] =   ext->get_id();
-    row[_page_list_columns._col_page] = NULL;
 
     return iter;
 }