diff options
| author | Eric Greveson <eric@greveson.co.uk> | 2013-07-03 22:00:06 +0000 |
|---|---|---|
| committer | Eric Greveson <eric@greveson.co.uk> | 2013-07-03 22:00:06 +0000 |
| commit | 1c75594f5c37e86dec195ec1975254315ef180e9 (patch) | |
| tree | a2ef00ceb7bd72b60c61c61ece4dcfe413fac9f5 /src | |
| parent | Modified dbus interface so that it works in console mode (--dbus-listen) (diff) | |
| download | inkscape-1c75594f5c37e86dec195ec1975254315ef180e9.tar.gz inkscape-1c75594f5c37e86dec195ec1975254315ef180e9.zip | |
Changed dbus interface to treat 'division' like other boolops, with a new
return type for selection_combine to support this (array of string).
This also fixes a bug with not setting the error flag when returning NULL
from this method.
Refactored some more selection verbs to allow use in no-GUI mode.
(bzr r12387.1.5)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/dbus/application-interface.cpp | 6 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 26 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.h | 9 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.xml | 32 | ||||
| -rw-r--r-- | src/extension/dbus/wrapper/inkscape-dbus-wrapper.c | 18 | ||||
| -rw-r--r-- | src/extension/dbus/wrapper/inkscape-dbus-wrapper.h | 6 | ||||
| -rw-r--r-- | src/interface.cpp | 2 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 94 | ||||
| -rw-r--r-- | src/selection-chemistry.h | 12 | ||||
| -rw-r--r-- | src/verbs.cpp | 37 |
10 files changed, 94 insertions, 148 deletions
diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp index 399e1b244..1b1dbf0f5 100644 --- a/src/extension/dbus/application-interface.cpp +++ b/src/extension/dbus/application-interface.cpp @@ -150,7 +150,11 @@ gchar* application_interface_get_active_document(ApplicationInterface *object, GError **error) { - return (gchar*)Inkscape::Extension::Dbus::init_active_document(); + gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document(); + if (!result) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "No active document"); + } + return result; } gchar** diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index f0cc71de1..87b769e26 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -1222,13 +1222,11 @@ document_interface_selection_invert (DocumentInterface *object, GError **error) gboolean document_interface_selection_group (DocumentInterface *object, GError **error) { - //sp_selection_group (object->desk); return dbus_call_verb (object, SP_VERB_SELECTION_GROUP, error); } gboolean document_interface_selection_ungroup (DocumentInterface *object, GError **error) { - //sp_selection_ungroup (object->desk); return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error); } @@ -1362,8 +1360,8 @@ document_interface_selection_to_path (DocumentInterface *object, GError **error) } -gchar * -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, +gboolean +document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, GError **error) { if (strcmp(cmd, "union") == 0) @@ -1374,20 +1372,14 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, dbus_call_verb (object, SP_VERB_SELECTION_DIFF, error); else if (strcmp(cmd, "exclusion") == 0) dbus_call_verb (object, SP_VERB_SELECTION_SYMDIFF, error); - else - return NULL; - - if (object->context.getSelection()->singleRepr() != NULL) - return g_strdup(object->context.getSelection()->singleRepr()->attribute("id")); - return NULL; -} - -gboolean -document_interface_selection_divide (DocumentInterface *object, char ***out, GError **error) -{ - dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else if (strcmp(cmd, "division") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Operation command not recognised"); + return FALSE; + } - return document_interface_selection_get (object, out, error); + return document_interface_selection_get (object, newpaths, error); } gboolean diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 9b8d34dd3..5eef3d0c0 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -363,14 +363,9 @@ document_interface_selection_get_center (DocumentInterface *object); gboolean document_interface_selection_to_path (DocumentInterface *object, GError **error); -gchar * -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, - GError **error); - gboolean -document_interface_selection_divide (DocumentInterface *object, - char ***out, GError **error); - +document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, + GError **error); gboolean document_interface_selection_change_level (DocumentInterface *object, gchar *cmd, diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index aeacfae44..7481c0893 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -21,7 +21,7 @@ <node name="/org/inkscape/document" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" > - +c <interface name="org.inkscape.document"> <!-- MISC FUNCTIONS --> @@ -1348,36 +1348,20 @@ <doc:summary>Type of combination.</doc:summary> </doc:doc> </arg> - <arg type="s" name="newpath" direction="out" > - <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <arg type="as" name="newpaths" direction="out" > <doc:doc> - <doc:summary>The new path created, if there is one. NULL otherwise.</doc:summary> + <doc:summary>List of the ids of resulting paths after applying the operation.</doc:summary> </doc:doc> </arg> <doc:doc> <doc:description> <doc:para>Will erase all objects in the selection and replace with a single aggregate path.</doc:para> <doc:para>There are 5 types that can be passed in:</doc:para> - <doc:para>Union: The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.)</doc:para> - <doc:para>Intersection: The new shape is composed of the area where ALL the objects in the selection overlap. If there is no area where all shapes overlap the new shape will be empty.</doc:para> - <doc:para>Difference: The area of the second shape is subtracted from the first, only works with two objects.</doc:para> - <doc:para>Exclusion: The new shape is the area(s) where none of the objects in the selection overlaped. Only works with two objects.</doc:para> - <doc:para>Division: the first object is split into multiple segments by the second object. Only works with two objects and if multiple paths result they are grouped and the group id is returned.</doc:para> - </doc:description> - </doc:doc> - </method> - - <method name="selection_divide"> - <arg type="as" name="pieces" direction="out" > - <!-- <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> --> - <doc:doc> - <doc:summary>List of the ids of resulting paths.</doc:summary> - </doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para>Returns the result of cutting the bottom object by all other intersecting paths.</doc:para> - <doc:para>This may make many seperate layers.</doc:para> + <doc:para>'union': The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.)</doc:para> + <doc:para>'intersection': The new shape is composed of the area where ALL the objects in the selection overlap. If there is no area where all shapes overlap the new shape will be empty.</doc:para> + <doc:para>'difference': The area of the second shape is subtracted from the first, only works with two objects.</doc:para> + <doc:para>'exclusion': The new shape is the area(s) where none of the objects in the selection overlaped. Only works with two objects.</doc:para> + <doc:para>'division': the first object is split into multiple segments by the second object. Only works with two objects.</doc:para> </doc:description> </doc:doc> </method> diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c index 0be1be42e..c7e453593 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c @@ -688,23 +688,13 @@ inkscape_selection_to_path (DocumentInterface *doc, GError **error) } //static -char * -inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) -{ - char * OUT_newpath; - DBusGProxy *proxy = doc->proxy; - org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpath, error); - return OUT_newpath; -} - -//static char ** -inkscape_selection_divide (DocumentInterface *doc, GError **error) +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) { - char ** OUT_pieces; + char ** OUT_newpaths; DBusGProxy *proxy = doc->proxy; - org_inkscape_document_selection_divide (proxy, &OUT_pieces, error); - return OUT_pieces; + org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpaths, error); + return OUT_newpaths; } //static diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h index 684f1b142..79f8188d4 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -304,12 +304,8 @@ gboolean inkscape_selection_to_path (DocumentInterface *doc, GError **error); //static -char * -inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); - -//static char ** -inkscape_selection_divide (DocumentInterface *doc, GError **error); +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); //static gboolean diff --git a/src/interface.cpp b/src/interface.cpp index e3036afdd..98c30bf3c 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -1987,7 +1987,7 @@ void ContextMenu::MakeGroupMenu(void) void ContextMenu::ActivateGroup(void) { - sp_selection_group(_desktop); + sp_selection_group(_desktop->selection, _desktop); } void ContextMenu::ActivateUngroup(void) diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 591f9d68d..9f8dd984a 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -125,6 +125,21 @@ because the layer manipulation code uses them. It should be rewritten specifical for that purpose. */ +// helper for printing error messages, regardless of whether we have a GUI or not +// If desktop == NULL, errors will be shown on stderr +static void +selection_display_message(SPDesktop *desktop, Inkscape::MessageType msgType, Glib::ustring const &msg) +{ + if (desktop) { + desktop->messageStack()->flash(msgType, msg); + } else { + if (msgType == Inkscape::IMMEDIATE_MESSAGE || + msgType == Inkscape::WARNING_MESSAGE || + msgType == Inkscape::ERROR_MESSAGE) { + g_printerr("%s\n", msg.c_str()); + } + } +} namespace Inkscape { @@ -722,20 +737,14 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc group->setPosition(topmost + 1); } -void sp_selection_group(SPDesktop *desktop) +void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) { - if (desktop == NULL) { - return; - } - - SPDocument *doc = sp_desktop_document(desktop); + SPDocument *doc = selection->layerModel()->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::Selection *selection = sp_desktop_selection(desktop); - // Check if something is selected. if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>some objects</b> to group.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>some objects</b> to group.")); return; } @@ -749,22 +758,17 @@ void sp_selection_group(SPDesktop *desktop) sp_selection_group_impl(p, group, xml_doc, doc); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_GROUP, + DocumentUndo::done(doc, SP_VERB_SELECTION_GROUP, _("Group")); selection->set(group); Inkscape::GC::release(group); } -void sp_selection_ungroup(SPDesktop *desktop) +void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) { - if (desktop == NULL) - return; - - Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>group</b> to ungroup.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select a <b>group</b> to ungroup.")); return; } @@ -807,12 +811,12 @@ void sp_selection_ungroup(SPDesktop *desktop) g_slist_free(new_select); } if (!ungrouped) { - desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No groups</b> to ungroup in the selection.")); + selection_display_message(desktop, Inkscape::ERROR_MESSAGE, _("<b>No groups</b> to ungroup in the selection.")); } g_slist_free(items); - - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_UNGROUP, + + DocumentUndo::done(selection->layerModel()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); } @@ -890,22 +894,17 @@ static SPObject *prev_sibling(SPObject *child) } void -sp_selection_raise(SPDesktop *desktop) +sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) { - if (!desktop) - return; - - Inkscape::Selection *selection = sp_desktop_selection(desktop); - GSList const *items = const_cast<GSList *>(selection->itemList()); if (!items) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise.")); return; } SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { - desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); + selection_display_message(desktop, Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); return; } @@ -943,21 +942,17 @@ sp_selection_raise(SPDesktop *desktop) g_slist_free(rev); } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_RAISE, + DocumentUndo::done(selection->layerModel()->getDocument(), SP_VERB_SELECTION_RAISE, //TRANSLATORS: "Raise" means "to raise an object" in the undo history C_("Undo action", "Raise")); } -void sp_selection_raise_to_top(SPDesktop *desktop) +void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop) { - if (desktop == NULL) - return; - - SPDocument *document = sp_desktop_document(desktop); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPDocument *document = selection->layerModel()->getDocument(); if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise to top.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise to top.")); return; } @@ -965,7 +960,7 @@ void sp_selection_raise_to_top(SPDesktop *desktop) SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { - desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); + selection_display_message(desktop, Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); return; } @@ -983,22 +978,17 @@ void sp_selection_raise_to_top(SPDesktop *desktop) _("Raise to top")); } -void sp_selection_lower(SPDesktop *desktop) +void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - if (desktop == NULL) - return; - - Inkscape::Selection *selection = sp_desktop_selection(desktop); - GSList const *items = const_cast<GSList *>(selection->itemList()); if (!items) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower.")); return; } SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { - desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); + selection_display_message(desktop, Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); return; } @@ -1041,20 +1031,16 @@ void sp_selection_lower(SPDesktop *desktop) g_slist_free(rev); } - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_LOWER, + DocumentUndo::done(selection->layerModel()->getDocument(), SP_VERB_SELECTION_LOWER, _("Lower")); } -void sp_selection_lower_to_bottom(SPDesktop *desktop) +void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop) { - if (desktop == NULL) - return; - - SPDocument *document = sp_desktop_document(desktop); - Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPDocument *document = selection->layerModel()->getDocument(); if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower to bottom.")); + selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower to bottom.")); return; } @@ -1062,7 +1048,7 @@ void sp_selection_lower_to_bottom(SPDesktop *desktop) SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { - desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); + selection_display_message(desktop, Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>.")); return; } diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index f58ede21a..f7a4f928c 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -77,13 +77,13 @@ void sp_selection_tile(SPDesktop *desktop, bool apply = true); void sp_selection_untile(SPDesktop *desktop); //void sp_selection_group_impl(GSList const *reprs_to_group, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc); -void sp_selection_group(SPDesktop *desktop); -void sp_selection_ungroup(SPDesktop *desktop); +void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop); -void sp_selection_raise(SPDesktop *desktop); -void sp_selection_raise_to_top(SPDesktop *desktop); -void sp_selection_lower(SPDesktop *desktop); -void sp_selection_lower_to_bottom(SPDesktop *desktop); +void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop); SPCSSAttr *take_style_from_item (SPItem *item); diff --git a/src/verbs.cpp b/src/verbs.cpp index 6187cfb4c..fed9622fb 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1089,6 +1089,24 @@ void SelectionVerb::perform(SPAction *action, void *data) case SP_VERB_SELECTION_SLICE: sp_selected_path_slice(selection, dt); break; + case SP_VERB_SELECTION_TO_FRONT: + sp_selection_raise_to_top(selection, dt); + break; + case SP_VERB_SELECTION_TO_BACK: + sp_selection_lower_to_bottom(selection, dt); + break; + case SP_VERB_SELECTION_RAISE: + sp_selection_raise(selection, dt); + break; + case SP_VERB_SELECTION_LOWER: + sp_selection_lower(selection, dt); + break; + case SP_VERB_SELECTION_GROUP: + sp_selection_group(selection, dt); + break; + case SP_VERB_SELECTION_UNGROUP: + sp_selection_ungroup(selection, dt); + break; default: handled = false; break; @@ -1107,25 +1125,6 @@ void SelectionVerb::perform(SPAction *action, void *data) g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { - case SP_VERB_SELECTION_TO_FRONT: - sp_selection_raise_to_top(dt); - break; - case SP_VERB_SELECTION_TO_BACK: - sp_selection_lower_to_bottom(dt); - break; - case SP_VERB_SELECTION_RAISE: - sp_selection_raise(dt); - break; - case SP_VERB_SELECTION_LOWER: - sp_selection_lower(dt); - break; - case SP_VERB_SELECTION_GROUP: - sp_selection_group(dt); - break; - case SP_VERB_SELECTION_UNGROUP: - sp_selection_ungroup(dt); - break; - case SP_VERB_SELECTION_TEXTTOPATH: text_put_on_path(); break; |
