mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Fix suffixes converter, part 1
1. fix #568, fix #566 fix #553, fix #559 2. simple refactoring
This commit is contained in:
@@ -49,14 +49,15 @@ namespace Wox.Plugin.Program
|
|||||||
|
|
||||||
if(_editing == null)
|
if(_editing == null)
|
||||||
{
|
{
|
||||||
_settings.ProgramSources.Add(new ProgramSource
|
var source = new ProgramSource
|
||||||
{
|
{
|
||||||
Location = Directory.Text,
|
Location = Directory.Text,
|
||||||
MaxDepth = max,
|
MaxDepth = max,
|
||||||
Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator),
|
Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator),
|
||||||
Type = "FileSystemProgramSource",
|
Type = "FileSystemProgramSource",
|
||||||
Enabled = true
|
Enabled = true
|
||||||
});
|
};
|
||||||
|
_settings.ProgramSources.Add(source);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,14 +28,14 @@
|
|||||||
<GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="250">
|
<GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="250">
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
|
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:LocationConverter}}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
<GridViewColumn Header="{DynamicResource wox_plugin_program_suffixes_header}" Width="220">
|
<GridViewColumn Header="{DynamicResource wox_plugin_program_suffixes_header}" Width="220">
|
||||||
<GridViewColumn.CellTemplate>
|
<GridViewColumn.CellTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding Suffixes, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
|
<TextBlock Text="{Binding Suffixes, ConverterParameter=(null), Converter={program:SuffixesConvert}}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GridViewColumn.CellTemplate>
|
</GridViewColumn.CellTemplate>
|
||||||
</GridViewColumn>
|
</GridViewColumn>
|
||||||
|
|||||||
@@ -5,20 +5,26 @@ using System.Windows.Markup;
|
|||||||
|
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program
|
||||||
{
|
{
|
||||||
public class StringEmptyConverter : MarkupExtension, IValueConverter
|
public class LocationConverter : MarkupExtension, IValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
return string.IsNullOrEmpty((string)value) ? parameter : value;
|
var text = value as string;
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
object value, Type targetType, object parameter, CultureInfo culture)
|
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
33
Plugins/Wox.Plugin.Program/SuffixesConverter.cs
Normal file
33
Plugins/Wox.Plugin.Program/SuffixesConverter.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Markup;
|
||||||
|
|
||||||
|
namespace Wox.Plugin.Program
|
||||||
|
{
|
||||||
|
public class SuffixesConvert : MarkupExtension, IValueConverter
|
||||||
|
{
|
||||||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
var text = value as string[];
|
||||||
|
if (text != null)
|
||||||
|
{
|
||||||
|
return string.Join("", text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="FileChangeWatcher.cs" />
|
<Compile Include="FileChangeWatcher.cs" />
|
||||||
<Compile Include="IProgramSource.cs" />
|
<Compile Include="IProgramSource.cs" />
|
||||||
|
<Compile Include="SuffixesConverter.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="ProgramIndexCache.cs" />
|
<Compile Include="ProgramIndexCache.cs" />
|
||||||
<Compile Include="Programs.cs" />
|
<Compile Include="Programs.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user