Skip to content

Commit

Permalink
#99
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Oct 17, 2015
1 parent d6c676f commit e4ac11f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 7 additions & 3 deletions xFunc/Views/Converter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ limitations under the License. -->
ShowInTaskbar="False" ResizeMode="NoResize"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Window.CommandBindings>
<CommandBinding Command="views:Converter.CalculateCommand" Executed="CalculateCommand_Execute" CanExecute="CalculateCommand_CanExecute" />
<CommandBinding Command="views:Converter.CalculateCommand" Executed="CalculateCommand_Executed" CanExecute="CalculateCommand_CanExecute" />
<CommandBinding Command="views:Converter.CopyFromCommand" Executed="CopyFromCommand_Executed" CanExecute="CopyFromCommand_CanExecute" />
<CommandBinding Command="views:Converter.CopyToCommand" Executed="CopyToCommand_Executed" CanExecute="CopyToCommand_CanExecute" />
</Window.CommandBindings>

<Grid>
Expand All @@ -40,7 +42,8 @@ limitations under the License. -->
<Label Content="{x:Static res:Resource.UnitsText}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Target="{Binding ElementName=fromComboBox}" />
<ComboBox x:Name="fromComboBox" Margin="74,2,10,0" VerticalAlignment="Top" DisplayMemberPath="Value" SelectedIndex="0" SelectionChanged="fromToComboBox_SelectionChanged" />
<Label Content="{x:Static res:Resource.ValueText}" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Target="{Binding ElementName=fromTextBox}" />
<TextBox x:Name="fromTextBox" Height="23" Margin="74,35,10,0" VerticalAlignment="Top" TextChanged="fromTextBox_TextChanged" />
<TextBox x:Name="fromTextBox" Height="23" Margin="74,35,38,0" VerticalAlignment="Top" TextChanged="fromTextBox_TextChanged" />
<Button Height="23" Width="23" Margin="389,35,10,0" VerticalAlignment="Top" Command="views:Converter.CopyFromCommand" />
</Grid>
</GroupBox>

Expand All @@ -49,7 +52,8 @@ limitations under the License. -->
<Label Content="{x:Static res:Resource.UnitsText}" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Target="{Binding ElementName=toComboBox}" />
<ComboBox x:Name="toComboBox" Margin="74,2,10,0" VerticalAlignment="Top" DisplayMemberPath="Value" SelectedIndex="0" SelectionChanged="fromToComboBox_SelectionChanged" />
<Label Content="{x:Static res:Resource.ValueText}" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Target="{Binding ElementName=toTextBox}" />
<TextBox x:Name="toTextBox" Height="23" Margin="74,35,10,0" VerticalAlignment="Top" TextChanged="toTextBox_TextChanged" />
<TextBox x:Name="toTextBox" Height="23" Margin="74,35,38,0" VerticalAlignment="Top" TextChanged="toTextBox_TextChanged" />
<Button Height="23" Width="23" Margin="389,35,10,0" VerticalAlignment="Top" Command="views:Converter.CopyToCommand" />
</Grid>
</GroupBox>

Expand Down
29 changes: 27 additions & 2 deletions xFunc/Views/Converter.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ public partial class Converter : Window

private readonly IConverter[] converters;

private MathControl mathControl;

public static RoutedCommand CalculateCommand = new RoutedCommand();
public static RoutedCommand CopyFromCommand = new RoutedCommand();
public static RoutedCommand CopyToCommand = new RoutedCommand();

public Converter()
public Converter(MathControl mathControl)
{
converters = new IConverter[]
{
Expand All @@ -42,6 +46,7 @@ public Converter()
new TimeConverter(),
new VolumeConverter()
};
this.mathControl = mathControl;

InitializeComponent();

Expand Down Expand Up @@ -77,7 +82,7 @@ private void ConvertToFrom()
fromTextBox.Text = conv.Convert(value, to.Key, from.Key).ToString(CultureInfo.InvariantCulture);
}

private void CalculateCommand_Execute(object o, ExecutedRoutedEventArgs args)
private void CalculateCommand_Executed(object o, ExecutedRoutedEventArgs args)
{
var conv = (IConverter)convertersComboBox.SelectedItem;
var from = (KeyValuePair<object, string>)fromComboBox.SelectedItem;
Expand Down Expand Up @@ -105,6 +110,26 @@ private void CalculateCommand_CanExecute(object o, CanExecuteRoutedEventArgs arg
&& (double.TryParse(fromTextBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out d) || double.TryParse(toTextBox.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out d));
}

private void CopyFromCommand_Executed(object o, ExecutedRoutedEventArgs args)
{
mathControl.mathExpressionBox.Text += this.fromTextBox.Text;
}

private void CopyFromCommand_CanExecute(object o, CanExecuteRoutedEventArgs args)
{
args.CanExecute = !string.IsNullOrWhiteSpace(this.fromTextBox.Text);
}

private void CopyToCommand_Executed(object o, ExecutedRoutedEventArgs args)
{
mathControl.mathExpressionBox.Text += this.toTextBox.Text;
}

private void CopyToCommand_CanExecute(object o, CanExecuteRoutedEventArgs args)
{
args.CanExecute = !string.IsNullOrWhiteSpace(this.toTextBox.Text);
}

private void SetUnits()
{
fromComboBox.ItemsSource = Units;
Expand Down
2 changes: 1 addition & 1 deletion xFunc/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ private void ConverterCommand_Execute(object o, ExecutedRoutedEventArgs args)
{
if (converterView == null)
{
converterView = new Converter()
converterView = new Converter(this.mathControl)
{
Owner = this,
Top = Settings.Default.ConverterTop == -1 ? this.Top + 100 : Settings.Default.ConverterTop,
Expand Down

0 comments on commit e4ac11f

Please sign in to comment.