Skip to content

Double click in the input config table to rename a config (+ bug fixes) #4960

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

Merged
merged 10 commits into from
Jun 8, 2024

Conversation

uiryuu
Copy link
Member

@uiryuu uiryuu commented May 29, 2024


Description:
This PR:

  • Enable the user to change the config name by double clicking in the input config table
  • Refactors the configuration creation/duplication to eliminate duplicated code
  • Change some of the wordings to make things clearer
  • Stabilize the default input config files by using KeyValuePairs

Besides, this PR also fixes the usage of the Utility.quickAskPanel:

if Utility.quickAskPanel("config.file_existing", sheetWindow: self.view.window) {
// - delete file
do {
try fm.removeItem(atPath: newFilePath)
} catch {
Utility.showAlert("error_deleting_file", sheetWindow: self.view.window)
return
}
} else {
NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: newFilePath)])
return
}

Previously it used the return value of the quickAskPanel, however, if the quickAskPanel is provided with the sheet window, it will always return false immediately without waiting for user input in the NSAlert panel. So 1) the "delete file" part of code could never be called, and 2) it always shows the existing file in Finder after the NSAlert is initiated (instead of after the user clicking the cancel button).

This PR changes the logic to show the existing file when clicking on OK, and do nothing when clicking on cancel. And also change the wording from "This should not happen..." to "A config file with the same filename already exists..."

I also remove the file deletion code because maybe its too dangerous to remove user files with "OK" or an enter hit in a seemingly unrelated alert window (the user want to create a config, but end up with deleting their file), let alone that part of code was never been executed before due to the erroneous usage.

uiryuu added 2 commits May 29, 2024 20:22
- Eliminated duplicate code
- Fix existing config file cannot be shown in Finder
- Remove the ability to remove existing config file
- Changed the alert text to reflect the changes
- Make `userConfigNames` a computed property
- Stablize the default input config files by using `KeyValuePairs`
@uiryuu uiryuu force-pushed the input-config-table-fixes branch from 3765a80 to feea96d Compare May 29, 2024 13:46
@svobs
Copy link
Contributor

svobs commented May 30, 2024

When I saw the commit comment "don't maintain userConfigNames manually" I got excited. It would be better if Preference.Key.inputConfigs was no longer used at all, and instead the list of user configs was made by checking the input_conf directory for files ending in `.conf.

@uiryuu
Copy link
Member Author

uiryuu commented May 30, 2024

In the latest commit, I removed Preference.Key.inputConfigs and made userConfigs a computed variable, so that even if the user adds a file to the folder manually, the table will show the file when refreshed. This commit needs more testing.

@uiryuu uiryuu force-pushed the input-config-table-fixes branch from 24eed5c to 8fb983c Compare May 30, 2024 06:53
}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I also remove the file deletion code because maybe its too dangerous to remove user files with "OK" or an enter hit in a seemingly unrelated alert window (the user want to create a config, but end up with deleting their file), let alone that part of code was never been executed before due to the erroneous usage.

At least we should tell the user how to delete this file (where it is) in the dialog.

Copy link
Member Author

Choose a reason for hiding this comment

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

The default action (OK button or enter) will bring up the Finder and show the conflicting config file


}

@IBAction func configFileListDoubleAction(_ sender: NSTableView) {
Copy link
Member

Choose a reason for hiding this comment

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

TBH I think when double clicking a table row people should expect the cell become editable, rather than a pop-up dialog. It's fine though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Initially I wanted to implement this way, however, I noticed that if the renaming fails, it would be messy to bring up another dialog window to give the user info on why the action failed. So I just used the alert window as other actions (new, duplicate) in this window.

@@ -434,11 +384,11 @@ extension PrefKeyBindingViewController: NSTableViewDelegate, NSTableViewDataSour
}

func tableViewSelectionDidChange(_ notification: Notification) {
guard !isLoading else { return }
Copy link
Member

Choose a reason for hiding this comment

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

Seems that isLoading's only usage is to filter out didChange notifications when calling loadConfigFile? If so, it's better to add a parameter like loadConfigFile(_, reloadTable:)

Copy link
Member Author

@uiryuu uiryuu May 31, 2024

Choose a reason for hiding this comment

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

isLoading is preventing infinite loops, since we call loadConfigFile in tableViewSelectionDidChange, and we also call reloadData in loadConfigFile, which will cause another tableViewSelectionDidChange, thus causing an infinite loop.

@svobs
Copy link
Contributor

svobs commented May 31, 2024

In the latest commit, I removed Preference.Key.inputConfigs and made userConfigs a computed variable, so that even if the user adds a file to the folder manually, the table will show the file when refreshed. This commit needs more testing.

Very much appreciate the update! And yes @lhc70000 is right about the performance issue when checking the file system each time. IMHO it's still a good improvement to do a lazy property for now.

Later (or hopefully sooner) a good way to do a live update of the list would be to make a DispatchSourceFileSystemObject for the directory so we can get notified when its contents change, and do a reload in response to those. The author of #3724 posted some helpful links showing how to set this up. But it does take more than a little code to set up, so probably better to leave for later.

@uiryuu uiryuu requested a review from lhc70000 June 7, 2024 07:27
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, built IINA, started IINA, opened settings. clicked on Key Bindings and the panel did not display any bindings for IINA Default:
bindings

If I click on another configuration the bindings are shown.

@uiryuu uiryuu requested a review from low-batt June 8, 2024 03:47
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.

I confirmed the latest commit fixes the issue with the bindings not being drawn when the panel first comes up.

I would think it would be better to follow the conventions of Finder where you press return and the name becomes editable. Finder also has to deal with the case where the file can't be renamed, like when you make the directory read only. Finder puts up an alert when that happens.

@uiryuu
Copy link
Member Author

uiryuu commented Jun 8, 2024

I would think it would be better to follow the conventions of Finder where you press return and the name becomes editable. Finder also has to deal with the case where the file can't be renamed, like when you make the directory read only. Finder puts up an alert when that happens.

We can make this happen in another PR

@lhc70000 lhc70000 merged commit bb2d6c6 into develop Jun 8, 2024
@lhc70000 lhc70000 deleted the input-config-table-fixes branch June 8, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants