Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 21, 2025

  • Analyze the issue: Cancelling texture selection in material editor unsets the texture instead of keeping the current texture
  • Identify the root cause: In TexturePanel.texturePreviewMouseClicked(), property.setValue(EMPTY) is called immediately before showing the dialog, and if the user cancels, the texture isn't restored
  • Located the relevant files: TexturePanel.java and TextureBrowser.java
  • Examined the existing test structure: Found TexturePanelTest.java with comprehensive test coverage
  • Implement improved fix: Initialize dialog with current texture and only clear property after knowing user's choice
  • Add specific test cases for both cancellation and "No Texture" selection scenarios
  • Verify the fix works correctly through testing
  • Manually test the UI behavior if possible

Improved Changes Made:

  1. Enhanced TexturePanel.texturePreviewMouseClicked() method:

    • Initialize the TexturePropertyEditor with the current texture before showing the dialog
    • Don't clear the property until after knowing what the user selected
    • Properly handle all three scenarios:
      • Texture selected: Clear property and set new texture
      • "No Texture" selected: Clear property and texture
      • Dialog cancelled: Do nothing (preserve original state)
  2. Updated test cases to reflect the improved logic

The improved fix ensures that:

  • The texture browser dialog initializes with the current texture selected
  • When user cancels texture selection, the original texture is preserved
  • When user explicitly selects "No Texture", the texture is properly cleared
  • The property is only modified when necessary, reducing side effects

This approach is more robust and follows the pattern used in other parts of the codebase (like the terrain editor).

Fixes #674.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits September 21, 2025 15:54
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Copy link
Contributor

@neph1 neph1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Tested and it works well. Just check my review comment

@neph1 neph1 requested a review from Copilot September 21, 2025 17:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where cancelling texture selection in the material editor would unset the current texture instead of preserving it. The fix ensures the texture browser dialog initializes with the current texture and only modifies the property when the user makes an explicit selection.

  • Moved the property clearing logic to only execute after determining the user's choice
  • Added proper initialization of the texture editor with the current texture before showing the dialog
  • Enhanced the logic to distinguish between texture selection, "No Texture" selection, and dialog cancellation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
TexturePanel.java Fixed the texturePreviewMouseClicked method to preserve texture state on cancellation
TexturePanelTest.java Added test cases to verify cancellation and "No Texture" selection behaviors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…ts/TexturePanel.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@neph1 neph1 marked this pull request as ready for review September 21, 2025 17:48
@neph1
Copy link
Contributor

neph1 commented Sep 21, 2025

Will merge soon, unless there are objections

@neph1 neph1 merged commit 5d19db7 into master Sep 22, 2025
3 checks passed
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.

Cancelling texture selection in material editor unsets the texture instead
2 participants