OSDN Git Service

Testプロジェクトで最初に見つかった文字を選択する機能を追加した
authorgdkhd812 <jbh03215@htmil.co.jp>
Mon, 7 Oct 2013 10:06:16 +0000 (19:06 +0900)
committergdkhd812 <jbh03215@htmil.co.jp>
Mon, 7 Oct 2013 10:06:16 +0000 (19:06 +0900)
WPF/Test/MainWindow.xaml
WPF/Test/MainWindow.xaml.cs

index 24d52e3..81eb7e8 100644 (file)
         <MyNamespace:FooTextBox x:Name="fooTextBox" Grid.Row="1"/>
         <StackPanel Grid.Row="2" Orientation="Horizontal">
             <TextBlock Text="{Binding Selection,ElementName=fooTextBox,Converter={StaticResource TextRangeConverter}}" Margin="10,0,0,0"/>
-            <TextBlock Text="FindPattern" Margin="10,0,0,0"/>
+            <TextBlock Text="Find" Margin="10,0,0,0"/>
             <TextBox Name="FindPattern" Width="100"/>
-            <TextBlock Text="ReplaceAll" Margin="10,0,0,0"/>
+            <TextBlock Text="Replace" Margin="10,0,0,0"/>
             <TextBox Name="ReplacePattern" Width="100"/>
+            <Button Name="Find" Content="Find" Click="Find_Click" Margin="10,0,0,0"/>
             <Button Name="ReplaceAll" Content="ReplaceAll" Click="ReplaceAll_Click" Margin="10,0,0,0"/>
         </StackPanel>
     </Grid>
index 58464a7..e812e3f 100644 (file)
@@ -8,6 +8,7 @@
 
 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
+using System.Collections.Generic;
 using System.Text;
 using System.Windows;
 using System.Windows.Controls;
@@ -242,6 +243,20 @@ namespace Test
             }
             this.fooTextBox.Refresh();
         }
+
+        private void Find_Click(object sender, RoutedEventArgs e)
+        {
+            this.fooTextBox.Document.SetFindParam(this.FindPattern.Text, false, System.Text.RegularExpressions.RegexOptions.None);
+            var it = this.fooTextBox.Document.Find();
+            it.MoveNext();
+            if (it.Current != null)
+            {
+                SearchResult sr = it.Current;
+                this.fooTextBox.JumpCaret(sr.Start);
+                this.fooTextBox.Selection = new FooEditEngine.TextRange(sr.Start, sr.End - sr.Start + 1);
+                this.fooTextBox.Refresh();
+            }
+        }
     }
     public class TextRangeConveter : System.Windows.Data.IValueConverter
     {