Skip to content

Commit

Permalink
Add json data saving
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinyZero0 committed Dec 29, 2022
1 parent f1202e8 commit a0cbf7c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public override void OnFrameworkInitializationCompleted()
{
DataContext = new MainWindowViewModel(db),
};

}

base.OnFrameworkInitializationCompleted();
Expand Down
13 changes: 13 additions & 0 deletions Avalonia.AXAML.LanguageServer.Log20221229.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3411,3 +3411,16 @@ System.Threading.Channels.ChannelClosedException: The channel has been closed.
2022-12-29 18:57:01.075 +03:00 [VRB] Converting params for Notification textDocument/didSave to OmniSharp.Extensions.LanguageServer.Protocol.Models.DidSaveTextDocumentParams
2022-12-29 18:57:01.075 +03:00 [DBG] Finished: Routing Notification textDocument/didSave in 0ms
2022-12-29 18:57:01.075 +03:00 [DBG] Finished: Processing notification textDocument/didSave in 0ms
2022-12-29 20:30:38.397 +03:00 [DBG] Finding descriptors for textDocument/didOpen
2022-12-29 20:30:38.397 +03:00 [VRB] Created attribute xml::file:///home/zero/dev/CSharp/Avalonia/ToDoMVVM/ToDo/App.axaml
2022-12-29 20:30:38.397 +03:00 [VRB] Looking for handler for descriptors textDocument/didOpen
2022-12-29 20:30:38.398 +03:00 [VRB] Checking handler textDocument/didOpen:Avalonia.AXAML.LanguageServer.Handlers.TextDocumentHandler
2022-12-29 20:30:38.398 +03:00 [VRB] Registration options OmniSharp.Extensions.LanguageServer.Protocol.Models.TextDocumentOpenRegistrationOptions
2022-12-29 20:30:38.398 +03:00 [VRB] Document Selector [**/*.xaml], [**/*.axaml]
2022-12-29 20:30:38.406 +03:00 [VRB] Handler Selected: Avalonia.AXAML.LanguageServer.Handlers.TextDocumentHandler via [**/*.xaml], [**/*.axaml] (targeting OmniSharp.Extensions.JsonRpc.IJsonRpcNotificationHandler`1[[OmniSharp.Extensions.LanguageServer.Protocol.Models.DidOpenTextDocumentParams, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022]])
2022-12-29 20:30:38.406 +03:00 [DBG] Queueing "Serial":textDocument/didOpen request for processing
2022-12-29 20:30:38.406 +03:00 [DBG] Starting: Processing notification textDocument/didOpen
2022-12-29 20:30:38.406 +03:00 [DBG] Starting: Routing Notification textDocument/didOpen
2022-12-29 20:30:38.406 +03:00 [VRB] Converting params for Notification textDocument/didOpen to OmniSharp.Extensions.LanguageServer.Protocol.Models.DidOpenTextDocumentParams
2022-12-29 20:30:38.407 +03:00 [DBG] Finished: Routing Notification textDocument/didOpen in 0ms
2022-12-29 20:30:38.407 +03:00 [DBG] Finished: Processing notification textDocument/didOpen in 0ms
7 changes: 5 additions & 2 deletions Models/DataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public IEnumerable<ToDoItem> Get()
}
else return new List<ToDoItem>();
}
public void Save()
public void Save(IEnumerable<ToDoItem> items)
{

using (var jsonSW = new StreamWriter(@"data.json"))
{
jsonSW.Write(JsonConvert.SerializeObject(items, Formatting.Indented));
}
}

}
Expand Down
6 changes: 6 additions & 0 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ToDo.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
DataBase DB;
ViewModelBase content;
public ViewModelBase Content
{
Expand All @@ -19,6 +20,7 @@ public ViewModelBase Content
public MainWindowViewModel(DataBase db)
{
Content = Items = new ToDoListViewModel(db.Get());
this.DB = db;
}
public void NewItem()
{
Expand All @@ -42,5 +44,9 @@ public void RemoveItem()
{
Items.Items.Remove(Items.Items.ToList().Find(x => x.Name == Items.ItemSelected.Name));
}
public void Save()
{
this.DB.Save(Items.Items);
}
}
}
4 changes: 3 additions & 1 deletion Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
}
this.Closing += delegate { ((MainWindowViewModel)this.DataContext).Save(); };
}
}

}
8 changes: 8 additions & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"Name": "sdgscgsge5",
"Content": "Filler",
"IsDone": true,
"Priority": 0
}
]

0 comments on commit a0cbf7c

Please sign in to comment.