anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: gaphor/gaphor
Issue: Blocks do not show parts when show parts button is set

### Describe the bug
The list of parts is not shown when the _Show Parts_ button is set to "on"

### To Reproduce
Steps to reproduce the behavior:
1. Make and block with some component blocks
2. With the block highlighted, Click on 'Show Parts'
3. See the parts compartment appear on the block
4. See it has no content


### Expected behavior
The component parts should be listed

### Screenshots
If applicable, add screenshots to help explain your problem.
<img width="838" alt="Screen Shot 2023-08-08 at 10 28 43 pm" src="https://github.com/gaphor/gaphor/assets/50702106/b3c7a843-3ba0-4203-87e2-c1fc9fa4d9f3">
The diargam showing no listed parts

<img width="889" alt="Screen Shot 2023-08-08 at 10 29 02 pm" src="https://github.com/gaphor/gaphor/assets/50702106/a13b11c9-49f4-4cb3-84b5-d9b8d51a653e">
The bdd of the referenced block

### OS
- [ ] Linux (Please put in notes the specific distro)
- [x] macOS
- [ ] Windows

### Version
Version of Gaphor: 2.20



Changed files:
gaphor/SysML/blocks/block.py

diff --git a/gaphor/SysML/blocks/block.py b/gaphor/SysML/blocks/block.py
index 348612501..a11a2a93e 100644
--- a/gaphor/SysML/blocks/block.py
+++ b/gaphor/SysML/blocks/block.py
@@ -103,8 +103,7 @@ class BlockItem(Classified, ElementPresentation[Block]):
                 and [
                     self.block_compartment(
                         self.diagram.gettext("parts"),
-                        lambda a: a.aggregation
-                        and a.aggregation in ("composite", "shared"),
+                        lambda a: a.aggregation and a.aggregation == "composite",
                     )
                 ]
                 or []
@@ -115,7 +114,7 @@ class BlockItem(Classified, ElementPresentation[Block]):
                 and [
                     self.block_compartment(
                         self.diagram.gettext("references"),
-                        lambda a: not a.association and a.aggregation != "composite",
+                        lambda a: a.aggregation and a.aggregation == "shared",
                     )
                 ]
                 or []
Repository: gaphor/gaphor
Issue: Appearance/placing of ports on activity diagram is unusual

### Describe the bug
When placing an input/output pin or proxy port on an activity or block diagram, the pin does not automatically attach to a nearby action or block, and it doesn't appear as a pin. The pin can be dragged onto an activity and seems to function as expected, but the appearance looks strange. 

### To Reproduce
Steps to reproduce the behavior:
1. Add an action to an activity diagram and place an input/output pin
2. Attempt to attach the pin to the action
3. Same steps for adding a block and proxy pin to a block diagram

### Expected behavior
The pin to appear as expected (small square on the outside of the action). Notably, the pin behaviour seems to be correct on the coffee machine example model, but it is only on my own model that the pins behave this way.

