Skip to content

Commit

Permalink
feat: keep the top option highlighted after canceling the mouse hook #16
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jan 19, 2024
1 parent a14f164 commit c2d5efb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions STranslate.Model/ConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public partial class ConfigModel : ObservableObject
/// </summary>
public string CustomFont { get; set; } = ConstStr.DEFAULTFONTNAME;

/// <summary>
/// 鼠标划词取消后是否保留置顶
/// </summary>
public bool IsKeepTopmostAfterMousehook { get; set; } = false;

/// <summary>
/// 服务
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion STranslate/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public bool WriteConfig(CommonViewModel model)
CurrentConfig.IsRemoveLineBreakGettingWords = model.IsRemoveLineBreakGettingWords;
CurrentConfig.DoubleTapTrayFunc = model.DoubleTapTrayFunc;
CurrentConfig.CustomFont = model.CustomFont;

CurrentConfig.IsKeepTopmostAfterMousehook = model.IsKeepTopmostAfterMousehook;
WriteConfig(CurrentConfig);
isSuccess = true;
}
Expand Down Expand Up @@ -258,6 +258,7 @@ private ConfigModel InitialConfig()
IsRemoveLineBreakGettingWords = false,
DoubleTapTrayFunc = DoubleTapFuncEnum.InputFunc,
CustomFont = ConstStr.DEFAULTFONTNAME,
IsKeepTopmostAfterMousehook = false,
SourceLanguage = LanguageEnum.AUTO.GetDescription(),
TargetLanguage = LanguageEnum.AUTO.GetDescription(),
Services =
Expand Down
9 changes: 6 additions & 3 deletions STranslate/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ private void MouseHook(Window view)
}
else
{
view.Topmost = false;
IsTopMost = ConstStr.TAGFALSE;
TopMostContent = ConstStr.UNTOPMOSTCONTENT;
if (!(Singleton<ConfigHelper>.Instance.CurrentConfig?.IsKeepTopmostAfterMousehook ?? false))
{
view.Topmost = false;
IsTopMost = ConstStr.TAGFALSE;
TopMostContent = ConstStr.UNTOPMOSTCONTENT;
}
Singleton<MouseHookHelper>.Instance.MouseHookStop();
Singleton<MouseHookHelper>.Instance.OnGetwordsHandler -= OnGetwordsHandlerChanged;
ToastHelper.Show("关闭鼠标划词");
Expand Down
4 changes: 4 additions & 0 deletions STranslate/ViewModels/Preference/CommonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private void Reset()
IsRemoveLineBreakGettingWords = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsRemoveLineBreakGettingWords ?? false;
DoubleTapTrayFunc = Singleton<ConfigHelper>.Instance.CurrentConfig?.DoubleTapTrayFunc ?? DoubleTapFuncEnum.InputFunc;
CustomFont = Singleton<ConfigHelper>.Instance.CurrentConfig?.CustomFont ?? ConstStr.DEFAULTFONTNAME;
IsKeepTopmostAfterMousehook = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsKeepTopmostAfterMousehook ?? false;

ToastHelper.Show("重置配置", WindowType.Preference);
if (IsStartup)
Expand Down Expand Up @@ -213,5 +214,8 @@ public string CustomFont
}
}
}

[ObservableProperty]
private bool isKeepTopmostAfterMousehook = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsKeepTopmostAfterMousehook ?? false;
}
}
10 changes: 8 additions & 2 deletions STranslate/Views/Preference/CommonPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

<DockPanel Margin="20,10">
<TextBlock Text="禁用系统代理" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="是否禁用彻底不走系统代理,默认走系统代理(如果开启)禁用后不论系统代理是否开启均走直连" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="是否禁用彻底不走系统代理,默认走系统代理(如果开启)&#13;禁用后不论系统代理是否开启均走直连(立即生效)" />
<ToggleButton Height="26" HorizontalAlignment="Right" IsChecked="{Binding IsDisableSystemProxy}" />
</DockPanel>
</StackPanel>
Expand All @@ -91,7 +91,7 @@
<StackPanel>
<DockPanel Margin="20,10">
<TextBlock Text="明暗主题" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="亮色主题、暗色主题切换" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="亮色主题、暗色主题切换(立即生效)" />
<ToggleButton Height="26" HorizontalAlignment="Right" IsChecked="{Binding IsBright}" />
</DockPanel>

Expand Down Expand Up @@ -121,6 +121,12 @@
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="非16:9的拓展显示器截图移位的问题" />
<ToggleButton Height="26" HorizontalAlignment="Right" IsChecked="{Binding UnconventionalScreen}" />
</DockPanel>

<DockPanel Margin="20,10">
<TextBlock HorizontalAlignment="Left" Text="关闭鼠标划词保持置顶" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="关闭鼠标划词功能后保持窗口置顶" />
<ToggleButton Height="26" HorizontalAlignment="Right" IsChecked="{Binding IsKeepTopmostAfterMousehook}" />
</DockPanel>
</StackPanel>
</Border>

Expand Down

0 comments on commit c2d5efb

Please sign in to comment.