|
1 | | -// |
| 1 | +// |
2 | 2 | // MacSelectFileDialogHandler.cs |
3 | 3 | // |
4 | 4 | // Author: |
@@ -76,29 +76,29 @@ public bool Run (OpenFileDialogData data) |
76 | 76 | try { |
77 | 77 | using (var panel = CreatePanel (data, out var state)) { |
78 | 78 | bool pathAlreadySet = false; |
79 | | - //TODO: DidChangeToDirectory is broken on Catalina |
80 | | - if (MacSystemInformation.OsVersion < MacSystemInformation.Catalina) { |
81 | | - var panelClosedToken = panelClosedSource.Token; |
82 | | - panel.DidChangeToDirectory += (sender, e) => { |
83 | | - var directoryPath = e.NewDirectoryUrl?.AbsoluteString; |
84 | | - if (string.IsNullOrEmpty (directoryPath)) |
85 | | - return; |
86 | | - var selectedPath = data.OnDirectoryChanged (this, directoryPath); |
87 | | - if (selectedPath.IsNull) |
88 | | - return; |
89 | | - data.SelectedFiles = new FilePath [] { selectedPath }; |
90 | | - pathAlreadySet = true; |
| 79 | + var panelClosedToken = panelClosedSource.Token; |
| 80 | + panel.DidChangeToDirectory += (sender, e) => { |
| 81 | + // HACK: On Catalina e.NewDirectoryUrl might be NSNull instead of null |
| 82 | + if (e.NewDirectoryUrl == null || ((NSObject)e.NewDirectoryUrl) is NSNull) |
| 83 | + return; |
| 84 | + var directoryPath = e.NewDirectoryUrl.AbsoluteString; |
| 85 | + if (string.IsNullOrEmpty (directoryPath)) |
| 86 | + return; |
| 87 | + var selectedPath = data.OnDirectoryChanged (this, directoryPath); |
| 88 | + if (selectedPath.IsNull) |
| 89 | + return; |
| 90 | + data.SelectedFiles = new FilePath [] { selectedPath }; |
| 91 | + pathAlreadySet = true; |
91 | 92 |
|
92 | | - // We need to call Cancel on 1ms delay so it's executed after DidChangeToDirectory event handler is finished |
93 | | - // this is needed because it's possible that DidChangeToDirectory event is executed while dialog is opening |
94 | | - // in that case calling .Cancel() leaves dialog in weird state... |
95 | | - // Fun fact: DidChangeToDirectory event is called from Open on 10.12 but not on 10.13 |
96 | | - System.Threading.Tasks.Task.Delay (1).ContinueWith (delegate { |
97 | | - if (!panelClosedToken.IsCancellationRequested) |
98 | | - panel.Cancel (panel); |
99 | | - }, panelClosedToken, System.Threading.Tasks.TaskContinuationOptions.None, Runtime.MainTaskScheduler); |
100 | | - }; |
101 | | - } |
| 93 | + // We need to call Cancel on 1ms delay so it's executed after DidChangeToDirectory event handler is finished |
| 94 | + // this is needed because it's possible that DidChangeToDirectory event is executed while dialog is opening |
| 95 | + // in that case calling .Cancel() leaves dialog in weird state... |
| 96 | + // Fun fact: DidChangeToDirectory event is called from Open on 10.12 but not on 10.13 |
| 97 | + System.Threading.Tasks.Task.Delay (1).ContinueWith (delegate { |
| 98 | + if (!panelClosedToken.IsCancellationRequested) |
| 99 | + panel.Cancel (panel); |
| 100 | + }, panelClosedToken, System.Threading.Tasks.TaskContinuationOptions.None, Runtime.MainTaskScheduler); |
| 101 | + }; |
102 | 102 |
|
103 | 103 | panel.SelectionDidChange += delegate { |
104 | 104 | var selection = MacSelectFileDialogHandler.GetSelectedFiles (panel); |
|
0 commit comments