Skip to content

Commit

Permalink
#137 Fix proxy tab unselection.
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkAlex committed Jun 12, 2019
1 parent bb280da commit 57edd1c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
3 changes: 3 additions & 0 deletions MangaReader.Avalonia/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
<Application.Styles>
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
<Style Selector="Button">
<Setter Property="MinWidth" Value="72"/>
</Style>
</Application.Styles>
</Application>
2 changes: 1 addition & 1 deletion MangaReader.Avalonia/View/ProxySetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:view="clr-namespace:MangaReader.Avalonia.View;assemlby=MangaReader.Avalonia"
xmlns:view="clr-namespace:MangaReader.Avalonia.View;assembly=MangaReader.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MangaReader.Avalonia.View.ProxySetting">
<StackPanel Margin="10">
Expand Down
14 changes: 2 additions & 12 deletions MangaReader.Avalonia/ViewModel/Explorer/MangaSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace MangaReader.Avalonia.ViewModel.Explorer
{
public class MangaSettingsViewModel : ExplorerTabViewModel
public class MangaSettingsViewModel : SettingTabViewModel
{
private readonly int mangaSettingsId;

Expand Down Expand Up @@ -66,17 +66,7 @@ public Compression.CompressionMode Compression
}

private Compression.CompressionMode compression;

public override async Task OnUnselected(ExplorerTabViewModel newModel)
{
await base.OnUnselected(newModel).ConfigureAwait(true);
if (!(newModel is SettingsViewModel || newModel is MangaSettingsViewModel || newModel is ProxySettingSelectorModel))
{
foreach (var tab in ExplorerViewModel.Instance.Tabs.OfType<MangaSettingsViewModel>().ToList())
ExplorerViewModel.Instance.Tabs.Remove(tab);
}
}


public ICommand Save { get; }

public ICommand UndoChanged { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace MangaReader.Avalonia.ViewModel.Explorer
{
public class ProxySettingSelectorModel : ExplorerTabViewModel
public class ProxySettingSelectorModel : SettingTabViewModel
{

public ProxySettingModel SelectedProxySettingModel
Expand Down
20 changes: 20 additions & 0 deletions MangaReader.Avalonia/ViewModel/Explorer/SettingTabViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using System.Threading.Tasks;

namespace MangaReader.Avalonia.ViewModel.Explorer
{
public class SettingTabViewModel : ExplorerTabViewModel
{
public bool HideTab { get; set; } = true;

public override async Task OnUnselected(ExplorerTabViewModel newModel)
{
await base.OnUnselected(newModel).ConfigureAwait(true);
if (!(newModel is SettingTabViewModel))
{
foreach (var tab in ExplorerViewModel.Instance.Tabs.OfType<SettingTabViewModel>().Where(t => t.HideTab).ToList())
ExplorerViewModel.Instance.Tabs.Remove(tab);
}
}
}
}
12 changes: 4 additions & 8 deletions MangaReader.Avalonia/ViewModel/Explorer/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MangaReader.Avalonia.ViewModel.Explorer
{
public class SettingsViewModel : ExplorerTabViewModel
public class SettingsViewModel : SettingTabViewModel
{
public int AutoupdateLibraryInHours
{
Expand Down Expand Up @@ -84,15 +84,10 @@ public override async Task OnSelected(ExplorerTabViewModel previousModel)
public override async Task OnUnselected(ExplorerTabViewModel newModel)
{
await base.OnUnselected(newModel).ConfigureAwait(true);
if (!(newModel is SettingsViewModel || newModel is MangaSettingsViewModel || newModel is ProxySettingSelectorModel))
{
foreach (var tab in ExplorerViewModel.Instance.Tabs.OfType<MangaSettingsViewModel>().ToList())
ExplorerViewModel.Instance.Tabs.Remove(tab);

#warning Нужно ресетить только после изменения порядка сортировки.
foreach (var model in ExplorerViewModel.Instance.Tabs.OfType<LibraryViewModel>())
model.ResetView();
}
foreach (var model in ExplorerViewModel.Instance.Tabs.OfType<LibraryViewModel>())
model.ResetView();
}

public ICommand Save { get; }
Expand Down Expand Up @@ -145,6 +140,7 @@ public SettingsViewModel()
{
this.Name = "Settings";
this.Priority = 100;
this.HideTab = false;

this.Save = new DelegateCommand(SaveConfig, () => true);
this.UndoChanged = new DelegateCommand(ReloadConfig, () => true);
Expand Down

0 comments on commit 57edd1c

Please sign in to comment.