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.Print(args.Request, "Text Print", this.fooTextBox);
\r
52 /// このページがフレームに表示されるときに呼び出されます。
\r
54 /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
\r
55 /// プロパティは、通常、ページを構成するために使用します。</param>
\r
56 protected override void OnNavigatedTo(NavigationEventArgs e)
\r
58 AppSettings.Current.ChangedSetting += Current_ChangedSetting;
\r
61 void currentView_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
\r
63 this.fooTextBox.Margin = new Thickness(0);
\r
64 args.EnsuredFocusedElementInView = true;
\r
67 void currentView_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
\r
69 this.fooTextBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
\r
70 args.EnsuredFocusedElementInView = true;
\r
73 void Current_ChangedSetting(object sender, EventArgs e)
\r
75 AppSettings setting = (AppSettings)sender;
\r
76 this.fooTextBox.FlowDirection = setting.IsRTL ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
\r
77 this.fooTextBox.DrawCaretLine = setting.ShowLineMarker;
\r
78 this.fooTextBox.DrawLineNumber = setting.ShowLineNumber;
\r
79 this.fooTextBox.DrawRuler = setting.ShowRuler;
\r
80 if (setting.HilightXML)
\r
82 this.fooTextBox.Hilighter = new XmlHilighter();
\r
83 this.fooTextBox.LayoutLineCollection.HilightAll();
\r
87 this.fooTextBox.Hilighter = null;
\r
88 this.fooTextBox.LayoutLineCollection.ClearHilight();
\r
90 this.fooTextBox.LineBreakMethod = setting.CurrentLineBreakMethod.Method;
\r
91 this.fooTextBox.LineBreakCharCount = 50;
\r
92 this.fooTextBox.Refresh();
\r
95 private async void Button_Click(object sender, RoutedEventArgs e)
\r
97 FileOpenPicker openPicker = new FileOpenPicker();
\r
99 openPicker.ViewMode = PickerViewMode.List;
\r
102 openPicker.FileTypeFilter.Add("*");
\r
105 openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
107 StorageFile file = await openPicker.PickSingleFileAsync();
\r
110 using (Stream stream = await file.OpenStreamForReadAsync())
\r
111 using(StreamReader reader = new StreamReader(stream))
\r
113 await this.fooTextBox.Document.LoadAsync(reader);
\r
114 this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
\r
115 this.fooTextBox.LayoutLineCollection.GenerateFolding();
\r
116 this.fooTextBox.Refresh();
\r
121 private async void Button_Click_1(object sender, RoutedEventArgs e)
\r
123 FileSavePicker savePicker = new FileSavePicker();
\r
124 savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
125 savePicker.FileTypeChoices.Add("Text Types", new List<string>() { ".txt" });
\r
126 savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
\r
127 StorageFile file = await savePicker.PickSaveFileAsync();
\r
130 using (Stream stream = await file.OpenStreamForWriteAsync())
\r
131 using (StreamWriter writer = new StreamWriter(stream))
\r
133 await this.fooTextBox.Document.SaveAsync(writer);
\r