2 * Copyright (C) 2013 FooProject
\r
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
\r
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
\r
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
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/>.
\r
12 using System.Collections.Generic;
\r
15 using Windows.Graphics.Printing;
\r
16 using Windows.Storage.Pickers;
\r
17 using Windows.Storage;
\r
18 using Windows.UI.ViewManagement;
\r
19 using Windows.UI.Xaml;
\r
20 using Windows.UI.Xaml.Controls;
\r
21 using Windows.UI.Xaml.Navigation;
\r
22 using Windows.UI.ApplicationSettings;
\r
23 using FooEditEngine;
\r
24 using FooEditEngine.Metro;
\r
26 // 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
\r
31 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
\r
33 public sealed partial class MainPage : Page
\r
37 this.InitializeComponent();
\r
38 this.Current_ChangedSetting(AppSettings.Current, null);
\r
39 InputPane currentView = InputPane.GetForCurrentView();
\r
40 currentView.Showing += currentView_Showing;
\r
41 currentView.Hiding += currentView_Hiding;
\r
42 PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
\r
45 void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
\r
47 FooPrintText printtext = new FooPrintText();
\r
48 printtext.Fotter = "fotter";
\r
49 printtext.Header = "header";
\r
50 printtext.Padding = new FooEditEngine.Padding(20, 20, 20, 20);
\r
51 printtext.Print(args.Request, "Text Print", this.fooTextBox);
\r
55 /// このページがフレームに表示されるときに呼び出されます。
\r
57 /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
\r
58 /// プロパティは、通常、ページを構成するために使用します。</param>
\r
59 protected override void OnNavigatedTo(NavigationEventArgs e)
\r
61 AppSettings.Current.ChangedSetting += Current_ChangedSetting;
\r
64 void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
\r
66 this.fooTextBox.Margin = new Thickness(0);
\r
67 args.EnsuredFocusedElementInView = true;
\r
70 void currentView_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
\r
72 this.fooTextBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
\r
73 args.EnsuredFocusedElementInView = true;
\r
76 void Current_ChangedSetting(object sender, EventArgs e)
\r
78 AppSettings setting = (AppSettings)sender;
\r
79 this.fooTextBox.FlowDirection = setting.IsRTL ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
\r
80 this.fooTextBox.DrawCaretLine = setting.ShowLineMarker;
\r
81 this.fooTextBox.DrawLineNumber = setting.ShowLineNumber;
\r
82 this.fooTextBox.DrawRuler = setting.ShowRuler;
\r
83 if (setting.HilightXML)
\r
85 this.fooTextBox.Hilighter = new XmlHilighter();
\r
86 this.fooTextBox.LayoutLineCollection.HilightAll();
\r
90 this.fooTextBox.Hilighter = null;
\r
91 this.fooTextBox.LayoutLineCollection.ClearHilight();
\r
93 this.fooTextBox.LineBreakMethod = setting.CurrentLineBreakMethod.Method;
\r
94 this.fooTextBox.LineBreakCharCount = 50;
\r
95 this.fooTextBox.Padding = new Thickness(setting.Padding);
\r
96 this.fooTextBox.Refresh();
\r
99 private async void Button_Click(object sender, RoutedEventArgs e)
\r
101 FileOpenPicker openPicker = new FileOpenPicker();
\r
103 openPicker.ViewMode = PickerViewMode.List;
\r
106 openPicker.FileTypeFilter.Add("*");
\r
109 openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
111 StorageFile file = await openPicker.PickSingleFileAsync();
\r
114 using (Stream stream = await file.OpenStreamForReadAsync())
\r
115 using(StreamReader reader = new StreamReader(stream))
\r
117 await this.fooTextBox.Document.LoadAsync(reader);
\r
118 this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
\r
119 this.fooTextBox.LayoutLineCollection.GenerateFolding();
\r
120 this.fooTextBox.Refresh();
\r
125 private async void Button_Click_1(object sender, RoutedEventArgs e)
\r
127 FileSavePicker savePicker = new FileSavePicker();
\r
128 savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
129 savePicker.FileTypeChoices.Add("Text Types", new List<string>() { ".txt" });
\r
130 savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
131 StorageFile file = await savePicker.PickSaveFileAsync();
\r
134 using (Stream stream = await file.OpenStreamForWriteAsync())
\r
135 using (StreamWriter writer = new StreamWriter(stream))
\r
137 await this.fooTextBox.Document.SaveAsync(writer);
\r