2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2022-04-24 06:27:42 +00:00
|
|
|
from inkex import errormsg
|
|
|
|
|
|
|
|
from ..i18n import _
|
2021-03-04 17:40:53 +00:00
|
|
|
from .base import InkstitchExtension
|
|
|
|
|
|
|
|
|
|
|
|
class Reorder(InkstitchExtension):
|
2021-12-09 14:05:21 +00:00
|
|
|
# Remove selected objects from the document and re-add them in the order they
|
2021-03-04 17:40:53 +00:00
|
|
|
# were selected.
|
|
|
|
|
|
|
|
def effect(self):
|
2022-04-24 06:27:42 +00:00
|
|
|
objects = self.svg.selection
|
|
|
|
|
|
|
|
if not objects:
|
2022-05-18 14:02:07 +00:00
|
|
|
errormsg(_("Please select at least two elements to reorder."))
|
2022-04-24 06:27:42 +00:00
|
|
|
return
|
2021-03-04 17:40:53 +00:00
|
|
|
|
2022-04-24 06:27:42 +00:00
|
|
|
for obj in objects:
|
|
|
|
if not obj == objects.first():
|
|
|
|
obj.getparent().remove(obj)
|
2021-03-04 17:40:53 +00:00
|
|
|
|
|
|
|
insert_parent = objects[0].getparent()
|
|
|
|
insert_pos = insert_parent.index(objects[0])
|
|
|
|
|
|
|
|
insert_parent.remove(objects[0])
|
|
|
|
|
|
|
|
insert_parent[insert_pos:insert_pos] = objects
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
e = Reorder()
|
|
|
|
e.affect()
|