OSDN Git Service

行を生成するメソッドをLineToIndexTableに移動した
[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                 System.Diagnostics.Debug.WriteLine("hilight enable");
87                 this.fooTextBox.Hilighter = new XmlHilighter();
88                 this.fooTextBox.LayoutLineCollection.HilightAll();
89             }
90             else
91             {
92                 System.Diagnostics.Debug.WriteLine("hilight disable");
93                 this.fooTextBox.Hilighter = null;
94                 this.fooTextBox.LayoutLineCollection.ClearHilight();
95             }
96             this.fooTextBox.Visibility = setting.IsVisible ? Visibility.Visible : Visibility.Collapsed;
97             this.fooTextBox.LineBreakMethod = setting.CurrentLineBreakMethod.Method;
98             this.fooTextBox.LineBreakCharCount = 50;
99             this.fooTextBox.PerfomLayouts();
100             this.fooTextBox.Refresh();
101         }
102
103         private async void Button_Click(object sender, RoutedEventArgs e)
104         {
105             FileOpenPicker openPicker = new FileOpenPicker();
106
107             openPicker.ViewMode = PickerViewMode.List;
108
109             // ファイル形式
110             openPicker.FileTypeFilter.Add("*");
111
112             // 最初に表示される場所
113             openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
114
115             StorageFile file = await openPicker.PickSingleFileAsync();
116             if (file != null)
117             {
118                 this.fooTextBox.IsEnabled = false;
119                 using (Stream stream = await file.OpenStreamForReadAsync())
120                 using(StreamReader reader = new StreamReader(stream))
121                 {
122                     await this.fooTextBox.LoadFileAsync(reader,null);
123                     this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
124                     this.fooTextBox.LayoutLineCollection.GenerateFolding();
125                     this.fooTextBox.IsEnabled = true;
126                     this.fooTextBox.Refresh();
127                 }
128             }
129         }
130
131         private async void Button_Click_1(object sender, RoutedEventArgs e)
132         {
133             FileSavePicker savePicker = new FileSavePicker();
134             savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
135             savePicker.FileTypeChoices.Add("Text Types", new List<string>() { ".txt" });
136             savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
137             StorageFile file = await savePicker.PickSaveFileAsync();
138             if (file != null)
139             {
140                 using (Stream stream = await file.OpenStreamForWriteAsync())
141                 using (StreamWriter writer = new StreamWriter(stream))
142                 {
143                     await this.fooTextBox.SaveFile(writer,null);
144                 }
145             }
146         }
147
148     }
149 }