Skip to content

Conversation

svobs
Copy link
Contributor

@svobs svobs commented Feb 17, 2023


Description:
If technical debt could be measured, MenuController should be declaring bankruptcy. Had to fight my natural tendency to try to go beyond and try to refactor it. But I think I found a solution which works fairly well, even though it's also kind of ugly.

There are 16 menu items (which I found at least) in which MenuController will change the their title and associated data based on their value parameter. IINA has been deriving these based on their defaults in bindMenuItems() at program start. It has also been deriving these from the user's active key bindings in updateKeyEquivalentsFrom() - but only if they matched one of the user's bindings.

Unfortunately, bindMenuItems() doesn't cache the default values it generates, and there's no easy way to modify that method without it being a lot of work. However, the settings array inside the updateKeyEquivalentsFrom() method contains all the information needed in order to re-derive those default values. It's just necessary to supply the default values twice in order to be able to derive it via the existing code:

let (_, value) = sameKeyAction(actions, actions, normalizeLastNum, numRange)

Finally, this PR removes some code in bindMenuItems() which sets the representedObject for those 16 fields at program load. They are completely unnecessary, because the updated code will get the same result when it calls updateKeyEquivalentsFrom() at program start. Following the DRY principle, it's important to remove them as a potential source of error, in case their values ever needed to be changed in the future.

…o their defaults after their key bindings were removed
Copy link
Contributor

@low-batt low-batt left a comment

Choose a reason for hiding this comment

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

Pulled PR locally, built IINA and tested. Looks good to me.

@low-batt low-batt requested a review from uiryuu April 8, 2023 23:21
@uiryuu uiryuu merged commit 5aa9318 into iina:develop Apr 11, 2023
@uiryuu
Copy link
Member

uiryuu commented Apr 11, 2023

Thanks

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.

Numbers in menu items do not change back to defaults when their bindings are removed
3 participants