Reove alignment plugin
The functionality has been superseeded by guides on the canvas.
This commit is contained in:
parent
21b02545eb
commit
f8a35c884e
@ -1,166 +0,0 @@
|
||||
"""
|
||||
This plugin extends Gaphor with XMI alignment actions.
|
||||
"""
|
||||
|
||||
from gaphor.core import event_handler, transactional, action, build_action_group
|
||||
from gaphor.abc import Service, ActionProvider
|
||||
from gaphor.ui.event import DiagramSelectionChange
|
||||
|
||||
|
||||
class Alignment(Service, ActionProvider):
|
||||
|
||||
menu_xml = """
|
||||
<ui>
|
||||
<menubar action="mainwindow">
|
||||
<menu action="diagram">
|
||||
<placeholder name="ternary">
|
||||
<separator />
|
||||
<menuitem action="align-left" />
|
||||
<menuitem action="align-center" />
|
||||
<menuitem action="align-right" />
|
||||
<separator />
|
||||
<menuitem action="align-top" />
|
||||
<menuitem action="align-bottom" />
|
||||
<menuitem action="align-middle" />
|
||||
</placeholder>
|
||||
</menu>
|
||||
</menubar>
|
||||
</ui>"""
|
||||
|
||||
def __init__(self, event_manager):
|
||||
self.action_group = build_action_group(self)
|
||||
self.event_manager = event_manager
|
||||
self._last_update = None
|
||||
self.event_manager.subscribe(self.update)
|
||||
self.update()
|
||||
|
||||
def shutdown(self):
|
||||
self.event_manager.unsubscribe(self.update)
|
||||
|
||||
@event_handler(DiagramSelectionChange)
|
||||
def update(self, event=None):
|
||||
self._last_update = event
|
||||
sensitive = event and len(event.selected_items) > 1
|
||||
if sensitive is not None:
|
||||
self.action_group.get_action("align-left").set_sensitive(sensitive)
|
||||
self.action_group.get_action("align-center").set_sensitive(sensitive)
|
||||
self.action_group.get_action("align-right").set_sensitive(sensitive)
|
||||
self.action_group.get_action("align-top").set_sensitive(sensitive)
|
||||
self.action_group.get_action("align-middle").set_sensitive(sensitive)
|
||||
self.action_group.get_action("align-bottom").set_sensitive(sensitive)
|
||||
|
||||
def get_items(self):
|
||||
return (self._last_update and self._last_update.selected_items) or []
|
||||
|
||||
def get_focused_item(self):
|
||||
return self._last_update.focused_item
|
||||
|
||||
def getXCoordsLeft(self, items):
|
||||
return [item.matrix[4] for item in items]
|
||||
|
||||
def getXCoordsRight(self, items):
|
||||
return [item.matrix[4] + item.width for item in items]
|
||||
|
||||
def getYCoordsTop(self, items):
|
||||
return [item.matrix[5] for item in items]
|
||||
|
||||
def getYCoordsBottom(self, items):
|
||||
return [item.matrix[5] + item.height for item in items]
|
||||
|
||||
@action(
|
||||
name="align-left",
|
||||
label="Left",
|
||||
tooltip="Vertically align diagram elements on the left",
|
||||
shortcut="<Primary><Shift>l",
|
||||
)
|
||||
@transactional
|
||||
def align_left(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
target_x = fitem.matrix[4]
|
||||
for item in items:
|
||||
x = target_x - item.matrix[4]
|
||||
item.matrix.translate(x, 0)
|
||||
item.request_update()
|
||||
|
||||
@action(
|
||||
name="align-center",
|
||||
label="Center",
|
||||
tooltip="Vertically align diagram elements on their centers",
|
||||
shortcut="<Primary><Shift>c",
|
||||
)
|
||||
@transactional
|
||||
def align_center(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
min_x = min(self.getXCoordsLeft(items))
|
||||
max_x = max(self.getXCoordsRight(items))
|
||||
center_x = fitem.matrix[4] + (fitem.width / 2)
|
||||
for item in items:
|
||||
x = center_x - (item.width / 2) - item.matrix[4]
|
||||
item.matrix.translate(x, 0)
|
||||
item.request_update()
|
||||
|
||||
@action(
|
||||
name="align-right",
|
||||
label="Right",
|
||||
tooltip="Vertically align diagram elements on the right",
|
||||
shortcut="<Primary><Shift>r",
|
||||
)
|
||||
@transactional
|
||||
def align_right(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
target_x = fitem.matrix[4] + fitem.width
|
||||
for item in items:
|
||||
x = target_x - item.width - item.matrix[4]
|
||||
item.matrix.translate(x, 0)
|
||||
item.request_update()
|
||||
|
||||
@action(
|
||||
name="align-top",
|
||||
label="Top",
|
||||
tooltip="Horizontally align diagram elements on their tops",
|
||||
shortcut="<Primary><Shift>t",
|
||||
)
|
||||
@transactional
|
||||
def align_top(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
target_y = fitem.matrix[5]
|
||||
for item in items:
|
||||
y = target_y - item.matrix[5]
|
||||
item.matrix.translate(0, y)
|
||||
item.request_update()
|
||||
|
||||
@action(
|
||||
name="align-middle",
|
||||
label="Middle",
|
||||
tooltip="Horizontally align diagram elements on their middles",
|
||||
shortcut="<Primary><Shift>m",
|
||||
)
|
||||
@transactional
|
||||
def align_middle(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
middle_y = fitem.matrix[5] + (fitem.height / 2)
|
||||
for item in items:
|
||||
y = middle_y - (item.height / 2) - item.matrix[5]
|
||||
item.matrix.translate(0, y)
|
||||
item.request_update()
|
||||
|
||||
@action(
|
||||
name="align-bottom",
|
||||
label="Bottom",
|
||||
tooltip="Horizontally align diagram elements on their bottoms",
|
||||
shortcut="<Primary><Shift>b",
|
||||
)
|
||||
@transactional
|
||||
def align_bottom(self):
|
||||
items = self.get_items()
|
||||
fitem = self.get_focused_item()
|
||||
target_y = fitem.matrix[5] + fitem.height
|
||||
for item in items:
|
||||
y = target_y - item.height - item.matrix[5]
|
||||
item.matrix.translate(0, y)
|
||||
item.request_update()
|
31
model.xmi
Normal file
31
model.xmi
Normal file
@ -0,0 +1,31 @@
|
||||
<XMI xmi.version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:UML="http://schema.omg.org/spec/UML/2.1">
|
||||
<UML:Package XMI:id="1b439328-ea0b-11e9-b8cf-79eeea4e0b01" name="New model" visibility="public">
|
||||
<ownedMember>
|
||||
<UML:Class XMI:id="1ccd946e-ea0b-11e9-b8cf-79eeea4e0b01" name="NewClass" isAbstract="False"/>
|
||||
</ownedMember>
|
||||
<ownedMember>
|
||||
<UML:Association XMI:id="24d6eac0-ea0b-11e9-b8cf-79eeea4e0b01" isDerived="False">
|
||||
<memberEnd>
|
||||
<UML:Property XMI:id="24d6eac1-ea0b-11e9-b8cf-79eeea4e0b01" isStatic="False" isOrdered="True" isUnique="True" isDerived="False" isDerivedUnion="False" isReadOnly="False"/>
|
||||
</memberEnd>
|
||||
<memberEnd>
|
||||
<UML:Property XMI:id="24d6eac2-ea0b-11e9-b8cf-79eeea4e0b01" isStatic="False" isOrdered="True" isUnique="True" isDerived="False" isDerivedUnion="False" isReadOnly="False"/>
|
||||
</memberEnd>
|
||||
<ownedEnd>
|
||||
<UML:Property XMI:id="24d6eac1-ea0b-11e9-b8cf-79eeea4e0b01" isStatic="False" isOrdered="True" isUnique="True" isDerived="False" isDerivedUnion="False" isReadOnly="False"/>
|
||||
</ownedEnd>
|
||||
<ownedEnd>
|
||||
<UML:Property XMI:id="24d6eac2-ea0b-11e9-b8cf-79eeea4e0b01" isStatic="False" isOrdered="True" isUnique="True" isDerived="False" isDerivedUnion="False" isReadOnly="False"/>
|
||||
</ownedEnd>
|
||||
</UML:Association>
|
||||
</ownedMember>
|
||||
<ownedMember/>
|
||||
<ownedMember>
|
||||
<UML:Package XMI:id="1efa97be-ea0b-11e9-b8cf-79eeea4e0b01" name="NewPackage" visibility="public"/>
|
||||
</ownedMember>
|
||||
<ownedMember>
|
||||
<UML:Class XMI:id="20b33214-ea0b-11e9-b8cf-79eeea4e0b01" name="NewClass" isAbstract="False"/>
|
||||
</ownedMember>
|
||||
</UML:Package>
|
||||
<UML:Package XMI:id="1efa97be-ea0b-11e9-b8cf-79eeea4e0b01" name="NewPackage" visibility="public"/>
|
||||
</XMI>
|
@ -77,7 +77,6 @@ gaphorconvert = 'gaphor.tools.gaphorconvert:main'
|
||||
"xmi_export" = "gaphor.plugins.xmiexport:XMIExport"
|
||||
"diagram_layout" = "gaphor.plugins.diagramlayout:DiagramLayout"
|
||||
"pynsource" = "gaphor.plugins.pynsource:PyNSource"
|
||||
"alignment" = "gaphor.plugins.alignment:Alignment"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry==1.0.0b1"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user