Skip to content

Commit

Permalink
Make open/save dialogs block window input while open (fixes iina#4583) (
Browse files Browse the repository at this point in the history
iina#4590)

* Attach the following open/save dialogs to parent windows so that arrow key navigation works inside them instead of activating menu items: (1) "Load external audio file", (2) "Load external subtitle" (Subtitles menu), (3) "Load subtitle..." (Quick Settings button), (4) "Save downloaded subtitle" (Subtitles menu)

* Make Save Playlist dialog into a sheet
  • Loading branch information
svobs authored Jan 2, 2024
1 parent f97a5d5 commit ac6d17c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions iina/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainMenuActionHandler: NSResponder {
}

@objc func menuSavePlaylist(_ sender: NSMenuItem) {
Utility.quickSavePanel(title: "Save to playlist", types: ["m3u8"]) { (url) in
Utility.quickSavePanel(title: "Save to playlist", types: ["m3u8"], sheetWindow: player.currentWindow) { (url) in
if url.isFileURL {
var playlist = ""
for item in self.player.info.playlist {
Expand Down Expand Up @@ -325,7 +325,8 @@ extension MainMenuActionHandler {
extension MainMenuActionHandler {
@objc func menuLoadExternalSub(_ sender: NSMenuItem) {
let currentDir = player.info.currentURL?.deletingLastPathComponent()
Utility.quickOpenPanel(title: "Load external subtitle file", chooseDir: false, dir: currentDir) { url in
Utility.quickOpenPanel(title: "Load external subtitle file", chooseDir: false, dir: currentDir,
sheetWindow: player.currentWindow) { url in
self.player.loadExternalSubFile(url, delay: true)
}
}
Expand Down Expand Up @@ -409,8 +410,8 @@ extension MainMenuActionHandler {
}
let subURL = URL(fileURLWithPath: path)
let subFileName = subURL.lastPathComponent
Utility.quickSavePanel(title: NSLocalizedString("alert.sub.save_downloaded.title",
comment: "Save Downloaded Subtitle"), filename: subFileName) { (destURL) in
let windowTitle = NSLocalizedString("alert.sub.save_downloaded.title", comment: "Save Downloaded Subtitle")
Utility.quickSavePanel(title: windowTitle, filename: subFileName, sheetWindow: player.currentWindow) { (destURL) in
do {
// The Save panel checks to see if a file already exists and if so asks if it should be
// replaced. The quickSavePanel would not have called this code if the user canceled, so if
Expand Down
4 changes: 4 additions & 0 deletions iina/PlayerCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ class PlayerCore: NSObject {
var initialWindow: InitialWindowController!
var miniPlayer: MiniPlayerWindowController!

var currentWindow: NSWindow? {
return isInMiniPlayer ? miniPlayer.window : mainWindow.window
}

var mpv: MPVController!

var plugins: [JavascriptPluginInstance] = []
Expand Down
6 changes: 4 additions & 2 deletions iina/QuickSettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab

@IBAction func loadExternalAudioAction(_ sender: NSButton) {
let currentDir = player.info.currentURL?.deletingLastPathComponent()
Utility.quickOpenPanel(title: "Load external audio file", chooseDir: false, dir: currentDir, allowedFileTypes: Utility.supportedFileExt[.audio]) { url in
Utility.quickOpenPanel(title: "Load external audio file", chooseDir: false, dir: currentDir,
sheetWindow: player.currentWindow, allowedFileTypes: Utility.supportedFileExt[.audio]) { url in
self.player.loadExternalAudioFile(url)
self.audioTableView.reloadData()
}
Expand Down Expand Up @@ -722,7 +723,8 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
@IBAction func loadExternalSubAction(_ sender: NSSegmentedControl) {
if sender.selectedSegment == 0 {
let currentDir = player.info.currentURL?.deletingLastPathComponent()
Utility.quickOpenPanel(title: "Load external subtitle", chooseDir: false, dir: currentDir, allowedFileTypes: Utility.supportedFileExt[.sub]) { url in
Utility.quickOpenPanel(title: "Load external subtitle", chooseDir: false, dir: currentDir,
sheetWindow: player.currentWindow, allowedFileTypes: Utility.supportedFileExt[.sub]) { url in
// set a delay
self.player.loadExternalSubFile(url, delay: true)
self.subTableView.reloadData()
Expand Down

0 comments on commit ac6d17c

Please sign in to comment.