Fix IsEnabled logic

This commit is contained in:
Jack251970 2025-09-29 23:12:02 +08:00
parent 175571a130
commit d106c5144b
3 changed files with 13 additions and 30 deletions

View file

@ -1,22 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Flow.Launcher.Plugin.Shell.Converters;
public class CloseShellAfterPressEnabledConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool)
return Binding.DoNothing;
var leaveShellOpen = (bool)value;
return !leaveShellOpen;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View file

@ -4,18 +4,18 @@ using System.Windows.Data;
namespace Flow.Launcher.Plugin.Shell.Converters;
public class LeaveShellOpenEnabledConverter : IMultiValueConverter
public class LeaveShellOpenOrCloseShellAfterPressEnabledConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (
values.Length != 2 ||
values[0] is not bool closeShellAfterPress ||
values[0] is not bool closeShellAfterPressOrLeaveShellOpen ||
values[1] is not Shell shell
)
return Binding.DoNothing;
return (!closeShellAfterPress) && shell != Shell.RunCommand;
return (!closeShellAfterPressOrLeaveShellOpen) && shell != Shell.RunCommand;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

View file

@ -11,8 +11,7 @@
d:DesignWidth="300"
mc:Ignorable="d">
<UserControl.Resources>
<converters:CloseShellAfterPressEnabledConverter x:Key="CloseShellAfterPressEnabledConverter" />
<converters:LeaveShellOpenEnabledConverter x:Key="LeaveShellOpenEnabledConverter" />
<converters:LeaveShellOpenOrCloseShellAfterPressEnabledConverter x:Key="LeaveShellOpenOrCloseShellAfterPressEnabledConverter" />
</UserControl.Resources>
<Grid Margin="{StaticResource SettingPanelMargin}" VerticalAlignment="Top">
@ -38,8 +37,14 @@
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_cmd_close_cmd_after_press}"
IsChecked="{Binding CloseShellAfterPress, Mode=TwoWay}"
IsEnabled="{Binding LeaveShellOpen, Converter={StaticResource CloseShellAfterPressEnabledConverter}, Mode=OneWay}" />
IsChecked="{Binding CloseShellAfterPress, Mode=TwoWay}">
<CheckBox.IsEnabled>
<MultiBinding Converter="{StaticResource LeaveShellOpenOrCloseShellAfterPressEnabledConverter}">
<Binding Mode="OneWay" Path="LeaveShellOpen" />
<Binding Mode="OneWay" Path="SelectedShell" />
</MultiBinding>
</CheckBox.IsEnabled>
</CheckBox>
<CheckBox
x:Name="LeaveShellOpen"
Grid.Row="2"
@ -48,7 +53,7 @@
Content="{DynamicResource flowlauncher_plugin_cmd_leave_cmd_open}"
IsChecked="{Binding LeaveShellOpen, Mode=TwoWay}">
<CheckBox.IsEnabled>
<MultiBinding Converter="{StaticResource LeaveShellOpenEnabledConverter}">
<MultiBinding Converter="{StaticResource LeaveShellOpenOrCloseShellAfterPressEnabledConverter}">
<Binding Mode="OneWay" Path="CloseShellAfterPress" />
<Binding Mode="OneWay" Path="SelectedShell" />
</MultiBinding>