• R/O
  • HTTP
  • SSH
  • HTTPS

FooEditEngine: Commit


Commit MetaInfo

Revisiond117ef4b20116abb3c954ef6d3f7c92ad4065241 (tree)
Time2020-08-24 21:30:23
Authortest <test@yaho...>
Commitertest

Log Message

ドキュメントリストをシングルトンで保持すると落ちるらしい

Change Summary

Incremental Difference

--- a/UWP/Test/App.xaml.cs
+++ b/UWP/Test/App.xaml.cs
@@ -79,7 +79,7 @@ namespace Test
7979 }
8080 }
8181
82- protected override void OnFileActivated(FileActivatedEventArgs e)
82+ protected override async void OnFileActivated(FileActivatedEventArgs e)
8383 {
8484 base.OnFileActivated(e);
8585 Frame rootFrame = Window.Current.Content as Frame;
@@ -90,7 +90,15 @@ namespace Test
9090 rootFrame.NavigationFailed += OnNavigationFailed;
9191 Window.Current.Content = rootFrame;
9292 }
93- rootFrame.Navigate(typeof(MainPage), e);
93+ if (rootFrame.Content == null)
94+ {
95+ rootFrame.Navigate(typeof(MainPage), e);
96+ }
97+ else
98+ {
99+ MainPage page = rootFrame.Content as MainPage;
100+ await page.LoadManyFiles(e);
101+ }
94102 Window.Current.Activate();
95103 }
96104
--- a/UWP/Test/MainPage.xaml.cs
+++ b/UWP/Test/MainPage.xaml.cs
@@ -39,16 +39,7 @@ namespace Test
3939 var fileargs = e.Parameter as FileActivatedEventArgs;
4040 if (fileargs != null)
4141 {
42- var filepaths = from file in fileargs.Files
43- select file.Path;
44-
45- //MRUに追加しないと後で開けない
46- foreach (var file in fileargs.Files)
47- {
48- StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "mrufile");
49- await this.vm.AddDocumentFromFile(file as IStorageFile);
50- }
51-
42+ await this.LoadManyFiles(fileargs);
5243 }
5344 else if(this.vm.DocumentList.Count == 0)
5445 {
@@ -61,6 +52,20 @@ namespace Test
6152 currentView.Hiding += currentView_Hiding;
6253 }
6354
55+ public async Task LoadManyFiles(FileActivatedEventArgs fileargs)
56+ {
57+ var filepaths = from file in fileargs.Files
58+ select file.Path;
59+
60+ //MRUに追加しないと後で開けない
61+ foreach (var file in fileargs.Files)
62+ {
63+ StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "mrufile");
64+ await this.vm.AddDocumentFromFile(file as IStorageFile);
65+ }
66+
67+ }
68+
6469 protected override void OnNavigatedFrom(NavigationEventArgs e)
6570 {
6671 base.OnNavigatedFrom(e);
--- a/UWP/Test/MainViewModel.cs
+++ b/UWP/Test/MainViewModel.cs
@@ -13,7 +13,7 @@ namespace Test
1313 {
1414 class MainViewModel : INotifyPropertyChanged
1515 {
16- static ObservableCollection<Document> _list = new ObservableCollection<Document>();
16+ ObservableCollection<Document> _list = new ObservableCollection<Document>();
1717
1818 public MainViewModel()
1919 {
@@ -23,7 +23,7 @@ namespace Test
2323 {
2424 get
2525 {
26- return MainViewModel._list;
26+ return this._list;
2727 }
2828 }
2929
@@ -63,35 +63,37 @@ namespace Test
6363 doc.AutoComplete.Items = complete_collection;
6464 doc.AutoComplete.Enabled = true;
6565 doc.ShowLineBreak = true;
66- MainViewModel._list.Add(doc);
66+ _list.Add(doc);
6767
6868 doc = new Document() { Title = "test2" };
69- MainViewModel._list.Add(doc);
69+ _list.Add(doc);
7070
71- this.CurrentDocument = MainViewModel._list[0];
71+ this.CurrentDocument = _list[0];
7272 }
7373
7474 public void AddDocument()
7575 {
76- var doc = new Document() { Title = "test" + MainViewModel._list.Count };
77- MainViewModel._list.Add(doc);
78- this.CurrentDocument = MainViewModel._list.Last();
76+ var doc = new Document() { Title = "test" + _list.Count };
77+ _list.Add(doc);
78+ this.CurrentDocument = _list.Last();
7979 }
8080
8181 public async Task AddDocumentFromFile(IStorageFile file)
8282 {
8383 if (file != null)
8484 {
85- var doc = new Document() { Title = "test" + MainViewModel._list.Count };
85+ var doc = new Document() { Title = "test" + _list.Count };
8686 doc.ShowLineBreak = true;
87+ doc.ShowFullSpace = true;
88+ doc.ShowTab = true;
8789 using (var ws = await file.OpenAsync(FileAccessMode.Read))
8890 using (var fs = new StreamReader(ws.AsStream()))
8991 {
9092 await doc.LoadAsync(fs, null);
9193 }
9294 doc.RequestRedraw();
93- MainViewModel._list.Add(doc);
94- this.CurrentDocument = MainViewModel._list.Last();
95+ _list.Add(doc);
96+ this.CurrentDocument = _list.Last();
9597 }
9698 }
9799
Show on old repository browser