Skip to content

Commit

Permalink
Move the "Always on top" setting from "General" to "Textbox"
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 30, 2022
1 parent 851256f commit ea5fada
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 49 deletions.
20 changes: 11 additions & 9 deletions JL.Core/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private static async Task DeserializeFreqs()

public static string GetMd5String(byte[] bytes)
{
byte[] hash = MD5.Create().ComputeHash(bytes);
byte[] hash = MD5.HashData(bytes);
string encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();

return encoded;
Expand Down Expand Up @@ -393,20 +393,22 @@ public static async Task CoreInitialize()
if (!File.Exists($"{Storage.ResourcesPath}/custom_names.txt"))
await File.Create($"{Storage.ResourcesPath}/custom_names.txt").DisposeAsync();

Task[] tasks = new Task[2];
tasks[0] = Task.Run(async () =>
List<Task> tasks = new()
{
Task.Run(async () =>
{
await DeserializeDicts().ConfigureAwait(false);
await Storage.LoadDictionaries(false).ConfigureAwait(false);
await SerializeDicts().ConfigureAwait(false);
await Storage.InitializeWordClassDictionary().ConfigureAwait(false);
});
}),

tasks[1] = Task.Run(async () =>
{
await DeserializeFreqs().ConfigureAwait(false);
await Storage.LoadFrequencies(false).ConfigureAwait(false);
});
Task.Run(async () =>
{
await DeserializeFreqs().ConfigureAwait(false);
await Storage.LoadFrequencies(false).ConfigureAwait(false);
})
};

await Storage.InitializeKanjiCompositionDict().ConfigureAwait(false);
await Task.WhenAll(tasks).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static ConfigManager Instance
public static bool HighlightLongestMatch { get; private set; } = false;
public static bool AutoPlayAudio { get; private set; } = false;
public static bool CheckForJLUpdatesOnStartUp { get; private set; } = true;
public static bool AlwaysOnTop { get; set; } = true;
public static bool DisableHotkeys { get; set; } = false;
public static bool Focusable { get; private set; } = true;
public static string SearchUrl { get; private set; } = "https://www.google.com/search?q={SearchTerm}&hl=ja";
Expand All @@ -67,6 +66,7 @@ public static ConfigManager Instance
public static double MainWindowMaxDynamicHeight { get; private set; } = 269;
public static Brush MainWindowTextColor { get; private set; } = Brushes.White;
public static Brush MainWindowBacklogTextColor { get; private set; } = Brushes.Bisque;
public static bool AlwaysOnTop { get; set; } = true;
public static bool TextOnlyVisibleOnHover { get; set; } = false;
public static bool ChangeMainWindowBackgroundOpacityOnUnhover { get; private set; } = false;
public static double MainWindowBackgroundOpacityOnUnhover { get; private set; } = 0.2; // 0.2-100
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/InfoWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="" MaxHeight="800" MaxWidth="800" ShowInTaskbar="False" Topmost="True" Closing="Window_Closing" SizeToContent="WidthAndHeight" Background="{DynamicResource RegionBrush}" >
Title="" MaxHeight="800" MaxWidth="800" ShowInTaskbar="False" Topmost="True" SizeToContent="WidthAndHeight" Background="{DynamicResource RegionBrush}" >
<Grid>
<TextBox Name="InfoTextBox" Padding="20" FontSize="20" IsReadOnly="true" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto"
TextWrapping="Wrap" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Cursor="Arrow" BorderThickness="0"/>
Expand Down
6 changes: 0 additions & 6 deletions JL.Windows/GUI/InfoWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,4 @@ protected override void OnActivated(EventArgs e)
WinApi.PreventActivation(_windowHandle);
}
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
Hide();
}
}
33 changes: 13 additions & 20 deletions JL.Windows/GUI/ManageDictionariesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public partial class ManageDictionariesWindow : Window

private IntPtr _windowHandle;

private InfoWindow? _jmdictAbbreviationWindow = null;
private InfoWindow? _jmnedictAbbreviationWindow = null;

