Skip to content

Commit

Permalink
Update MainWindowViewModel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Aug 16, 2022
1 parent a9b8c41 commit bb49dff
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions samples/Notepad/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -88,7 +89,7 @@ private void AddFileViewModel(FileViewModel fileViewModel)

private FileViewModel GetUntitledFileViewModel()
{
return new()
return new FileViewModel
{
Path = string.Empty,
Title = "Untitled",
Expand Down Expand Up @@ -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<FileDialogFilter>
{
new() {Name = "Text document", Extensions = {"txt"}},
new() {Name = "All", Extensions = {"*"}}
},
AllowMultiple = true
};
var window = GetWindow();
if (window is null)
{
Expand Down Expand Up @@ -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<FileDialogFilter>
{
new() {Name = "Text document", Extensions = {"txt"}},
new() {Name = "All", Extensions = {"*"}}
},
InitialFileName = fileViewModel.Title,
DefaultExtension = "txt"
};
var window = GetWindow();
if (window is null)
{
Expand Down

0 comments on commit bb49dff

Please sign in to comment.