summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-11-03 00:55:01 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2018-05-09 19:42:10 +0000
commit61cbbcbe02f11d67e4fe9f3c4f452442d2e9f778 (patch)
tree3ed5e5b78b00cf25892a3a18e118eee41cbc15ec /src/extension
parentFix typo (diff)
downloadinkscape-61cbbcbe02f11d67e4fe9f3c4f452442d2e9f778.tar.gz
inkscape-61cbbcbe02f11d67e4fe9f3c4f452442d2e9f778.zip
Start migrating 0.92 patch to master
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/execution-env.cpp37
-rw-r--r--src/extension/execution-env.h3
-rw-r--r--src/extension/implementation/script.cpp137
-rw-r--r--src/extension/internal/bitmap/imagemagick.cpp10
-rw-r--r--src/extension/internal/bluredge.cpp13
-rw-r--r--src/extension/internal/filter/filter.cpp13
-rw-r--r--src/extension/internal/grid.cpp12
-rw-r--r--src/extension/prefdialog.cpp28
8 files changed, 115 insertions, 138 deletions
diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp
index 7e233d215..bde04d924 100644
--- a/src/extension/execution-env.cpp
+++ b/src/extension/execution-env.cpp
@@ -22,6 +22,8 @@
#include "selection.h"
#include "effect.h"
#include "document.h"
+#include "desktop.h"
+#include "inkscape.h"
#include "document-undo.h"
#include "desktop.h"
#include "object/sp-namedview.h"
@@ -52,19 +54,6 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp
_show_working(show_working),
_show_errors(show_errors)
{
- SPDesktop *desktop = (SPDesktop *)_doc;
- sp_namedview_document_from_window(desktop);
-
- if (desktop != NULL) {
- auto selected = desktop->getSelection()->items();
- for(auto x = selected.begin(); x != selected.end(); ++x){
- Glib::ustring selected_id;
- selected_id = (*x)->getId();
- _selected.insert(_selected.end(), selected_id);
- //std::cout << "Selected: " << selected_id << std::endl;
- }
- }
-
genDocCache();
return;
@@ -189,24 +178,14 @@ ExecutionEnv::commit (void) {
void
ExecutionEnv::reselect (void) {
- if (_doc == NULL) { return; }
- SPDocument * doc = _doc->doc();
- if (doc == NULL) { return; }
-
- SPDesktop *desktop = (SPDesktop *)_doc;
- sp_namedview_document_from_window(desktop);
-
- if (desktop == NULL) { return; }
-
- Inkscape::Selection * selection = desktop->getSelection();
-
- for (std::list<Glib::ustring>::iterator i = _selected.begin(); i != _selected.end(); ++i) {
- SPObject * obj = doc->getObjectById(i->c_str());
- if (obj != NULL) {
- selection->add(obj);
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ Inkscape::Selection * selection = NULL;
+ if(desktop) {
+ selection = desktop->getSelection();
+ if (!desktop->on_live_extension) {
+ selection->restoreBackup();
}
}
-
return;
}
diff --git a/src/extension/execution-env.h b/src/extension/execution-env.h
index b1a3a8ea2..8af97cd92 100644
--- a/src/extension/execution-env.h
+++ b/src/extension/execution-env.h
@@ -54,9 +54,6 @@ private:
Glib::RefPtr<Glib::MainLoop> _mainloop;
/** \brief The document that we're working on. */
Inkscape::UI::View::View * _doc;
- /** \brief A list of the IDs of all the selected objects before
- we started to work on this document. */
- std::list<Glib::ustring> _selected;
/** \brief A document cache if we were passed one. */
Implementation::ImplementationDocumentCache * _docCache;
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index f25c8a5d6..42867b823 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -417,11 +417,29 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) :
SPDesktop *desktop = (SPDesktop *) view;
sp_namedview_document_from_window(desktop);
-
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool sort_attributes = prefs->getBool("/options/svgoutput/sort_attributes", false);
+ bool incorrect_style_properties_remove = prefs->getBool("/options/svgoutput/incorrect_style_properties_remove", false);
+ bool incorrect_attributes_remove = prefs->getBool("/options/svgoutput/incorrect_attributes_remove", false);
+ bool usenamedcolors = prefs->getBool("/options/svgoutput/usenamedcolors", false);
+ bool forcerepeatcommands = prefs->getBool("/options/svgoutput/forcerepeatcommands", false);
+ bool style_defaults_remove = prefs->getBool("/options/svgoutput/style_defaults_remove", false);
+ prefs->setBool("/options/svgoutput/sort_attributes", false);
+ prefs->setBool("/options/svgoutput/incorrect_style_properties_remove", false);
+ prefs->setBool("/options/svgoutput/incorrect_attributes_remove", false);
+ prefs->setBool("/options/svgoutput/usenamedcolors", false);
+ prefs->setBool("/options/svgoutput/forcerepeatcommands", false);
+ prefs->setBool("/options/svgoutput/style_defaults_remove", false);
Inkscape::Extension::save(
Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE),
view->doc(), _filename.c_str(), false, false, false, Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY);
+ prefs->setBool("/options/svgoutput/sort_attributes", sort_attributes);
+ prefs->setBool("/options/svgoutput/incorrect_style_properties_remove", incorrect_style_properties_remove);
+ prefs->setBool("/options/svgoutput/incorrect_attributes_remove", incorrect_attributes_remove);
+ prefs->setBool("/options/svgoutput/usenamedcolors", usenamedcolors);
+ prefs->setBool("/options/svgoutput/forcerepeatcommands", forcerepeatcommands);
+ prefs->setBool("/options/svgoutput/style_defaults_remove", style_defaults_remove);
return;
}
@@ -686,57 +704,14 @@ void Script::effect(Inkscape::Extension::Effect *module,
return;
}
- auto selected =
- desktop->getSelection()->items(); //desktop should not be NULL since doc was checked and desktop is a casted pointer
- for(auto x = selected.begin(); x != selected.end(); ++x){
- Glib::ustring selected_id;
- selected_id += "--id=";
- selected_id += (*x)->getId();
- params.push_front(selected_id);
- }
-
- {//add selected nodes
- Inkscape::UI::Tools::NodeTool *tool = 0;
- if (SP_ACTIVE_DESKTOP ) {
- Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
- if (INK_IS_NODE_TOOL(ec)) {
- tool = static_cast<Inkscape::UI::Tools::NodeTool*>(ec);
- }
- }
-
- if(tool){
- Inkscape::UI::ControlPointSelection *cps = tool->_selected_nodes;
- for (Inkscape::UI::ControlPointSelection::iterator i = cps->begin(); i != cps->end(); ++i) {
- Inkscape::UI::Node *node = dynamic_cast<Inkscape::UI::Node*>(*i);
- if (node) {
- std::string id = node->nodeList().subpathList().pm().item()->getId();
-
- int sp = 0;
- bool found_sp = false;
- for(Inkscape::UI::SubpathList::iterator i = node->nodeList().subpathList().begin(); i != node->nodeList().subpathList().end(); ++i,++sp){
- if(&**i == &(node->nodeList())){
- found_sp = true;
- break;
- }
- }
- int nl=0;
- bool found_nl = false;
- for (Inkscape::UI::NodeList::iterator j = node->nodeList().begin(); j != node->nodeList().end(); ++j, ++nl){
- if(&*j==node){
- found_nl = true;
- break;
- }
- }
- std::ostringstream ss;
- ss<< "--selected-nodes=" << id << ":" << sp << ":" << nl;
- Glib::ustring selected = ss.str();
-
- if(found_nl && found_sp)params.push_front(selected);
- else g_warning("Something went wrong while trying to pass selected nodes to extension. Please report a bug.");
- }
+ if (desktop) {
+ Inkscape::Selection * selection = desktop->getSelection();
+ if (!selection->isEmpty()) {
+ selection->setBackup();
}
+ params = selection->params;
+ module->paramListString(params);
}
- }//end add selected nodes
file_listener fileout;
int data_read = execute(command, params, dc->_filename, fileout);
@@ -790,6 +765,7 @@ void Script::effect(Inkscape::Extension::Effect *module,
layer = document->getObjectById(g_quark_to_string(nv->default_layer_id));
}
}
+ desktop->showGrids(nv->grids_visible);
}
sp_namedview_update_layers_from_document(desktop);
@@ -798,6 +774,14 @@ void Script::effect(Inkscape::Extension::Effect *module,
//set the current layer
desktop->setCurrentLayer(layer);
}
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop) {
+ Inkscape::Selection * selection = desktop->getSelection();
+ if (selection && selection->isEmpty() && !desktop->on_live_extension) {
+ selection->restoreBackup();
+ selection->emptyBackup();
+ }
+ }
}
mydoc->release();
}
@@ -833,12 +817,10 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr
g_warning("Error on copy_doc: NULL pointer input.");
return;
}
-
// For copying attributes in root and in namedview
using Inkscape::Util::List;
using Inkscape::XML::AttributeRecord;
std::vector<gchar const *> attribs;
-
// Must explicitly copy root attributes. This must be done first since
// copying grid lines calls "SPGuide::set()" which needs to know the
// width, height, and viewBox of the root element.
@@ -859,80 +841,33 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr
oldroot->setAttribute(name, newroot->attribute(name));
}
-
// Question: Why is the "sodipodi:namedview" special? Treating it as a normal
// elmement results in crashes.
// Seems to be a bug:
// http://inkscape.13.x6.nabble.com/Effect-that-modifies-the-document-properties-tt2822126.html
std::vector<Inkscape::XML::Node *> delete_list;
- Inkscape::XML::Node * oldroot_namedview = NULL;
- Inkscape::XML::Node * newroot_namedview = NULL;
// Make list
for (Inkscape::XML::Node * child = oldroot->firstChild();
child != NULL;
child = child->next()) {
if (!strcmp("sodipodi:namedview", child->name())) {
- oldroot_namedview = child;
for (Inkscape::XML::Node * oldroot_namedview_child = child->firstChild();
oldroot_namedview_child != NULL;
oldroot_namedview_child = oldroot_namedview_child->next()) {
delete_list.push_back(oldroot_namedview_child);
}
- } else {
- delete_list.push_back(child);
+ break;
}
}
- if(!oldroot_namedview)
- {
- g_warning("Error on copy_doc: No namedview on destination document.");
- return;
- }
-
// Unparent (delete)
for (unsigned int i = 0; i < delete_list.size(); i++) {
sp_repr_unparent(delete_list[i]);
}
-
- // Copy
- for (Inkscape::XML::Node * child = newroot->firstChild();
- child != NULL;
- child = child->next()) {
- if (!strcmp("sodipodi:namedview", child->name())) {
- newroot_namedview = child;
- for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild();
- newroot_namedview_child != NULL;
- newroot_namedview_child = newroot_namedview_child->next()) {
- oldroot_namedview->appendChild(newroot_namedview_child->duplicate(oldroot->document()));
- }
- } else {
- oldroot->appendChild(child->duplicate(oldroot->document()));
- }
- }
-
attribs.clear();
-
- // Must explicitly copy namedview attributes.
- // Make a list of all attributes of the old namedview node.
- for (List<AttributeRecord const> iter = oldroot_namedview->attributeList(); iter; ++iter) {
- attribs.push_back(g_quark_to_string(iter->key));
- }
-
- // Delete the attributes of the old namedview node.
- for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
- oldroot_namedview->setAttribute(*it, NULL);
- }
-
- // Set the new attributes.
- for (List<AttributeRecord const> iter = newroot_namedview->attributeList(); iter; ++iter) {
- gchar const *name = g_quark_to_string(iter->key);
- oldroot_namedview->setAttribute(name, newroot_namedview->attribute(name));
- }
-
- /** \todo Restore correct layer */
- /** \todo Restore correct selection */
+ oldroot->mergeFrom(newroot, "id", true, true);
}
/** \brief This function checks the stderr file, and if it has data,
diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp
index 636b9d6a4..32d6f59e3 100644
--- a/src/extension/internal/bitmap/imagemagick.cpp
+++ b/src/extension/internal/bitmap/imagemagick.cpp
@@ -64,6 +64,16 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) :
_imageItems(NULL)
{
SPDesktop *desktop = (SPDesktop*)view;
+ Inkscape::Selection * selection = NULL;
+ if (desktop) {
+ selection = desktop->getSelection();
+ if (selection && !selection->params.empty()) {
+ selection->restoreBackup();
+ if (!desktop->on_live_extension) {
+ selection->emptyBackup();
+ }
+ }
+ }
auto selectedItemList = desktop->selection->items();
int selectCount = (int) boost::distance(selectedItemList);
diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp
index f04007d00..c086405e5 100644
--- a/src/extension/internal/bluredge.cpp
+++ b/src/extension/internal/bluredge.cpp
@@ -53,7 +53,7 @@ BlurEdge::load (Inkscape::Extension::Extension */*module*/)
void
BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *desktop, Inkscape::Extension::Implementation::ImplementationDocumentCache * /*docCache*/)
{
- Inkscape::Selection * selection = static_cast<SPDesktop *>(desktop)->selection;
+
float width = module->get_param_float("blur-width");
int steps = module->get_param_int("num-steps");
@@ -61,6 +61,17 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px");
+ SPDesktop *deskt = static_cast<SPDesktop *>(desktop);
+ Inkscape::Selection * selection = NULL;
+ if (deskt) {
+ selection = deskt->selection;
+ if (selection && !selection->params.empty()) {
+ selection->restoreBackup();
+ if (!deskt->on_live_extension) {
+ selection->emptyBackup();
+ }
+ }
+ }
// TODO need to properly refcount the items, at least
std::vector<SPItem*> items(selection->items().begin(), selection->items().end());
selection->clear();
diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp
index 166e5406f..af4997eba 100644
--- a/src/extension/internal/filter/filter.cpp
+++ b/src/extension/internal/filter/filter.cpp
@@ -122,8 +122,17 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie
}
//printf("Calling filter effect\n");
- Inkscape::Selection * selection = ((SPDesktop *)document)->selection;
-
+ SPDesktop *desktop = (SPDesktop *)document;
+ Inkscape::Selection * selection = NULL;
+ if (desktop) {
+ selection = desktop->selection;
+ if (selection && !selection->params.empty()) {
+ selection->restoreBackup();
+ if (!desktop->on_live_extension) {
+ selection->emptyBackup();
+ }
+ }
+ }
// TODO need to properly refcount the items, at least
std::vector<SPItem*> items(selection->items().begin(), selection->items().end());
diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp
index c7ebf2494..6b3f2efe3 100644
--- a/src/extension/internal/grid.cpp
+++ b/src/extension/internal/grid.cpp
@@ -86,7 +86,17 @@ Glib::ustring build_lines(Geom::Rect bounding_area,
void
Grid::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache * /*docCache*/)
{
- Inkscape::Selection * selection = ((SPDesktop *)document)->selection;
+ SPDesktop *desktop = ((SPDesktop *)document);
+ Inkscape::Selection * selection = NULL;
+ if (desktop) {
+ selection = desktop->getSelection();
+ if (selection && !selection->params.empty()) {
+ selection->restoreBackup();
+ if (!desktop->on_live_extension) {
+ selection->emptyBackup();
+ }
+ }
+ }
Geom::Rect bounding_area = Geom::Rect(Geom::Point(0,0), Geom::Point(100,100));
if (selection->isEmpty()) {
diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp
index 0247e18e9..4c799eb68 100644
--- a/src/extension/prefdialog.cpp
+++ b/src/extension/prefdialog.cpp
@@ -18,6 +18,8 @@
// Used to get SP_ACTIVE_DESKTOP
#include "inkscape.h"
#include "desktop.h"
+#include "document.h"
+#include "document-undo.h"
#include "effect.h"
#include "implementation/implementation.h"
@@ -61,6 +63,13 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co
controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, NULL);
_signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change));
}
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop) {
+ Inkscape::Selection * selection = desktop->getSelection();
+ if (selection) {
+ selection->emptyBackup();
+ }
+ }
hbox->pack_start(*controls, true, true, 0);
hbox->show();
@@ -170,12 +179,29 @@ PrefDialog::run (void) {
void
PrefDialog::preview_toggle (void) {
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDocument *document = SP_ACTIVE_DOCUMENT;
+ Inkscape::Selection * selection = NULL;
+ bool modified = document->isModifiedSinceSave();
+ if(desktop) {
+ selection = desktop->getSelection();
+ if (!selection->isEmpty()) {
+ selection->setBackup();
+ }
+ }
if(_param_preview->get_bool(NULL, NULL)) {
- set_modal(true);
if (_exEnv == NULL) {
+ set_modal(true);
+ if (desktop && selection) {
+ desktop->on_live_extension = true;
+
+ }
_exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, false, false);
_effect->set_execution_env(_exEnv);
_exEnv->run();
+ if (desktop && selection) {
+ selection->clear();
+ }
}
} else {
set_modal(false);