• R/O
  • HTTP
  • SSH
  • HTTPS

FooEditEngine: Commit


Commit MetaInfo

Revision74e1d6edb76d6e8281138b0a34e29e54cfc14998 (tree)
Time2020-08-23 14:55:05
Authortest <test@yaho...>
Commitertest

Log Message

関連付けからの起動もできるようにした

Change Summary

Incremental Difference

--- a/UWP/Test/MainPage.xaml.cs
+++ b/UWP/Test/MainPage.xaml.cs
@@ -32,10 +32,6 @@ namespace Test
3232 this.InitializeComponent();
3333 this.DataContext = this.vm;
3434 //this.fooTextBox.AllowFocusOnInteraction = true;
35- PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
36- InputPane currentView = InputPane.GetForCurrentView();
37- currentView.Showing += currentView_Showing;
38- currentView.Hiding += currentView_Hiding;
3935 }
4036
4137 protected override async void OnNavigatedTo(NavigationEventArgs e)
@@ -50,8 +46,7 @@ namespace Test
5046 foreach (var file in fileargs.Files)
5147 {
5248 StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "mrufile");
53- this.vm.AddDocument();
54- await LoadFile(this.vm.CurrentDocument, file as IStorageFile);
49+ await this.vm.AddDocumentFromFile(file as IStorageFile);
5550 }
5651
5752 }
@@ -59,6 +54,20 @@ namespace Test
5954 {
6055 this.vm.Initalize();
6156 }
57+
58+ PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
59+ InputPane currentView = InputPane.GetForCurrentView();
60+ currentView.Showing += currentView_Showing;
61+ currentView.Hiding += currentView_Hiding;
62+ }
63+
64+ protected override void OnNavigatedFrom(NavigationEventArgs e)
65+ {
66+ base.OnNavigatedFrom(e);
67+ PrintManager.GetForCurrentView().PrintTaskRequested -= MainPage_PrintTaskRequested;
68+ InputPane currentView = InputPane.GetForCurrentView();
69+ currentView.Showing -= currentView_Showing;
70+ currentView.Hiding -= currentView_Hiding;
6271 }
6372
6473 void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
@@ -112,20 +121,7 @@ namespace Test
112121 var filepicker = new FileOpenPicker();
113122 filepicker.FileTypeFilter.Add(".txt");
114123 var file = await filepicker.PickSingleFileAsync();
115- await LoadFile(this.vm.CurrentDocument, file);
116- }
117-
118- private async Task LoadFile(FooEditEngine.Document doc,IStorageFile file)
119- {
120- if (file != null)
121- {
122- using (var ws = await file.OpenAsync(FileAccessMode.Read))
123- using (var fs = new StreamReader(ws.AsStream()))
124- {
125- await doc.LoadAsync(fs, null);
126- }
127- doc.RequestRedraw();
128- }
124+ await this.vm.AddDocumentFromFile(file);
129125 }
130126
131127 private async void Print_Button_Click(object sender, RoutedEventArgs e)
--- a/UWP/Test/MainViewModel.cs
+++ b/UWP/Test/MainViewModel.cs
@@ -7,12 +7,13 @@ using System.Text;
77 using System.Threading.Tasks;
88 using FooEditEngine;
99 using FooEditEngine.UWP;
10+using Windows.Storage;
1011
1112 namespace Test
1213 {
1314 class MainViewModel : INotifyPropertyChanged
1415 {
15- ObservableCollection<Document> _list = new ObservableCollection<Document>();
16+ static ObservableCollection<Document> _list = new ObservableCollection<Document>();
1617
1718 public MainViewModel()
1819 {
@@ -22,7 +23,7 @@ namespace Test
2223 {
2324 get
2425 {
25- return this._list;
26+ return MainViewModel._list;
2627 }
2728 }
2829
@@ -61,19 +62,35 @@ namespace Test
6162 doc.AutoComplete = new AutoCompleteBox(doc);
6263 doc.AutoComplete.Items = complete_collection;
6364 doc.AutoComplete.Enabled = true;
64- this._list.Add(doc);
65+ MainViewModel._list.Add(doc);
6566
6667 doc = new Document() { Title = "test2" };
67- this._list.Add(doc);
68+ MainViewModel._list.Add(doc);
6869
69- this.CurrentDocument = this._list[0];
70+ this.CurrentDocument = MainViewModel._list[0];
7071 }
7172
7273 public void AddDocument()
7374 {
74- var doc = new Document() { Title = "test" + this._list.Count };
75- this._list.Add(doc);
76- this.CurrentDocument = this._list.Last();
75+ var doc = new Document() { Title = "test" + MainViewModel._list.Count };
76+ MainViewModel._list.Add(doc);
77+ this.CurrentDocument = MainViewModel._list.Last();
78+ }
79+
80+ public async Task AddDocumentFromFile(IStorageFile file)
81+ {
82+ if (file != null)
83+ {
84+ var doc = new Document() { Title = "test" + MainViewModel._list.Count };
85+ using (var ws = await file.OpenAsync(FileAccessMode.Read))
86+ using (var fs = new StreamReader(ws.AsStream()))
87+ {
88+ await doc.LoadAsync(fs, null);
89+ }
90+ doc.RequestRedraw();
91+ MainViewModel._list.Add(doc);
92+ this.CurrentDocument = MainViewModel._list.Last();
93+ }
7794 }
7895
7996 private void OnPropertyChanged(object sender, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
Show on old repository browser