summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSlagvi Public <JandotDarowskiattgmaildottcom>2013-09-21 22:15:43 +0000
committerSlagvi Public <JandotDarowskiattgmaildottcom>2013-09-21 22:15:43 +0000
commitfebaf7e22bf572e36e9511505aa77551be274c91 (patch)
tree0f825ed22433afd6563c43fba733a8651e05f79d /src
parentFixed segfault on copying text. (diff)
parentSmall style fixes. (diff)
downloadinkscape-febaf7e22bf572e36e9511505aa77551be274c91.tar.gz
inkscape-febaf7e22bf572e36e9511505aa77551be274c91.zip
Merge gsoc procedural templates work.
(bzr r12570)
Diffstat (limited to 'src')
-rw-r--r--src/file.cpp30
-rw-r--r--src/file.h3
-rw-r--r--src/ui/dialog/template-load-tab.cpp123
-rw-r--r--src/ui/dialog/template-load-tab.h15
-rw-r--r--src/ui/dialog/template-widget.cpp71
-rw-r--r--src/ui/dialog/template-widget.h3
6 files changed, 153 insertions, 92 deletions
diff --git a/src/file.cpp b/src/file.cpp
index caea05d95..baa7b12b5 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -74,6 +74,8 @@
#include <glibmm/i18n.h>
#include <glibmm/miscutils.h>
+#include <string>
+
using Inkscape::DocumentUndo;
#ifdef WITH_GNOME_VFS
@@ -124,7 +126,7 @@ static void sp_file_add_recent(gchar const *uri)
/**
* Create a blank document and add it to the desktop
*/
-SPDesktop *sp_file_new(const Glib::ustring &templ)
+SPDesktop *sp_file_new(const std::string &templ)
{
SPDocument *doc = SPDocument::createNewDoc( !templ.empty() ? templ.c_str() : 0 , TRUE, true );
g_return_val_if_fail(doc != NULL, NULL);
@@ -139,24 +141,13 @@ SPDesktop *sp_file_new(const Glib::ustring &templ)
}
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (desktop) {
+ if (desktop)
desktop->setWaitingCursor();
- }
- SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL;
-
- if (existing && existing->virgin) {
- // If the current desktop is empty, open the document there
- doc->ensureUpToDate(); // TODO this will trigger broken link warnings, etc.
- desktop->change_document(doc);
- doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px"));
- } else {
- // create a whole new desktop and window
- SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
- g_return_val_if_fail(dtw != NULL, NULL);
- sp_create_window(dtw, TRUE);
- desktop = static_cast<SPDesktop *>(dtw->view);
- }
+ SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
+ g_return_val_if_fail(dtw != NULL, NULL);
+ sp_create_window(dtw, TRUE);
+ desktop = static_cast<SPDesktop *>(dtw->view);
doc->doUnref();
@@ -166,6 +157,9 @@ SPDesktop *sp_file_new(const Glib::ustring &templ)
#ifdef WITH_DBUS
Inkscape::Extension::Dbus::dbus_init_desktop_interface(desktop);
#endif
+
+ if (desktop)
+ desktop->clearWaitingCursor();
return desktop;
}
@@ -220,7 +214,7 @@ SPDesktop* sp_file_new_default()
{
Glib::ustring templateUri = sp_file_default_template_uri();
SPDesktop* desk = sp_file_new(sp_file_default_template_uri());
- rdf_add_from_preferences( SP_ACTIVE_DOCUMENT );
+ //rdf_add_from_preferences( SP_ACTIVE_DOCUMENT );
return desk;
}
diff --git a/src/file.h b/src/file.h
index 682ca422e..7f80f3645 100644
--- a/src/file.h
+++ b/src/file.h
@@ -16,6 +16,7 @@
*/
#include <glibmm/ustring.h>
+#include <string>
#include "extension/system.h"
class SPDesktop;
@@ -43,7 +44,7 @@ Glib::ustring sp_file_default_template_uri();
* Creates a new Inkscape document and window.
* Return value is a pointer to the newly created desktop.
*/
-SPDesktop* sp_file_new (const Glib::ustring &templ);
+SPDesktop* sp_file_new (const std::string &templ);
SPDesktop* sp_file_new_default (void);
/*######################
diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp
index 265ee8026..8e33cf503 100644
--- a/src/ui/dialog/template-load-tab.cpp
+++ b/src/ui/dialog/template-load-tab.cpp
@@ -18,12 +18,16 @@
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include <glibmm/stringutils.h>
+#include <iostream>
+#include <list>
+#include "extension/db.h"
+#include "extension/effect.h"
+#include "inkscape.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"
@@ -152,7 +156,7 @@ void TemplateLoadTab::_refreshTemplatesList()
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){
+ if (it->second.keywords.count(_current_keyword.lowercase()) != 0){
Gtk::TreeModel::iterator iter = _tlist_store->append();
Gtk::TreeModel::Row row = *iter;
row[_columns.textValue] = it->first;
@@ -163,11 +167,11 @@ void TemplateLoadTab::_refreshTemplatesList()
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 )
+ if (it->second.keywords.count(_current_keyword.lowercase()) != 0 ||
+ it->second.display_name.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ||
+ it->second.author.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ||
+ it->second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ||
+ it->second.long_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos )
{
Gtk::TreeModel::iterator iter = _tlist_store->append();
Gtk::TreeModel::Row row = *iter;
@@ -187,10 +191,13 @@ void TemplateLoadTab::_loadTemplates()
// system templates dir
_getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path);
+
+ // procedural templates
+ _getProceduralTemplates();
}
-TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib::ustring &path)
+TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::string &path)
{
TemplateData result;
result.path = path;
@@ -209,7 +216,6 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib::
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();
@@ -221,44 +227,14 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib::
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);
- }
- }
+ _getDataFromNode(myRoot, result);
}
return result;
}
-void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path)
+void TemplateLoadTab::_getTemplatesFromDir(const std::string &path)
{
if ( !Glib::file_test(path, Glib::FILE_TEST_EXISTS) ||
!Glib::file_test(path, Glib::FILE_TEST_IS_DIR))
@@ -266,9 +242,9 @@ void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path)
Glib::Dir dir(path);
- Glib::ustring file = Glib::build_filename(path, dir.read_name());
+ std::string 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")){
+ 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;
@@ -277,5 +253,66 @@ void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path)
}
}
+
+void TemplateLoadTab::_getProceduralTemplates()
+{
+ std::list<Inkscape::Extension::Effect *> effects;
+ Inkscape::Extension::db.get_effect_list(effects);
+
+ std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin();
+ while (it != effects.end()){
+ Inkscape::XML::Node *myRoot;
+ myRoot = (*it)->get_repr();
+ myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo");
+
+ if (myRoot){
+ TemplateData result;
+ result.display_name = (*it)->get_name();
+ result.is_procedural = true;
+ result.path = "";
+ result.tpl_effect = *it;
+
+ _getDataFromNode(myRoot, result);
+ _tdata[result.display_name] = result;
+ }
+ ++it;
+ }
+}
+
+
+void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data)
+{
+ Inkscape::XML::Node *currentData;
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != NULL)
+ data.display_name = dgettext("Document template name", currentData->firstChild()->content());
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:author")) != NULL)
+ data.author = currentData->firstChild()->content();
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != NULL)
+ data.short_description = dgettext("Document template short description", currentData->firstChild()->content());
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_long") )!= NULL)
+ data.long_description = dgettext("Document template long description", currentData->firstChild()->content());
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != NULL)
+ data.preview_name = currentData->firstChild()->content();
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != NULL)
+ data.creation_date = currentData->firstChild()->content();
+
+ if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != NULL){
+ Glib::ustring tplKeywords = currentData->firstChild()->content();
+ while (!tplKeywords.empty()){
+ std::size_t pos = tplKeywords.find_first_of(" ");
+ if (pos == Glib::ustring::npos)
+ pos = tplKeywords.size();
+
+ Glib::ustring keyword = dgettext("Document template keyword", tplKeywords.substr(0, pos).data());
+ data.keywords.insert(keyword.lowercase());
+ _keywords.insert(keyword.lowercase());
+
+ if (pos == tplKeywords.size())
+ break;
+ tplKeywords.erase(0, pos+1);
+ }
+ }
+}
+
}
}
diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h
index 50f3e0be2..744a2a9fb 100644
--- a/src/ui/dialog/template-load-tab.h
+++ b/src/ui/dialog/template-load-tab.h
@@ -18,6 +18,10 @@
#include <gtkmm/treeview.h>
#include <map>
#include <set>
+#include <string>
+
+#include "xml/node.h"
+#include "extension/effect.h"
namespace Inkscape {
@@ -32,7 +36,7 @@ public:
struct TemplateData
{
bool is_procedural;
- Glib::ustring path;
+ std::string path;
Glib::ustring display_name;
Glib::ustring author;
Glib::ustring short_description;
@@ -40,6 +44,7 @@ public:
Glib::ustring preview_name;
Glib::ustring creation_date;
std::set<Glib::ustring> keywords;
+ Inkscape::Extension::Effect *tpl_effect;
};
TemplateLoadTab();
@@ -60,7 +65,7 @@ protected:
Glib::ustring _current_keyword;
Glib::ustring _current_template;
- Glib::ustring _loading_path;
+ std::string _loading_path;
std::map<Glib::ustring, TemplateData> _tdata;
std::set<Glib::ustring> _keywords;
@@ -91,9 +96,11 @@ private:
SearchType _current_search_type;
- void _getTemplatesFromDir(const Glib::ustring &);
+ void _getDataFromNode(Inkscape::XML::Node *, TemplateData &);
+ void _getProceduralTemplates();
+ void _getTemplatesFromDir(const std::string &);
void _keywordSelected();
- TemplateData _processTemplateFile(const Glib::ustring &);
+ TemplateData _processTemplateFile(const std::string &);
};
}
diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp
index be7e2b515..7e34e5a58 100644
--- a/src/ui/dialog/template-widget.cpp
+++ b/src/ui/dialog/template-widget.cpp
@@ -19,7 +19,14 @@
#include <glibmm/miscutils.h>
#include "template-load-tab.h"
+#include "desktop.h"
+#include "desktop-handles.h"
+#include "document.h"
+#include "document-undo.h"
#include "file.h"
+#include "extension/implementation/implementation.h"
+#include "inkscape.h"
+
namespace Inkscape {
namespace UI {
@@ -28,18 +35,16 @@ namespace UI {
TemplateWidget::TemplateWidget()
: _more_info_button(_("More info"))
, _short_description_label(_(" "))
- , _template_author_label(_(" "))
, _template_name_label(_("no template selected"))
+ , _effect_prefs(NULL)
{
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));
@@ -55,10 +60,19 @@ TemplateWidget::TemplateWidget()
void TemplateWidget::create()
{
- if (_current_template.path == "")
+ if (_current_template.display_name == "")
return;
- if (_current_template.is_procedural) {}
+ if (_current_template.is_procedural){
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDesktop *desc = sp_file_new_default();
+ _current_template.tpl_effect->effect(desc);
+ DocumentUndo::clearUndo(sp_desktop_document(desc));
+ sp_desktop_document(desc)->setModifiedSinceSave(false);
+
+ if (desktop)
+ desktop->clearWaitingCursor();
+ }
else {
sp_file_new(_current_template.path);
}
@@ -68,34 +82,41 @@ void TemplateWidget::create()
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);
+
+ _template_name_label.set_text(_current_template.display_name);
+ _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();
- }
+ _preview_render.hide();
+ _preview_image.hide();
+
+ std::string 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();
+ }
+ else if (!data.is_procedural){
+ Glib::ustring gPath = data.path.c_str();
+ _preview_render.showImage(gPath);
+ _preview_render.show();
+ }
+
+ if (_effect_prefs != NULL){
+ remove (*_effect_prefs);
+ _effect_prefs = NULL;
+ }
+ if (data.is_procedural){
+ _effect_prefs = data.tpl_effect->get_imp()->prefs_effect(data.tpl_effect, SP_ACTIVE_DESKTOP, NULL, NULL);
+ pack_start(*_effect_prefs);
}
}
void TemplateWidget::_displayTemplateDetails()
{
- if (_current_template.path == "")
- return;
+ Glib::ustring message = _current_template.display_name + "\n\n";
- Glib::ustring message = _current_template.display_name + "\n\n" +
- _("Path: ") + _current_template.path + "\n\n";
+ if (_current_template.path != "")
+ message += _("Path: ") + _current_template.path + "\n\n";
if (_current_template.long_description != "")
message += _("Description: ") + _current_template.long_description + "\n\n";
diff --git a/src/ui/dialog/template-widget.h b/src/ui/dialog/template-widget.h
index f7e1267ce..bb35d26a0 100644
--- a/src/ui/dialog/template-widget.h
+++ b/src/ui/dialog/template-widget.h
@@ -17,6 +17,7 @@
#include "template-load-tab.h"
+
namespace Inkscape {
namespace UI {
@@ -36,8 +37,8 @@ private:
Gtk::Image _preview_image;
Dialog::SVGPreview _preview_render;
Gtk::Label _short_description_label;
- Gtk::Label _template_author_label;
Gtk::Label _template_name_label;
+ Gtk::Widget *_effect_prefs;
void _displayTemplateDetails();
};