mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-28 17:31:56 +01:00
Rework NavigationService.
This commit is contained in:
1 parent
5d7186f5b1
commit
f67f25d8e1
17 files changed
+300
-191
No files matched your search
@@ -72,13 +72,13 @@ namespace FileConverter
|
||||
|
||||
if (this.showHelp)
|
||||
{
|
||||
navigationService.NavigateTo(Pages.Help);
|
||||
navigationService.Show(Pages.Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.needToRunConversionThread)
|
||||
{
|
||||
navigationService.NavigateTo(Pages.Main);
|
||||
navigationService.Show(Pages.Main);
|
||||
|
||||
IConversionService conversionService = SimpleIoc.Default.GetInstance<IConversionService>();
|
||||
conversionService.ConversionJobsTerminated += this.ConversionService_ConversionJobsTerminated;
|
||||
@@ -87,12 +87,12 @@ namespace FileConverter
|
||||
|
||||
if (this.showSettings)
|
||||
{
|
||||
navigationService.NavigateTo(Pages.Settings);
|
||||
navigationService.Show(Pages.Settings);
|
||||
}
|
||||
|
||||
if (this.verbose)
|
||||
{
|
||||
navigationService.NavigateTo(Pages.Diagnostics);
|
||||
navigationService.Show(Pages.Diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,11 +184,11 @@ namespace FileConverter
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
|
||||
navigationService.RegisterPage<HelpWindow>(Pages.Help, false);
|
||||
navigationService.RegisterPage<MainWindow>(Pages.Main, false);
|
||||
navigationService.RegisterPage<SettingsWindow>(Pages.Settings, true);
|
||||
navigationService.RegisterPage<DiagnosticsWindow>(Pages.Diagnostics, true);
|
||||
navigationService.RegisterPage<UpgradeWindow>(Pages.Upgrade, true);
|
||||
navigationService.RegisterPage<HelpWindow>(Pages.Help, false, true);
|
||||
navigationService.RegisterPage<MainWindow>(Pages.Main, false, true);
|
||||
navigationService.RegisterPage<SettingsWindow>(Pages.Settings, true, true);
|
||||
navigationService.RegisterPage<DiagnosticsWindow>(Pages.Diagnostics, true, false);
|
||||
navigationService.RegisterPage<UpgradeWindow>(Pages.Upgrade, true, false);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
@@ -351,7 +351,7 @@ namespace FileConverter
|
||||
|
||||
private void UpgradeService_NewVersionAvailable(object sender, UpgradeVersionDescription e)
|
||||
{
|
||||
SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Upgrade);
|
||||
SimpleIoc.Default.GetInstance<INavigationService>().Show(Pages.Upgrade);
|
||||
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
upgradeService.NewVersionAvailable -= this.UpgradeService_NewVersionAvailable;
|
||||
|
||||
@@ -218,6 +218,7 @@
|
||||
<Compile Include="ValueConverters\OutputTypeToVisibility.cs" />
|
||||
<Compile Include="ValueConverters\Generic\StringToEnum.cs" />
|
||||
<Compile Include="ValueConverters\Generic\ValueConverterGroup.cs" />
|
||||
<Compile Include="ViewModels\DiagnosticsViewModel.cs" />
|
||||
<Compile Include="ViewModels\SettingsViewModel.cs" />
|
||||
<Compile Include="ViewModels\HelpViewModel.cs" />
|
||||
<Compile Include="ViewModels\UpgradeViewModel.cs" />
|
||||
|
||||
@@ -4,8 +4,12 @@ namespace FileConverter.Services
|
||||
{
|
||||
using System.Windows;
|
||||
|
||||
public interface INavigationService : GalaSoft.MvvmLight.Views.INavigationService
|
||||
public interface INavigationService
|
||||
{
|
||||
void RegisterPage<T>(string pageKey, bool cancelAutoExit) where T : Window;
|
||||
void RegisterPage<T>(string pageKey, bool cancelAutoExit, bool mainWindow) where T : Window;
|
||||
|
||||
void Show(string pageKey);
|
||||
|
||||
void Close(string pageKey, bool alreadyClosing);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ namespace FileConverter.Services
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
|
||||
@@ -17,76 +19,16 @@ namespace FileConverter.Services
|
||||
public class NavigationService : ObservableObject, INavigationService
|
||||
{
|
||||
private readonly Dictionary<string, PageInfo> pageInfoByType;
|
||||
private readonly List<string> historic;
|
||||
private string currentPageKey;
|
||||
private int numberOfPageShowed = 0;
|
||||
|
||||
public NavigationService()
|
||||
{
|
||||
this.pageInfoByType = new Dictionary<string, PageInfo>();
|
||||
this.historic = new List<string>();
|
||||
|
||||
SimpleIoc.Default.Register<INavigationService>(() => this);
|
||||
}
|
||||
|
||||
public string CurrentPageKey
|
||||
{
|
||||
get => this.currentPageKey;
|
||||
|
||||
private set
|
||||
{
|
||||
if (this.currentPageKey == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentPageKey = value;
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public object Parameter { get; private set; }
|
||||
|
||||
public void GoBack()
|
||||
{
|
||||
lock (this.pageInfoByType)
|
||||
{
|
||||
if (this.historic.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string pageKey = this.historic.Last();
|
||||
PageInfo pageInfo;
|
||||
if (!this.pageInfoByType.TryGetValue(pageKey, out pageInfo))
|
||||
{
|
||||
throw new ArgumentException($"No such page: {pageKey} ", nameof(pageKey));
|
||||
}
|
||||
|
||||
this.historic.RemoveAt(this.historic.Count - 1);
|
||||
this.CurrentPageKey = this.historic.LastOrDefault();
|
||||
|
||||
Diagnostics.Debug.Log($"Go back from {pageKey ?? "null"} to {this.CurrentPageKey ?? "null"}.");
|
||||
|
||||
this.pageInfoByType[pageKey] = pageInfo;
|
||||
|
||||
if (pageInfo.Instance.IsVisible)
|
||||
{
|
||||
pageInfo.Instance.Close();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(this.CurrentPageKey))
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NavigateTo(string pageKey)
|
||||
{
|
||||
this.NavigateTo(pageKey, null);
|
||||
}
|
||||
|
||||
public virtual void NavigateTo(string pageKey, object parameter)
|
||||
public void Show([NotNull] string pageKey)
|
||||
{
|
||||
lock (this.pageInfoByType)
|
||||
{
|
||||
@@ -96,23 +38,23 @@ namespace FileConverter.Services
|
||||
throw new ArgumentException($"No such page: {pageKey}.", nameof(pageKey));
|
||||
}
|
||||
|
||||
if (pageInfo.Showed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pageInfo.Showed = true;
|
||||
|
||||
if (pageInfo.Instance == null || !pageInfo.Instance.IsLoaded)
|
||||
{
|
||||
pageInfo.Instance = Activator.CreateInstance(pageInfo.Type) as Window;
|
||||
}
|
||||
|
||||
this.Parameter = parameter;
|
||||
this.historic.Add(pageKey);
|
||||
this.CurrentPageKey = pageKey;
|
||||
|
||||
Diagnostics.Debug.Log($"Navigate to {this.CurrentPageKey ?? "null"}.");
|
||||
Diagnostics.Debug.Log($"Show page {pageKey}.");
|
||||
|
||||
this.pageInfoByType[pageKey] = pageInfo;
|
||||
|
||||
if (pageInfo.Instance.IsVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.numberOfPageShowed++;
|
||||
|
||||
if (pageInfo.CancelAutoExit)
|
||||
{
|
||||
@@ -124,7 +66,75 @@ namespace FileConverter.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterPage<T>(string pageKey, bool cancelAutoExit) where T : Window
|
||||
public void Close([NotNull] string pageKey, bool alreadyClosing)
|
||||
{
|
||||
if (pageKey == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pageKey));
|
||||
}
|
||||
|
||||
lock (this.pageInfoByType)
|
||||
{
|
||||
PageInfo pageInfo;
|
||||
if (!this.pageInfoByType.TryGetValue(pageKey, out pageInfo))
|
||||
{
|
||||
throw new ArgumentException($"No such page: {pageKey}.", nameof(pageKey));
|
||||
}
|
||||
|
||||
if (!pageInfo.Showed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pageInfo.Showed = false;
|
||||
|
||||
Diagnostics.Debug.Log($"Close page {pageKey}.");
|
||||
|
||||
this.pageInfoByType[pageKey] = pageInfo;
|
||||
|
||||
if (pageInfo.MainWindow)
|
||||
{
|
||||
this.CloseSecondaryWindowsIfThereIsNoOtherMainWindowShowed();
|
||||
}
|
||||
|
||||
if (!alreadyClosing)
|
||||
{
|
||||
pageInfo.Instance.Close();
|
||||
}
|
||||
|
||||
this.numberOfPageShowed--;
|
||||
|
||||
// If this is the last window.
|
||||
if (this.numberOfPageShowed == 0)
|
||||
{
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
bool upgradeInProgress = upgradeService.UpgradeVersionDescription != null &&
|
||||
upgradeService.UpgradeVersionDescription.NeedToUpgrade &&
|
||||
!upgradeService.UpgradeVersionDescription.InstallerDownloadDone;
|
||||
|
||||
if (upgradeInProgress)
|
||||
{
|
||||
if (pageKey == Pages.Upgrade)
|
||||
{
|
||||
upgradeService.CancelUpgrade();
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Show(Pages.Upgrade);
|
||||
Diagnostics.Debug.Log("There is an upgrade in progress, display the upgrade window.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterPage<T>(string pageKey, bool cancelAutoExit, bool mainWindow) where T : Window
|
||||
{
|
||||
if (string.IsNullOrEmpty(pageKey))
|
||||
{
|
||||
@@ -135,7 +145,7 @@ namespace FileConverter.Services
|
||||
{
|
||||
if (!this.pageInfoByType.ContainsKey(pageKey))
|
||||
{
|
||||
this.pageInfoByType.Add(pageKey, new PageInfo(typeof(T), cancelAutoExit));
|
||||
this.pageInfoByType.Add(pageKey, new PageInfo(typeof(T), cancelAutoExit, mainWindow));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -144,17 +154,46 @@ namespace FileConverter.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseSecondaryWindowsIfThereIsNoOtherMainWindowShowed()
|
||||
{
|
||||
List<string> windowsToClose = new List<string>();
|
||||
foreach (KeyValuePair<string, PageInfo> keyValuePair in this.pageInfoByType)
|
||||
{
|
||||
if (keyValuePair.Value.MainWindow && keyValuePair.Value.Showed)
|
||||
{
|
||||
// There is another main window showed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyValuePair.Value.Showed)
|
||||
{
|
||||
windowsToClose.Add(keyValuePair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Close all windows.
|
||||
for (int index = 0; index < windowsToClose.Count; index++)
|
||||
{
|
||||
this.Close(windowsToClose[index], false);
|
||||
}
|
||||
}
|
||||
|
||||
private struct PageInfo
|
||||
{
|
||||
public Window Instance;
|
||||
public Type Type;
|
||||
public bool CancelAutoExit;
|
||||
public bool MainWindow;
|
||||
|
||||
public PageInfo(Type type, bool cancelAutoExit)
|
||||
public bool Showed;
|
||||
|
||||
public PageInfo(Type type, bool cancelAutoExit, bool mainWindow)
|
||||
{
|
||||
this.Instance = null;
|
||||
this.Type = type;
|
||||
this.CancelAutoExit = cancelAutoExit;
|
||||
this.MainWindow = mainWindow;
|
||||
this.Showed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
namespace FileConverter.ViewModels
|
||||
{
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
using FileConverter.Commands;
|
||||
using FileConverter.ConversionJobs;
|
||||
using FileConverter.Services;
|
||||
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
|
||||
/// <summary>
|
||||
/// This class contains properties that the main View can data bind to.
|
||||
/// <para>
|
||||
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// You can also use Blend to data bind with the tool's support.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// See http://www.galasoft.ch/mvvm
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class DiagnosticsViewModel : ViewModelBase
|
||||
{
|
||||
private RelayCommand<CancelEventArgs> closeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HelpViewModel class.
|
||||
/// </summary>
|
||||
public DiagnosticsViewModel()
|
||||
{
|
||||
if (this.IsInDesignMode)
|
||||
{
|
||||
// Code runs in Blend --> create design time data.
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.closeCommand == null)
|
||||
{
|
||||
this.closeCommand = new RelayCommand<CancelEventArgs>(this.Close);
|
||||
}
|
||||
|
||||
return this.closeCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(CancelEventArgs args)
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Close(Pages.Diagnostics, args != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace FileConverter.ViewModels
|
||||
/// </summary>
|
||||
public class HelpViewModel : ViewModelBase
|
||||
{
|
||||
private RelayCommand quitCommand;
|
||||
private RelayCommand<CancelEventArgs> closeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the HelpViewModel class.
|
||||
@@ -44,17 +44,23 @@ namespace FileConverter.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand QuitCommand
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.quitCommand == null)
|
||||
if (this.closeCommand == null)
|
||||
{
|
||||
this.quitCommand = new RelayCommand(() => System.Windows.Application.Current.Shutdown());
|
||||
this.closeCommand = new RelayCommand<CancelEventArgs>(this.Close);
|
||||
}
|
||||
|
||||
return this.quitCommand;
|
||||
return this.closeCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(CancelEventArgs args)
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Close(Pages.Help, args != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ namespace FileConverter.ViewModels
|
||||
|
||||
private RelayCommand showSettingsCommand;
|
||||
private RelayCommand showDiagnosticsCommand;
|
||||
private RelayCommand<CancelEventArgs> closeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MainViewModel class.
|
||||
@@ -92,7 +93,7 @@ namespace FileConverter.ViewModels
|
||||
{
|
||||
if (this.showSettingsCommand == null)
|
||||
{
|
||||
this.showSettingsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Settings));
|
||||
this.showSettingsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().Show(Pages.Settings));
|
||||
}
|
||||
|
||||
return this.showSettingsCommand;
|
||||
@@ -105,13 +106,32 @@ namespace FileConverter.ViewModels
|
||||
{
|
||||
if (this.showDiagnosticsCommand == null)
|
||||
{
|
||||
this.showDiagnosticsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Diagnostics));
|
||||
this.showDiagnosticsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().Show(Pages.Diagnostics));
|
||||
}
|
||||
|
||||
return this.showDiagnosticsCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.closeCommand == null)
|
||||
{
|
||||
this.closeCommand = new RelayCommand<CancelEventArgs>(this.Close);
|
||||
}
|
||||
|
||||
return this.closeCommand;
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(CancelEventArgs args)
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Close(Pages.Main, args != null);
|
||||
}
|
||||
|
||||
private void ConversionJob_PropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.PropertyName != "State" && eventArgs.PropertyName != "Progress")
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace FileConverter.ViewModels
|
||||
private RelayCommand addNewPresetCommand;
|
||||
private RelayCommand removePresetCommand;
|
||||
private RelayCommand saveCommand;
|
||||
private RelayCommand closeCommand;
|
||||
private RelayCommand<CancelEventArgs> closeCommand;
|
||||
|
||||
private ListCollectionView outputTypes;
|
||||
private CultureInfo[] supportedCultures;
|
||||
@@ -314,7 +314,7 @@ namespace FileConverter.ViewModels
|
||||
{
|
||||
if (this.closeCommand == null)
|
||||
{
|
||||
this.closeCommand = new RelayCommand(this.CloseSettings);
|
||||
this.closeCommand = new RelayCommand<CancelEventArgs>(this.CloseSettings);
|
||||
}
|
||||
|
||||
return this.closeCommand;
|
||||
@@ -377,13 +377,13 @@ namespace FileConverter.ViewModels
|
||||
this.RaisePropertyChanged(nameof(this.InputCategories));
|
||||
}
|
||||
|
||||
private void CloseSettings()
|
||||
private void CloseSettings(CancelEventArgs args)
|
||||
{
|
||||
ISettingsService settingsService = SimpleIoc.Default.GetInstance<ISettingsService>();
|
||||
settingsService.RevertSettings();
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.GoBack();
|
||||
navigationService.Close(Pages.Settings, args != null);
|
||||
}
|
||||
|
||||
private bool CanSaveSettings()
|
||||
@@ -398,7 +398,7 @@ namespace FileConverter.ViewModels
|
||||
settingsService.Settings.Save();
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.GoBack();
|
||||
navigationService.Close(Pages.Settings, false);
|
||||
}
|
||||
|
||||
private bool CanMoveSelectedPresetUp()
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace FileConverter.ViewModels
|
||||
|
||||
private RelayCommand downloadInstallerCommand;
|
||||
private RelayCommand launchInstallerCommand;
|
||||
private RelayCommand<CancelEventArgs> closeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the UpgradeViewModel class.
|
||||
@@ -79,6 +80,19 @@ namespace FileConverter.ViewModels
|
||||
return this.launchInstallerCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.closeCommand == null)
|
||||
{
|
||||
this.closeCommand = new RelayCommand<CancelEventArgs>(this.Close);
|
||||
}
|
||||
|
||||
return this.closeCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public UpgradeVersionDescription VersionDescription
|
||||
{
|
||||
@@ -131,13 +145,19 @@ namespace FileConverter.ViewModels
|
||||
upgradeService.StartUpgrade();
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.GoBack();
|
||||
navigationService.Close(Pages.Upgrade, false);
|
||||
}
|
||||
|
||||
private void ExecuteLaunchInstallerCommand()
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.GoBack();
|
||||
navigationService.Close(Pages.Upgrade, false);
|
||||
}
|
||||
|
||||
private void Close(CancelEventArgs args)
|
||||
{
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.Close(Pages.Upgrade, args != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ namespace FileConverter.ViewModels
|
||||
SimpleIoc.Default.Register<MainViewModel>();
|
||||
SimpleIoc.Default.Register<UpgradeViewModel>();
|
||||
SimpleIoc.Default.Register<SettingsViewModel>();
|
||||
SimpleIoc.Default.Register<DiagnosticsViewModel>();
|
||||
}
|
||||
|
||||
public HelpViewModel Help => ServiceLocator.Current.GetInstance<HelpViewModel>();
|
||||
@@ -61,9 +62,6 @@ namespace FileConverter.ViewModels
|
||||
|
||||
public SettingsViewModel Settings => ServiceLocator.Current.GetInstance<SettingsViewModel>();
|
||||
|
||||
public static void Cleanup()
|
||||
{
|
||||
// TODO Clear the ViewModels
|
||||
}
|
||||
public DiagnosticsViewModel Diagnostics => ServiceLocator.Current.GetInstance<DiagnosticsViewModel>();
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,16 @@
|
||||
xmlns:diagnostics="clr-namespace:FileConverter.Diagnostics"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:local="clr-namespace:FileConverter"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:command="http://www.galasoft.ch/mvvmlight"
|
||||
mc:Ignorable="d"
|
||||
Height="600" Width="800" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
|
||||
Height="600" Width="800" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
DataContext="{Binding Diagnostics, Source={StaticResource Locator}}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Closing">
|
||||
<command:EventToCommand Command="{Binding CloseCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Window.Title>
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
</Window.Title>
|
||||
|
||||
@@ -6,9 +6,16 @@
|
||||
xmlns:fileConverter="clr-namespace:FileConverter"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:gif="http://wpfanimatedgif.codeplex.com"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:command="http://www.galasoft.ch/mvvmlight"
|
||||
mc:Ignorable="d" Icon="/FileConverter;component/Resources/ApplicationIcon.ico" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ResizeMode="NoResize"
|
||||
Width="640" Height="545"
|
||||
DataContext="{Binding Help, Source={StaticResource Locator}}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Closing">
|
||||
<command:EventToCommand Command="{Binding CloseCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Window.Resources>
|
||||
</Window.Resources>
|
||||
<Window.Title>
|
||||
@@ -21,6 +28,6 @@
|
||||
<Image Margin="0,7,0,7" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="Auto"
|
||||
gif:ImageBehavior.AnimatedSource="/FileConverter;component/Resources/FileConverterUsage.gif"
|
||||
Stretch="Fill"/>
|
||||
<Button Content="{x:Static project:Resources.Ok}" Height="28" Command="{Binding QuitCommand}"/>
|
||||
<Button Content="{x:Static project:Resources.Ok}" Height="28" Command="{Binding CloseCommand}"/>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
@@ -6,9 +6,16 @@
|
||||
xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:controls="clr-namespace:FileConverter.Controls"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:command="http://www.galasoft.ch/mvvmlight"
|
||||
mc:Ignorable="d" x:Class="FileConverter.Views.MainWindow"
|
||||
Height="500" Width="950" MinHeight="250" MinWidth="500" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
DataContext="{Binding Main, Source={StaticResource Locator}}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Closing">
|
||||
<command:EventToCommand Command="{Binding CloseCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Window.Resources>
|
||||
<valueConverters:ConversionJobsToProgressState x:Key="ConversionJobsToProgressState" />
|
||||
<valueConverters:ConversionJobsToProgressValue x:Key="ConversionJobsToProgressValue" />
|
||||
|
||||
@@ -2,84 +2,13 @@
|
||||
|
||||
namespace FileConverter.Views
|
||||
{
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.Services;
|
||||
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
|
||||
using Application = FileConverter.Application;
|
||||
|
||||
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private UpgradeWindow upgradeWindow;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs eventArgs)
|
||||
{
|
||||
base.OnClosing(eventArgs);
|
||||
|
||||
IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
|
||||
if (upgradeService.UpgradeVersionDescription != null &&
|
||||
upgradeService.UpgradeVersionDescription.NeedToUpgrade &&
|
||||
!upgradeService.UpgradeVersionDescription.InstallerDownloadDone)
|
||||
{
|
||||
eventArgs.Cancel = true;
|
||||
|
||||
INavigationService navigationService = SimpleIoc.Default.GetInstance<INavigationService>();
|
||||
navigationService.NavigateTo(Pages.Upgrade);
|
||||
}
|
||||
}
|
||||
|
||||
//private void ShowUpgradeWindow()
|
||||
//{
|
||||
// if (this.upgradeWindow != null && this.upgradeWindow.IsVisible)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// else if (this.upgradeWindow == null)
|
||||
// {
|
||||
// this.upgradeWindow = new UpgradeWindow();
|
||||
// this.upgradeWindow.Closed += this.UpgradeWindow_Closed;
|
||||
// }
|
||||
|
||||
// Application application = Application.Current as Application;
|
||||
// application?.CancelAutoExit();
|
||||
// this.upgradeWindow.Show();
|
||||
//}
|
||||
|
||||
//private void UpgradeWindow_Closed(object sender, System.EventArgs e)
|
||||
//{
|
||||
// Application application = Application.Current as Application;
|
||||
|
||||
// if (this.IsVisible)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// IUpgradeService upgradeService = SimpleIoc.Default.GetInstance<IUpgradeService>();
|
||||
// if (upgradeService.UpgradeVersionDescription != null &&
|
||||
// upgradeService.UpgradeVersionDescription.NeedToUpgrade &&
|
||||
// upgradeService.UpgradeVersionDescription.InstallerDownloadDone)
|
||||
// {
|
||||
// this.Close();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:FileConverter"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:views="clr-namespace:FileConverter.Views"
|
||||
xmlns:viewModels="clr-namespace:FileConverter.ViewModels"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:command="http://www.galasoft.ch/mvvmlight"
|
||||
x:Class="FileConverter.Views.SettingsWindow"
|
||||
MinWidth="640" MinHeight="480"
|
||||
Width="920" Height="675"
|
||||
WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
DataContext="{Binding Settings, Source={StaticResource Locator}}"
|
||||
Closing="SettingsWindow_OnClosing">
|
||||
DataContext="{Binding Settings, Source={StaticResource Locator}}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Closing">
|
||||
<command:EventToCommand Command="{Binding CloseCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace FileConverter.Views
|
||||
{
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -115,13 +114,5 @@ namespace FileConverter.Views
|
||||
dataContext.SelectedPreset.RemoveInputType(inputExtension);
|
||||
}
|
||||
}
|
||||
|
||||
private void SettingsWindow_OnClosing(object sender, CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
|
||||
SettingsViewModel settingsViewModel = (SettingsViewModel)this.DataContext;
|
||||
settingsViewModel.CloseCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,19 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:project="clr-namespace:FileConverter.Properties"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:command="http://www.galasoft.ch/mvvmlight"
|
||||
mc:Ignorable="d"
|
||||
Title="{x:Static project:Resources.UpgradeWindowTitle}"
|
||||
WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico"
|
||||
MinHeight="300" MinWidth="450"
|
||||
Height="450" Width="450" WindowStyle="ToolWindow"
|
||||
DataContext="{Binding Upgrade, Source={StaticResource Locator}}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Closing">
|
||||
<command:EventToCommand Command="{Binding CloseCommand}" PassEventArgsToCommand="True" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<Window.Resources>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
|
||||
Reference in new issue
Block a user