Skip to content

Commit 3bdba58

Browse files
authoredNov 11, 2024··
Prevent duplicate panes in context.layout (#1153)
## Description Make sure panes added in `context.layout` have a unique name Fixes #1145
1 parent 0f21eea commit 3bdba58

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed
 

‎gef.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10035,13 +10035,13 @@ def add_context_layout_mapping(self, current_pane_name: str, display_pane_functi
1003510035

1003610036
def add_context_pane(self, pane_name: str, display_pane_function: Callable, pane_title_function: Callable, condition: Callable | None) -> None:
1003710037
"""Add a new context pane to ContextCommand."""
10038-
context = self.commands["context"]
10039-
assert isinstance(context, ContextCommand)
10040-
1004110038
# assure users can toggle the new context
1004210039
corrected_settings_name: str = pane_name.replace(" ", "_")
10043-
gef.config["context.layout"] += f" {corrected_settings_name}"
10040+
if corrected_settings_name in gef.config["context.layout"]:
10041+
warn(f"Duplicate name for `{pane_name}` (`{corrected_settings_name}`), skipping")
10042+
return
1004410043

10044+
gef.config["context.layout"] += f" {corrected_settings_name}"
1004510045
self.add_context_layout_mapping(corrected_settings_name, display_pane_function, pane_title_function, condition)
1004610046

1004710047
def load(self) -> None:

‎tests/commands/context.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,25 @@ class ContextCommand(RemoteGefUnitTestGeneric):
1313
cmd = "context"
1414

1515

16-
# See https://github.com/hugsy/gef/projects/10
16+
# TODO See https://github.com/hugsy/gef/projects/10
17+
18+
def test_duplicate_pane_name(self):
19+
# Make sure we cannot have 2 context panes with an identical identifier
20+
# See #1145 , #1153
21+
gdb = self._gdb
22+
gef = self._gef
23+
24+
new_pane_id = "new_pane1"
25+
current_layout = gef.config["context.layout"]
26+
assert not current_layout.endswith(new_pane_id)
27+
28+
res = gdb.execute(f"pi register_external_context_pane('{new_pane_id}', print, print, None)", to_string=True)
29+
assert "Python Exception" not in res
30+
new_layout = gef.config["context.layout"]
31+
assert new_layout.endswith(new_pane_id)
32+
33+
res = gdb.execute(f"pi register_external_context_pane('{new_pane_id}', print, print, None)", to_string=True)
34+
assert "Python Exception" not in res
35+
new_layout2 = gef.config["context.layout"]
36+
assert new_layout == new_layout2
37+
assert f"Duplicate name for `{new_pane_id}`" in res

0 commit comments

Comments
 (0)
Please sign in to comment.