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.
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.
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/>.
12 using System.Collections.Generic;
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;
24 using FooEditEngine.Metro;
25 using FooEditEngine.Test;
27 // 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
32 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
34 public sealed partial class MainPage : Page
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;
46 void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
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);
56 /// このページがフレームに表示されるときに呼び出されます。
58 /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
59 /// プロパティは、通常、ページを構成するために使用します。</param>
60 protected override void OnNavigatedTo(NavigationEventArgs e)
62 AppSettings.Current.ChangedSetting += Current_ChangedSetting;
65 void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
67 this.fooTextBox.Margin = new Thickness(0);
68 args.EnsuredFocusedElementInView = true;
71 void currentView_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
73 this.fooTextBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
74 args.EnsuredFocusedElementInView = true;
77 void Current_ChangedSetting(object sender, EventArgs e)
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)
86 System.Diagnostics.Debug.WriteLine("hilight enable");
87 this.fooTextBox.Hilighter = new XmlHilighter();
88 this.fooTextBox.LayoutLineCollection.HilightAll();
92 System.Diagnostics.Debug.WriteLine("hilight disable");
93 this.fooTextBox.Hilighter = null;
94 this.fooTextBox.LayoutLineCollection.ClearHilight();
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();
103 private async void Button_Click(object sender, RoutedEventArgs e)
105 FileOpenPicker openPicker = new FileOpenPicker();
107 openPicker.ViewMode = PickerViewMode.List;
110 openPicker.FileTypeFilter.Add("*");
113 openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
115 StorageFile file = await openPicker.PickSingleFileAsync();
118 this.fooTextBox.IsEnabled = false;
119 using (Stream stream = await file.OpenStreamForReadAsync())
120 using(StreamReader reader = new StreamReader(stream))
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();
131 private async void Button_Click_1(object sender, RoutedEventArgs e)
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();
140 using (Stream stream = await file.OpenStreamForWriteAsync())
141 using (StreamWriter writer = new StreamWriter(stream))
143 await this.fooTextBox.SaveFile(writer,null);