This repository has been archived by the owner on Nov 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented GUI for string mod settings.
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
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,66 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace ModMyFactory.Controls | ||
{ | ||
class ExtendedTextBox : TextBox | ||
{ | ||
const string DefaultDefaultText = "Default"; | ||
|
||
public static readonly DependencyProperty AllowEmptyTextProperty = DependencyProperty.Register("AllowEmptyText", typeof(bool), typeof(ExtendedTextBox), new PropertyMetadata(true, OnAllowEmptyTextChanged)); | ||
public static readonly DependencyProperty DefaultTextProperty = DependencyProperty.Register("DefaultText", typeof(string), typeof(ExtendedTextBox), new PropertyMetadata(DefaultDefaultText, OnDefaultTextChanged, CoerceDefaultText)); | ||
|
||
private static void OnAllowEmptyTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var etb = (ExtendedTextBox)sender; | ||
if (!(bool)e.NewValue && string.IsNullOrEmpty(etb.Text)) etb.Text = etb.DefaultText; | ||
etb.OnAllowEmptyTextChanged(e); | ||
} | ||
|
||
private static void OnDefaultTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var etb = (ExtendedTextBox)sender; | ||
etb.OnDefaultTextChanged(e); | ||
} | ||
|
||
private static object CoerceDefaultText(DependencyObject sender, object value) | ||
{ | ||
var s = (string)value; | ||
if (string.IsNullOrEmpty(s)) return DefaultDefaultText; | ||
else return s; | ||
} | ||
|
||
|
||
public event DependencyPropertyChangedEventHandler AllowEmptyTextChanged; | ||
public event DependencyPropertyChangedEventHandler DefaultTextChanged; | ||
|
||
public bool AllowEmptyText | ||
{ | ||
get => (bool)GetValue(AllowEmptyTextProperty); | ||
set => SetValue(AllowEmptyTextProperty, value); | ||
} | ||
|
||
public string DefaultText | ||
{ | ||
get => (string)GetValue(DefaultTextProperty); | ||
set => SetValue(DefaultTextProperty, value); | ||
} | ||
|
||
protected virtual void OnAllowEmptyTextChanged(DependencyPropertyChangedEventArgs e) | ||
{ | ||
AllowEmptyTextChanged?.Invoke(this, e); | ||
} | ||
|
||
protected virtual void OnDefaultTextChanged(DependencyPropertyChangedEventArgs e) | ||
{ | ||
DefaultTextChanged?.Invoke(this, e); | ||
} | ||
|
||
protected override void OnTextChanged(TextChangedEventArgs e) | ||
{ | ||
base.OnTextChanged(e); | ||
|
||
if (!AllowEmptyText && string.IsNullOrEmpty(Text)) Text = DefaultText; | ||
} | ||
} | ||
} |
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