OSDN Git Service

デモプロジェクトで折り返し方法の変更が反映されないバグを修正した
[fooeditengine/FooEditEngine.git] / Metro / Test / MainPage.xaml.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11 using System;
12 using System.Collections.Generic;
13 using System.Text;
14 using System.IO;
15 using Windows.Graphics.Printing;
16 using Windows.Storage.Pickers;
17 using Windows.Storage;
18 using Windows.UI.ViewManagement;
19 using Windows.UI.Xaml;
20 using Windows.UI.Xaml.Controls;
21 using Windows.UI.Xaml.Navigation;
22 using Windows.UI.ApplicationSettings;
23 using FooEditEngine;
24 using FooEditEngine.Metro;
25 using FooEditEngine.Test;
26
27 // 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
28
29 namespace Test
30 {
31     /// <summary>
32     /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
33     /// </summary>
34     public sealed partial class MainPage : Page
35     {
36         public MainPage()
37         {
38             this.InitializeComponent();
39             this.Current_ChangedSetting(AppSettings.Current, null);
40             InputPane currentView = InputPane.GetForCurrentView();
41             currentView.Showing += currentView_Showing;
42             currentView.Hiding += currentView_Hiding;
43             PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
44         }
45
46         void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
47         {
48             FooPrintText printtext = new FooPrintText();
49             printtext.Fotter = "fotter";
50             printtext.Header = "header";
51             printtext.Padding = new FooEditEngine.Padding(20, 20, 20, 20);
52             printtext.Print(args.Request, "Text Print", this.fooTextBox);
53         }
54
55         /// <summary>
56         /// このページがフレームに表示されるときに呼び出されます。
57         /// </summary>
58         /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter 
59         /// プロパティは、通常、ページを構成するために使用します。</param>
60         protected override void OnNavigatedTo(NavigationEventArgs e)
61         {
62             AppSettings.Current.ChangedSetting += Current_ChangedSetting;
63         }
64
65         void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
66         {
67             this.fooTextBox.Margin = new Thickness(0);
68             args.EnsuredFocusedElementInView = true;
69         }
70
71         void currentView_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
72         {
73             this.fooTextBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
74             args.EnsuredFocusedElementInView = true;
75         }
76
77         void Current_ChangedSetting(object sender, EventArgs e)
78         {
79             AppSettings setting = (AppSettings)sender;
80             this.fooTextBox.FlowDirection = setting.IsRTL ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
81             this.fooTextBox.DrawCaretLine = setting.ShowLineMarker;
82             this.fooTextBox.DrawLineNumber = setting.ShowLineNumber;
83             this.fooTextBox.DrawRuler = setting.ShowRuler;
84             if (setting.HilightXML)
85             {
86                 this.fooTextBox.Hilighter = new XmlHilighter();
87                 this.fooTextBox.LayoutLineCollection.HilightAll();
88             }
89             else
90             {
91                 this.fooTextBox.Hilighter = null;
92                 this.fooTextBox.LayoutLineCollection.ClearHilight();
93             }
94             this.fooTextBox.Visibility = setting.IsVisible ? Visibility.Visible : Visibility.Collapsed;
95             this.fooTextBox.LineBreakMethod = setting.CurrentLineBreakMethod.Method;
96             this.fooTextBox.LineBreakCharCount = 50;
97             this.fooTextBox.PerfomLayouts();
98             this.fooTextBox.Refresh();
99         }
100
101         private async void Button_Click(object sender, RoutedEventArgs e)
102         {
103             FileOpenPicker openPicker = new FileOpenPicker();
104
105             openPicker.ViewMode = PickerViewMode.List;
106
107             // ファイル形式
108             openPicker.FileTypeFilter.Add("*");
109
110             // 最初に表示される場所
111             openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
112
113             StorageFile file = await openPicker.PickSingleFileAsync();
114             if (file != null)
115             {
116                 this.fooTextBox.IsEnabled = false;
117                 using (Stream stream = await file.OpenStreamForReadAsync())
118                 using(StreamReader reader = new StreamReader(stream))
119                 {
120                     await this.fooTextBox.LoadFileAsync(reader,null);
121                     this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
122                     this.fooTextBox.LayoutLineCollection.GenerateFolding();
123                     this.fooTextBox.IsEnabled = true;
124                     this.fooTextBox.Refresh();
125                 }
126             }
127         }
128
129         private async void Button_Click_1(object sender, RoutedEventArgs e)
130         {
131             FileSavePicker savePicker = new FileSavePicker();
132             savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
133             savePicker.FileTypeChoices.Add("Text Types", new List<string>() { ".txt" });
134             savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
135             StorageFile file = await savePicker.PickSaveFileAsync();
136             if (file != null)
137             {
138                 using (Stream stream = await file.OpenStreamForWriteAsync())
139                 using (StreamWriter writer = new StreamWriter(stream))
140                 {
141                     await this.fooTextBox.SaveFile(writer,null);
142                 }
143             }
144         }
145
146     }
147 }