Skip to content

Commit

Permalink
Make main window show on the screen faster. If loading data into trev…
Browse files Browse the repository at this point in the history
…iew takes long time Loading... is shown until it finishes.
  • Loading branch information
dominikgolda committed May 7, 2019
1 parent 86261e0 commit 87c4507
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
17 changes: 14 additions & 3 deletions src/Soloplan.WhatsON.GUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
Height="450"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
Style="{StaticResource BorderLessWindowStyle}"
TextElement.FontSize="14"
TextElement.FontWeight="Medium"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
mc:Ignorable="d"
Style="{StaticResource BorderLessWindowStyle}">
mc:Ignorable="d">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
</Window.Resources>
<DockPanel>
<materialDesign:ColorZone Margin="0"
Padding="6"
Expand Down Expand Up @@ -74,6 +77,14 @@

</DockPanel>
</materialDesign:ColorZone>
<subjectTreeView:SubjectsTreeView DockPanel.Dock="Bottom" x:Name="mainTreeView" />
<Grid DockPanel.Dock="Bottom">
<subjectTreeView:SubjectsTreeView x:Name="mainTreeView" Visibility="{Binding IsTreeInitialized, Converter={StaticResource BoolToVisibility}}" />
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="18"
FontWeight="Bold"
Text="Loading..."
Visibility="{Binding IsTreeNotInitialized, Converter={StaticResource BoolToVisibility}}" />
</Grid>
</DockPanel>
</Window>
61 changes: 45 additions & 16 deletions src/Soloplan.WhatsON.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Soloplan.WhatsON.GUI
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Soloplan.WhatsON.GUI.Common.VisualConfig;
Expand All @@ -17,12 +18,14 @@ namespace Soloplan.WhatsON.GUI
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
public partial class MainWindow : INotifyPropertyChanged
{
private readonly IList<Subject> initialSubjectState;

/// <summary>
/// Gets or sets the configuration.
/// </summary>
public ApplicationConfiguration Config { get; set; }
private ApplicationConfiguration config;

/// <summary>
/// The scheduler used for observing subjects.
Expand All @@ -34,6 +37,15 @@ public partial class MainWindow
/// </summary>
private MainWindowSettigns settings;

private bool initialized;

/// <summary>
/// Occurs when configuration was applied.
/// </summary>
public event EventHandler<ValueEventArgs<ApplicationConfiguration>> ConfigurationApplied;

public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
Expand All @@ -44,16 +56,28 @@ public MainWindow(ObservationScheduler scheduler, ApplicationConfiguration confi
{
this.InitializeComponent();
this.scheduler = scheduler;
this.Config = configuration;
this.mainTreeView.Init(this.scheduler, this.Config, initialSubjectState);
this.ShowInTaskbar = this.Config.ShowInTaskbar;
this.Topmost = this.Config.AlwaysOnTop;
this.config = configuration;
this.initialSubjectState = initialSubjectState;
this.ShowInTaskbar = this.config.ShowInTaskbar;
this.Topmost = this.config.AlwaysOnTop;
this.DataContext = this;
}

/// <summary>
/// Occurs when configuration was applied.
/// </summary>
public event EventHandler<ValueEventArgs<ApplicationConfiguration>> ConfigurationApplied;
public bool IsTreeInitialized
{
get => this.initialized;
set
{
this.initialized = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.IsTreeInitialized)));
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.IsTreeNotInitialized)));
}
}

public bool IsTreeNotInitialized
{
get => !this.IsTreeInitialized;
}

public MainWindowSettigns GetVisualSettigns()
{
Expand All @@ -76,7 +100,6 @@ public void ApplyVisualSettings(MainWindowSettigns visualSettings)
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}

this.mainTreeView.ApplyTreeListSettings(this.settings.TreeListSettings);
this.MinimizeButton.Visibility = this.ShowInTaskbar ? Visibility.Visible : Visibility.Hidden;
}

Expand All @@ -86,16 +109,22 @@ public void ApplyVisualSettings(MainWindowSettigns visualSettings)
/// <param name="configuration">New configuration.</param>
public void ApplyConfiguration(ApplicationConfiguration configuration)
{
this.Config = configuration;
this.mainTreeView.Update(this.Config);
this.ShowInTaskbar = this.Config.ShowInTaskbar;
this.Topmost = this.Config.AlwaysOnTop;
this.config = configuration;
this.mainTreeView.Update(this.config);
this.ShowInTaskbar = this.config.ShowInTaskbar;
this.Topmost = this.config.AlwaysOnTop;
this.MinimizeButton.Visibility = this.ShowInTaskbar ? Visibility.Visible : Visibility.Hidden;
}

public void FinishDrawing()
{
this.mainTreeView.Init(this.scheduler, this.config, this.initialSubjectState);
this.mainTreeView.ApplyTreeListSettings(this.settings.TreeListSettings);
}

private void OpenConfig(object sender, RoutedEventArgs e)
{
var configWindow = new ConfigWindow(this.Config);
var configWindow = new ConfigWindow(this.config);
configWindow.Owner = this;
configWindow.ConfigurationApplied += (s, ev) =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/Soloplan.WhatsON.GUI/TrayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ private void ShowOrHideWindow()
Application.Current.MainWindow = this.MainWindow;
this.MainWindow.Show();
this.MainWindow.Activate();
this.MainWindow.FinishDrawing();
this.MainWindow.IsTreeInitialized = true;
}
}

Expand Down

0 comments on commit 87c4507

Please sign in to comment.