public static ManageDictionariesWindow Instance
{
get { return s_instance ??= new(); }
Expand Down Expand Up @@ -72,9 +69,10 @@ public static bool IsItVisible()

private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
WindowsUtils.HideWindow(this);
Storage.Frontend.InvalidateDisplayCache();
WindowsUtils.UpdateMainWindowVisibility();
MainWindow.Instance.Focus();
s_instance = null;
await Utils.SerializeDicts().ConfigureAwait(false);
await Storage.LoadDictionaries().ConfigureAwait(false);
}
Expand Down Expand Up @@ -432,34 +430,29 @@ private static string EntityDictToString(Dictionary<string, string> entityDict)
return sb.ToString()[..^Environment.NewLine.Length];
}

private void ShowInfoWindow(ref InfoWindow? infoWindow, Dictionary<string, string> entityDict, string title)
private void ShowInfoWindow(Dictionary<string, string> entityDict, string title)
{
if (infoWindow is null)
InfoWindow infoWindow = new()
{
infoWindow = new()
{
Owner = this,
Title = title,
InfoTextBox = { Text = EntityDictToString(entityDict) }
};
}
Owner = this,
Title = title,
InfoTextBox = { Text = EntityDictToString(entityDict) }
};

else
{
infoWindow.InfoTextBox.ScrollToHome();
}
infoWindow.Owner = this;
infoWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;

infoWindow.ShowDialog();
}

private void JmdictInfoButton_Click(object sender, RoutedEventArgs e)
{
ShowInfoWindow(ref _jmdictAbbreviationWindow, Storage.JmdictEntities, "JMdict Abbreviations");
ShowInfoWindow(Storage.JmdictEntities, "JMdict Abbreviations");
}

private void JmnedictInfoButton_Click(object sender, RoutedEventArgs e)
{
ShowInfoWindow(ref _jmnedictAbbreviationWindow, Storage.JmnedictEntities, "JMnedict Abbreviations");
ShowInfoWindow(Storage.JmnedictEntities, "JMnedict Abbreviations");
}

private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
Expand Down
5 changes: 3 additions & 2 deletions JL.Windows/GUI/ManageFrequenciesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public static bool IsItVisible()

private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
WindowsUtils.HideWindow(this);
Storage.Frontend.InvalidateDisplayCache();
WindowsUtils.UpdateMainWindowVisibility();
MainWindow.Instance.Focus();
s_instance = null;
await Utils.SerializeFreqs().ConfigureAwait(false);
await Storage.LoadFrequencies().ConfigureAwait(false);
}
Expand Down
16 changes: 8 additions & 8 deletions JL.Windows/GUI/PreferencesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@
TextWrapping="Wrap" />
<TextBox x:Name="SearchUrlTextBox" HorizontalAlignment="Right" MinWidth="250" MaxWidth="350" MaxHeight="60" TextWrapping="Wrap" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Always on top"
TextWrapping="Wrap" VerticalAlignment="Center" />
<CheckBox x:Name="AlwaysOnTopCheckBox" HorizontalAlignment="Right" />
</DockPanel>


<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Focusable"
Cursor="Help" TextWrapping="Wrap" VerticalAlignment="Center"
Expand Down Expand Up @@ -225,7 +219,13 @@
<hc:NumericUpDown x:Name="MainWindowOpacityNumericUpDown" Maximum="100" Minimum="0.2" DecimalPlaces="1"
HorizontalAlignment="Right" />
</DockPanel>


<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Always on top"
TextWrapping="Wrap" VerticalAlignment="Center" />
<CheckBox x:Name="AlwaysOnTopCheckBox" HorizontalAlignment="Right" />
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Enable clipboard text capture"
TextWrapping="Wrap" VerticalAlignment="Center" />
Expand Down
6 changes: 4 additions & 2 deletions JL.Windows/GUI/PreferencesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ private void CancelButton_Click(object sender, RoutedEventArgs e)

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
WindowsUtils.HideWindow(this);
Storage.Frontend.InvalidateDisplayCache();
WindowsUtils.UpdateMainWindowVisibility();
MainWindow.Instance.Focus();
s_instance = null;
}

private async void TabItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
Expand Down

0 comments on commit ea5fada

Please sign in to comment.