-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
changbowen
committed
Dec 10, 2016
1 parent
f2a4779
commit 3b711ae
Showing
11 changed files
with
413 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window x:Class="DesktopNote.Win_Search" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
Title="Search" Height="110" Width="310" MouseDown="Window_MouseDown" WindowStyle="None" Loaded="Window_Loaded" ShowInTaskbar="False" AllowsTransparency="True" Background="{x:Null}" Topmost="True" UseLayoutRounding="True"> | ||
<Grid Margin="10"> | ||
<Rectangle Fill="#FFDCF1FF" RadiusY="12" RadiusX="12" Opacity="0.7"/> | ||
<TextBlock HorizontalAlignment="Left" Margin="10,13,0,0" TextWrapping="Wrap" Text="Search for" VerticalAlignment="Top"/> | ||
<TextBox x:Name="TB_Search" HorizontalAlignment="Left" Height="23" Margin="91,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="191" TextChanged="TB_Search_TextChanged"/> | ||
<Button x:Name="Btn_Search" Content="Search" HorizontalAlignment="Right" Margin="0,0,65,10" VerticalAlignment="Bottom" Width="50" IsDefault="True" Background="White" Height="25" Click="Btn_Search_Click"/> | ||
<Button x:Name="Btn_Cancel" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="50" IsCancel="True" Background="White" Height="25" Click="Btn_Cancel_Click"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
|
||
namespace DesktopNote | ||
{ | ||
/// <summary> | ||
/// Interaction logic for Win_Search.xaml | ||
/// </summary> | ||
public partial class Win_Search : Window | ||
{ | ||
private bool textchanged = true; | ||
|
||
public Win_Search() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void MarkTextInRange(RichTextBox richTextBox, string searchText, bool searchNext) | ||
{ | ||
//Get the range to search | ||
TextRange searchRange; | ||
if (searchNext) | ||
searchRange = new TextRange(richTextBox.Selection.Start.GetPositionAtOffset(1), richTextBox.Document.ContentEnd); | ||
else | ||
searchRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); | ||
|
||
TextPointer start = searchRange.Start.GetNextContextPosition(LogicalDirection.Forward); | ||
while (start != null) | ||
{ | ||
var txt = start.GetTextInRun(LogicalDirection.Forward); | ||
if (txt.Length > 0) | ||
{ | ||
int tgtindex = txt.IndexOf(searchText, StringComparison.OrdinalIgnoreCase); | ||
if (tgtindex >= 0) | ||
{ | ||
var selstart = start.GetPositionAtOffset(tgtindex); | ||
var selend = start.GetPositionAtOffset(tgtindex + searchText.Length); | ||
//if search string is at line start, non chars are included in below msgbox | ||
//MsgBox(New TextRange(tgtptr, start.GetNextContextPosition(LogicalDirection.Forward)).Text) | ||
((FrameworkContentElement)selstart.Parent).BringIntoView(); | ||
richTextBox.Selection.Select(selstart, selend); | ||
richTextBox.Focus(); | ||
break; | ||
} | ||
} | ||
start = start.GetNextContextPosition(LogicalDirection.Forward); | ||
if (start == null) | ||
{ | ||
textchanged = true; | ||
MessageBox.Show("Search has reached the end of the document.", "", MessageBoxButton.OK, MessageBoxImage.Information); | ||
} | ||
} | ||
} | ||
|
||
private void Window_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
var mainwin = (MainWindow)Application.Current.MainWindow; | ||
Left = mainwin.Left + (mainwin.Width - Width) / 2; | ||
Top = mainwin.Top + (mainwin.Height - Height) / 2; | ||
TB_Search.Focus(); | ||
} | ||
|
||
private void Window_MouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (e.ChangedButton == MouseButton.Left) DragMove(); | ||
} | ||
|
||
private void TB_Search_TextChanged(object sender, TextChangedEventArgs e) | ||
{ | ||
textchanged = true; | ||
} | ||
|
||
private void Btn_Search_Click(object sender, RoutedEventArgs e) | ||
{ | ||
if (TB_Search.Text.Trim() == "") | ||
Close(); | ||
else | ||
{ | ||
var mainwin = (MainWindow)Application.Current.MainWindow; | ||
if (textchanged) | ||
{ | ||
textchanged = false; | ||
MarkTextInRange(mainwin.RTB_Main, TB_Search.Text, false); | ||
} | ||
else | ||
{ | ||
MarkTextInRange(mainwin.RTB_Main, TB_Search.Text, true); | ||
} | ||
Activate(); | ||
} | ||
} | ||
|
||
private void Btn_Cancel_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#pragma checksum "..\..\Win_Search.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "60D5F737ADB076ED6A0D66C799181A8C" | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// Runtime Version:4.0.30319.42000 | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Automation; | ||
using System.Windows.Controls; | ||
using System.Windows.Controls.Primitives; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Ink; | ||
using System.Windows.Input; | ||
using System.Windows.Markup; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Animation; | ||
using System.Windows.Media.Effects; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Media.Media3D; | ||
using System.Windows.Media.TextFormatting; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
using System.Windows.Shell; | ||
|
||
|
||
namespace DesktopNote { | ||
|
||
|
||
/// <summary> | ||
/// Win_Search | ||
/// </summary> | ||
public partial class Win_Search : System.Windows.Window, System.Windows.Markup.IComponentConnector { | ||
|
||
|
||
#line 8 "..\..\Win_Search.xaml" | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | ||
internal System.Windows.Controls.TextBox TB_Search; | ||
|
||
#line default | ||
#line hidden | ||
|
||
|
||
#line 9 "..\..\Win_Search.xaml" | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | ||
internal System.Windows.Controls.Button Btn_Search; | ||
|
||
#line default | ||
#line hidden | ||
|
||
|
||
#line 10 "..\..\Win_Search.xaml" | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | ||
internal System.Windows.Controls.Button Btn_Cancel; | ||
|
||
#line default | ||
#line hidden | ||
|
||
private bool _contentLoaded; | ||
|
||
/// <summary> | ||
/// InitializeComponent | ||
/// </summary> | ||
[System.Diagnostics.DebuggerNonUserCodeAttribute()] | ||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] | ||
public void InitializeComponent() { | ||
if (_contentLoaded) { | ||
return; | ||
} | ||
_contentLoaded = true; | ||
System.Uri resourceLocater = new System.Uri("/DesktopNote;component/win_search.xaml", System.UriKind.Relative); | ||
|
||
#line 1 "..\..\Win_Search.xaml" | ||
System.Windows.Application.LoadComponent(this, resourceLocater); | ||
|
||
#line default | ||
#line hidden | ||
} | ||
|
||
[System.Diagnostics.DebuggerNonUserCodeAttribute()] | ||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] | ||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] | ||
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { | ||
switch (connectionId) | ||
{ | ||
case 1: | ||
|
||
#line 4 "..\..\Win_Search.xaml" | ||
((DesktopNote.Win_Search)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Window_MouseDown); | ||
|
||
#line default | ||
#line hidden | ||
|
||
#line 4 "..\..\Win_Search.xaml" | ||
((DesktopNote.Win_Search)(target)).Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded); | ||
|
||
#line default | ||
#line hidden | ||
return; | ||
case 2: | ||
this.TB_Search = ((System.Windows.Controls.TextBox)(target)); | ||
|
||
#line 8 "..\..\Win_Search.xaml" | ||
this.TB_Search.TextChanged += new System.Windows.Controls.TextChangedEventHandler(this.TB_Search_TextChanged); | ||
|
||
#line default | ||
#line hidden | ||
return; | ||
case 3: | ||
this.Btn_Search = ((System.Windows.Controls.Button)(target)); | ||
|
||
#line 9 "..\..\Win_Search.xaml" | ||
this.Btn_Search.Click += new System.Windows.RoutedEventHandler(this.Btn_Search_Click); | ||
|
||
#line default | ||
#line hidden | ||
return; | ||
case 4: | ||
this.Btn_Cancel = ((System.Windows.Controls.Button)(target)); | ||
|
||
#line 10 "..\..\Win_Search.xaml" | ||
this.Btn_Cancel.Click += new System.Windows.RoutedEventHandler(this.Btn_Cancel_Click); | ||
|
||
#line default | ||
#line hidden | ||
return; | ||
} | ||
this._contentLoaded = true; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.