-
Notifications
You must be signed in to change notification settings - Fork 119
/
ChoMruComboBox.cs
112 lines (90 loc) · 3.24 KB
/
ChoMruComboBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace ChoEazyCopy
{
public class ChoMruComboBox : Control
{
#region Dependency Properties
public static readonly DependencyProperty MruSourceProperty =
DependencyProperty.Register("MruSource", typeof(ChoObservableMruList<string>), typeof(ChoMruComboBox));
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(ChoMruComboBox), new PropertyMetadata(OnTextChanged));
#endregion
#region Constructors
static ChoMruComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ChoMruComboBox), new FrameworkPropertyMetadata(typeof(ChoMruComboBox)));
}
public ChoMruComboBox()
{
this.Focusable = false;
this.IsTabStop = false;
}
#endregion
#region Properties
public ChoObservableMruList<string> MruSource
{
get { return (ChoObservableMruList<string>)GetValue(MruSourceProperty); }
set { SetValue(MruSourceProperty, value); }
}
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
#endregion
#region Event Handlers
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ChoMruComboBox srcControl = d as ChoMruComboBox;
if (srcControl != null)
{
if (srcControl.MruSource != null)
{
var dir = e.NewValue.ToString();
if (!dir.IsNullOrWhiteSpace() && Directory.Exists(dir))
srcControl.MruSource.Add(dir);
}
}
}
private static void OnTextChanged1(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ChoMruComboBox srcControl = d as ChoMruComboBox;
if (srcControl != null)
{
if (srcControl.MruSource != null)
{
System.Threading.ThreadPool.RegisterWaitForSingleObject(new AutoResetEvent(false),
(state, bTimeout) => srcControl.HandleMruUpdate(e.NewValue.ToString()), "", TimeSpan.FromSeconds(1), true);
}
}
}
private void HandleMruUpdate(string listVal)
{
if (this.Dispatcher.CheckAccess())
{
if (Directory.Exists(listVal))
this.MruSource.Add(listVal);
}
else
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<string>(HandleMruUpdate), listVal);
}
}
#endregion
}
}