diff --git a/src/selection.cpp b/src/selection.cpp
index 473a7202e594e1eecabcac3e1b9067774d7a64c9..702cc6594ac5579ea4f63c21335f1462f7b74965 100644 (file)
--- a/src/selection.cpp
+++ b/src/selection.cpp
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
* bulia byak <buliabyak@users.sf.net>
+ * Andrius R. <knutux@gmail.com>
*
+ * Copyright (C) 2006 Andrius R.
* Copyright (C) 2004-2005 MenTaLguY
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2001-2002 Ximian, Inc.
_reprs(NULL),
_items(NULL),
_desktop(desktop),
+ _selection_context(NULL),
+ _context_release_handler_id(0),
_flags(0),
_idle(0)
{
_modified_signal.emit(this, flags);
}
-void Selection::_emitChanged() {
+void Selection::_emitChanged(bool persist_selection_context/* = false */) {
+ if (persist_selection_context) {
+ if (NULL == _selection_context) {
+ _selection_context = desktop()->currentLayer();
+ sp_object_ref(_selection_context, NULL);
+ _context_release_handler_id = g_signal_connect(
+ G_OBJECT(_selection_context), "release",
+ G_CALLBACK(&Selection::_releaseSelectionContext),
+ this);
+ }
+ } else {
+ _releaseContext(_selection_context);
+ }
+
inkscape_selection_changed(this);
_changed_signal.emit(this);
}
+void
+Selection::_releaseSelectionContext(SPObject *obj, Selection *selection)
+{
+ selection->_releaseContext(obj);
+}
+
+void
+Selection::_releaseContext(SPObject *obj)
+{
+ if (NULL == _selection_context || _selection_context != obj)
+ return;
+
+ g_signal_handler_disconnect(G_OBJECT(_selection_context), _context_release_handler_id);
+ sp_object_unref(_selection_context, NULL);
+ _context_release_handler_id = 0;
+ _selection_context = NULL;
+}
+
void Selection::_invalidateCachedLists() {
g_slist_free(_items);
_items = NULL;
}
}
+SPObject *Selection::activeContext() {
+ if (NULL != _selection_context)
+ return _selection_context;
+ return desktop()->currentLayer();
+ }
+
bool Selection::includes(SPObject *obj) const {
if (obj == NULL)
return FALSE;
return ( g_slist_find(_objs, obj) != NULL );
}
-void Selection::add(SPObject *obj) {
+void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) {
g_return_if_fail(obj != NULL);
g_return_if_fail(SP_IS_OBJECT(obj));
_invalidateCachedLists();
_add(obj);
- _emitChanged();
+ _emitChanged(persist_selection_context);
}
void Selection::_add(SPObject *obj) {
*/
}
-void Selection::set(SPObject *object) {
+void Selection::set(SPObject *object, bool persist_selection_context) {
_clear();
- add(object);
+ add(object, persist_selection_context);
}
void Selection::toggle(SPObject *obj) {