This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAppendingPathTextBox.cs
More file actions
95 lines (80 loc) · 3.63 KB
/
Copy pathAppendingPathTextBox.cs
File metadata and controls
95 lines (80 loc) · 3.63 KB
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
using System;
using System.Windows;
using System.Windows.Controls;
namespace GitHub.UI
{
public class AppendingPathTextBox : TextBox
{
public static readonly DependencyProperty ParentFolderPathProperty =
DependencyProperty.Register("ParentFolderPath", typeof(string), typeof(AppendingPathTextBox), new FrameworkPropertyMetadata(null, OnUpdateParentFolder));
public string ParentFolderPath
{
get { return (string)GetValue(ParentFolderPathProperty); }
set { SetValue(ParentFolderPathProperty, value); }
}
public string ChildFolderName
{
get { return (string)GetValue(ChildFolderNameProperty); }
set { SetValue(ChildFolderNameProperty, value); }
}
public static readonly DependencyProperty ChildFolderNameProperty =
DependencyProperty.Register("ChildFolderName", typeof(string), typeof(AppendingPathTextBox), new PropertyMetadata(null, UpdateVisibilities));
public Visibility PathSeparatorVisibility
{
get { return (Visibility)GetValue(PathSeparatorVisibilityProperty); }
set { SetValue(PathSeparatorVisibilityProperty, value); }
}
public static readonly DependencyProperty PathSeparatorVisibilityProperty =
DependencyProperty.Register("PathSeparatorVisibility", typeof(Visibility), typeof(AppendingPathTextBox), new PropertyMetadata(Visibility.Visible));
public Visibility ChildFolderVisibility
{
get { return (Visibility)GetValue(ChildFolderVisibilityProperty); }
set { SetValue(ChildFolderVisibilityProperty, value); }
}
public static readonly DependencyProperty ChildFolderVisibilityProperty =
DependencyProperty.Register("ChildFolderVisibility", typeof(Visibility), typeof(AppendingPathTextBox), new PropertyMetadata(Visibility.Visible));
protected override void OnTextChanged(TextChangedEventArgs e)
{
ParentFolderPath = Text;
base.OnTextChanged(e);
}
protected override void OnMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(e);
if (!e.Handled)
{
this.SelectAll();
}
}
static void OnUpdateParentFolder(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (AppendingPathTextBox)d;
control.Text = control.ParentFolderPath;
UpdatePathSeparatorVisibility(control);
UpdateChildFolderVisibilityVisibility(control);
}
static void UpdateVisibilities(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (AppendingPathTextBox)d;
UpdatePathSeparatorVisibility(control);
UpdateChildFolderVisibilityVisibility(control);
}
static void UpdateChildFolderVisibilityVisibility(AppendingPathTextBox control)
{
control.ChildFolderVisibility = string.IsNullOrEmpty(control.ParentFolderPath) ? Visibility.Collapsed : Visibility.Visible;
}
static void UpdatePathSeparatorVisibility(AppendingPathTextBox control)
{
if (!string.IsNullOrEmpty(control.ParentFolderPath))
{
control.PathSeparatorVisibility = control.ParentFolderPath.EndsWith("\\", StringComparison.Ordinal)
? Visibility.Collapsed
: Visibility.Visible;
}
else
{
control.PathSeparatorVisibility = Visibility.Collapsed;
}
}
}
}