Skip to content

Commit

Permalink
removed interence between settings | used static resource binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavius Motileng committed Apr 26, 2020
1 parent fa7741b commit 26fd731
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
10 changes: 10 additions & 0 deletions src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerToys.Settings.UI.Lib
Expand All @@ -25,5 +26,14 @@ public ImageresizerSizes(ObservableCollection<ImageSize> value)
{
Value = value;
}

public string ToJsonString()
{
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
return JsonSerializer.Serialize(this, options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PowerPreviewSettings()
{
properties = new PowerPreviewProperties();
version = "1";
name = "_unset_";
name = "File Explorer";
}

public PowerPreviewSettings(string ptName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public ObservableCollection<ImageSize> Sizes

set
{
SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
_advancedSizes = value;
Settings.Properties.ImageresizerSizes.Value = value;
Settings.Properties.ImageresizerSizes = new ImageresizerSizes(value);
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
OnPropertyChanged("Sizes");
}
Expand Down Expand Up @@ -218,6 +219,7 @@ public int Encoder
if (_encoderGuidId != value)
{
_encoderGuidId = value;
SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
Settings.Properties.ImageresizerFallbackEncoder.Value = GetEncoderGuid(value);
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
OnPropertyChanged("Encoder");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class PowerPreviewViewModel : Observable
{
private const string ModuleName = "File Explorer Preview";
private const string ModuleName = "File Explorer";

private PowerPreviewSettings Settings { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
Style="{StaticResource SettingsGroupTitleStyle}"/>

<!--x:Uid="ImageResizer_EnableToggle"-->
<ToggleSwitch IsOn="{ Binding Mode=TwoWay, Path=IsEnabled}"
<ToggleSwitch IsOn="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
Margin="{StaticResource SmallTopMargin}" />

<TextBlock x:Uid="ImageResizer_CustomSizes"
Expand All @@ -64,7 +64,7 @@
<ListView x:Name="ImagesSizesListView"
ItemsSource="{Binding Sizes, Mode=TwoWay, Source={StaticResource ViewModel}}"
Padding="0"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
Margin="0"
>

Expand Down Expand Up @@ -158,7 +158,7 @@
<StackPanel Orientation="Horizontal">
<AppBarButton Icon="Add"
x:Name="AddSizeButton"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
Label="Add Size"
Margin="{StaticResource SmallTopMargin}"
Command = "{Binding AddImageSizeEventHandler, Source={StaticResource ViewModel}}"
Expand All @@ -169,10 +169,10 @@
Style="{StaticResource SettingsGroupTitleStyle}"/>

<ComboBox Header="Fallback encoder"
SelectedIndex="{Binding Mode=TwoWay, Path=Encoder}"
SelectedIndex="{Binding Path=Encoder, Mode=TwoWay, Source={StaticResource ViewModel}}"
MinWidth="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}">
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_PNG" />
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_BMP" />
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_JPEG" />
Expand All @@ -185,28 +185,28 @@
<muxc:NumberBox Header="JPEG Quality level"
Minimum="0"
Maximum="100"
Value="{ Binding Mode=TwoWay, Path=JPEGQualityLevel}"
Value="{ Binding Mode=TwoWay, Path=JPEGQualityLevel, Source={StaticResource ViewModel}}"
MinWidth="240"
SpinButtonPlacementMode="Inline"
HorizontalAlignment="Left"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"/>
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"/>

<ComboBox Header="PNG interlacing"
SelectedIndex="{ Binding Mode=TwoWay, Path=PngInterlaceOption}"
SelectedIndex="{ Binding Mode=TwoWay, Path=PngInterlaceOption, Source={StaticResource ViewModel}}"
MinWidth="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}">
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
<ComboBoxItem x:Uid="Default"/>
<ComboBoxItem x:Uid="On"/>
<ComboBoxItem x:Uid="Off"/>
</ComboBox>

<ComboBox Header="TIFF Compression"
SelectedIndex="{ Binding Mode=TwoWay, Path=TiffCompressOption}"
SelectedIndex="{ Binding Mode=TwoWay, Path=TiffCompressOption, Source={StaticResource ViewModel}}"
MinWidth="240"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}">
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_Default"/>
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_None"/>
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_CCITT3"/>
Expand Down Expand Up @@ -248,16 +248,16 @@
</TextBlock>

<TextBox Header="Filename format"
Text="{ Binding Mode=TwoWay, Path=FileName}"
Text="{ Binding Mode=TwoWay, Path=FileName, Source={StaticResource ViewModel}}"
HorizontalAlignment="Left"
MinWidth="240"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
Margin="{StaticResource SmallTopMargin}"/>

<CheckBox Content="Use original date modified"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
Margin="{StaticResource SmallTopMargin}"
IsChecked="{Binding Mode=TwoWay, Path=KeepDateModified}"/>
IsChecked="{Binding Mode=TwoWay, Path=KeepDateModified, Source={StaticResource ViewModel}}"/>
</StackPanel>

<StackPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public ImageResizerPage()
{
InitializeComponent();
ViewModel = new ImageResizerViewModel();
this.ImageResizerView.DataContext = ViewModel;
}
}
}
1 change: 1 addition & 0 deletions src/settings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void send_message_to_powertoys_runner(const std::wstring& msg)
{
if (g_message_pipe != nullptr)
{
MessageBox(g_main_wnd, msg.c_str(), L"From Webview", MB_OK);
g_message_pipe->send(msg);
}
else
Expand Down

0 comments on commit 26fd731

Please sign in to comment.