diff options
| author | Eric Greveson <eric@greveson.co.uk> | 2013-07-04 14:01:44 +0000 |
|---|---|---|
| committer | Eric Greveson <eric@greveson.co.uk> | 2013-07-04 14:01:44 +0000 |
| commit | 104efe4e3ecadc975ab76748c66f041abf8ee7b1 (patch) | |
| tree | 01c6a23e2ee0bf43fda8eb78441a34e9dc338a3b /src | |
| parent | Merge recent changes from inkscape trunk (diff) | |
| download | inkscape-104efe4e3ecadc975ab76748c66f041abf8ee7b1.tar.gz inkscape-104efe4e3ecadc975ab76748c66f041abf8ee7b1.zip | |
Code readability improvements and licence changes for action-context.*
based on merge request code review and feedback
(bzr r12387.1.7)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.cpp | 50 | ||||
| -rw-r--r-- | src/desktop.h | 4 | ||||
| -rw-r--r-- | src/extension/dbus/dbus-init.cpp | 4 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 299 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.h | 2 | ||||
| -rw-r--r-- | src/extension/effect.cpp | 7 | ||||
| -rw-r--r-- | src/helper/action-context.cpp | 4 | ||||
| -rw-r--r-- | src/helper/action-context.h | 2 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 22 | ||||
| -rw-r--r-- | src/selection-describer.cpp | 4 | ||||
| -rw-r--r-- | src/selection.cpp | 14 | ||||
| -rw-r--r-- | src/selection.h | 8 | ||||
| -rw-r--r-- | src/splivarot.cpp | 2 | ||||
| -rw-r--r-- | src/verbs.cpp | 91 | ||||
| -rw-r--r-- | src/verbs.h | 2 |
15 files changed, 210 insertions, 305 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp index 485fcfcc4..ce740f76f 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -96,7 +96,7 @@ SPDesktop::SPDesktop() : _dlg_mgr( 0 ), namedview( 0 ), canvas( 0 ), - layer_model( 0 ), + layers( 0 ), selection( 0 ), event_context( 0 ), layer_manager( 0 ), @@ -142,11 +142,11 @@ SPDesktop::SPDesktop() : _d2w.setIdentity(); _w2d.setIdentity(); - layer_model = new Inkscape::LayerModel(); - layer_model->_layer_activated_signal.connect(sigc::bind(sigc::ptr_fun(_layer_activated), this)); - layer_model->_layer_deactivated_signal.connect(sigc::bind(sigc::ptr_fun(_layer_deactivated), this)); - layer_model->_layer_changed_signal.connect(sigc::bind(sigc::ptr_fun(_layer_hierarchy_changed), this)); - selection = Inkscape::GC::release( new Inkscape::Selection(layer_model, this) ); + layers = new Inkscape::LayerModel(); + layers->_layer_activated_signal.connect(sigc::bind(sigc::ptr_fun(_layer_activated), this)); + layers->_layer_deactivated_signal.connect(sigc::bind(sigc::ptr_fun(_layer_deactivated), this)); + layers->_layer_changed_signal.connect(sigc::bind(sigc::ptr_fun(_layer_hierarchy_changed), this)); + selection = Inkscape::GC::release( new Inkscape::Selection(layers, this) ); } void @@ -176,7 +176,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid dkey = SPItem::display_key_new(1); /* Connect display key to layer model */ - layer_model->setDisplayKey(dkey); + layers->setDisplayKey(dkey); /* Connect document */ setDocument (document); @@ -367,7 +367,7 @@ void SPDesktop::destroy() g_object_unref (G_OBJECT (ec)); } - delete layer_model; + delete layers; if (layer_manager) { delete layer_manager; @@ -491,42 +491,42 @@ void SPDesktop::displayColorModeToggle() { // Pass-through LayerModel functions SPObject *SPDesktop::currentRoot() const { - return layer_model->currentRoot(); + return layers->currentRoot(); } SPObject *SPDesktop::currentLayer() const { - return layer_model->currentLayer(); + return layers->currentLayer(); } void SPDesktop::setCurrentLayer(SPObject *object) { - layer_model->setCurrentLayer(object); + layers->setCurrentLayer(object); } void SPDesktop::toggleLayerSolo(SPObject *object) { - layer_model->toggleLayerSolo(object); + layers->toggleLayerSolo(object); } void SPDesktop::toggleHideAllLayers(bool hide) { - layer_model->toggleHideAllLayers(hide); + layers->toggleHideAllLayers(hide); } void SPDesktop::toggleLockAllLayers(bool lock) { - layer_model->toggleLockAllLayers(lock); + layers->toggleLockAllLayers(lock); } void SPDesktop::toggleLockOtherLayers(SPObject *object) { - layer_model->toggleLockOtherLayers(object); + layers->toggleLockOtherLayers(object); } bool SPDesktop::isLayer(SPObject *object) const { - return layer_model->isLayer(object); + return layers->isLayer(object); } /** @@ -1491,7 +1491,7 @@ SPDesktop::setDocument (SPDocument *doc) this->doc()->getRoot()->invoke_hide(dkey); } - layer_model->setDocument(doc); + layers->setDocument(doc); // remove old EventLog if it exists (see also: bug #1071082) if (event_log) { @@ -1599,9 +1599,9 @@ _onSelectionChanged */ SPItem *item=selection->singleItem(); if (item) { - SPObject *layer=desktop->layer_model->layerForObject(item); + SPObject *layer=desktop->layers->layerForObject(item); if ( layer && layer != desktop->currentLayer() ) { - desktop->layer_model->setCurrentLayer(layer); + desktop->layers->setCurrentLayer(layer); } } } @@ -1646,9 +1646,9 @@ _layer_hierarchy_changed(SPObject */*top*/, SPObject *bottom, /// Called when document is starting to be rebuilt. static void _reconstruction_start(SPDesktop * desktop) { - // printf("Desktop, starting reconstruction\n"); + g_debug("Desktop, starting reconstruction\n"); desktop->_reconstruction_old_layer_id = desktop->currentLayer()->getId() ? desktop->currentLayer()->getId() : ""; - desktop->layer_model->reset(); + desktop->layers->reset(); /* GSList const * selection_objs = desktop->selection->list(); @@ -1658,22 +1658,22 @@ static void _reconstruction_start(SPDesktop * desktop) */ desktop->selection->clear(); - // printf("Desktop, starting reconstruction end\n"); + g_debug("Desktop, starting reconstruction end\n"); } /// Called when document rebuild is finished. static void _reconstruction_finish(SPDesktop * desktop) { - // printf("Desktop, finishing reconstruction\n"); + g_debug("Desktop, finishing reconstruction\n"); if ( !desktop->_reconstruction_old_layer_id.empty() ) { SPObject * newLayer = desktop->namedview->document->getObjectById(desktop->_reconstruction_old_layer_id); if (newLayer != NULL) { - desktop->layer_model->setCurrentLayer(newLayer); + desktop->layers->setCurrentLayer(newLayer); } desktop->_reconstruction_old_layer_id.clear(); - // printf("Desktop, finishing reconstruction end\n"); } + g_debug("Desktop, finishing reconstruction end\n"); } /** diff --git a/src/desktop.h b/src/desktop.h index 661470ded..9a3c609d0 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -125,7 +125,7 @@ public: Inkscape::UI::Dialog::DialogManager *_dlg_mgr; SPNamedView *namedview; SPCanvas *canvas; - Inkscape::LayerModel *layer_model; + Inkscape::LayerModel *layers; /// current selection; will never generally be NULL Inkscape::Selection *selection; SPEventContext *event_context; @@ -263,7 +263,7 @@ public: void set_active (bool new_active); - // Could make all callers use layer_model instead of passing calls through? + // Could make all callers use this->layers instead of passing calls through? SPObject *currentRoot() const; SPObject *currentLayer() const; void setCurrentLayer(SPObject *object); diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 96d72c0f6..fe59fc154 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -153,7 +153,7 @@ init_active_document() name.c_str()); // Set the document info for this interface - obj->context = inkscape_active_action_context(); + obj->doc_context = inkscape_active_action_context(); } return strdup(name.c_str()); } @@ -178,7 +178,7 @@ dbus_init_desktop_interface (SPDesktop * dt) obj = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->context = Inkscape::ActionContext(dt); + obj->doc_context = Inkscape::ActionContext(dt); obj->updates = TRUE; dt->dbus_document_interface=obj; return strdup(name.c_str()); diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 87b769e26..6d6f983c5 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -190,7 +190,7 @@ selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) { const GSList *oldsel = g_slist_copy((GSList *)sel->list()); - sel->set(get_object_by_name(sel->layerModel()->getDocument(), name, error)); + sel->set(get_object_by_name(sel->layers()->getDocument(), name, error)); return oldsel; } @@ -224,8 +224,8 @@ dbus_create_node (SPDocument *doc, const gchar *type) gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) { SPCSSAttr *style = NULL; - if (object->context.getDesktop()) { - style = sp_desktop_get_style(object->context.getDesktop(), TRUE); + if (object->doc_context.getDesktop()) { + style = sp_desktop_get_style(object->doc_context.getDesktop(), TRUE); } if (style) { Glib::ustring str; @@ -236,13 +236,11 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE); } - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), 0, (gchar *)desc); - //} else { - //document_interface_pause_updates(object, error); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, (gchar *)desc); } return strdup(newNode->attribute("id")); @@ -259,21 +257,17 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks gboolean dbus_call_verb (DocumentInterface *object, int verbid, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->context); + SPAction *action = verb->get_action(object->doc_context); if ( action ) { - //if (!object->updates) - //document_interface_pause_updates (object, error); sp_action_perform( action, NULL ); if (object->updates) - Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); - //if (!object->updates) - //document_interface_pause_updates (object, error); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); return TRUE; } } @@ -281,6 +275,20 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) return FALSE; } +/* + * Check that the desktop is not NULL. If it is NULL, set the error to a useful message. + */ +bool +ensure_desktop_valid(SPDesktop* desk, GError **error) +{ + if (desk) { + return true; + } + + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document interface action requires a GUI"); + return false; +} + /**************************************************************************** DOCUMENT INTERFACE CLASS STUFF ****************************************************************************/ @@ -313,7 +321,7 @@ document_interface_class_init (DocumentInterfaceClass *klass) static void document_interface_init (DocumentInterface *object) { - object->context = Inkscape::ActionContext(); + object->doc_context = Inkscape::ActionContext(); } @@ -331,24 +339,24 @@ document_interface_new (void) gboolean document_interface_delete_all(DocumentInterface *object, GError ** /*error*/) { - sp_edit_clear_all(object->context.getSelection()); + sp_edit_clear_all(object->doc_context.getSelection()); return TRUE; } gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->context); + SPAction *action = verb->get_action(object->doc_context); if ( action ) { sp_action_perform( action, NULL ); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); } return TRUE; } @@ -368,7 +376,7 @@ document_interface_rectangle (DocumentInterface *object, int x, int y, { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:rect"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:rect"); sp_repr_set_int(newNode, "x", x); //could also use newNode->setAttribute() sp_repr_set_int(newNode, "y", y); sp_repr_set_int(newNode, "width", width); @@ -380,7 +388,7 @@ gchar* document_interface_ellipse_center (DocumentInterface *object, int cx, int cy, int rx, int ry, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "arc"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -395,7 +403,7 @@ document_interface_polygon (DocumentInterface *object, int cx, int cy, GError **error) { gdouble rot = ((rotation / 180.0) * 3.14159265) - ( 3.14159265 / 2.0); - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "true"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -416,7 +424,7 @@ document_interface_star (DocumentInterface *object, int cx, int cy, int r1, int r2, int sides, gdouble rounded, gdouble arg1, gdouble arg2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "false"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -445,7 +453,7 @@ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); std::stringstream out; // Not sure why this works. out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y; @@ -457,7 +465,7 @@ gchar* document_interface_spiral (DocumentInterface *object, int cx, int cy, int r, int revolutions, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "spiral"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -478,13 +486,13 @@ gchar* document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - Inkscape::XML::Node *text_node = dbus_create_node(object->context.getDocument(), "svg:text"); + Inkscape::XML::Node *text_node = dbus_create_node(object->doc_context.getDocument(), "svg:text"); sp_repr_set_int(text_node, "x", x); sp_repr_set_int(text_node, "y", y); //just a workaround so i can get an spitem from the name gchar *name = finish_create_shape (object, error, text_node, (gchar *)"create text"); - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); sp_te_set_repr_text_multiline(text_obj, text); return name; @@ -497,16 +505,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena if (!uri) return FALSE; - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:image"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:image"); sp_repr_set_int(newNode, "x", x); sp_repr_set_int(newNode, "y", y); newNode->setAttribute("xlink:href", uri); - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) - Inkscape::DocumentUndo::done(object->context.getDocument(), 0, "Imported bitmap."); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, "Imported bitmap."); //g_free(uri); return strdup(newNode->attribute("id")); @@ -514,18 +522,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *newNode = xml_doc->createElement(type); - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) { Inkscape::DocumentUndo::done(doc, 0, (gchar *)"created empty node"); - //} else { - //document_interface_pause_updates(object, error); } return strdup(newNode->attribute("id")); @@ -537,22 +543,19 @@ gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** gdouble document_interface_document_get_width (DocumentInterface *object) { - return object->context.getDocument()->getWidth(); + return object->doc_context.getDocument()->getWidth(); } gdouble document_interface_document_get_height (DocumentInterface *object) { - return object->context.getDocument()->getHeight(); + return object->doc_context.getDocument()->getHeight(); } gchar *document_interface_document_get_css(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document get CSS requires a GUI"); - return NULL; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), NULL); SPCSSAttr *current = desk->current; Glib::ustring str; sp_repr_css_write_string(current, str); @@ -562,11 +565,8 @@ gchar *document_interface_document_get_css(DocumentInterface *object, GError ** gboolean document_interface_document_merge_css(DocumentInterface *object, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document merge CSS requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(style, stylestring); sp_desktop_set_style(desk, style); @@ -576,11 +576,8 @@ gboolean document_interface_document_merge_css(DocumentInterface *object, gboolean document_interface_document_set_css(DocumentInterface *object, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set CSS requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (style, stylestring); //Memory leak? @@ -604,11 +601,8 @@ document_interface_document_set_display_area (DocumentInterface *object, double border, GError **error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set display area requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); desk->set_display_area (x0, y0, x1, @@ -621,7 +615,7 @@ document_interface_document_set_display_area (DocumentInterface *object, GArray * document_interface_document_get_display_area (DocumentInterface *object) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (!desk) { return NULL; } @@ -650,7 +644,7 @@ gboolean document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); @@ -670,7 +664,7 @@ document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (!newNode) return FALSE; @@ -684,7 +678,7 @@ document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "New value string was empty.")) return FALSE; @@ -699,7 +693,7 @@ gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "Attribute name empty.")) return NULL; @@ -713,11 +707,11 @@ gboolean document_interface_move (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); if (!oldsel) return FALSE; - sp_selection_move (object->context.getSelection(), x, 0 - y); - selection_restore(object->context.getSelection(), oldsel); + sp_selection_move (object->doc_context.getSelection(), x, 0 - y); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -725,13 +719,13 @@ gboolean document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); if (!oldsel) return FALSE; - Inkscape::Selection * sel = object->context.getSelection(); - sp_selection_move (object->context.getSelection(), x - selection_get_center_x(sel), + Inkscape::Selection * sel = object->doc_context.getSelection(); + sp_selection_move (object->doc_context.getSelection(), x - selection_get_center_x(sel), 0 - (y - selection_get_center_y(sel))); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -739,18 +733,18 @@ gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); if (!oldsel) return FALSE; dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), pathname, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), pathname, error); if (!node) return NULL; @@ -787,7 +781,7 @@ document_interface_modify_css (DocumentInterface *object, gchar *shape, { // Doesn't like non-variable strings for some reason. gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (cssattrb, error, "Attribute string empty.")) return FALSE; @@ -808,7 +802,7 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, { gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (stylestring, error, "Style string empty.")) return FALSE; @@ -854,12 +848,12 @@ gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); if (!oldsel) return FALSE; document_interface_selection_move_to_layer(object, layerstr, error); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -867,7 +861,7 @@ GArray *document_interface_get_node_coordinates(DocumentInterface * /*object*/, { //FIXME: Needs lot's of work. /* - Inkscape::XML::Node *shapenode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *shapenode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -885,7 +879,7 @@ gboolean document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); //TODO verify object type if (!text_obj) return FALSE; @@ -902,7 +896,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) //TODO verify object type @@ -931,7 +925,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, gboolean document_interface_save (DocumentInterface *object, GError **error) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); printf("1: %s\n2: %s\n3: %s\n", doc->getURI(), doc->getBase(), doc->getName()); if (doc->getURI()) return document_interface_save_as (object, doc->getURI(), error); @@ -941,14 +935,14 @@ document_interface_save (DocumentInterface *object, GError **error) gboolean document_interface_load(DocumentInterface *object, gchar *filename, GError ** /*error*/) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); sp_file_open(file, NULL, TRUE, TRUE); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); } return TRUE; } @@ -957,12 +951,12 @@ gchar * document_interface_import (DocumentInterface *object, gchar *filename, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); SPObject *new_obj = NULL; new_obj = file_import(doc, file, NULL); @@ -973,7 +967,8 @@ gboolean document_interface_save_as (DocumentInterface *object, const gchar *filename, GError **error) { - SPDocument * doc = object->context.getDocument(); + // FIXME: Isn't there a verb we can use for this instead? + SPDocument * doc = object->doc_context.getDocument(); #ifdef WITH_GNOME_VFS const Glib::ustring file(filename); return file_save_remote(doc, file, NULL, TRUE, TRUE); @@ -986,18 +981,16 @@ document_interface_save_as (DocumentInterface *object, Inkscape::Extension::save(NULL, doc, filename, false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } catch (...) { - //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); + // FIXME: catch ... is not usually a great idea, why is it needed here? return false; } - //SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); - //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved."); return true; } gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); if (doc) { doc->modified_since_save = FALSE; } @@ -1008,7 +1001,7 @@ gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError gboolean document_interface_print_to_file (DocumentInterface *object, GError **error) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); return TRUE; @@ -1053,45 +1046,27 @@ document_interface_redo (DocumentInterface *object, GError **error) void document_interface_pause_updates(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document pause updates requires a GUI"); - return; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); object->updates = FALSE; desk->canvas->drawing_disabled = 1; - //desk->canvas->need_redraw = 0; - //desk->canvas->need_repick = 0; - //object->context.getDocument()->root->uflags = FALSE; - //object->context.getDocument()->root->mflags = FALSE; } void document_interface_resume_updates(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document resume updates requires a GUI"); - return; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); object->updates = TRUE; desk->canvas->drawing_disabled = 0; - //desk->canvas->need_redraw = 1; - //desk->canvas->need_repick = 1; - //object->context.getDocument()->root->uflags = TRUE; - //object->context.getDocument()->root->mflags = TRUE; - //object->context.getDocument()->_updateDocument(); //FIXME: use better verb than rect. - Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); } void document_interface_update(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document update requires a GUI"); - return; - } - SPDocument *doc = object->context.getDocument(); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); + SPDocument *doc = object->doc_context.getDocument(); doc->getRoot()->uflags = TRUE; doc->getRoot()->mflags = TRUE; desk->enableInteraction(); @@ -1108,7 +1083,7 @@ void document_interface_update(DocumentInterface *object, GError ** error) gboolean document_interface_selection_get(DocumentInterface *object, char ***out, GError ** /*error*/) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); GSList const *oldsel = sel->list(); int size = g_slist_length((GSList *) oldsel); @@ -1128,11 +1103,11 @@ gboolean document_interface_selection_get(DocumentInterface *object, char ***out gboolean document_interface_selection_add (DocumentInterface *object, char *name, GError **error) { - SPObject * obj = get_object_by_name(object->context.getDocument(), name, error); + SPObject * obj = get_object_by_name(object->doc_context.getDocument(), name, error); if (!obj) return FALSE; - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); selection->add(obj); return TRUE; @@ -1151,8 +1126,8 @@ document_interface_selection_add_list (DocumentInterface *object, gboolean document_interface_selection_set(DocumentInterface *object, char *name, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); - Inkscape::Selection *selection = object->context.getSelection(); + SPDocument * doc = object->doc_context.getDocument(); + Inkscape::Selection *selection = object->doc_context.getSelection(); selection->set(doc->getObjectById(name)); return TRUE; } @@ -1161,7 +1136,7 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { - object->context.getSelection()->clear(); + object->doc_context.getSelection()->clear(); int i; for (i=0;names[i] != NULL;i++) { document_interface_selection_add(object, names[i], error); @@ -1171,7 +1146,7 @@ document_interface_selection_set_list (DocumentInterface *object, gboolean document_interface_selection_rotate(DocumentInterface *object, int angle, GError ** /*error*/) { - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); sp_selection_rotate(selection, angle); return TRUE; } @@ -1179,20 +1154,18 @@ gboolean document_interface_selection_rotate(DocumentInterface *object, int angl gboolean document_interface_selection_delete (DocumentInterface *object, GError **error) { - //sp_selection_delete (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error); } gboolean document_interface_selection_clear(DocumentInterface *object, GError ** /*error*/) { - object->context.getSelection()->clear(); + object->doc_context.getSelection()->clear(); return TRUE; } gboolean document_interface_select_all (DocumentInterface *object, GError **error) { - //sp_edit_select_all (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL, error); } @@ -1200,7 +1173,6 @@ gboolean document_interface_select_all_in_all_layers(DocumentInterface *object, GError **error) { - //sp_edit_select_all_in_all_layers (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); } @@ -1215,7 +1187,6 @@ gboolean document_interface_selection_box(DocumentInterface * /*object*/, int /* gboolean document_interface_selection_invert (DocumentInterface *object, GError **error) { - //sp_edit_invert (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_INVERT, error); } @@ -1233,46 +1204,30 @@ document_interface_selection_ungroup (DocumentInterface *object, GError **error) gboolean document_interface_selection_cut (DocumentInterface *object, GError **error) { - //desktop_ensure_active (object->desk); - //sp_selection_cut (object->desk); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_CUT, error); } gboolean document_interface_selection_copy (DocumentInterface *object, GError **error) { - //desktop_ensure_active (object->desk); - //sp_selection_copy (); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_COPY, error); } -/* -gboolean -document_interface_selection_paste (DocumentInterface *object, GError **error) -{ - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection paste requires a GUI"); - return FALSE; - } - desktop_ensure_active (desk); - if (!object->updates) - document_interface_pause_updates (object, error); - sp_selection_paste (object->desk, TRUE); - if (!object->updates) - document_interface_pause_updates (object, error); - return TRUE; - //return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); -} -*/ + gboolean document_interface_selection_paste (DocumentInterface *object, GError **error) { + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); } gboolean document_interface_selection_scale(DocumentInterface *object, gdouble grow, GError ** /*error*/) { - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); if (!selection) { return FALSE; @@ -1283,13 +1238,13 @@ gboolean document_interface_selection_scale(DocumentInterface *object, gdouble g gboolean document_interface_selection_move(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - sp_selection_move(object->context.getSelection(), x, 0 - y); //switching coordinate systems. + sp_selection_move(object->doc_context.getSelection(), x, 0 - y); //switching coordinate systems. return TRUE; } gboolean document_interface_selection_move_to(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); Geom::OptRect sel_bbox = sel->visualBounds(); if (sel_bbox) { @@ -1306,19 +1261,16 @@ gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error) { - SPDesktop *dt = object->context.getDesktop(); - if (!dt) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection move to layer requires a GUI"); - return FALSE; - } + SPDesktop *dt = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(dt, error), FALSE); - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); // check if something is selected if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->context.getDocument(), layerstr, error); + SPObject *next = get_object_by_name(object->doc_context.getDocument(), layerstr, error); if (!next) return FALSE; @@ -1327,7 +1279,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, sp_selection_cut(dt); - object->context.getSelection()->layerModel()->setCurrentLayer(next); + object->doc_context.getSelection()->layers()->setCurrentLayer(next); sp_selection_paste(dt, TRUE); } @@ -1337,7 +1289,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, GArray * document_interface_selection_get_center (DocumentInterface *object) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); if (sel) { @@ -1403,9 +1355,9 @@ document_interface_selection_change_level (DocumentInterface *object, gchar *cmd gchar *document_interface_layer_new(DocumentInterface *object, GError ** /*error*/) { - Inkscape::LayerModel * layerModel = object->context.getSelection()->layerModel(); - SPObject *new_layer = Inkscape::create_layer(layerModel->currentRoot(), layerModel->currentLayer(), Inkscape::LPOS_BELOW); - layerModel->setCurrentLayer(new_layer); + Inkscape::LayerModel * layers = object->doc_context.getSelection()->layers(); + SPObject *new_layer = Inkscape::create_layer(layers->currentRoot(), layers->currentLayer(), Inkscape::LPOS_BELOW); + layers->setCurrentLayer(new_layer); return g_strdup(get_name_from_object(new_layer)); } @@ -1413,12 +1365,12 @@ gboolean document_interface_layer_set (DocumentInterface *object, gchar *layerstr, GError **error) { - SPObject * obj = get_object_by_name (object->context.getDocument(), layerstr, error); + SPObject * obj = get_object_by_name (object->doc_context.getDocument(), layerstr, error); if (!obj) return FALSE; - object->context.getSelection()->layerModel()->setCurrentLayer (obj); + object->doc_context.getSelection()->layers()->setCurrentLayer (obj); return TRUE; } @@ -1462,7 +1414,6 @@ document_interface_layer_previous (DocumentInterface *object, GError **error) DocumentInterface *fugly; gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) { - //DocumentInterface *obj; if (!item) return TRUE; g_signal_emit (desk->dbus_document_interface, signals[OBJECT_MOVED_SIGNAL], 0, item->getId()); return TRUE; @@ -1474,7 +1425,7 @@ gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) gboolean document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error) { - SPItem* parent=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* parent=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); GSList const *children = parent->childList(false); @@ -1497,7 +1448,7 @@ document_interface_get_children (DocumentInterface *object, char *name, char ** gchar* document_interface_get_parent (DocumentInterface *object, char *name, GError **error) { - SPItem* node=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* node=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); SPObject* parent=node->parent; @@ -1509,7 +1460,7 @@ document_interface_get_parent (DocumentInterface *object, char *name, GError ** //just pseudo code gboolean document_interface_get_xpath (DocumentInterface *object, char *xpath_expression, char ***out, GError **error){ - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); Inkscape::XML::Document *repr = doc->getReprDoc(); xmlXPathObjectPtr xpathObj; diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 5eef3d0c0..f90fe7c80 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -52,7 +52,7 @@ typedef struct _DocumentInterfaceClass DocumentInterfaceClass; struct _DocumentInterface { GObject parent; - Inkscape::ActionContext context; + Inkscape::ActionContext doc_context; ///< stores information about which document, selection, desktop etc this interface is linked to gboolean updates; }; diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 93b1bb91d..dcccf3d7d 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -368,12 +368,9 @@ Effect::EffectVerb::make_action (Inkscape::ActionContext const & context) void Effect::EffectVerb::perform( SPAction *action, void * data ) { + g_return_if_fail(ensure_desktop_valid(action)); Inkscape::UI::View::View * current_view = sp_action_get_view(action); - if (current_view == NULL) { - show_gui_required_message(action); - return; - } -// SPDocument * current_document = current_view->doc; + Effect::EffectVerb * ev = reinterpret_cast<Effect::EffectVerb *>(data); Effect * effect = ev->_effect; diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp index f211d775d..d52e43d96 100644 --- a/src/helper/action-context.cpp +++ b/src/helper/action-context.cpp @@ -6,7 +6,7 @@ * * Copyright (C) 2013 Eric Greveson * - * This code is in public domain + * Released under GNU GPL, read the file 'COPYING' for more information */ #include "desktop.h" @@ -47,7 +47,7 @@ SPDocument *ActionContext::getDocument() const } // Should be the same as the view's document, if view is non-NULL - return _selection->layerModel()->getDocument(); + return _selection->layers()->getDocument(); } Selection *ActionContext::getSelection() const diff --git a/src/helper/action-context.h b/src/helper/action-context.h index 3a7a19112..bb538f413 100644 --- a/src/helper/action-context.h +++ b/src/helper/action-context.h @@ -6,7 +6,7 @@ * * Copyright (C) 2013 Eric Greveson * - * This code is in public domain + * Released under GNU GPL, read the file 'COPYING' for more information */ #ifndef SEEN_INKSCAPE_ACTION_CONTEXT_H diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 9f8dd984a..29cb208d9 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -542,11 +542,11 @@ void sp_edit_clear_all(Inkscape::Selection *selection) if (!selection) return; - SPDocument *doc = selection->layerModel()->getDocument(); + SPDocument *doc = selection->layers()->getDocument(); selection->clear(); - g_return_if_fail(SP_IS_GROUP(selection->layerModel()->currentLayer())); - GSList *items = sp_item_group_item_list(SP_GROUP(selection->layerModel()->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(); @@ -739,7 +739,7 @@ static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inksc void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) { - SPDocument *doc = selection->layerModel()->getDocument(); + SPDocument *doc = selection->layers()->getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); // Check if something is selected. @@ -816,7 +816,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) g_slist_free(items); - DocumentUndo::done(selection->layerModel()->getDocument(), SP_VERB_SELECTION_UNGROUP, + DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP, _("Ungroup")); } @@ -942,14 +942,14 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) g_slist_free(rev); } - DocumentUndo::done(selection->layerModel()->getDocument(), 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(Inkscape::Selection *selection, SPDesktop *desktop) { - SPDocument *document = selection->layerModel()->getDocument(); + SPDocument *document = selection->layers()->getDocument(); if (selection->isEmpty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise to top.")); @@ -1031,13 +1031,13 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) g_slist_free(rev); } - DocumentUndo::done(selection->layerModel()->getDocument(), SP_VERB_SELECTION_LOWER, + DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, _("Lower")); } void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop) { - SPDocument *document = selection->layerModel()->getDocument(); + SPDocument *document = selection->layers()->getDocument(); if (selection->isEmpty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower to bottom.")); @@ -2152,7 +2152,7 @@ sp_selection_move(Inkscape::Selection *selection, gdouble dx, gdouble dy) sp_selection_move_relative(selection, dx, dy); - SPDocument *doc = selection->layerModel()->getDocument(); + SPDocument *doc = selection->layers()->getDocument(); if (dx == 0) { DocumentUndo::maybeDone(doc, "selector:move:vertical", SP_VERB_CONTEXT_SELECT, _("Move vertically")); @@ -2178,7 +2178,7 @@ sp_selection_move_screen(Inkscape::Selection *selection, gdouble dx, gdouble dy) gdouble const zdy = dy / zoom; sp_selection_move_relative(selection, zdx, zdy); - SPDocument *doc = selection->layerModel()->getDocument(); + SPDocument *doc = selection->layers()->getDocument(); if (dx == 0) { DocumentUndo::maybeDone(doc, "selector:move:vertical", SP_VERB_CONTEXT_SELECT, _("Move vertically by pixels")); diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index ce2d1c90b..6ed8ca584 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -145,8 +145,8 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); } else { SPItem *item = SP_ITEM(items->data); - SPObject *layer = selection->layerModel()->layerForObject(item); - SPObject *root = selection->layerModel()->currentRoot(); + SPObject *layer = selection->layers()->layerForObject(item); + SPObject *root = selection->layers()->currentRoot(); // Layer name gchar *layer_name; diff --git a/src/selection.cpp b/src/selection.cpp index 76f49f544..d018aba0c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -41,11 +41,11 @@ namespace Inkscape { -Selection::Selection(LayerModel *layer_model, SPDesktop *desktop) : +Selection::Selection(LayerModel *layers, SPDesktop *desktop) : _objs(NULL), _reprs(NULL), _items(NULL), - _layer_model(layer_model), + _layers(layers), _desktop(desktop), _selection_context(NULL), _flags(0), @@ -55,7 +55,7 @@ Selection::Selection(LayerModel *layer_model, SPDesktop *desktop) : Selection::~Selection() { _clear(); - _layer_model = NULL; + _layers = NULL; if (_idle) { g_source_remove(_idle); _idle = 0; @@ -96,7 +96,7 @@ void Selection::_emitModified(guint flags) { void Selection::_emitChanged(bool persist_selection_context/* = false */) { if (persist_selection_context) { if (NULL == _selection_context) { - _selection_context = _layer_model->currentLayer(); + _selection_context = _layers->currentLayer(); sp_object_ref(_selection_context, NULL); _context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext)); } @@ -139,7 +139,7 @@ void Selection::_clear() { SPObject *Selection::activeContext() { if (NULL != _selection_context) return _selection_context; - return _layer_model->currentLayer(); + return _layers->currentLayer(); } bool Selection::includes(SPObject *obj) const { @@ -487,7 +487,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { g_return_val_if_fail(repr != NULL, NULL); gchar const *id = repr->attribute("id"); g_return_val_if_fail(id != NULL, NULL); - SPObject *object=_layer_model->getDocument()->getObjectById(id); + SPObject *object=_layers->getDocument()->getObjectById(id); g_return_val_if_fail(object != NULL, NULL); return object; } @@ -496,7 +496,7 @@ guint Selection::numberOfLayers() { GSList const *items = const_cast<Selection *>(this)->itemList(); GSList *layers = NULL; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SPObject *layer = _layer_model->layerForObject(SP_OBJECT(iter->data)); + SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data)); if (g_slist_find (layers, layer) == NULL) { layers = g_slist_prepend (layers, layer); } diff --git a/src/selection.h b/src/selection.h index 65a6c5140..f076cf7aa 100644 --- a/src/selection.h +++ b/src/selection.h @@ -67,10 +67,10 @@ public: * Constructs an selection object, bound to a particular * layer model * - * @param layer_model the layer model (for the SPDesktop, if GUI) + * @param layers the layer model (for the SPDesktop, if GUI) * @param desktop the desktop associated with the layer model, or NULL if in console mode */ - Selection(LayerModel *layer_model, SPDesktop *desktop); + Selection(LayerModel *layers, SPDesktop *desktop); ~Selection(); /** @@ -79,7 +79,7 @@ public: * @return the layer model the selection is bound to, which is the same as the desktop * layer model for GUI mode */ - LayerModel *layerModel() { return _layer_model; } + LayerModel *layers() { return _layers; } /** * Returns the desktop the selection is bound to @@ -352,7 +352,7 @@ private: std::list<SPBox3D *> _3dboxes; - LayerModel *_layer_model; + LayerModel *_layers; GC::soft_ptr<SPDesktop> _desktop; SPObject* _selection_context; guint _flags; diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 0ec9da2a7..356cf0161 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -126,7 +126,7 @@ boolop_display_error_message(SPDesktop *desktop, Glib::ustring const &msg) void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { - SPDocument *doc = selection->layerModel()->getDocument(); + SPDocument *doc = selection->layers()->getDocument(); GSList *il = (GSList *) selection->itemList(); // allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334) diff --git a/src/verbs.cpp b/src/verbs.cpp index 2e6417ce1..1dae8bcf0 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -628,9 +628,13 @@ SPAction *Verb::get_action(Inkscape::ActionContext const & context) } /* static */ -void Verb::show_gui_required_message(SPAction *action) +bool Verb::ensure_desktop_valid(SPAction *action) { + if (sp_action_get_desktop(action) != NULL) { + return true; + } g_printerr("WARNING: ignoring verb %s - GUI required for this verb.\n", action->id); + return false; } void Verb::sensitive(SPDocument *in_doc, bool in_sensitive) @@ -827,12 +831,9 @@ void FileVerb::perform(SPAction *action, void *data) if (handled) { return; } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *desktop = sp_action_get_desktop(action); - if (desktop == NULL) { - show_gui_required_message(action); - return; - } Gtk::Window *parent = desktop->getToplevel(); g_assert(parent != NULL); @@ -905,12 +906,9 @@ void EditVerb::perform(SPAction *action, void *data) if (handled) { return; } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_EDIT_UNDO: @@ -1118,10 +1116,7 @@ void SelectionVerb::perform(SPAction *action, void *data) } // The remaining operations require a desktop - if (dt == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); g_assert(dt->_dlg_mgr != NULL); @@ -1200,13 +1195,10 @@ void SelectionVerb::perform(SPAction *action, void *data) */ void LayerVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); size_t verb = reinterpret_cast<std::size_t>(data); - if (dt == NULL) { - show_gui_required_message(action); - return; - } if ( !dt->currentLayer() ) { return; } @@ -1455,11 +1447,8 @@ void LayerVerb::perform(SPAction *action, void *data) */ void ObjectVerb::perform( SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPEventContext *ec = dt->event_context; @@ -1544,13 +1533,9 @@ void ContextVerb::perform(SPAction *action, void *data) SPDesktop *dt; sp_verb_t verb; int vidx; - - dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); + dt = sp_action_get_desktop(action); verb = (sp_verb_t)GPOINTER_TO_INT((gpointer)data); @@ -1748,11 +1733,8 @@ void ContextVerb::perform(SPAction *action, void *data) */ void TextVerb::perform(SPAction *action, void */*data*/) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPDocument *doc = sp_desktop_document(dt); (void)doc; @@ -1765,11 +1747,8 @@ void TextVerb::perform(SPAction *action, void */*data*/) */ void ZoomVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPEventContext *ec = dt->event_context; SPDocument *doc = sp_desktop_document(dt); @@ -1956,12 +1935,9 @@ void DialogVerb::perform(SPAction *action, void *data) // unhide all when opening a new dialog inkscape_dialogs_unhide(); } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { @@ -2073,11 +2049,8 @@ void DialogVerb::perform(SPAction *action, void *data) */ void HelpVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { @@ -2112,10 +2085,7 @@ void HelpVerb::perform(SPAction *action, void *data) */ void TutorialVerb::perform(SPAction *action, void *data) { - if (sp_action_get_desktop(action) == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_TUTORIAL_BASIC: // TRANSLATORS: If you have translated the tutorial-basic.en.svgz file to your language, @@ -2197,14 +2167,9 @@ SPAction *EffectLastVerb::make_action(Inkscape::ActionContext const & context) */ void EffectLastVerb::perform(SPAction *action, void *data) { - // These aren't used, but are here to remind people not to use - // the CURRENT_DOCUMENT macros unless they really have to. + g_return_if_fail(ensure_desktop_valid(action)); Inkscape::UI::View::View *current_view = sp_action_get_view(action); - if (current_view == NULL) { - show_gui_required_message(action); - return; - } - // SPDocument *current_document = SP_VIEW_DOCUMENT(current_view); + Inkscape::Extension::Effect *effect = Inkscape::Extension::Effect::get_last_effect(); if (effect == NULL) return; @@ -2266,12 +2231,8 @@ SPAction *FitCanvasVerb::make_action(Inkscape::ActionContext const & context) */ void FitCanvasVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } - SPDocument *doc = sp_desktop_document(dt); if (!doc) return; @@ -2336,12 +2297,8 @@ SPAction *LockAndHideVerb::make_action(Inkscape::ActionContext const & context) */ void LockAndHideVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } - SPDocument *doc = sp_desktop_document(dt); if (!doc) return; diff --git a/src/verbs.h b/src/verbs.h index dd58134dd..053441b89 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -554,7 +554,7 @@ public: /** * Print a message to stderr indicating that this verb needs a GUI to run */ - static void show_gui_required_message(SPAction *action); + static bool ensure_desktop_valid(SPAction *action); static void delete_all_view (Inkscape::UI::View::View * view); void delete_view (Inkscape::UI::View::View * view); |
