5 changed files with 232 additions and 27 deletions
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Window |
||||
x:Class="ICSharpCode.SharpDevelop.Editor.Dialogs.RenameSymbolDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
Title="{sd:Localize SharpDevelop.Refactoring.Rename}" |
||||
WindowStyle="ToolWindow" |
||||
Style="{x:Static sd:GlobalStyles.DialogWindowStyle}" |
||||
ResizeMode="NoResize" |
||||
WindowStartupLocation="CenterScreen" |
||||
Width="527.6" |
||||
SizeToContent="Height"> |
||||
|
||||
<Window.Resources> |
||||
<BooleanToVisibilityConverter x:Key="BoolToVisibility" /> |
||||
</Window.Resources> |
||||
|
||||
<Grid> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
<RowDefinition Height="Auto" /> |
||||
</Grid.RowDefinitions> |
||||
|
||||
<TextBlock |
||||
Text="{sd:Localize SharpDevelop.Refactoring.RenameMemberText}" |
||||
Grid.Row="0" |
||||
HorizontalAlignment="Stretch" |
||||
VerticalAlignment="Top" |
||||
Margin="10,5" /> |
||||
|
||||
<TextBox |
||||
Name="symbolNameTextBox" |
||||
Grid.Row="1" |
||||
HorizontalAlignment="Stretch" |
||||
VerticalAlignment="Top" |
||||
Margin="10,5" |
||||
Text="{Binding Path=NewSymbolName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" |
||||
Grid.ColumnSpan="3" /> |
||||
|
||||
<TextBlock |
||||
Name="invalidSymbolWarningTextBlock" |
||||
Grid.Row="2" |
||||
HorizontalAlignment="Stretch" |
||||
VerticalAlignment="Top" |
||||
Margin="10,5" |
||||
Text="{sd:Localize SharpDevelop.Refactoring.InvalidName}" |
||||
Visibility="{Binding Path=IsError, Converter={StaticResource BoolToVisibility}}" |
||||
Foreground="Red" /> |
||||
|
||||
<Grid Grid.Row="3"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="*" /> |
||||
<ColumnDefinition Width="Auto" /> |
||||
<ColumnDefinition Width="Auto" /> |
||||
</Grid.ColumnDefinitions> |
||||
|
||||
<Button |
||||
Content="{sd:Localize Global.RenameButtonText}" |
||||
Name="okButton" |
||||
Click="okButton_Click" |
||||
IsDefault="True" |
||||
IsEnabled="{Binding IsValidSymbolName}" |
||||
Height="23" |
||||
Width="75" |
||||
HorizontalAlignment="Right" |
||||
Margin="0,5,10,5" |
||||
Grid.Column="1" /> |
||||
|
||||
<Button |
||||
Content="{sd:Localize Global.CancelButtonText}" |
||||
Name="cancelButton" |
||||
IsCancel="True" |
||||
HorizontalAlignment="Right" |
||||
Margin="0,5,10,5" |
||||
Width="75" |
||||
Height="23" |
||||
Grid.Column="2" /> |
||||
</Grid> |
||||
</Grid> |
||||
</Window> |
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor.Dialogs |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for RenameSymbolDialog.xaml
|
||||
/// </summary>
|
||||
public partial class RenameSymbolDialog : Window |
||||
{ |
||||
public static readonly DependencyProperty NewSymbolNameProperty = |
||||
DependencyProperty.Register("NewSymbolName", typeof(string), typeof(RenameSymbolDialog), |
||||
new FrameworkPropertyMetadata()); |
||||
public static readonly DependencyProperty IsValidSymbolNameProperty = |
||||
DependencyProperty.Register("IsValidSymbolName", typeof(bool), typeof(RenameSymbolDialog), |
||||
new FrameworkPropertyMetadata()); |
||||
public static readonly DependencyProperty IsErrorProperty = |
||||
DependencyProperty.Register("IsError", typeof(bool), typeof(RenameSymbolDialog), |
||||
new FrameworkPropertyMetadata()); |
||||
|
||||
Predicate<string> symbolNameValidationPredicate = n => true; // Just to always have one
|
||||
|
||||
public RenameSymbolDialog(Predicate<string> symbolNameValidator) |
||||
{ |
||||
InitializeComponent(); |
||||
|
||||
this.DataContext = this; |
||||
|
||||
if (symbolNameValidator != null) { |
||||
symbolNameValidationPredicate = symbolNameValidator; |
||||
} |
||||
|
||||
// Set focus into TextBox
|
||||
this.symbolNameTextBox.Focus(); |
||||
} |
||||
|
||||
public string OldSymbolName |
||||
{ |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public string NewSymbolName |
||||
{ |
||||
get { return (string)GetValue(NewSymbolNameProperty); } |
||||
set { SetValue(NewSymbolNameProperty, value); } |
||||
} |
||||
|
||||
public bool IsValidSymbolName |
||||
{ |
||||
get { return (bool)GetValue(IsValidSymbolNameProperty); } |
||||
set { SetValue(IsValidSymbolNameProperty, value); } |
||||
} |
||||
|
||||
public bool IsError |
||||
{ |
||||
get { return (bool)GetValue(IsErrorProperty); } |
||||
set { SetValue(IsErrorProperty, value); } |
||||
} |
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
base.OnPropertyChanged(e); |
||||
|
||||
if (e.Property.Name == "NewSymbolName") |
||||
ValidateSymbolName(); |
||||
} |
||||
|
||||
void okButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
this.DialogResult = true; |
||||
} |
||||
|
||||
void ValidateSymbolName() |
||||
{ |
||||
// Execute defined validator on input
|
||||
bool isValidSymbolName = symbolNameValidationPredicate(NewSymbolName); |
||||
|
||||
// Update error states
|
||||
IsValidSymbolName = isValidSymbolName && (OldSymbolName != NewSymbolName); |
||||
IsError = !isValidSymbolName; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue