Skip to content

Commit

Permalink
#137 WPF realization - move to page in settings. Add or delete not im…
Browse files Browse the repository at this point in the history
…plemented now.
  • Loading branch information
MonkAlex committed Jun 2, 2019
1 parent 1b3e06e commit 9aea166
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 201 deletions.
8 changes: 0 additions & 8 deletions MangaReader/MangaReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@
<Compile Include="UI\Setting\ProxySetting.xaml.cs">
<DependentUpon>ProxySetting.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Setting\ProxySettingSelector.xaml.cs">
<DependentUpon>ProxySettingSelector.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Setting\SettingsForm.xaml.cs">
<DependentUpon>SettingsForm.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -180,7 +177,6 @@
<Compile Include="ViewModel\Commands\OpenWikiCommand.cs" />
<Compile Include="ViewModel\Commands\Primitives\MultipleMangasBaseCommand.cs" />
<Compile Include="ViewModel\Commands\Primitives\NavigationCommand.cs" />
<Compile Include="ViewModel\Commands\Setting\SaveProxySettingCommand.cs" />
<Compile Include="ViewModel\Manga\MangaModel.cs" />
<Compile Include="ViewModel\Primitive\ImageSourceVM.cs" />
<Compile Include="ViewModel\Setting\AppSettingModel.cs" />
Expand Down Expand Up @@ -283,10 +279,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\Setting\ProxySettingSelector.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\Setting\SettingsForm.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
7 changes: 6 additions & 1 deletion MangaReader/UI/Setting/AppSettingView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@
TextTrimming="WordEllipsis"
Text="Настройка прокси"
VerticalAlignment="Center"/>
<setting:ProxySettingSelector DataContext="{Binding ProxySettingSelector}" Grid.Row="6" Grid.Column="1"/>
<ComboBox Grid.Row="6" Grid.Column="1"
ItemsSource="{Binding ProxySettingModels}"
SelectedItem="{Binding SelectedProxySettingModel}"
DisplayMemberPath="Name"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"/>

<CheckBox Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2"
IsChecked="{Binding UpdateReader}"
Expand Down
7 changes: 6 additions & 1 deletion MangaReader/UI/Setting/MangaSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
TextTrimming="WordEllipsis"
Text="Настройка прокси"
VerticalAlignment="Center"/>
<setting:ProxySettingSelector DataContext="{Binding ProxySettingSelector}" Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="1"/>
<ComboBox Grid.Row="6" Grid.Column="2"
ItemsSource="{Binding ProxySettingModels}"
SelectedItem="{Binding SelectedProxySettingModel}"
DisplayMemberPath="Name"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"/>

<CheckBox Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="3"
Content="{x:Static resx:Strings.Settings_Update}"
Expand Down
58 changes: 25 additions & 33 deletions MangaReader/UI/Setting/ProxySetting.xaml
Original file line number Diff line number Diff line change
@@ -1,67 +1,59 @@
<Window x:Class="MangaReader.UI.Setting.ProxySetting"
<UserControl x:Class="MangaReader.UI.Setting.ProxySetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:MangaReader.Properties"
xmlns:addNewManga="clr-namespace:MangaReader.UI.AddNewManga"
mc:Ignorable="d"
ShowInTaskbar="True"
WindowStyle="ToolWindow"
Height="230"
Width="500"
d:DesignHeight="230" d:DesignWidth="500">

<StackPanel>
<Grid>
<DockPanel LastChildFill="True">
<DockPanel DockPanel.Dock="Left" LastChildFill="False">
<ListBox DockPanel.Dock="Top"
DisplayMemberPath="Name"
ItemsSource="{Binding ProxySettingModels}" SelectedItem="{Binding SelectedProxySettingModel}">
</ListBox>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom">
<Button Content="+"/>
<Button Content="-"/>
</StackPanel>
</DockPanel>
<Grid DockPanel.Dock="Right" DataContext="{Binding SelectedProxySettingModel}">
<Grid.RowDefinitions>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="30*"></ColumnDefinition>
<ColumnDefinition Width="30*"></ColumnDefinition>
</Grid.ColumnDefinitions>

<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
Content="Название: " />
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Name}" IsEnabled="{Binding IsManual}"/>
<TextBox Grid.Row="0" Grid.Column="2" Text="{Binding Name}" IsEnabled="{Binding IsManual}"/>


<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
Content="Тип: " />
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding SettingType}" IsEnabled="False"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding SettingType}" IsEnabled="False"/>


<Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
Content="Адрес прокси: " />
<TextBox Grid.Row="3" Grid.Column="2" Text="{Binding Address}" IsEnabled="{Binding IsManual}"/>
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding Address}" IsEnabled="{Binding IsManual}"/>

<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
<Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"
Content="Имя пользователя: " />
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding UserName}" IsEnabled="{Binding IsManual}"/>
<TextBox Grid.Row="3" Grid.Column="2" Text="{Binding UserName}" IsEnabled="{Binding IsManual}"/>

<Label Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2"
<Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
Content="Пароль: " />
<TextBox Grid.Row="5" Grid.Column="2" Text="{Binding Password}" IsEnabled="{Binding IsManual}"/>

<Grid Grid.Row="6" VerticalAlignment="Bottom" Grid.ColumnSpan="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" IsDefault="True" Command="{Binding Save}"/>
<Button Grid.Column="2" IsCancel="True" Content="Отмена"/>
</Grid>
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding Password}" IsEnabled="{Binding IsManual}"/>
</Grid>
</StackPanel>
</Window>

</DockPanel>
</UserControl>
3 changes: 2 additions & 1 deletion MangaReader/UI/Setting/ProxySetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ namespace MangaReader.UI.Setting
/// <summary>
/// Interaction logic for ProxySetting.xaml
/// </summary>
public partial class ProxySetting : Window
public partial class ProxySetting : UserControl
{
public ProxySetting()
{
InitializeComponent();
ViewModel.Primitive.BaseViewModel.SubToViewModel(this);
}
}
}
18 changes: 0 additions & 18 deletions MangaReader/UI/Setting/ProxySettingSelector.xaml

This file was deleted.

28 changes: 0 additions & 28 deletions MangaReader/UI/Setting/ProxySettingSelector.xaml.cs

This file was deleted.

3 changes: 3 additions & 0 deletions MangaReader/UI/Setting/SettingsForm.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<DataTemplate DataType="{x:Type setting:MangaSettingModel}">
<ui:MangaSettings/>
</DataTemplate>
<DataTemplate DataType="{x:Type setting:ProxySettingSelectorModel}">
<ui:ProxySetting/>
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemTemplate>
<DataTemplate>
Expand Down
37 changes: 0 additions & 37 deletions MangaReader/ViewModel/Commands/Setting/SaveProxySettingCommand.cs

This file was deleted.

46 changes: 43 additions & 3 deletions MangaReader/ViewModel/Setting/AppSettingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using MangaReader.Core.Account;
using MangaReader.Core.NHibernate;
using MangaReader.Core.Services;
using MangaReader.Core.Services.Config;
Expand Down Expand Up @@ -87,7 +88,44 @@ public bool StartAppMinimizedToTray

public SortModel Sort { get; set; }

public ProxySettingSelectorModel ProxySettingSelector { get; private set; }
private int proxySettingId;

public IEnumerable<ProxySettingModel> ProxySettingModels
{
get => proxySettingModels;
set
{
proxySettingModels = value;
OnPropertyChanged();
}
}

private IEnumerable<ProxySettingModel> proxySettingModels;

public ProxySettingModel SelectedProxySettingModel
{
get => selectedProxySettingModel;
set
{
selectedProxySettingModel = value;
if (selectedProxySettingModel != null)
proxySettingId = selectedProxySettingModel.Id;
OnPropertyChanged();
}
}

private ProxySettingModel selectedProxySettingModel;

public override void Load()
{
base.Load();

using (var context = Repository.GetEntityContext())
{
this.ProxySettingModels = context.Get<ProxySetting>().Where(s => s.SettingType != ProxySettingType.Parent).Select(s => new ProxySettingModel(s)).ToList();
this.SelectedProxySettingModel = this.ProxySettingModels.FirstOrDefault(m => m.Id == proxySettingId);
}
}

public override async Task Save()
{
Expand All @@ -111,11 +149,13 @@ public override async Task Save()
{
var config = await context.Get<DatabaseConfig>().SingleAsync().ConfigureAwait(true);
config.FolderNamingStrategy = FolderNamingStrategy.Selected.Id;
if (proxySettingId != config.ProxySetting.Id)
config.ProxySetting = await context.Get<ProxySetting>().SingleAsync(s => s.Id == proxySettingId).ConfigureAwait(false);
await context.Save(config).ConfigureAwait(true);
}
}

public AppSettingModel(ObservableCollection<ProxySettingModel> proxySettingModels)
public AppSettingModel()
{
this.Header = "Основные настройки";
this.Languages = Generic.GetEnumValues<Languages>();
Expand All @@ -135,7 +175,7 @@ public AppSettingModel(ObservableCollection<ProxySettingModel> proxySettingModel
#warning DB connection in ctor
var config = context.Get<DatabaseConfig>().Single();
this.FolderNamingStrategy.SelectedGuid = config.FolderNamingStrategy;
this.ProxySettingSelector = new ProxySettingSelectorModel(config.ProxySetting, proxySettingModels);
this.proxySettingId = config.ProxySetting.Id;
}

this.Sort = new SortModel();
Expand Down
Loading

0 comments on commit 9aea166

Please sign in to comment.