Skip to content

Show no context menu instead of throwing for objects without one - #505

Open
dsn27 wants to merge 1 commit into
masterfrom
fix/missing-context-menu
Open

dsn27 wants to merge 1 commit into
masterfrom
fix/missing-context-menu

Conversation

@dsn27

@dsn27 dsn27 commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

Right-clicking a selected picture in CADability.App threw an exception, found while testing 1.8.0-preview.1:

System.NullReferenceException
   at CADability.UserInterface.MenuResource.LoadMenuDefinition(String MenuName, Boolean main, ICommandHandler handler) in MenuResource.cs:line 315
   at CADability.Actions.SelectObjectsAction.OnMouseUp(MouseEventArgs e, IView vw) in SelectObjectsAction.cs:line 1644
   ...

When exactly one object is selected, SelectObjectsAction.OnMouseUp loads the context menu whose id the object's IGeoObjectShowProperty.GetContextMenuId() returns. A picture has no context menu of its own, so ShowPropertyPicture returns null. LoadMenuDefinition then found no menu node and dereferenced it.

The show properties of UnscaledIcon and UnscaledGeoObject threw "The method or operation is not implemented." from GetContextMenuId, so a right click on those objects failed the same way.

The bug is older than 1.7.1; none of these files changed for #412.

Fix

  • MenuResource.LoadMenuDefinition returns an empty menu for a null name and for a name with no menu in the resource. The selection menu (MenuId.SelectedObjects) is still shown.
  • ShowPropertyUnscaledIcon and ShowPropertyUnscaledGeoObject return null from GetContextMenuId, like the picture.

No public API changes.

Tests

ContextMenuTests:

  • A null or unknown menu name, main menu or popup, gives an empty menu.
  • An existing popup (MenuId.Picture.Path) still loads its entries.
  • For the show properties of a picture, an unscaled icon and an unscaled object, the menu that SelectObjectsAction loads is empty and nothing throws.

Without the fix, 4 of the 5 tests fail. With it, all pass. CADability.Tests on Linux: 709 passed, 0 failed.


Generated by Claude Code

A right click on a selected picture threw a NullReferenceException:
SelectObjectsAction loads the context menu whose id the object's
IGeoObjectShowProperty returns, ShowPropertyPicture returns null because a
picture has no context menu of its own, and MenuResource.LoadMenuDefinition
dereferenced the menu node it did not find. LoadMenuDefinition now returns
an empty menu for a null or unknown name.

The show properties of UnscaledIcon and UnscaledGeoObject threw "not
implemented" from GetContextMenuId, so a right click on them failed the same
way; they return null now, like the picture.

The bug is older than 1.7.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YXvDW91oXpy7RquGHNxgR5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants