Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate panes in context.layout #1153

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -10038,13 +10038,13 @@ def add_context_layout_mapping(self, current_pane_name: str, display_pane_functi

def add_context_pane(self, pane_name: str, display_pane_function: Callable, pane_title_function: Callable, condition: Optional[Callable]) -> None:
"""Add a new context pane to ContextCommand."""
context = self.commands["context"]
assert isinstance(context, ContextCommand)

# assure users can toggle the new context
corrected_settings_name: str = pane_name.replace(" ", "_")
gef.config["context.layout"] += f" {corrected_settings_name}"
if corrected_settings_name in gef.config["context.layout"]:
warn(f"Duplicate name for `{pane_name}` (`{corrected_settings_name}`), skipping")
return

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

def load(self) -> None:
Expand Down
23 changes: 22 additions & 1 deletion tests/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,25 @@ class ContextCommand(RemoteGefUnitTestGeneric):
cmd = "context"


# See https://github.com/hugsy/gef/projects/10
# TODO See https://github.com/hugsy/gef/projects/10

def test_duplicate_pane_name(self):
# Make sure we cannot have 2 context panes with an identical identifier
# See #1145 , #1153
gdb = self._gdb
gef = self._gef

new_pane_id = "new_pane1"
current_layout = gef.config["context.layout"]
assert not current_layout.endswith(new_pane_id)

res = gdb.execute(f"pi register_external_context_pane('{new_pane_id}', print, print, None)", to_string=True)
assert "Python Exception" not in res
new_layout = gef.config["context.layout"]
assert new_layout.endswith(new_pane_id)

res = gdb.execute(f"pi register_external_context_pane('{new_pane_id}', print, print, None)", to_string=True)
assert "Python Exception" not in res
new_layout2 = gef.config["context.layout"]
assert new_layout == new_layout2
assert f"Duplicate name for `{new_pane_id}`" in res
Loading