From bb49dffd470b1d3e20d9de04af20bf349087c0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Tue, 16 Aug 2022 17:56:47 +0200 Subject: [PATCH] Update MainWindowViewModel.cs --- .../Notepad/ViewModels/MainWindowViewModel.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/samples/Notepad/ViewModels/MainWindowViewModel.cs b/samples/Notepad/ViewModels/MainWindowViewModel.cs index 530448ac9..a183afae9 100644 --- a/samples/Notepad/ViewModels/MainWindowViewModel.cs +++ b/samples/Notepad/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Text; using System.Threading.Tasks; using Avalonia; @@ -46,7 +47,7 @@ private Encoding GetEncoding(string path) private FileViewModel OpenFileViewModel(string path) { - Encoding encoding = GetEncoding(path); + var encoding = GetEncoding(path); string text = File.ReadAllText(path, encoding); string title = Path.GetFileName(path); return new FileViewModel() @@ -88,7 +89,7 @@ private void AddFileViewModel(FileViewModel fileViewModel) private FileViewModel GetUntitledFileViewModel() { - return new() + return new FileViewModel { Path = string.Empty, Title = "Untitled", @@ -116,10 +117,15 @@ public void FileNew() public async void FileOpen() { - var dlg = new OpenFileDialog(); - dlg.Filters.Add(new FileDialogFilter() { Name = "Text document", Extensions = { "txt" } }); - dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } }); - dlg.AllowMultiple = true; + var dlg = new OpenFileDialog + { + Filters = new List + { + new() {Name = "Text document", Extensions = {"txt"}}, + new() {Name = "All", Extensions = {"*"}} + }, + AllowMultiple = true + }; var window = GetWindow(); if (window is null) { @@ -164,11 +170,16 @@ public async void FileSaveAs() private async Task FileSaveAsImpl(FileViewModel fileViewModel) { - var dlg = new SaveFileDialog(); - dlg.Filters.Add(new FileDialogFilter() { Name = "Text document", Extensions = { "txt" } }); - dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } }); - dlg.InitialFileName = fileViewModel.Title; - dlg.DefaultExtension = "txt"; + var dlg = new SaveFileDialog + { + Filters = new List + { + new() {Name = "Text document", Extensions = {"txt"}}, + new() {Name = "All", Extensions = {"*"}} + }, + InitialFileName = fileViewModel.Title, + DefaultExtension = "txt" + }; var window = GetWindow(); if (window is null) {