summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-12 23:14:21 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-12 23:14:21 +0000
commit51c44884aca2d41b8b38df329835e2a3c2d4e0ef (patch)
tree3b7576e868b9edbabc1bc77d5e0320971ddad243 /src/ui
parentFinish fixing document unit change undo bug. (diff)
parentMerge in fix for critical blocker #166371 (diff)
downloadinkscape-51c44884aca2d41b8b38df329835e2a3c2d4e0ef.tar.gz
inkscape-51c44884aca2d41b8b38df329835e2a3c2d4e0ef.zip
Merge from trunk.
(bzr r12475.1.16)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt7
-rw-r--r--src/ui/clipboard.cpp37
-rw-r--r--src/ui/dialog/Makefile_insert6
-rw-r--r--src/ui/dialog/export.cpp2
-rw-r--r--src/ui/dialog/filter-effects-dialog.cpp3
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp8
-rw-r--r--src/ui/dialog/inkscape-preferences.h2
-rw-r--r--src/ui/dialog/layers.cpp3
-rw-r--r--src/ui/dialog/new-from-template.cpp59
-rw-r--r--src/ui/dialog/new-from-template.h39
-rw-r--r--src/ui/dialog/template-load-tab.cpp281
-rw-r--r--src/ui/dialog/template-load-tab.h102
-rw-r--r--src/ui/dialog/template-widget.cpp117
-rw-r--r--src/ui/dialog/template-widget.h48
14 files changed, 691 insertions, 23 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index b592d2527..c95dd35cc 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -54,6 +54,7 @@ set(ui_SRC
dialog/livepatheffect-editor.cpp
dialog/memory.cpp
dialog/messages.cpp
+ dialog/new-from-template.cpp
dialog/object-attributes.cpp
dialog/object-properties.cpp
dialog/ocaldialogs.cpp
@@ -65,6 +66,8 @@ set(ui_SRC
dialog/spellcheck.cpp
dialog/svg-fonts-dialog.cpp
dialog/swatches.cpp
+ dialog/template-load-tab.cpp
+ dialog/template-widget.cpp
dialog/text-edit.cpp
dialog/tile.cpp
dialog/tracedialog.cpp
@@ -166,16 +169,20 @@ set(ui_SRC
dialog/livepatheffect-editor.h
dialog/memory.h
dialog/messages.h
+ dialog/new-from-template.h
dialog/object-attributes.h
dialog/object-properties.h
dialog/ocaldialogs.h
dialog/panel-dialog.h
dialog/print-colors-preview-dialog.h
dialog/print.h
+
dialog/spellcheck.h
dialog/svg-fonts-dialog.h
dialog/swatches.h
dialog/symbols.h
+ dialog/template-load-tab.h
+ dialog/template-widget.h
dialog/text-edit.h
dialog/tile.h
dialog/tracedialog.h
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index 084b2ebd8..48d32d64b 100644
--- a/src/ui/clipboard.cpp
+++ b/src/ui/clipboard.cpp
@@ -94,12 +94,6 @@
#ifdef WIN32
#include <windows.h>
-// Clipboard Formats: http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx
-// On Windows, most graphical applications can handle CF_DIB/CF_BITMAP and/or CF_ENHMETAFILE
-// GTK automatically presents an "image/bmp" target as CF_DIB/CF_BITMAP
-// Presenting "image/x-emf" as CF_ENHMETAFILE must be done by Inkscape ?
-#define CLIPBOARD_WIN32_EMF_TARGET "CF_ENHMETAFILE"
-#define CLIPBOARD_WIN32_EMF_MIME "image/x-emf"
#endif
namespace Inkscape {
@@ -179,13 +173,18 @@ ClipboardManagerImpl::ClipboardManagerImpl()
_text_style(NULL),
_clipboard( Gtk::Clipboard::get() )
{
+ // Clipboard Formats: http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx
+ // On Windows, most graphical applications can handle CF_DIB/CF_BITMAP and/or CF_ENHMETAFILE
+ // GTK automatically presents an "image/bmp" target as CF_DIB/CF_BITMAP
+ // Presenting "image/x-emf" as CF_ENHMETAFILE must be done by Inkscape ?
+
// push supported clipboard targets, in order of preference
_preferred_targets.push_back("image/x-inkscape-svg");
_preferred_targets.push_back("image/svg+xml");
_preferred_targets.push_back("image/svg+xml-compressed");
-#ifdef WIN32
- _preferred_targets.push_back(CLIPBOARD_WIN32_EMF_MIME);
-#endif
+ _preferred_targets.push_back("image/x-emf");
+ _preferred_targets.push_back("CF_ENHMETAFILE");
+ _preferred_targets.push_back("WCF_ENHMETAFILE"); // seen on Wine
_preferred_targets.push_back("application/pdf");
_preferred_targets.push_back("image/x-adobe-illustrator");
}
@@ -981,7 +980,7 @@ SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_targ
Glib::ustring target = best_target;
#ifdef WIN32
- if (best_target == CLIPBOARD_WIN32_EMF_TARGET)
+ if (best_target == "CF_ENHMETAFILE" || best_target == "WCF_ENHMETAFILE")
{ // Try to save clipboard data as en emf file (using win32 api)
if (OpenClipboard(NULL)) {
HGLOBAL hglb = GetClipboardData(CF_ENHMETAFILE);
@@ -989,7 +988,7 @@ SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_targ
HENHMETAFILE hemf = CopyEnhMetaFile((HENHMETAFILE) hglb, filename);
if (hemf) {
file_saved = true;
- target = CLIPBOARD_WIN32_EMF_MIME;
+ target = "image/x-emf";
DeleteEnhMetaFile(hemf);
}
}
@@ -1020,6 +1019,10 @@ SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_targ
if (target == "image/x-inkscape-svg") {
target = "image/svg+xml";
}
+ // Use the EMF extension to import metafiles
+ if (target == "CF_ENHMETAFILE" || target == "WCF_ENHMETAFILE") {
+ target = "image/x-emf";
+ }
Inkscape::Extension::DB::InputList inlist;
Inkscape::Extension::db.get_input_list(inlist);
@@ -1213,10 +1216,10 @@ Glib::ustring ClipboardManagerImpl::_getBestTarget()
// clipboard target debugging snippet
/*
- g_debug("Begin clipboard targets");
+ g_message("Begin clipboard targets");
for ( std::list<Glib::ustring>::iterator x = targets.begin() ; x != targets.end(); ++x )
- g_debug("Clipboard target: %s", (*x).data());
- g_debug("End clipboard targets\n");
+ g_message("Clipboard target: %s", (*x).data());
+ g_message("End clipboard targets\n");
//*/
for (std::list<Glib::ustring>::iterator i = _preferred_targets.begin() ;
@@ -1239,7 +1242,7 @@ Glib::ustring ClipboardManagerImpl::_getBestTarget()
CloseClipboard();
if (format == CF_ENHMETAFILE) {
- return CLIPBOARD_WIN32_EMF_TARGET;
+ return "CF_ENHMETAFILE";
}
if (format == CF_DIB || format == CF_BITMAP) {
return CLIPBOARD_GDK_PIXBUF_TARGET;
@@ -1247,7 +1250,7 @@ Glib::ustring ClipboardManagerImpl::_getBestTarget()
}
if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) {
- return CLIPBOARD_WIN32_EMF_TARGET;
+ return "CF_ENHMETAFILE";
}
#endif
if (_clipboard->wait_is_image_available()) {
@@ -1311,7 +1314,7 @@ void ClipboardManagerImpl::_setClipboardTargets()
if (OpenClipboard(NULL)) {
if ( _clipboardSPDoc != NULL ) {
- const Glib::ustring target = CLIPBOARD_WIN32_EMF_MIME;
+ const Glib::ustring target = "image/x-emf";
Inkscape::Extension::DB::OutputList outlist;
Inkscape::Extension::db.get_output_list(outlist);
diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert
index bbede9df1..09a7ef573 100644
--- a/src/ui/dialog/Makefile_insert
+++ b/src/ui/dialog/Makefile_insert
@@ -70,6 +70,8 @@ ink_common_sources += \
ui/dialog/memory.h \
ui/dialog/messages.cpp \
ui/dialog/messages.h \
+ ui/dialog/new-from-template.cpp \
+ ui/dialog/new-from-template.h \
ui/dialog/ocaldialogs.cpp \
ui/dialog/ocaldialogs.h \
ui/dialog/object-attributes.cpp \
@@ -89,6 +91,10 @@ ink_common_sources += \
ui/dialog/swatches.h \
ui/dialog/symbols.cpp \
ui/dialog/symbols.h \
+ ui/dialog/template-load-tab.cpp \
+ ui/dialog/template-load-tab.h \
+ ui/dialog/template-widget.cpp \
+ ui/dialog/template-widget.h \
ui/dialog/text-edit.cpp \
ui/dialog/text-edit.h \
ui/dialog/tile.cpp \
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index c98e23000..577793496 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -201,11 +201,11 @@ Export::Export (void) :
earlier than that */
unit_selector = new Inkscape::UI::Widget::UnitMenu();
unit_selector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR);
- unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged));
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop)
unit_selector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr);
+ unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged));
unitbox.pack_end(*unit_selector, false, false, 0);
unitbox.pack_end(units_label, false, false, 3);
diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp
index 4401d5658..4ce2eafd1 100644
--- a/src/ui/dialog/filter-effects-dialog.cpp
+++ b/src/ui/dialog/filter-effects-dialog.cpp
@@ -1310,7 +1310,8 @@ void FilterEffectsDialog::FilterModifier::on_name_edited(const Glib::ustring& pa
void FilterEffectsDialog::FilterModifier::on_filter_reorder(const Gtk::TreeModel::Path& path) {
for(Gtk::TreeModel::iterator i = _model->children().begin(); i != _model->children().end(); ++i) {
SPObject* object = (*i)[_columns.filter];
- object->getRepr()->setPosition(0);
+ if(object && object->getRepr())
+ object->getRepr()->setPosition(0);
}
}
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 7890b0b4c..b06c1fd1f 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -879,8 +879,12 @@ void InkscapePreferences::initPageIO()
_page_svgoutput.add_group_header( _("Path data"));
- _svgoutput_allowrelativecoordinates.init( _("Allow relative coordinates"), "/options/svgoutput/allowrelativecoordinates", true);
- _page_svgoutput.add_line( true, "", _svgoutput_allowrelativecoordinates, "", _("If set, relative coordinates may be used in path data"), false);
+ int const numPathstringFormat = 3;
+ Glib::ustring pathstringFormatLabels[numPathstringFormat] = {_("Absolute"), _("Relative"), _("Optimized")};
+ int pathstringFormatValues[numPathstringFormat] = {0, 1, 2};
+
+ _svgoutput_pathformat.init("/options/svgoutput/pathstring_format", pathstringFormatLabels, pathstringFormatValues, numPathstringFormat, 2);
+ _page_svgoutput.add_line( true, _("Path string format"), _svgoutput_pathformat, "", _("Path data should be written: only with absolute coordinates, only with relative coordinates, or optimized for string length (mixed absolute and relative coordinates)"), false);
_svgoutput_forcerepeatcommands.init( _("Force repeat commands"), "/options/svgoutput/forcerepeatcommands", false);
_page_svgoutput.add_line( true, "", _svgoutput_forcerepeatcommands, "", _("Force repeating of the same path command (for example, 'L 1,2 L 3,4' instead of 'L 1,2 3,4')"), false);
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index 37c05df05..56222fb22 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -426,7 +426,7 @@ protected:
UI::Widget::PrefSpinButton _svgoutput_minimumexponent;
UI::Widget::PrefCheckButton _svgoutput_inlineattrs;
UI::Widget::PrefSpinButton _svgoutput_indent;
- UI::Widget::PrefCheckButton _svgoutput_allowrelativecoordinates;
+ UI::Widget::PrefCombo _svgoutput_pathformat;
UI::Widget::PrefCheckButton _svgoutput_forcerepeatcommands;
// Attribute Checking controls for SVG Output page:
diff --git a/src/ui/dialog/layers.cpp b/src/ui/dialog/layers.cpp
index c41046123..c01903f94 100644
--- a/src/ui/dialog/layers.cpp
+++ b/src/ui/dialog/layers.cpp
@@ -838,7 +838,8 @@ LayersPanel::LayersPanel() :
_name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel);
_tree.set_expander_column( *_tree.get_column(nameColNum) );
-
+ _tree.set_search_column(nameColNum + 1);
+
_compositeSettings.setSubject(&_subject);
_selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
diff --git a/src/ui/dialog/new-from-template.cpp b/src/ui/dialog/new-from-template.cpp
new file mode 100644
index 000000000..2595e2cf5
--- /dev/null
+++ b/src/ui/dialog/new-from-template.cpp
@@ -0,0 +1,59 @@
+/** @file
+ * @brief New From Template main dialog - implementation
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+
+#include "new-from-template.h"
+#include "file.h"
+
+#include <gtkmm/alignment.h>
+#include <glibmm/i18n.h>
+
+
+namespace Inkscape {
+namespace UI {
+
+
+NewFromTemplate::NewFromTemplate()
+ : _create_template_button(_("Create from template"))
+{
+ set_title(_("New From Template"));
+ resize(400, 400);
+
+ get_vbox()->pack_start(_main_widget);
+
+ Gtk::Alignment *align;
+ align = manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0));
+ get_vbox()->pack_end(*align, Gtk::PACK_SHRINK);
+ align->set_padding(0, 0, 0, 15);
+ align->add(_create_template_button);
+
+ _create_template_button.signal_pressed().connect(
+ sigc::mem_fun(*this, &NewFromTemplate::_createFromTemplate));
+
+ show_all();
+}
+
+
+void NewFromTemplate::_createFromTemplate()
+{
+ _main_widget.createTemplate();
+
+ response(0);
+}
+
+
+void NewFromTemplate::load_new_from_template()
+{
+ NewFromTemplate dl;
+ dl.run();
+}
+
+}
+}
diff --git a/src/ui/dialog/new-from-template.h b/src/ui/dialog/new-from-template.h
new file mode 100644
index 000000000..8ebcb2863
--- /dev/null
+++ b/src/ui/dialog/new-from-template.h
@@ -0,0 +1,39 @@
+/** @file
+ * @brief New From Template main dialog
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_SEEN_UI_DIALOG_NEW_FROM_TEMPLATE_H
+#define INKSCAPE_SEEN_UI_DIALOG_NEW_FROM_TEMPLATE_H
+
+#include <gtkmm/dialog.h>
+#include <gtkmm/button.h>
+
+#include "template-load-tab.h"
+
+
+namespace Inkscape {
+namespace UI {
+
+
+class NewFromTemplate : public Gtk::Dialog
+{
+public:
+ static void load_new_from_template();
+
+private:
+ NewFromTemplate();
+ Gtk::Button _create_template_button;
+ TemplateLoadTab _main_widget;
+
+ void _createFromTemplate();
+};
+
+}
+}
+#endif
diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp
new file mode 100644
index 000000000..265ee8026
--- /dev/null
+++ b/src/ui/dialog/template-load-tab.cpp
@@ -0,0 +1,281 @@
+/** @file
+ * @brief New From Template abstract tab implementation
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "template-widget.h"
+
+#include "template-load-tab.h"
+
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/scrolledwindow.h>
+#include <glibmm/i18n.h>
+#include <glibmm/fileutils.h>
+#include <glibmm/miscutils.h>
+#include <glibmm/stringutils.h>
+
+#include "interface.h"
+#include "file.h"
+#include "path-prefix.h"
+#include "preferences.h"
+#include "inkscape.h"
+#include "xml/repr.h"
+#include "xml/document.h"
+#include "xml/node.h"
+
+
+namespace Inkscape {
+namespace UI {
+
+
+TemplateLoadTab::TemplateLoadTab()
+ : _current_keyword("")
+ , _keywords_combo(true)
+ , _current_search_type(ALL)
+{
+ set_border_width(10);
+
+ _info_widget = manage(new TemplateWidget());
+
+ Gtk::Label *title;
+ title = manage(new Gtk::Label(_("Search:")));
+ _search_box.pack_start(*title, Gtk::PACK_SHRINK);
+ _search_box.pack_start(_keywords_combo, Gtk::PACK_SHRINK, 5);
+
+ _tlist_box.pack_start(_search_box, Gtk::PACK_SHRINK, 10);
+
+ pack_start(_tlist_box, Gtk::PACK_SHRINK);
+ pack_start(*_info_widget, Gtk::PACK_EXPAND_WIDGET, 5);
+
+ Gtk::ScrolledWindow *scrolled;
+ scrolled = manage(new Gtk::ScrolledWindow());
+ scrolled->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+ scrolled->add(_tlist_view);
+ _tlist_box.pack_start(*scrolled, Gtk::PACK_EXPAND_WIDGET, 5);
+
+ _keywords_combo.signal_changed().connect(
+ sigc::mem_fun(*this, &TemplateLoadTab::_keywordSelected));
+ this->show_all();
+
+ _loading_path = "";
+ _loadTemplates();
+ _initLists();
+}
+
+
+TemplateLoadTab::~TemplateLoadTab()
+{
+}
+
+
+void TemplateLoadTab::createTemplate()
+{
+ _info_widget->create();
+}
+
+
+void TemplateLoadTab::_displayTemplateInfo()
+{
+ Glib::RefPtr<Gtk::TreeSelection> templateSelectionRef = _tlist_view.get_selection();
+ if (templateSelectionRef->get_selected()) {
+ _current_template = (*templateSelectionRef->get_selected())[_columns.textValue];
+
+ _info_widget->display(_tdata[_current_template]);
+ }
+
+}
+
+
+void TemplateLoadTab::_initKeywordsList()
+{
+ _keywords_combo.append(_("All"));
+
+ for (std::set<Glib::ustring>::iterator it = _keywords.begin() ; it != _keywords.end() ; ++it){
+ _keywords_combo.append(*it);
+ }
+}
+
+
+void TemplateLoadTab::_initLists()
+{
+ _tlist_store = Gtk::ListStore::create(_columns);
+ _tlist_view.set_model(_tlist_store);
+ _tlist_view.append_column("", _columns.textValue);
+ _tlist_view.set_headers_visible(false);
+
+ _initKeywordsList();
+ _refreshTemplatesList();
+
+ Glib::RefPtr<Gtk::TreeSelection> templateSelectionRef =
+ _tlist_view.get_selection();
+ templateSelectionRef->signal_changed().connect(
+ sigc::mem_fun(*this, &TemplateLoadTab::_displayTemplateInfo));
+}
+
+
+void TemplateLoadTab::_keywordSelected()
+{
+ _current_keyword = _keywords_combo.get_active_text();
+ if (_current_keyword == ""){
+ _current_keyword = _keywords_combo.get_entry_text();
+ _current_search_type = USER_SPECIFIED;
+ }
+ else
+ _current_search_type = LIST_KEYWORD;
+
+ if (_current_keyword == "" || _current_keyword == _("All"))
+ _current_search_type = ALL;
+
+ _refreshTemplatesList();
+}
+
+
+void TemplateLoadTab::_refreshTemplatesList()
+{
+ _tlist_store->clear();
+
+ switch (_current_search_type){
+ case ALL :{
+
+ for (std::map<Glib::ustring, TemplateData>::iterator it = _tdata.begin() ; it != _tdata.end() ; ++it) {
+ Gtk::TreeModel::iterator iter = _tlist_store->append();
+ Gtk::TreeModel::Row row = *iter;
+ row[_columns.textValue] = it->first;
+ }
+ break;
+ }
+
+ case LIST_KEYWORD: {
+ for (std::map<Glib::ustring, TemplateData>::iterator it = _tdata.begin() ; it != _tdata.end() ; ++it) {
+ if (it->second.keywords.count(_current_keyword) != 0){
+ Gtk::TreeModel::iterator iter = _tlist_store->append();
+ Gtk::TreeModel::Row row = *iter;
+ row[_columns.textValue] = it->first;
+ }
+ }
+ break;
+ }
+
+ case USER_SPECIFIED : {
+ for (std::map<Glib::ustring, TemplateData>::iterator it = _tdata.begin() ; it != _tdata.end() ; ++it) {
+ if (it->second.keywords.count(_current_keyword) != 0 ||
+ it->second.display_name.find(_current_keyword) != Glib::ustring::npos ||
+ it->second.author.find(_current_keyword) != Glib::ustring::npos ||
+ it->second.short_description.find(_current_keyword) != Glib::ustring::npos ||
+ it->second.long_description.find(_current_keyword) != Glib::ustring::npos )
+ {
+ Gtk::TreeModel::iterator iter = _tlist_store->append();
+ Gtk::TreeModel::Row row = *iter;
+ row[_columns.textValue] = it->first;
+ }
+ }
+ break;
+ }
+ }
+}
+
+
+void TemplateLoadTab::_loadTemplates()
+{
+ // user's local dir
+ _getTemplatesFromDir(profile_path("templates") + _loading_path);
+
+ // system templates dir
+ _getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path);
+}
+
+
+TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib::ustring &path)
+{
+ TemplateData result;
+ result.path = path;
+ result.is_procedural = false;
+ result.preview_name = "";
+
+ // convert path into valid template name
+ result.display_name = Glib::path_get_basename(path);
+ gsize n = 0;
+ while ((n = result.display_name.find_first_of("_", 0)) < Glib::ustring::npos){
+ result.display_name.replace(n, 1, 1, ' ');
+ }
+ n = result.display_name.rfind(".svg");
+ result.display_name.replace(n, 4, 1, ' ');
+
+ Inkscape::XML::Document *rdoc;
+ rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI);
+ Inkscape::XML::Node *myRoot;
+ Inkscape::XML::Node *dataNode;
+
+ if (rdoc){
+ myRoot = rdoc->root();
+ if (strcmp(myRoot->name(), "svg:svg") != 0){ // Wrong file format
+ return result;
+ }
+
+ myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo");
+
+ if (myRoot == NULL) // No template info
+ return result;
+
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_name")) != NULL)
+ result.display_name = dgettext("Document template name", dataNode->firstChild()->content());
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:author")) != NULL)
+ result.author = dataNode->firstChild()->content();
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_short")) != NULL)
+ result.short_description = dgettext("Document template short description", dataNode->firstChild()->content());
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_long") )!= NULL)
+ result.long_description = dgettext("Document template long description", dataNode->firstChild()->content());
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:preview")) != NULL)
+ result.preview_name = dataNode->firstChild()->content();
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:date")) != NULL){
+ result.creation_date = dataNode->firstChild()->content();
+ }
+
+ if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_keywords")) != NULL){
+ Glib::ustring data = dataNode->firstChild()->content();
+ while (!data.empty()){
+ std::size_t pos = data.find_first_of(" ");
+ if (pos == Glib::ustring::npos)
+ pos = data.size();
+
+ Glib::ustring keyword = dgettext("Document template keyword", data.substr(0, pos).data());
+ result.keywords.insert(keyword);
+ _keywords.insert(keyword);
+
+ if (pos == data.size())
+ break;
+ data.erase(0, pos+1);
+ }
+ }
+ }
+
+ return result;
+}
+
+
+void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path)
+{
+ if ( !Glib::file_test(path, Glib::FILE_TEST_EXISTS) ||
+ !Glib::file_test(path, Glib::FILE_TEST_IS_DIR))
+ return;
+
+ Glib::Dir dir(path);
+
+ Glib::ustring file = Glib::build_filename(path, dir.read_name());
+ while (file != path){
+ if (Glib::str_has_suffix(file, ".svg") && !Glib::str_has_prefix(Glib::path_get_basename(file), "default")){
+ TemplateData tmp = _processTemplateFile(file);
+ if (tmp.display_name != "")
+ _tdata[tmp.display_name] = tmp;
+ }
+ file = Glib::build_filename(path, dir.read_name());
+ }
+}
+
+}
+}
diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h
new file mode 100644
index 000000000..50f3e0be2
--- /dev/null
+++ b/src/ui/dialog/template-load-tab.h
@@ -0,0 +1,102 @@
+/** @file
+ * @brief New From Template abstract tab class
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_SEEN_UI_DIALOG_TEMPLATE_LOAD_TAB_H
+#define INKSCAPE_SEEN_UI_DIALOG_TEMPLATE_LOAD_TAB_H
+
+#include <gtkmm/box.h>
+#include <gtkmm/comboboxtext.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/liststore.h>
+#include <gtkmm/treeview.h>
+#include <map>
+#include <set>
+
+
+namespace Inkscape {
+namespace UI {
+
+class TemplateWidget;
+
+class TemplateLoadTab : public Gtk::HBox
+{
+
+public:
+ struct TemplateData
+ {
+ bool is_procedural;
+ Glib::ustring path;
+ Glib::ustring display_name;
+ Glib::ustring author;
+ Glib::ustring short_description;
+ Glib::ustring long_description;
+ Glib::ustring preview_name;
+ Glib::ustring creation_date;
+ std::set<Glib::ustring> keywords;
+ };
+
+ TemplateLoadTab();
+ virtual ~TemplateLoadTab();
+ virtual void createTemplate();
+
+protected:
+ class StringModelColumns : public Gtk::TreeModelColumnRecord
+ {
+ public:
+ StringModelColumns()
+ {
+ add(textValue);
+ }
+
+ Gtk::TreeModelColumn<Glib::ustring> textValue;
+ };
+
+ Glib::ustring _current_keyword;
+ Glib::ustring _current_template;
+ Glib::ustring _loading_path;
+ std::map<Glib::ustring, TemplateData> _tdata;
+ std::set<Glib::ustring> _keywords;
+
+
+ virtual void _displayTemplateInfo();
+ virtual void _initKeywordsList();
+ virtual void _refreshTemplatesList();
+ void _loadTemplates();
+ void _initLists();
+
+ Gtk::VBox _tlist_box;
+ Gtk::HBox _search_box;
+ TemplateWidget *_info_widget;
+
+ Gtk::ComboBoxText _keywords_combo;
+
+ Gtk::TreeView _tlist_view;
+ Glib::RefPtr<Gtk::ListStore> _tlist_store;
+ StringModelColumns _columns;
+
+private:
+ enum SearchType
+ {
+ LIST_KEYWORD,
+ USER_SPECIFIED,
+ ALL
+ };
+
+ SearchType _current_search_type;
+
+ void _getTemplatesFromDir(const Glib::ustring &);
+ void _keywordSelected();
+ TemplateData _processTemplateFile(const Glib::ustring &);
+};
+
+}
+}
+
+#endif
diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp
new file mode 100644
index 000000000..be7e2b515
--- /dev/null
+++ b/src/ui/dialog/template-widget.cpp
@@ -0,0 +1,117 @@
+/** @file
+ * @brief New From Template - templates widget - implementation
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "template-widget.h"
+
+#include <gtkmm/alignment.h>
+#include <gtkmm/button.h>
+#include <gtkmm/label.h>
+#include <gtkmm/messagedialog.h>
+
+#include <glibmm/i18n.h>
+#include <glibmm/miscutils.h>
+
+#include "template-load-tab.h"
+#include "file.h"
+
+namespace Inkscape {
+namespace UI {
+
+
+TemplateWidget::TemplateWidget()
+ : _more_info_button(_("More info"))
+ , _short_description_label(_(" "))
+ , _template_author_label(_(" "))
+ , _template_name_label(_("no template selected"))
+{
+ pack_start(_template_name_label, Gtk::PACK_SHRINK, 10);
+ pack_start(_template_author_label, Gtk::PACK_SHRINK, 0);
+ pack_start(_preview_box, Gtk::PACK_SHRINK, 0);
+
+ _preview_box.pack_start(_preview_image, Gtk::PACK_EXPAND_PADDING, 15);
+ _preview_box.pack_start(_preview_render, Gtk::PACK_EXPAND_PADDING, 10);
+
+ _short_description_label.set_line_wrap(true);
+ //_short_description_label.set_size_request(200);
+
+ Gtk::Alignment *align;
+ align = manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0));
+ pack_end(*align, Gtk::PACK_SHRINK);
+ align->add(_more_info_button);
+
+ pack_end(_short_description_label, Gtk::PACK_SHRINK, 5);
+
+ _more_info_button.signal_pressed().connect(
+ sigc::mem_fun(*this, &TemplateWidget::_displayTemplateDetails));
+}
+
+
+void TemplateWidget::create()
+{
+ if (_current_template.path == "")
+ return;
+
+ if (_current_template.is_procedural) {}
+ else {
+ sp_file_new(_current_template.path);
+ }
+}
+
+
+void TemplateWidget::display(TemplateLoadTab::TemplateData data)
+{
+ _current_template = data;
+ if (data.is_procedural){}
+ else{
+ _template_name_label.set_text(_current_template.display_name);
+ _template_author_label.set_text(_current_template.author);
+ _short_description_label.set_text(_current_template.short_description);
+
+ Glib::ustring imagePath = Glib::build_filename(Glib::path_get_dirname(_current_template.path), _current_template.preview_name);
+ if (data.preview_name != ""){
+ _preview_image.set(imagePath);
+ _preview_image.show();
+ _preview_render.hide();
+ }
+ else{
+ _preview_render.showImage(data.path);
+ _preview_render.show();
+ _preview_image.hide();
+ }
+ }
+}
+
+
+void TemplateWidget::_displayTemplateDetails()
+{
+ if (_current_template.path == "")
+ return;
+
+ Glib::ustring message = _current_template.display_name + "\n\n" +
+ _("Path: ") + _current_template.path + "\n\n";
+
+ if (_current_template.long_description != "")
+ message += _("Description: ") + _current_template.long_description + "\n\n";
+ if (_current_template.keywords.size() > 0){
+ message += _("Keywords: ");
+ for (std::set<Glib::ustring>::iterator it = _current_template.keywords.begin(); it != _current_template.keywords.end(); ++it)
+ message += *it + " ";
+ message += "\n\n";
+ }
+
+ if (_current_template.author != "")
+ message += _("By: ") + _current_template.author + " " + _current_template.creation_date + "\n\n";
+
+ Gtk::MessageDialog dl(message, false, Gtk::MESSAGE_OTHER);
+ dl.run();
+}
+
+}
+}
diff --git a/src/ui/dialog/template-widget.h b/src/ui/dialog/template-widget.h
new file mode 100644
index 000000000..f7e1267ce
--- /dev/null
+++ b/src/ui/dialog/template-widget.h
@@ -0,0 +1,48 @@
+/** @file
+ * @brief New From Template - template widget
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_SEEN_UI_DIALOG_TEMPLATE_WIDGET_H
+#define INKSCAPE_SEEN_UI_DIALOG_TEMPLATE_WIDGET_H
+
+#include "filedialogimpl-gtkmm.h"
+
+#include <gtkmm/box.h>
+
+#include "template-load-tab.h"
+
+namespace Inkscape {
+namespace UI {
+
+
+class TemplateWidget : public Gtk::VBox
+{
+public:
+ TemplateWidget ();
+ void create();
+ void display(TemplateLoadTab::TemplateData);
+
+private:
+ TemplateLoadTab::TemplateData _current_template;
+
+ Gtk::Button _more_info_button;
+ Gtk::HBox _preview_box;
+ Gtk::Image _preview_image;
+ Dialog::SVGPreview _preview_render;
+ Gtk::Label _short_description_label;
+ Gtk::Label _template_author_label;
+ Gtk::Label _template_name_label;
+
+ void _displayTemplateDetails();
+};
+
+}
+}
+
+#endif