Skip to content

Commit

Permalink
Added full "Date" creator UI (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Jun 19, 2022
1 parent 31ad351 commit 7b635b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
14 changes: 12 additions & 2 deletions Datalya/Pages/CreatorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@
<ToolTip Content="{x:Static lang:Resources.Selector}" Background="{Binding Source={StaticResource Background1}}" Foreground="{Binding Source={StaticResource Foreground1}}"/>
</Button.ToolTip>
</Button>

<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="5,7,5,7" Background="{Binding Source={StaticResource Background2}}"/>

<Button Foreground="{Binding Source={StaticResource Foreground1}}" x:Name="DateBlockBtn" Click="DateBlockBtn_Click" Padding="5" Margin="5" Style="{DynamicResource RegularButtonStyle}" Background="{Binding Source={StaticResource LightBackground}}" Cursor="Hand" BorderThickness="0" FontSize="18">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF22B;" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,5,0" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.Date}" FontSize="13" VerticalAlignment="Center"/>
</StackPanel>
<Button.ToolTip>
<ToolTip Content="{x:Static lang:Resources.Date}" Background="{Binding Source={StaticResource Background1}}" Foreground="{Binding Source={StaticResource Foreground1}}"/>
</Button.ToolTip>
</Button>

<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="5,7,5,7" Background="{Binding Source={StaticResource Background2}}"/>

<Button Foreground="{Binding Source={StaticResource Foreground1}}" x:Name="ImportBlockBtn" Click="ImportBlockBtn_Click" Content="&#xF151;" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Padding="5" Margin="5" Style="{DynamicResource RegularButtonStyle}" Background="{Binding Source={StaticResource LightBackground}}" Cursor="Hand" BorderThickness="0" FontSize="18">
<Button.ToolTip>
Expand Down
21 changes: 21 additions & 0 deletions Datalya/Pages/CreatorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ internal void InitUI()
{
BlockDisplayer.Children.Add(new SelectorBlockCreatorUI(s));
}
else if (Global.CurrentDataBase.Blocks[i] is DateBlock dateBlock)
{
BlockDisplayer.Children.Add(new DateBlockCreatorUI(dateBlock));
}
}
}

Expand Down Expand Up @@ -153,6 +157,13 @@ internal void SaveChanges()
blocks.Add(choiceBlockCreatorUI.SingleChoiceBlock); // Add item
}
}
else if (uIElement is DateBlockCreatorUI dateBlockCreatorUI)
{
if (dateBlockCreatorUI.DateBlock is not null)
{
blocks.Add(dateBlockCreatorUI.DateBlock); // Add item
}
}
}
Global.CurrentDataBase.Blocks = blocks;
Global.IsModified = true;
Expand Down Expand Up @@ -193,4 +204,14 @@ private void ExportBlockBtn_Click(object sender, RoutedEventArgs e)
}
}
}

private void DateBlockBtn_Click(object sender, RoutedEventArgs e)
{
BlockDisplayer.Children.Add(new DateBlockCreatorUI()); // Add block
for (int i = 0; i < Global.CurrentDataBase.ItemsContent.Count; i++)
{
Global.CurrentDataBase.ItemsContent[i].Add("");
}
SaveChanges(); // Save
}
}
4 changes: 2 additions & 2 deletions Datalya/UserControls/DateBlockPropertiesUI.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.Name}" FontWeight="Bold" Margin="10,0,0,0"/>
<TextBox x:Name="NameTxt" Style="{DynamicResource RegularTextBoxStyle}" Padding="7" Margin="10,5,10,15" BorderThickness="0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" Text="{x:Static lang:Resources.Input}" FontWeight="Bold" TextAlignment="Center"/>
<TextBox x:Name="NameTxt" Style="{DynamicResource RegularTextBoxStyle}" Padding="7" Margin="10,5,10,15" BorderThickness="0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" Text="{x:Static lang:Resources.Date}" FontWeight="Bold" TextAlignment="Center"/>

<TextBlock Text="{x:Static lang:Resources.DateDefaultValue}" FontWeight="Bold" Margin="10,0,0,0"/>
<CheckBox Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background1}}" x:Name="UseDefaultDateChk" BorderThickness="2" Content="{x:Static lang:Resources.UseDefaultDate}" FontWeight="Bold" Margin="10 2" Style="{DynamicResource CheckBoxStyle1}" VerticalContentAlignment="Center" FontSize="10"/>
<CheckBox Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background1}}" x:Name="UseDefaultDateChk" BorderThickness="2" Content="{x:Static lang:Resources.UseDefaultDate}" FontWeight="Bold" Margin="10 2" Style="{DynamicResource CheckBoxStyle1}" VerticalContentAlignment="Center" FontSize="10" Checked="UseDefaultDateChk_Checked" Unchecked="UseDefaultDateChk_Checked"/>

<TextBlock Text="{x:Static lang:Resources.Date}" FontWeight="Bold" Margin="10,0,0,0"/>
<DatePicker x:Name="DefaultDatePicker" Margin="10 2"></DatePicker>
Expand Down
10 changes: 8 additions & 2 deletions Datalya/UserControls/DateBlockPropertiesUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public DateBlockPropertiesUI(DateBlockCreatorUI dateBlockCreatorUI, DateBlock da
InitializeComponent();
DateBlock = dateBlock; // Set
ParentElement = dateBlockCreatorUI; // Set
UseDefaultDateChk.IsChecked = true; // Set

if (dateBlock is not null)
{
NameTxt.Text = dateBlock.Name; // Set text
UseDefaultDateChk.IsChecked = dateBlock.UseDefaultDate; // Set the check state
DefaultDatePicker.DisplayDate = Env.UnixTimeToDateTime(dateBlock.DefaultDate ?? Env.UnixTime); // Set the date
DefaultDatePicker.DisplayDate = Env.UnixTimeToDateTime(dateBlock.DefaultDate); // Set the date
}
}

Expand All @@ -55,8 +56,13 @@ private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
DateBlock = new() { Name = NameTxt.Text, UseDefaultDate = UseDefaultDateChk.IsChecked.Value, DefaultDate = DefaultDatePicker.DisplayDate.Second };
ParentElement.NameTxt.Text = DateBlock.Name; // Set name
ParentElement.Date = InputBlock; // Set
ParentElement.DateBlock = DateBlock; // Set
Global.CreatorPage.SaveChanges(); // Save
}
}

private void UseDefaultDateChk_Checked(object sender, RoutedEventArgs e)
{
DefaultDatePicker.IsEnabled = !UseDefaultDateChk.IsChecked.Value;
}
}

0 comments on commit 7b635b3

Please sign in to comment.