Skip to content

Commit

Permalink
The configuration isn't saved immediately after changes were made to …
Browse files Browse the repository at this point in the history
…tree view, panel with save/reset appears insted.
  • Loading branch information
dominikgolda committed May 30, 2019
1 parent 8cb9429 commit 5049699
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Soloplan.WhatsON.GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,62 @@
TextElement.FontWeight="Medium"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
mc:Ignorable="d">
<Window.Resources>
<Storyboard x:Key="hideStorBoard">
<DoubleAnimation Storyboard.TargetName="HideableStackPanel"
Storyboard.TargetProperty="RenderTransform.Y"
From="0"
To="100"
Duration="0:00:.300" />
</Storyboard>

<Storyboard x:Key="showStoryBoard">
<DoubleAnimation Storyboard.TargetName="HideableStackPanel"
Storyboard.TargetProperty="RenderTransform.Y"
From="100"
To="0"
Duration="0:00:.300" />
</Storyboard>

</Window.Resources>
<DockPanel>
<local:CustomTitleBar ButtonClicked="OpenConfig"
CustomButtonIcon="SettingsOutline"
CustomButtonVisible="True"
DockPanel.Dock="Top"
ShowMinimizeButton="{Binding Path=ShowInTaskbar, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}"
Window="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}" />

<Border x:Name="HideableStackPanel"
Padding="8,8,30,8"
DockPanel.Dock="Bottom">
<DockPanel Background="{DynamicResource MaterialDesignBody}"
LastChildFill="False"
Visibility="{Binding ConfigurationModifiedFromTree, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Converter={StaticResource BoolToVis}}">
<TextBlock Padding="5"
VerticalAlignment="Center"
Foreground="{DynamicResource MaterialDesignBackground}"
Text="Configuration is modified" />
<DockPanel DockPanel.Dock="Right">
<Button Margin="5"
Padding="5"
Click="SaveClick"
Style="{StaticResource MaterialDesignFlatButton}">
Save
</Button>
<Button Margin="5"
Padding="5"
Click="ResetClick"
Style="{StaticResource MaterialDesignFlatButton}">
Reset
</Button>
</DockPanel>
</DockPanel>
<Border.RenderTransform>
<TranslateTransform Y="0" />
</Border.RenderTransform>
</Border>

<Grid DockPanel.Dock="Bottom">

<Button Width="56"
Expand Down
56 changes: 56 additions & 0 deletions src/Soloplan.WhatsON.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Soloplan.WhatsON.GUI
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media.Animation;
using Soloplan.WhatsON.GUI.Common.VisualConfig;
using Soloplan.WhatsON.GUI.Config.View;
using Soloplan.WhatsON.GUI.Config.Wizard;
Expand Down Expand Up @@ -39,6 +40,11 @@ public partial class MainWindow : INotifyPropertyChanged

private bool initialized;

/// <summary>
/// Backing field for <see cref="ConfigurationModifiedFromTree"/>.
/// </summary>
private bool configurationModifiedFromTree;

/// <summary>
/// Occurs when configuration was applied.
/// </summary>
Expand Down Expand Up @@ -81,6 +87,19 @@ public bool IsTreeNotInitialized
get => !this.IsTreeInitialized;
}

/// <summary>
/// Gets or sets a value indicating whether configuration was modified from tree view.
/// </summary>
public bool ConfigurationModifiedFromTree
{
get => this.configurationModifiedFromTree;
set
{
this.configurationModifiedFromTree = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.ConfigurationModifiedFromTree)));
}
}

public MainWindowSettigns GetVisualSettigns()
{
this.settings.TreeListSettings = this.mainTreeView.GetTreeListSettings();
Expand Down Expand Up @@ -181,9 +200,46 @@ private void NewConnectorClick(object sender, RoutedEventArgs e)

private void MainTreeViewOnConfigurationChanged(object sender, EventArgs e)
{
this.ConfigurationModifiedFromTree = true;
if (this.FindResource("showStoryBoard") is Storyboard sb)
{
this.BeginStoryboard(sb);
}
}

private void ResetClick(object sender, RoutedEventArgs e)
{
this.HideChangesPanel();
this.ConfigurationApplied?.Invoke(this, new ValueEventArgs<ApplicationConfiguration>(this.config));
}

private void SaveClick(object sender, RoutedEventArgs e)
{
this.HideChangesPanel();

this.mainTreeView.WriteToConfiguration(this.config);
SerializationHelper.SaveConfiguration(this.config);
this.ConfigurationApplied?.Invoke(this, new ValueEventArgs<ApplicationConfiguration>(this.config));
}

private void HideChangesPanel()
{
if (this.FindResource("hideStorBoard") is Storyboard sb)
{
void ChangePanelVisibility(object sender, EventArgs eventArgs)
{
this.ConfigurationModifiedFromTree = false;
sb.Completed -= ChangePanelVisibility;
}

sb.Completed += ChangePanelVisibility;

this.BeginStoryboard(sb);
}
else
{
this.ConfigurationModifiedFromTree = false;
}
}
}
}

0 comments on commit 5049699

Please sign in to comment.