diff --git a/samples/ControlGallery/Panels/ComboBoxPanel.cs b/samples/ControlGallery/Panels/ComboBoxPanel.cs index 9c80289..482817a 100644 --- a/samples/ControlGallery/Panels/ComboBoxPanel.cs +++ b/samples/ControlGallery/Panels/ComboBoxPanel.cs @@ -13,7 +13,7 @@ public ComboBoxPanel () var cb1 = Controls.Add (new ComboBox { Left = 10, Top = 35 }); cb1.Items.AddRange (fruits); - var button = Controls.Add (new Button { Text = "Toggle", Left = 140, Top = 35 }); + var button = Controls.Add (new Button { Text = "Open", Left = 140, Top = 35 }); button.Click += (o, e) => cb1.DroppedDown = !cb1.DroppedDown; Controls.Add (new Label { Text = "Disabled", Left = 10, Top = 70, Width = 200 }); diff --git a/src/Modern.Forms/Clipboard.cs b/src/Modern.Forms/Clipboard.cs index 40c2e39..90e3cb5 100644 --- a/src/Modern.Forms/Clipboard.cs +++ b/src/Modern.Forms/Clipboard.cs @@ -13,7 +13,7 @@ public static class Clipboard /// /// Gets the contents of the clipboard as text. /// - public static Task GetTextAsync () + public static Task GetTextAsync () => AvaloniaGlobals.GetRequiredService ().GetTextAsync (); /// diff --git a/src/Modern.Forms/Extensions/WindowKitExtensions.cs b/src/Modern.Forms/Extensions/WindowKitExtensions.cs index 0a80b26..1f50e36 100644 --- a/src/Modern.Forms/Extensions/WindowKitExtensions.cs +++ b/src/Modern.Forms/Extensions/WindowKitExtensions.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Modern.WindowKit.Input; using Modern.WindowKit.Platform.Storage; +using Modern.WindowKit.Platform.Storage.FileIO; namespace Modern.Forms { @@ -25,16 +26,16 @@ public static Keys AddModifiers (Keys keys, RawInputModifiers modifiers) public static string? GetFullPath (this IStorageFile file) { - if (file.TryGetUri (out var uri)) - return Path.GetFullPath (uri.LocalPath); + if (file is BclStorageFile path) + return path.FileInfo.FullName; return null; } public static string? GetFullPath (this IStorageFolder file) { - if (file.TryGetUri (out var uri)) - return Path.GetFullPath (uri.LocalPath); + if (file is BclStorageFolder path) + return path.DirectoryInfo.FullName; return null; } diff --git a/src/Modern.Forms/FileSystemDialog.cs b/src/Modern.Forms/FileSystemDialog.cs index 00e7e73..2d34562 100644 --- a/src/Modern.Forms/FileSystemDialog.cs +++ b/src/Modern.Forms/FileSystemDialog.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using Modern.WindowKit.Platform.Storage.FileIO; namespace Modern.Forms { @@ -16,5 +18,17 @@ public abstract class FileSystemDialog /// Gets or sets the title for the dialog. /// public string Title { get; set; } = string.Empty; + + internal BclStorageFolder? GetInitialDirectory () + { + if (InitialDirectory is not null) { + var dir_info = new DirectoryInfo (InitialDirectory); + + if (dir_info.Exists) + return new BclStorageFolder (dir_info); + } + + return null; + } } } diff --git a/src/Modern.Forms/FolderBrowserDialog.cs b/src/Modern.Forms/FolderBrowserDialog.cs index 1bd96a7..9677e2b 100644 --- a/src/Modern.Forms/FolderBrowserDialog.cs +++ b/src/Modern.Forms/FolderBrowserDialog.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using Modern.WindowKit.Controls.Platform; @@ -24,16 +25,16 @@ public class FolderBrowserDialog : FileSystemDialog /// The window that owns this dialog. public async Task ShowDialog (Form owner) { - if (owner.window is ITopLevelImplWithStorageProvider parent) { + if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) { var options = new FolderPickerOpenOptions { AllowMultiple = false, - SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null, + SuggestedStartLocation = GetInitialDirectory (), Title = Title }; - var result = await parent.StorageProvider.OpenFolderPickerAsync (options); + var result = await parent.OpenFolderPickerAsync (options); - var paths = result.Select (f => f.GetFullPath ()).WhereNotNull (); + var paths = result.Select (f => f.GetFullPath ()).WhereNotNull (); SelectedPath = paths?.FirstOrDefault (); diff --git a/src/Modern.Forms/Form.cs b/src/Modern.Forms/Form.cs index 97e8e72..d0cec12 100644 --- a/src/Modern.Forms/Form.cs +++ b/src/Modern.Forms/Form.cs @@ -38,7 +38,7 @@ public Form () : base (AvaloniaGlobals.GetRequiredService () Window.SetSystemDecorations (SystemDecorations.None); Window.SetExtendClientAreaToDecorationsHint (true); - Window.Closing = () => { + Window.Closing = (e) => { var args = new CancelEventArgs (); OnClosing (args); diff --git a/src/Modern.Forms/Modern.Forms.csproj b/src/Modern.Forms/Modern.Forms.csproj index 685353f..b73ef18 100644 --- a/src/Modern.Forms/Modern.Forms.csproj +++ b/src/Modern.Forms/Modern.Forms.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/Modern.Forms/OpenFileDialog.cs b/src/Modern.Forms/OpenFileDialog.cs index 97bc253..6d1f836 100644 --- a/src/Modern.Forms/OpenFileDialog.cs +++ b/src/Modern.Forms/OpenFileDialog.cs @@ -24,15 +24,15 @@ public class OpenFileDialog : FileDialog /// The window that owns this dialog. public async Task ShowDialog (Form owner) { - if (owner.window is ITopLevelImplWithStorageProvider parent) { + if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) { var options = new FilePickerOpenOptions { AllowMultiple = AllowMultiple, - SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null, + SuggestedStartLocation = GetInitialDirectory (), Title = Title, FileTypeFilter = filters }; - var result = await parent.StorageProvider.OpenFilePickerAsync (options); + var result = await parent.OpenFilePickerAsync (options); FileNames.Clear (); diff --git a/src/Modern.Forms/PopupWindow.cs b/src/Modern.Forms/PopupWindow.cs index 0526ba0..3824d18 100644 --- a/src/Modern.Forms/PopupWindow.cs +++ b/src/Modern.Forms/PopupWindow.cs @@ -50,7 +50,7 @@ public void Show (int x, int y) Size = Size.ToAvaloniaSize () }; - PopupImpl.PopupPositioner.Update (ppp); + PopupImpl.PopupPositioner?.Update (ppp); Show (); } diff --git a/src/Modern.Forms/SaveFileDialog.cs b/src/Modern.Forms/SaveFileDialog.cs index 876ba5f..6db212b 100644 --- a/src/Modern.Forms/SaveFileDialog.cs +++ b/src/Modern.Forms/SaveFileDialog.cs @@ -22,16 +22,16 @@ public class SaveFileDialog : FileDialog /// The window that owns this dialog. public async Task ShowDialog (Form owner) { - if (owner.window is ITopLevelImplWithStorageProvider parent) { + if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) { var options = new FilePickerSaveOptions { DefaultExtension= DefaultExtension, - SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null, + SuggestedStartLocation = GetInitialDirectory (), SuggestedFileName = FileName, Title = Title, FileTypeChoices = filters }; - var result = await parent.StorageProvider.SaveFilePickerAsync (options); + var result = await parent.SaveFilePickerAsync (options); FileNames.Clear (); diff --git a/src/Modern.Forms/WindowBase.cs b/src/Modern.Forms/WindowBase.cs index e712ec0..316d836 100644 --- a/src/Modern.Forms/WindowBase.cs +++ b/src/Modern.Forms/WindowBase.cs @@ -346,7 +346,7 @@ protected virtual void OnPaintBackground (PaintEventArgs e) e.Canvas.DrawBackground (Bounds, CurrentStyle); } - private void OnResize (Size size, PlatformResizeReason reason) + private void OnResize (Size size, WindowResizeReason reason) { adapter.SetBounds (DisplayRectangle.Left, DisplayRectangle.Top, Size.Width, Size.Height); }