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/>.
13 using System.Windows.Controls;
14 using System.Windows.Documents;
15 using System.Windows.Media;
16 using System.Windows.Threading;
18 using FooEditEngine.WPF;
19 using Microsoft.Win32;
24 /// MainWindow.xaml の相互作用ロジック
26 public partial class MainWindow : Window
28 System.Threading.CancellationTokenSource cancleTokenSrc = new System.Threading.CancellationTokenSource();
31 InitializeComponent();
32 this.fooTextBox.MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(fooTextBox_MouseDoubleClick);
33 this.fooTextBox.CaretMoved += fooTextBox_CaretMoved;
34 this.fooTextBox.ShowTab = true;
35 this.fooTextBox.ShowFullSpace = true;
36 this.fooTextBox.ShowLineBreak = true;
37 this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
38 this.Enable.IsChecked = true;
39 this.URLMark.IsChecked = true;
41 this.Closed += MainWindow_Closed;
44 void fooTextBox_CaretMoved(object sender, System.EventArgs e)
46 this.CaretIndex.Text = string.Format("Index:{0}", this.fooTextBox.SelectionStart);
47 this.SelectLength.Text = string.Format("Select Length:{0}", this.fooTextBox.SelectionLength);
50 void MainWindow_Closed(object sender, System.EventArgs e)
52 this.cancleTokenSrc.Cancel();
53 this.fooTextBox.Dispose();
56 void fooTextBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
58 FooMouseButtonEventArgs fe = (FooMouseButtonEventArgs)e;
59 foreach (Marker m in this.fooTextBox.Document.GetMarkers(fe.Index))
61 if (m.hilight == HilightType.Url)
63 MessageBox.Show(this.fooTextBox.Document.ToString(m.start, m.length));
70 private void MenuItem_Click(object sender, RoutedEventArgs e)
72 if (this.fooTextBox.IsEnabled)
73 this.fooTextBox.IsEnabled = false;
75 this.fooTextBox.IsEnabled = true;
76 this.Enable.IsChecked = this.fooTextBox.IsEnabled;
77 this.fooTextBox.Refresh();
80 private void MenuItem_Click_1(object sender, RoutedEventArgs e)
82 if (this.fooTextBox.DrawLineNumber)
83 this.fooTextBox.DrawLineNumber = false;
85 this.fooTextBox.DrawLineNumber = true;
86 this.ShowLineNumber.IsChecked = this.fooTextBox.DrawLineNumber;
87 this.fooTextBox.Refresh();
90 private void MenuItem_Click_2(object sender, RoutedEventArgs e)
92 PrintDialog pd = new PrintDialog();
93 pd.PageRangeSelection = PageRangeSelection.AllPages;
94 pd.UserPageRangeEnabled = true;
95 if (pd.ShowDialog() == false)
97 FooPrintText printtext = new FooPrintText();
98 printtext.Document = this.fooTextBox.Document;
99 printtext.Font = this.fooTextBox.FontFamily;
100 printtext.FontSize = this.fooTextBox.FontSize;
101 printtext.DrawLineNumber = this.fooTextBox.DrawLineNumber;
102 printtext.Header = "header";
103 printtext.Footer = "footter";
104 printtext.LineBreakMethod = this.fooTextBox.LineBreakMethod;
105 printtext.LineBreakCharCount = this.fooTextBox.LineBreakCharCount;
106 printtext.MarkURL = true;
107 printtext.Hilighter = this.fooTextBox.Hilighter;
108 printtext.Foreground = this.fooTextBox.Foreground;
109 printtext.URL = this.fooTextBox.URL;
110 printtext.Comment = this.fooTextBox.Comment;
111 printtext.Keyword1 = this.fooTextBox.Keyword1;
112 printtext.Keyword2 = this.fooTextBox.Keyword2;
113 printtext.Litral = this.fooTextBox.Literal;
114 printtext.FlowDirection = this.fooTextBox.FlowDirection;
115 if (pd.PageRangeSelection == PageRangeSelection.AllPages)
117 printtext.StartPage = -1;
118 printtext.EndPage = -1;
122 printtext.StartPage = pd.PageRange.PageFrom;
123 printtext.EndPage = pd.PageRange.PageTo;
125 printtext.PageRect = new Rect(0,0,pd.PrintableAreaWidth, pd.PrintableAreaHeight);
129 private async void MenuItem_Click_3(object sender, RoutedEventArgs e)
131 OpenFileDialog ofd = new OpenFileDialog();
132 bool result = (bool)ofd.ShowDialog(this);
135 await this.fooTextBox.Document.LoadAsync(ofd.FileName, Encoding.Default,this.cancleTokenSrc);
136 this.fooTextBox.Refresh();
140 private void MenuItem_Click_4(object sender, RoutedEventArgs e)
142 if (this.fooTextBox.LineBreakMethod == LineBreakMethod.None)
143 this.fooTextBox.LineBreakMethod = LineBreakMethod.CharUnit;
145 this.fooTextBox.LineBreakMethod = LineBreakMethod.None;
146 this.fooTextBox.LineBreakCharCount = 10;
147 this.fooTextBox.PerfomLayouts();
148 this.fooTextBox.Refresh();
151 private void MenuItem_Click_5(object sender, RoutedEventArgs e)
153 Document doc = this.fooTextBox.Document;
154 doc.Insert(0,"this is a pen");
155 doc.SetMarker(Marker.Create(0, 4, HilightType.Sold));
156 doc.SetMarker(Marker.Create(8, 1, HilightType.Select, 255, 128, 128, 128));
157 doc.SetMarker(Marker.Create(10, 3, HilightType.Squiggle, 255, 255, 0, 0));
158 this.fooTextBox.Refresh();
161 private void MenuItem_Click_6(object sender, RoutedEventArgs e)
163 this.fooTextBox.FlowDirection = this.RTL.IsChecked ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
164 this.fooTextBox.Refresh();
167 private void MenuItem_Click_7(object sender, RoutedEventArgs e)
169 if (this.fooTextBox.Hilighter != null)
171 this.fooTextBox.Hilighter = null;
172 this.fooTextBox.LayoutLineCollection.ClearHilight();
173 this.XMLHilight.IsChecked = false;
177 this.fooTextBox.Hilighter = new XmlHilighter();
178 this.fooTextBox.LayoutLineCollection.HilightAll();
179 this.XMLHilight.IsChecked = true;
181 this.fooTextBox.Refresh();
184 private void MenuItem_Click_9(object sender, RoutedEventArgs e)
186 this.fooTextBox.LayoutLineCollection.GenerateFolding();
187 this.fooTextBox.Refresh();
190 private void MenuItem_Click_8(object sender, RoutedEventArgs e)
192 if (this.fooTextBox.DrawRuler)
193 this.fooTextBox.DrawRuler = false;
195 this.fooTextBox.DrawRuler = true;
196 this.ShowRuler.IsChecked = this.fooTextBox.DrawRuler;
197 this.fooTextBox.Refresh();
200 private async void MenuItem_Click_10(object sender, RoutedEventArgs e)
202 SaveFileDialog sfd = new SaveFileDialog();
203 bool result = (bool)sfd.ShowDialog(this);
206 await this.fooTextBox.Document.SaveAsync(sfd.FileName,Encoding.Default,"\r\n",cancleTokenSrc);
207 MessageBox.Show("complete");
211 private void ReplaceAll_Click(object sender, RoutedEventArgs e)
213 System.Diagnostics.Stopwatch time = new System.Diagnostics.Stopwatch();
215 this.fooTextBox.Document.FireUpdateEvent = false;
216 this.fooTextBox.Document.ReplaceAll2(this.FindPattern.Text, this.ReplacePattern.Text,true);
217 this.fooTextBox.Document.FireUpdateEvent = true;
219 this.fooTextBox.Refresh();
220 MessageBox.Show(string.Format("complete elpased time:{0}s",time.ElapsedMilliseconds/1000.0f));
223 private void URLMark_Click(object sender, RoutedEventArgs e)
225 if (this.fooTextBox.MarkURL)
227 this.fooTextBox.MarkURL = false;
228 this.URLMark.IsChecked = false;
232 this.fooTextBox.MarkURL = true;
233 this.URLMark.IsChecked = true;
235 this.fooTextBox.Refresh();