diff options
Diffstat (limited to 'src/selection-chemistry.cpp')
| -rw-r--r-- | src/selection-chemistry.cpp | 131 |
1 files changed, 59 insertions, 72 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 56923859b..29cb208d9 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -35,6 +35,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "desktop.h" #include "desktop-style.h" #include "dir-util.h" +#include "layer-model.h" #include "selection.h" #include "tools-switch.h" #include "desktop-handles.h" @@ -124,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 { @@ -521,16 +537,16 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone) g_slist_free(newsel); } -void sp_edit_clear_all(SPDesktop *dt) +void sp_edit_clear_all(Inkscape::Selection *selection) { - if (!dt) + if (!selection) return; - SPDocument *doc = sp_desktop_document(dt); - sp_desktop_selection(dt)->clear(); + SPDocument *doc = selection->layers()->getDocument(); + selection->clear(); - g_return_if_fail(SP_IS_GROUP(dt->currentLayer())); - GSList *items = sp_item_group_item_list(SP_GROUP(dt->currentLayer())); + g_return_if_fail(SP_IS_GROUP(selection->layers()->currentLayer())); + GSList *items = sp_item_group_item_list(SP_GROUP(selection->layers()->currentLayer())); while (items) { reinterpret_cast<SPObject*>(items->data)->deleteObject(); @@ -721,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->layers()->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; } @@ -748,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; } @@ -806,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->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); } @@ -889,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; } @@ -942,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->layers()->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->layers()->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; } @@ -964,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; } @@ -982,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; } @@ -1040,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->layers()->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->layers()->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; } @@ -1061,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; } @@ -2157,49 +2144,49 @@ sp_selection_scale_times(Inkscape::Selection *selection, gdouble times) } void -sp_selection_move(SPDesktop *desktop, gdouble dx, gdouble dy) +sp_selection_move(Inkscape::Selection *selection, gdouble dx, gdouble dy) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { return; } sp_selection_move_relative(selection, dx, dy); + SPDocument *doc = selection->layers()->getDocument(); if (dx == 0) { - DocumentUndo::maybeDone(sp_desktop_document(desktop), "selector:move:vertical", SP_VERB_CONTEXT_SELECT, + DocumentUndo::maybeDone(doc, "selector:move:vertical", SP_VERB_CONTEXT_SELECT, _("Move vertically")); } else if (dy == 0) { - DocumentUndo::maybeDone(sp_desktop_document(desktop), "selector:move:horizontal", SP_VERB_CONTEXT_SELECT, + DocumentUndo::maybeDone(doc, "selector:move:horizontal", SP_VERB_CONTEXT_SELECT, _("Move horizontally")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(doc, SP_VERB_CONTEXT_SELECT, _("Move")); } } void -sp_selection_move_screen(SPDesktop *desktop, gdouble dx, gdouble dy) +sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) { - Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (selection->isEmpty()) { + if (selection->isEmpty() || !selection->desktop()) { return; } // same as sp_selection_move but divide deltas by zoom factor - gdouble const zoom = desktop->current_zoom(); + gdouble const zoom = selection->desktop()->current_zoom(); gdouble const zdx = dx / zoom; gdouble const zdy = dy / zoom; sp_selection_move_relative(selection, zdx, zdy); + SPDocument *doc = selection->layers()->getDocument(); if (dx == 0) { - DocumentUndo::maybeDone(sp_desktop_document(desktop), "selector:move:vertical", SP_VERB_CONTEXT_SELECT, + DocumentUndo::maybeDone(doc, "selector:move:vertical", SP_VERB_CONTEXT_SELECT, _("Move vertically by pixels")); } else if (dy == 0) { - DocumentUndo::maybeDone(sp_desktop_document(desktop), "selector:move:horizontal", SP_VERB_CONTEXT_SELECT, + DocumentUndo::maybeDone(doc, "selector:move:horizontal", SP_VERB_CONTEXT_SELECT, _("Move horizontally by pixels")); } else { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SELECT, + DocumentUndo::done(doc, SP_VERB_CONTEXT_SELECT, _("Move")); } } |
