-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completes #23 (except for some lingering selection bugs)
- Loading branch information
Showing
5 changed files
with
75 additions
and
3 deletions.
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,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using static ParseTreeVisualizer.Util.Functions; | ||
|
||
namespace ParseTreeVisualizer { | ||
public class BindableSelectionTextBox : TextBox { | ||
public static readonly DependencyProperty BindableSelectionStartProperty = | ||
DPRegister<int, BindableSelectionTextBox>(0, OnBindableSelectionStartChanged); | ||
|
||
public static readonly DependencyProperty BindableSelectionLengthProperty = | ||
DPRegister<int, BindableSelectionTextBox>(0, OnBindableSelectionStartChanged); | ||
|
||
private bool changeFromUI; | ||
|
||
public BindableSelectionTextBox() : base() { | ||
SelectionChanged += OnSelectionChanged; | ||
} | ||
|
||
public int BindableSelectionStart { | ||
get => (int)GetValue(BindableSelectionStartProperty); | ||
set => SetValue(BindableSelectionStartProperty, value); | ||
} | ||
|
||
public int BindableSelectionLength { | ||
get => (int)GetValue(BindableSelectionLengthProperty); | ||
set => SetValue(BindableSelectionLengthProperty, value); | ||
} | ||
|
||
private static void OnBindableSelectionStartChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { | ||
var textBox = dependencyObject as BindableSelectionTextBox; | ||
|
||
if (!textBox.changeFromUI) { | ||
int newValue = (int)args.NewValue; | ||
textBox.SelectionStart = newValue; | ||
} else { | ||
textBox.changeFromUI = false; | ||
} | ||
} | ||
|
||
private static void OnBindableSelectionLengthChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { | ||
var textBox = dependencyObject as BindableSelectionTextBox; | ||
|
||
if (!textBox.changeFromUI) { | ||
int newValue = (int)args.NewValue; | ||
textBox.SelectionLength = newValue; | ||
} else { | ||
textBox.changeFromUI = false; | ||
} | ||
} | ||
|
||
private void OnSelectionChanged(object sender, RoutedEventArgs e) { | ||
if (BindableSelectionStart != SelectionStart) { | ||
changeFromUI = true; | ||
BindableSelectionStart = SelectionStart; | ||
} | ||
|
||
if (BindableSelectionLength != SelectionLength) { | ||
changeFromUI = true; | ||
BindableSelectionLength = SelectionLength; | ||
} | ||
} | ||
} | ||
} |
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