Skip to content

Commit

Permalink
Make import config and import projects distinguishable
Browse files Browse the repository at this point in the history
Move the import/export for the configuration to the about page next to the configuration file.
Rename the import from the main menu to "Import project(s)" similar to "Add project(s)".
Provide default value for filenames of export .json files.
  • Loading branch information
steffen-wilke committed Feb 11, 2020
1 parent 95c5a0e commit 060fe9c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 99 deletions.
13 changes: 10 additions & 3 deletions src/Soloplan.WhatsON.GUI/Configuration/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Soloplan.WhatsON.GUI.Configuration"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:properties="clr-namespace:Soloplan.WhatsON.GUI.Properties"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="AboutPage"
Expand Down Expand Up @@ -36,9 +37,15 @@
</StackPanel>

<TextBlock Cursor="Hand" TextWrapping="Wrap" Text="Made by Soloplan GmbH" Margin="20,0,20,30" Foreground="#FF2B7AD2" AutomationProperties.Name="MadeBySoloplanLabel" MouseUp="MadeBySoloplanLinkMouseUp" MouseEnter="TextBlockMouseEnter" MouseLeave="TextBlockMouseLeave"/>
<TextBlock TextWrapping="Wrap" Text="Configuration:" Margin="20,0,20,10"/>
<TextBox x:Name="ConfigFile" Text="{}{CONFIG_FILE}" IsReadOnly="True" Margin="20,0,20,20" />
<TextBlock TextWrapping="Wrap" Text="Plugins:" Height="22" Margin="20,0,20,0"/>
<TextBlock TextWrapping="Wrap" Text="Configuration:" Margin="20,0,20,10" FontWeight="Bold"/>

<DockPanel Margin="20,0,20,20">
<Button Style="{StaticResource MaterialDesignFlatMidBgButton}" Content="{x:Static properties:Resources.Export}" DockPanel.Dock="Right" Click="ExportButtonClick"/>
<Button Style="{StaticResource MaterialDesignFlatMidBgButton}" Content="{x:Static properties:Resources.Import}" Margin="10,0,10,0" DockPanel.Dock="Right" Click="ImportButtonClick"/>
<TextBox x:Name="ConfigFile" Text="{}{CONFIG_FILE}" IsReadOnly="True" DockPanel.Dock="Left"/>
</DockPanel>

<TextBlock TextWrapping="Wrap" Text="Plugins:" Height="22" Margin="20,0,20,0" FontWeight="Bold"/>
<ListView Name="PluginList" Margin="20,0,20,10" FontSize="10">
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
Expand Down
59 changes: 57 additions & 2 deletions src/Soloplan.WhatsON.GUI/Configuration/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ namespace Soloplan.WhatsON.GUI.Configuration
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using Soloplan.WhatsON.Composition;
using Soloplan.WhatsON.GUI.Configuration.ViewModel;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;

