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)
|
||||
{
|
||||
_settings.ProgramSources.Add(new ProgramSource
|
||||
var source = new ProgramSource
|
||||
{
|
||||
Location = Directory.Text,
|
||||
MaxDepth = max,
|
||||
Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator),
|
||||
Type = "FileSystemProgramSource",
|
||||
Enabled = true
|
||||
});
|
||||
};
|
||||
_settings.ProgramSources.Add(source);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -28,14 +28,14 @@
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="250">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
|
||||
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:LocationConverter}}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_program_suffixes_header}" Width="220">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Suffixes, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
|
||||
<TextBlock Text="{Binding Suffixes, ConverterParameter=(null), Converter={program:SuffixesConvert}}"/>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
|
||||
@@ -5,20 +5,26 @@ using System.Windows.Markup;
|
||||
|
||||
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)
|
||||
{
|
||||
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(
|
||||
object value, Type targetType, object parameter, CultureInfo culture)
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
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 Include="FileChangeWatcher.cs" />
|
||||
<Compile Include="IProgramSource.cs" />
|
||||
<Compile Include="SuffixesConverter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="ProgramIndexCache.cs" />
|
||||
<Compile Include="Programs.cs" />
|
||||
|
||||
Reference in New Issue
Block a user