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

Fixed the name field in Sprite import panel #778 #811

Closed
wants to merge 2 commits into from

Conversation

iamllcoolray
Copy link
Contributor

@iamllcoolray iamllcoolray commented Feb 29, 2024

#778

utiliti-bug-fix-778.mp4

I got the Sprite name in the text field which updates the Sprite's name in the application.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Amazing, your first Pull Request in the LITIENGINE repository! You have earned the rank of "contributor" - let us know your nickname in the Forum and on Discord so we can reward you with the new role :).

Copy link
Member

@nightm4re94 nightm4re94 left a comment

Choose a reason for hiding this comment

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

Thank you! I have suggested some improvements below.

@@ -182,7 +180,7 @@ public Component getListCellRendererComponent(
textField = new JTextField();
ControlBehavior.apply(textField);
textField.setColumns(10);
textField.addActionListener(e -> fileList.getSelectedValue().setName(textField.getText()));
fileList.addListSelectionListener(e -> textField.setText(fileList.getSelectedValue().getName()));
Copy link
Member

Choose a reason for hiding this comment

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

I think the updates should be triggered as soon as the text field is updated, rather than when the selection in the file list changes. Try this:

Suggested change
fileList.addListSelectionListener(e -> textField.setText(fileList.getSelectedValue().getName()));
textField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
updateSelectedFile();
}
@Override
public void removeUpdate(DocumentEvent e) {
updateSelectedFile();
}
@Override
public void changedUpdate(DocumentEvent e) {
updateSelectedFile();
}
});

Then later, define the updateSelectedFile method as follows:

  private void updateSelectedFile() {
    int selectedIndex = fileList.getSelectedIndex();
    if (selectedIndex != -1) {
      SpriteFileWrapper selectedFile = fileListModel.getElementAt(selectedIndex);
      selectedFile.setName(textField.getText());
      fileList.repaint();
    }
  }

@iamllcoolray
Copy link
Contributor Author

I will make those changes tomorrow morning.

gurkenlabs#778 where the sprite name is updated simultaneously in the list and in the text field
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.

None yet

2 participants