/// <summary>
/// Interaction logic for AboutPage.xaml.
/// </summary>
public partial class AboutPage : Page
{
/// <summary>
/// The configuration view model.
/// </summary>
private readonly ConfigViewModel configurationViewModel;

/// <summary>
/// Initializes a new instance of the <see cref="AboutPage"/> class.
/// </summary>
public AboutPage()
public AboutPage(ConfigViewModel configurationViewModel)
{
this.InitializeComponent();
this.configurationViewModel = configurationViewModel;
try
{
this.VersionLabel.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
Expand Down Expand Up @@ -100,7 +110,7 @@ private void ReportABugMouseUp(object sender, MouseButtonEventArgs e)
/// Handles the MouseEnter event of the TextBlock control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
private void TextBlockMouseEnter(object sender, MouseEventArgs e)
{
if (sender is TextBlock textBlock)
Expand All @@ -121,5 +131,50 @@ private void TextBlockMouseLeave(object sender, MouseEventArgs e)
textBlock.TextDecorations = null;
}
}

/// <summary>
/// Handles import button click.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void ImportButtonClick(object sender, RoutedEventArgs e)
{
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = this.GetConfigFileFilter();
openFileDialog.FileName = !string.IsNullOrWhiteSpace(this.ConfigFile.Text) ? Path.GetFileName(this.ConfigFile.Text) : string.Empty;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var result = this.configurationViewModel.Import(openFileDialog.FileName, out var errorMessage);
if (!result)
{
System.Windows.MessageBox.Show(errorMessage, "Import error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}

/// <summary>
/// Handles export button click.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void ExportButtonClick(object sender, RoutedEventArgs e)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = this.GetConfigFileFilter();
saveFileDialog.FileName = !string.IsNullOrWhiteSpace(this.ConfigFile.Text) ? Path.GetFileName(this.ConfigFile.Text) : string.Empty;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.configurationViewModel.Export(saveFileDialog.FileName);
}
}
}

private string GetConfigFileFilter()
{
return $"{Properties.Resources.JsonFilesFilterName}|*.{SerializationHelper.Instance.ConfigFileExtension}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Soloplan.WhatsON.GUI.Configuration
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using NLog;
Expand All @@ -27,20 +28,20 @@ public class ProjectsDataInterchange
/// Exports the specified connector configuration.
/// </summary>
/// <param name="connectorConfiguration">The connector configuration.</param>
public void Export(ConnectorConfiguration connectorConfiguration)
public void Export(ConnectorConfiguration connectorConfiguration, string exportName)
{
var itemsList = new List<ConnectorConfiguration>();
itemsList.Add(connectorConfiguration);
this.Export(itemsList);
this.Export(itemsList, exportName);
}

/// <summary>
/// Exports the specified connectors configuration.
/// </summary>
/// <param name="connectorsConfiguration">The connectors configuration.</param>
public void Export(IList<ConnectorConfiguration> connectorsConfiguration)
public void Export(IList<ConnectorConfiguration> connectorsConfiguration, string exportName)
{
var filePath = this.GetExportFilePath();
var filePath = this.GetExportFilePath(exportName);
if (string.IsNullOrWhiteSpace(filePath))
{
return;
Expand Down Expand Up @@ -72,7 +73,7 @@ public bool Import(ApplicationConfiguration appConfiguration)
}
catch (Exception e)
{
var errorMessage = $"Import of the projects onfiguration from JSON file was not successfull; file path: {filePath}; exception: {e.Message}";
var errorMessage = $"Import of the projects onfiguration from JSON file was not successful; file path: {filePath}; exception: {e.Message}";
log.Error(errorMessage);
log.Error(e);
System.Windows.MessageBox.Show(errorMessage, "Import error", MessageBoxButton.OK, MessageBoxImage.Error);
Expand All @@ -91,11 +92,13 @@ private string GetProjectsInterchangeFileFilter()
/// Gets the export file path.
/// </summary>
/// <returns>The export file path.</returns>
private string GetExportFilePath()
private string GetExportFilePath(string fileName)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = this.GetProjectsInterchangeFileFilter();

saveFileDialog.FileName = $"whatson_{string.Join("_", fileName.Split(Path.GetInvalidFileNameChars()))}.json";
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
return saveFileDialog.FileName;
Expand Down
24 changes: 0 additions & 24 deletions src/Soloplan.WhatsON.GUI/Configuration/View/ConfigWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@
<ListBoxItem Content="Projects" Tag="{x:Static view:ConfigWindow.ConnectorsListItemTag}" />
<ListBoxItem Content="About" Tag="{x:Static view:ConfigWindow.AboutListItemTag}" />
</ListBox>

<materialDesign:PopupBox x:Name="uxImportExportPopup"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
HorizontalContentAlignment="Stretch"
DockPanel.Dock="Bottom"
StaysOpen="True">
<materialDesign:PopupBox.ToggleContent>
<Button x:Name="MainMenuButton"
Width="156"
Height="30"
Margin="0"
Click="ImportExportButtonClick"
Content="{x:Static properties:Resources.ImportExport}" />
</materialDesign:PopupBox.ToggleContent>
<StackPanel>
<Button Width="166"
Click="ImportButtonClick"
Content="{x:Static properties:Resources.Import}" />
<Button Width="166"
Click="ExportButtonClick"
Content="{x:Static properties:Resources.Export}" />
</StackPanel>
</materialDesign:PopupBox>
</DockPanel>
<Frame x:Name="ConfigFrame"
Margin="5,0,5,0"
Expand Down
56 changes: 1 addition & 55 deletions src/Soloplan.WhatsON.GUI/Configuration/View/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Soloplan.WhatsON.GUI.Configuration.View
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using Soloplan.WhatsON.Composition;
using Soloplan.WhatsON.Configuration;
using Soloplan.WhatsON.GUI.Common.VisualConfig;
Expand Down Expand Up @@ -232,7 +231,7 @@ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
this.ConfigFrame.Content = this.connectorPage;
return;
case AboutListItemTag:
this.aboutPage = this.aboutPage ?? new AboutPage();
this.aboutPage = this.aboutPage ?? new AboutPage(this.configurationViewModel);
this.ConfigFrame.Content = this.aboutPage;
return;
}
Expand Down Expand Up @@ -275,59 +274,6 @@ private void SnackbarResetClick(object sender, RoutedEventArgs e)
}
}

/// <summary>
/// Handles the Click event of the ImportExport button.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void ImportExportButtonClick(object sender, RoutedEventArgs e)
{
this.uxImportExportPopup.IsPopupOpen = !this.uxImportExportPopup.IsPopupOpen;
}

private string GetConfigFileFilter()
{
return $"{Properties.Resources.JsonFilesFilterName}|*.{SerializationHelper.Instance.ConfigFileExtension}";
}

/// <summary>
/// Handles import button click.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void ImportButtonClick(object sender, RoutedEventArgs e)
{
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = this.GetConfigFileFilter();
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var result = this.configurationViewModel.Import(openFileDialog.FileName, out var errorMessage);
if (!result)
{
System.Windows.MessageBox.Show(errorMessage, "Import error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}

/// <summary>
/// Handles export button click.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void ExportButtonClick(object sender, RoutedEventArgs e)
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = this.GetConfigFileFilter();
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.configurationViewModel.Export(saveFileDialog.FileName);
}
}
}

/// <summary>
/// Prevents parent from closing when configuration is modified.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public bool Import(string filePath, out string errorMessage)
}
catch (Exception e)
{
errorMessage = $"Import of the configuration from JSON file was not successfull; file path: {filePath}; exception: {e.Message}";
errorMessage = $"Import of the configuration from JSON file was not successful; file path: {filePath}; exception: {e.Message}";
log.Error(errorMessage);
log.Error(e);
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/Soloplan.WhatsON.GUI/CustomTitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@
<TextBlock Margin="10,0,0,0">Add project(s)</TextBlock>
</StackPanel>
</Button>
<Button Click="NewGroupClick" IsEnabled="{Binding CustomButtonVisible}">
<Button Click="ImportClick" IsEnabled="{Binding CustomButtonVisible}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Width="16" Height="16" Kind="LibraryAdd" />
<TextBlock Margin="10,0,0,0">Add new group</TextBlock>
<materialDesign:PackIcon Width="16" Height="16" Kind="Import" />
<TextBlock Margin="10,0,0,0">Import project(s)</TextBlock>
</StackPanel>
</Button>
<Button Click="ImportClick" IsEnabled="{Binding CustomButtonVisible}">
<Button Click="NewGroupClick" IsEnabled="{Binding CustomButtonVisible}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Width="16" Height="16" Kind="Import" />
<TextBlock Margin="10,0,0,0">Import</TextBlock>
<materialDesign:PackIcon Width="16" Height="16" Kind="LibraryAdd" />
<TextBlock Margin="10,0,0,0">Add group</TextBlock>
</StackPanel>
</Button>
</StackPanel>
Expand Down
4 changes: 2 additions & 2 deletions src/Soloplan.WhatsON.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ private void ExportTreeItem(object sender, ValueEventArgs<Common.ConnectorTreeVi
}

var projectsDataInterchange = new ProjectsDataInterchange();
projectsDataInterchange.Export(connectors);
projectsDataInterchange.Export(connectors, groupTreeViewModel.GroupName);
}

if (e.Value is Common.ConnectorTreeView.ConnectorViewModel connectorViewModel)
{
var projectsDataInterchange = new ProjectsDataInterchange();
projectsDataInterchange.Export(connectorViewModel.Connector.Configuration);
projectsDataInterchange.Export(connectorViewModel.Connector.Configuration, connectorViewModel.Name);
}
}

Expand Down

0 comments on commit 060fe9c

Please sign in to comment.