### Screenshots
Straight after adding the pin to the activity diagram:
![image](https://github.com/gaphor/gaphor/assets/136543386/3535b232-fe53-4a6d-9d1c-86b6751f2ae7)
After adding the pin to the action and connecting an object flow arrow:
![image](https://github.com/gaphor/gaphor/assets/136543386/63b3951c-5762-4fcc-964f-3cc4d34b1836)


### OS
- [ ] Linux (Please put in notes the specific distro)
- [ ] macOS
- [x ] Windows

### Version
Version of Gaphor: 2.19.1

### Additional information
Add any other context about the problem here.


Changed files:
gaphor/diagram/shapes.py, gaphor/ui/filedialog.py

diff --git a/gaphor/diagram/shapes.py b/gaphor/diagram/shapes.py
index 9e3e3d243..66f3d6e0f 100644
--- a/gaphor/diagram/shapes.py
+++ b/gaphor/diagram/shapes.py
@@ -52,21 +52,21 @@ def stroke(context: DrawContext, fill=True, dash=True):
 
 def draw_border(box, context: DrawContext, bounding_box: Rectangle):
     cr = context.cairo
-    d = context.style.get("border-radius", 0)
     x, y, width, height = bounding_box
+    d = min(context.style.get("border-radius", 0), width / 2.0, height / 2.0)
 
-    cr.move_to(x, d)
+    cr.move_to(x, y + d)
     cr.set_dash(context.style.get("dash-style", ()), 0)
     if d:
-        x1 = width + x
-        y1 = height + y
-        cr.arc(d, d, d, pi, 1.5 * pi)
+        x1 = x + width
+        y1 = y + height
+        cr.arc(x + d, y + d, d, pi, 1.5 * pi)
         cr.line_to(x1 - d, y)
-        cr.arc(x1 - d, d, d, 1.5 * pi, y)
+        cr.arc(x1 - d, y + d, d, 1.5 * pi, 0)
         cr.line_to(x1, y1 - d)
         cr.arc(x1 - d, y1 - d, d, 0, 0.5 * pi)
-        cr.line_to(d, y1)
-        cr.arc(d, y1 - d, d, 0.5 * pi, pi)
+        cr.line_to(x + d, y1)
+        cr.arc(x + d, y1 - d, d, 0.5 * pi, pi)
     else:
         cr.rectangle(x, y, width, height)
 
diff --git a/gaphor/ui/filedialog.py b/gaphor/ui/filedialog.py
index 062bc6055..a2f961a72 100644
--- a/gaphor/ui/filedialog.py
+++ b/gaphor/ui/filedialog.py
@@ -93,7 +93,7 @@ def save_file_dialog(
                 dialog.destroy()
                 handler(filename)
             else:
-                dialog.set_visible(True)
+                dialog.show()
         else:
             dialog.destroy()
Repository: gaphor/gaphor
Issue: Operations are not displayed for SysML Block

### Describe the bug

Operations are not displayed for SysML block.

### To Reproduce
1. Switch to SysML profile
2. Create a block
3. Add an operation
4. Enable display of operations
5. Bug: operations are not displayed

### Expected behavior

Operations shall be displayed (the same way as for class). 

### Screenshots

![image](https://github.com/gaphor/gaphor/assets/8182138/8157ad5d-080e-44a6-ae83-85257fb8f9b7)


### OS
- [ ] Linux (Please put in notes the specific distro)
- [ ] macOS
- [X] Windows

### Version
Version of Gaphor: 2.19.3.dev3420+5529a503

### Additional information
Add any other context about the problem here.


Changed files:
gaphor/SysML/blocks/block.py

diff --git a/gaphor/SysML/blocks/block.py b/gaphor/SysML/blocks/block.py
index 93929bae8..ff2ce1b94 100644
--- a/gaphor/SysML/blocks/block.py
+++ b/gaphor/SysML/blocks/block.py
@@ -18,7 +18,7 @@ from gaphor.SysML.sysml import Block, ValueType
 from gaphor.UML.classes.klass import attributes_compartment, operation_watches
 from gaphor.UML.classes.stereotype import stereotype_compartments, stereotype_watches
 from gaphor.UML.recipes import stereotypes_str
-from gaphor.UML.umlfmt import format_property
+from gaphor.UML.umlfmt import format_operation, format_property
 
 
 @represents(Block)
@@ -183,7 +183,9 @@ class BlockItem(Classified, ElementPresentation[Block]):
 
     def operations_compartment(self, name, predicate):
         def lazy_format(operation):
-            return lambda: format_property(operation) or self.diagram.gettext("unnamed")
+            return lambda: format_operation(operation) or self.diagram.gettext(
+                "unnamed"
+            )
 
         return Box(
             Text(
Repository: gaphor/gaphor
Issue: AttributeError when deleting diagrams with elements

### Describe the bug
I am getting the following AttributeError if I delete a diagram with elements on it.

```
Traceback (most recent call last):
  File "/home/dan/Projects/gaphor/.venv/lib/python3.11/site-packages/gaphas/decorators.py", line 86, in async_wrapper
    func(*args, **kwargs)
  File "/home/dan/Projects/gaphor/.venv/lib/python3.11/site-packages/gaphas/view/gtkview.py", line 319, in update
    self.update_bounding_box(dirty_items)
  File "/home/dan/Projects/gaphor/.venv/lib/python3.11/site-packages/gaphas/view/gtkview.py", line 356, in update_bounding_box
    painter.paint_item(item, cr)
  File "/home/dan/Projects/gaphor/gaphor/diagram/painter.py", line 28, in paint_item
    style = diagram.style(StyledItem(item, selection, self.dark_mode))
            ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'style'
```

### To Reproduce
Steps to reproduce the behavior:
1. Open the Generic Model
2. Open the New diagram
3. Create a class on the diagram
4. Delete the New Diagram

### Expected behavior
No Error.

### Screenshots
If applicable, add screenshots to help explain your problem.

### OS
- [X] Linux
- [ ] macOS
- [ ] Windows

### Version
Version of Gaphor: latest main

### Additional information
Add any other context about the problem here.


Changed files:
gaphor/diagram/painter.py

diff --git a/gaphor/diagram/painter.py b/gaphor/diagram/painter.py
index 07fa444fb..2ebc259ad 100644
--- a/gaphor/diagram/painter.py
+++ b/gaphor/diagram/painter.py
@@ -24,7 +24,9 @@ class ItemPainter:
 
     def paint_item(self, item, cr):
         selection = self.selection
-        diagram = item.diagram
+        if not (diagram := item.diagram):
+            return
+
         style = diagram.style(StyledItem(item, selection, self.dark_mode))
 
         cr.save()
Repository: gaphor/gaphor
Issue: Renaming a pin is not visible in tree

### Describe the bug
The name of the pin shall be visible in the tree. It is not.

### To Reproduce
Steps to reproduce the behavior:
1. Create an activity diagram
2. Add action
3. Add pin to action
4. Rename the pin
5. Problem: the name is not visible in the tree

### Expected behavior
The name shall be visible in the tree.

### Screenshots
![image](https://github.com/gaphor/gaphor/assets/8182138/d96b59fc-a501-46b3-8582-c61041095558)

### OS
- [X] Linux (Latest ubuntu)
- [ ] macOS
- [ ] Windows

### Version
Version of Gaphor: main branch


Changed files:
gaphor/UML/tests/test_umlfmt.py, gaphor/UML/umlfmt.py

diff --git a/gaphor/UML/tests/test_umlfmt.py b/gaphor/UML/tests/test_umlfmt.py
index cf7a76632..0146440f2 100644
--- a/gaphor/UML/tests/test_umlfmt.py
+++ b/gaphor/UML/tests/test_umlfmt.py
@@ -147,3 +147,10 @@ def test_slot(factory):
     slot = add_tag_is_foo_metadata_field(a, factory)
 
     assert 'tag = "foo"' == format(slot)
+
+
+def test_pin(factory):
+    pin = factory.create(UML.InputPin)
+    pin.name = "foo"
+
+    assert format(pin) == "foo"
diff --git a/gaphor/UML/umlfmt.py b/gaphor/UML/umlfmt.py
index f78a35291..aab4ef089 100644
--- a/gaphor/UML/umlfmt.py
+++ b/gaphor/UML/umlfmt.py
@@ -180,8 +180,8 @@ def format_slot(el):
 
 
 @format.register(UML.NamedElement)
+@format.register(UML.Pin)
 def format_namedelement(el, **kwargs):
-    """Format named element."""
     return el.name or ""
Repository: gaphor/gaphor
Issue: Do not close the tree when (last) element is removed

### Describe the bug
When removing an element from a diagram that is not referenced it will be also removed from the model. This is 
an expected behavior. However, it also closes the tree, which is pretty annoying. In my opinion it might refresh the
tree, that's fine, but should not close it.

### To Reproduce
Steps to reproduce the behavior:
1. Create a diagram
2. Open the tree
3. Add an element
4. Select the element
5. Press delete button
6. Element will be removed, but also tree is closing

It seems that when also deleting an element in the tree it will close the tree as well. The two cases might or might not related.

### Expected behavior
Do not close the tree.

### OS
- [ ] Linux
- [ ] macOS
- [X] Windows

### Version
Version of Gaphor: main branch


Changed files:
gaphor/ui/tests/test_modelbrowser.py, gaphor/ui/treemodel.py

diff --git a/gaphor/ui/tests/test_modelbrowser.py b/gaphor/ui/tests/test_modelbrowser.py
index a7839b17b..31d6e980a 100644
--- a/gaphor/ui/tests/test_modelbrowser.py
+++ b/gaphor/ui/tests/test_modelbrowser.py
@@ -288,6 +288,28 @@ def test_drop_multiple_elements(model_browser, element_factory, event_manager):
     assert class_a not in model_browser.get_selected_elements()
 
 
+def test_unlink_element_should_not_collapse_branch(
+    model_browser, element_factory, event_manager
+):
+    package = element_factory.create(UML.Package)
+    package.name = "p"
+    class_a = element_factory.create(UML.Class)
+    class_a.package = package
+    class_a.name = "a"
+    class_b = element_factory.create(UML.Class)
+    class_b.package = package
+    class_b.name = "b"
+
+    row0 = model_browser.selection.get_item(0)
+    row0.set_expanded(True)
+
+    class_a.unlink()
+
+    assert row0.get_item().element is package
+    assert row0.get_expanded()
+    assert model_browser.selection.get_item(1).get_item().element is class_b
+
+
 class MockRowItem:
     def __init__(self, list_item):
         self.list_item = list_item
diff --git a/gaphor/ui/treemodel.py b/gaphor/ui/treemodel.py
index cef69e73b..189db94a9 100644
--- a/gaphor/ui/treemodel.py
+++ b/gaphor/ui/treemodel.py
@@ -237,7 +237,10 @@ class TreeModel:
     def notify_child_model(self, element):
         # Only notify the change, the branch is created in child_model()
         owner_tree_item = self.tree_item_for_element(element.owner)
-        if (owner_branch := self.branches.get(owner_tree_item)) is not None:
+        if (
+            not self.branches.get(self.tree_item_for_element(element))
+            and (owner_branch := self.branches.get(owner_tree_item)) is not None
+        ):
             owner_branch.changed(element)
 
     def clear(self) -> None:
Repository: gaphor/gaphor
Issue: Double click on connections (relationships) causes error

### Describe the bug

Double clicking on connections (relationships, "Kapcsolatok") causes error:

### To Reproduce

Double clicking on connections (relationships) causes error:

Gaphor version:         2.19.2
Operating System:       Windows (10)
Display:                GdkWin32Display
Python version:         3.11.4
GTK version:            4.10.4
Adwaita version:        1.3.1
GtkSourceView version:  5.8.0
Cairo version:          1.17.8
Pango version:          1.50.14
PyGObject version:      3.44.1
Pycairo version:        1.24.0
pygit2/libgit2 version: 1.12.2  / 1.6.4


Hibák:

Time since application startup: 0:18:54
|Traceback (most recent call last):
|  File "C:\\Home\\Tools\\Gaphor\\gaphor-2.19.2-portable\\data\\gaphor\\ui\\modelbrowser.pyc", line 84, in list_view_activate
|  File "C:\\Home\\Tools\\Gaphor\\gaphor-2.19.2-portable\\data\\gaphor\\ui\\modelbrowser.pyc", line 135, in open_element
|AssertionError
└─────────────────────────────╌┄┈

### Expected behavior
A clear and concise description of what you expected to happen.

### Screenshots

![image](https://github.com/gaphor/gaphor/assets/8182138/5cc12555-82e4-4871-8286-3b9b1754aa6f)

### OS
- [ ] Linux (Please put in notes the specific distro)
- [ ] macOS
- [X] Windows

### Version
Version of Gaphor: 2.19.2



Changed files:
gaphor/ui/modelbrowser.py

diff --git a/gaphor/ui/modelbrowser.py b/gaphor/ui/modelbrowser.py
index 0125e794a..4c0a3ea4a 100644
--- a/gaphor/ui/modelbrowser.py
+++ b/gaphor/ui/modelbrowser.py
@@ -81,7 +81,8 @@ class ModelBrowser(UIComponent, ActionProvider):
 
         def list_view_activate(list_view, position):
             element = self.selection.get_item(position).get_item().element
-            self.open_element(element)
+            if element:
+                self.open_element(element)
 
         self.tree_view.connect("activate", list_view_activate)
Repository: gaphor/gaphor
Issue: Unexpected error after creating a package

### Describe the bug

Unexpected error when creating a package

### To Reproduce
Steps to reproduce the behavior:
1. Start gaphor
2. Select sysml
3. Select each element and press delete to remove all package
4. Create new package diagram
5. Select the diagram on left side and press right mouse click
6. Select new package menu item

OS: Windows (10)
Python version: 3.11.1
GTK version: 4.8.1
Display: GdkWin32Display
Gaphor version: 2.14.0

Errors:

Time since application startup: 0:01:01
|Traceback (most recent call last):
|  File "F:\\Development\\Tools\\Gaphor\\gaphor-2.14.0-portable\\data\\gaphor\\ui\\actiongroup.pyc", line 191, in _action_activate
|  File "F:\\Development\\Tools\\Gaphor\\gaphor-2.14.0-portable\\data\\gaphor\\ui\\treecomponent.pyc", line 159, in tree_view_create_package
|AssertionError
└─────────────────────────────╌┄┈


### Expected behavior
A clear and concise description of what you expected to happen.

### Screenshots
If applicable, add screenshots to help explain your problem.

### OS
- [ ] Linux (Please put in notes the specific distro)
- [ ] macOS
- [X] Windows

### Version
Version of Gaphor: 2.14.0

### Additional information
Add any other context about the problem here.


Changed files:
gaphor/ui/namespace.py

diff --git a/gaphor/ui/namespace.py b/gaphor/ui/namespace.py
index 5f8c946e2..7339c49ec 100644
--- a/gaphor/ui/namespace.py
+++ b/gaphor/ui/namespace.py
@@ -55,7 +55,8 @@ def popup_model(element, modeling_language):
     part.append_submenu(
         gettext("New _Diagram"), create_diagram_types_model(modeling_language)
     )
-    part.append(gettext("New _Package"), "tree-view.create-package")
+    if isinstance(element, UML.Package):
+        part.append(gettext("New _Package"), "tree-view.create-package")
     model.append_section(None, part)
 
     part = Gio.Menu.new()