Skip to content

Commit

Permalink
fix valid data path tick
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobharder committed Jun 11, 2022
1 parent 53c04f3 commit e6ef8bb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion AnnoMapEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:AnnoMapEditor.Controls"
xmlns:utils="clr-namespace:AnnoMapEditor.Utils"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
Background="#182B3F">
Expand Down Expand Up @@ -51,6 +52,7 @@
<Setter Property="Width" Value="auto" />
<Setter Property="Padding" Value="2,6,2,6" />
</Style>
<utils:BooleanToVisibilityConverter x:Key="VisibleOnTrue" />
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -63,7 +65,7 @@
<Button Click="Configure_Click" Style="{StaticResource DefaultButtonStyle}" Width="200" HorizontalAlignment="Left">Set RDA path...</Button>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<TextBlock Style="{StaticResource DefaultLabelStyle}" Text="{Binding Settings.DataPath, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Style="{StaticResource DefaultLabelStyle}" Text="" Visibility="{Binding Settings.IsValidDataPath, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Style="{StaticResource DefaultLabelStyle}" Text="" Visibility="{Binding Settings.IsValidDataPath, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibleOnTrue}}" />
</StackPanel>
</StackPanel>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion AnnoMapEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private async void OpenFile_Click(object sender, RoutedEventArgs e)

if (true == picker.ShowDialog())
{
if (string.IsNullOrEmpty(Settings.Instance.DataPath))
if (!Settings.Instance.IsValidDataPath)
{
int end = picker.FileName.IndexOf(@"\data\session");
if (end == -1)
Expand Down
23 changes: 23 additions & 0 deletions AnnoMapEditor/Utils/BooleanToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace AnnoMapEditor.Utils
{
[ValueConversion(typeof(bool), typeof(Visibility))]
public sealed class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
return (value is bool b && b) ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return Equals(value, Visibility.Visible);
}
}
}
7 changes: 6 additions & 1 deletion AnnoMapEditor/Utils/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public string? DataPath
}
}
}
private string? _dataPath = UserSettings.Default.DataPath;
private string? _dataPath;

public bool IsValidDataPath
{
Expand All @@ -33,6 +33,11 @@ public bool IsValidDataPath
}
private bool _isValidDataPath = false;

public Settings()
{
DataPath = UserSettings.Default.DataPath;
}

private static string? CorrectDataPath(string? path)
{
if (path is null)
Expand Down

0 comments on commit e6ef8bb

Please sign in to comment.