Add initial UI elements for General tab of Settings window

This commit is contained in:
Peter Kirmeier 2022-10-25 23:30:11 +02:00
parent fb84b2a705
commit 9ed9ca635e
2 changed files with 132 additions and 83 deletions

View file

@ -7,12 +7,58 @@
xmlns:u="clr-namespace:SystemTrayMenu.Utilities"
xmlns:local="clr-namespace:SystemTrayMenu.UserInterface"
x:Class="SystemTrayMenu.UserInterface.SettingsWindow"
mc:Ignorable="d" Title="{u:Translate 'Settings'}" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight">
<StackPanel>
<TabControl>
mc:Ignorable="d" Title="{u:Translate 'Settings'}" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight" MinWidth="200" MinHeight="250">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl Grid.Row="0">
<TabItem Header="{u:Translate 'General'}">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Label Content="fill me 1" Background="Red"/>
<StackPanel>
<GroupBox Header="{u:Translate 'Directory'}">
<StackPanel>
<TextBox x:Name="textBoxFolder" BorderBrush="{x:Null}" Background="{x:Null}" IsReadOnly="True" />
<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Content="{u:Translate 'Changing directory'}" Margin="3" MinWidth="76" Click="ButtonChange_Click"/>
<Button DockPanel.Dock="Right" Content="{u:Translate 'Open directory'}" Margin="3" MinWidth="76" Click="ButtonOpenFolder_Click"/>
</DockPanel>
<CheckBox x:Name="checkBoxSetFolderByWindowsContextMenu" Content="{u:Translate 'Set by context menu '}"/>
<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Content="{u:Translate 'Relative directory'}" Margin="3" MinWidth="76" Click="ButtonChangeRelativeFolder_Click"/>
<Button DockPanel.Dock="Right" Content="{u:Translate 'Open application directory'}" Margin="3" MinWidth="76" Click="ButtonOpenAssemblyLocation_Click"/>
</DockPanel>
</StackPanel>
</GroupBox>
<GroupBox Header="{u:Translate 'Configuration and log files'}">
<StackPanel>
<CheckBox x:Name="checkBoxSaveConfigInApplicationDirectory" Content="{u:Translate 'Save configuration file in application directory'}"/>
<CheckBox x:Name="checkBoxSaveLogFileInApplicationDirectory" Content="{u:Translate 'Saving log file in application directory'}"/>
</StackPanel>
</GroupBox>
<GroupBox x:Name="groupBoxAutostart" Header="{u:Translate 'App start'}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="checkBoxAutostart" Content="{u:Translate 'Start with Windows'}" VerticalAlignment="Center"/>
<Button x:Name="buttonAddStartup" Content="{u:Translate 'Start with Windows'}" Margin="3" MinWidth="76" Click="ButtonAddStartup_Click" VerticalAlignment="Center"/>
<Label x:Name="labelStartupStatus" VerticalAlignment="Center"/>
</StackPanel>
<CheckBox x:Name="checkBoxCheckForUpdates" Content="{u:Translate 'Check for updates'}"/>
</StackPanel>
</GroupBox>
<GroupBox Header="{u:Translate 'Hotkey'}">
<DockPanel LastChildFill="False">
<Label Content="textBoxHotkeyPlaceholder" Background="Red" VerticalAlignment="Center"/>
<Button x:Name="buttonHotkeyDefault" DockPanel.Dock="Right" Content="{u:Translate 'Default'}" Margin="3" MinWidth="76" Click="ButtonHotkeyDefault_Click" VerticalAlignment="Center"/>
</DockPanel>
</GroupBox>
<GroupBox Header="{u:Translate 'Language'}">
<ComboBox x:Name="comboBoxLanguage" HorizontalAlignment="Left" IsReadOnly="True" DisplayMemberPath="Name" SelectedValuePath="Value" MinWidth="120"/>
</GroupBox>
<Button Content="{u:Translate 'Default'}" Margin="3" MinWidth="76" Click="ButtonGeneralDefault_Click" HorizontalAlignment="Left"/>
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="{u:Translate 'Size and location'}">
@ -42,9 +88,9 @@
</TabItem>
</TabControl>
<StackPanel VerticalAlignment="Center" Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
<Button x:Name="buttonOk" Content="{u:Translate 'OK'}" Margin="3" MinWidth="76" Height="25" Click="ButtonOk_Click"/>
<Button x:Name="buttonCancel" Content="{u:Translate 'Abort'}" Margin="3" MinWidth="76" Height="25" Click="ButtonCancel_Click"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="buttonOk" Content="{u:Translate 'OK'}" Margin="3" MinWidth="76" Click="ButtonOk_Click"/>
<Button x:Name="buttonCancel" Content="{u:Translate 'Abort'}" Margin="3" MinWidth="76" Click="ButtonCancel_Click"/>
</StackPanel>
</Grid>
</Window>

View file

@ -6,10 +6,15 @@
namespace SystemTrayMenu.UserInterface
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Media.Imaging;
using SystemTrayMenu.Properties;
using SystemTrayMenu.Utilities;
using Windows.ApplicationModel;
/// <summary>
/// Logic of SettingsWindow.xaml .
@ -108,32 +113,15 @@ namespace SystemTrayMenu.UserInterface
textBoxColor.Tag = pictureBox;
pictureBox.Tag = textBoxColor;
}
#endif
Translate();
void Translate()
{
groupBoxFolder.Text = Translator.GetText("Directory");
buttonChangeFolder.Text = Translator.GetText("Changing directory");
buttonOpenFolder.Text = Translator.GetText("Open directory");
checkBoxSetFolderByWindowsContextMenu.Text = Translator.GetText("Set by context menu ");
groupBoxConfigAndLogfile.Text = Translator.GetText("Configuration and log files");
buttonChangeRelativeFolder.Text = Translator.GetText("Relative directory");
checkBoxSaveConfigInApplicationDirectory.Text = Translator.GetText("Save configuration file in application directory");
checkBoxSaveLogFileInApplicationDirectory.Text = Translator.GetText("Saving log file in application directory");
buttonOpenAssemblyLocation.Text = Translator.GetText("Open application directory");
groupBoxAutostart.Text = Translator.GetText("App start");
if (IsStartupTask())
{
groupBoxAutostart.Text += $" ({Translator.GetText("Task Manager")})";
groupBoxAutostart.Content = $"{(string)groupBoxAutostart.Content} ({Translator.GetText("Task Manager")})";
}
checkBoxAutostart.Text = Translator.GetText("Start with Windows");
checkBoxCheckForUpdates.Text = Translator.GetText("Check for updates");
buttonAddStartup.Text = Translator.GetText("Start with Windows");
groupBoxHotkey.Text = Translator.GetText("Hotkey");
buttonHotkeyDefault.Text = Translator.GetText("Default");
groupBoxLanguage.Text = Translator.GetText("Language");
buttonGeneralDefault.Text = Translator.GetText("Default");
#if TODO
groupBoxSize.Text = Translator.GetText("Sizes in percent");
labelSizeInPercent.Text = Translator.GetText("Application size");
@ -260,8 +248,9 @@ namespace SystemTrayMenu.UserInterface
buttonColorsDefault.Text = Translator.GetText("Default");
buttonColorsDefaultDarkMode.Text = Translator.GetText("Default");
#endif
}
#if TODO
textBoxFolder.Text = Config.Path;
checkBoxSetFolderByWindowsContextMenu.Checked = Settings.Default.SetFolderByWindowsContextMenu;
checkBoxSaveConfigInApplicationDirectory.Checked = CustomSettingsProvider.IsActivatedConfigPathAssembly();
@ -281,6 +270,7 @@ namespace SystemTrayMenu.UserInterface
checkBoxCheckForUpdates.Checked = Settings.Default.CheckForUpdates;
textBoxHotkey.SetHotkey(Settings.Default.HotKey);
#endif
InitializeLanguage();
void InitializeLanguage()
@ -355,14 +345,12 @@ namespace SystemTrayMenu.UserInterface
new Language() { Name = "中文(简体)", Value = "zh-CN" },
new Language() { Name = "日本語", Value = "ja" },
};
comboBoxLanguage.DataSource = dataSource;
comboBoxLanguage.DisplayMember = "Name";
comboBoxLanguage.ValueMember = "Value";
comboBoxLanguage.SelectedValue =
Settings.Default.CurrentCultureInfoName;
comboBoxLanguage.ItemsSource = dataSource;
comboBoxLanguage.SelectedValue = Settings.Default.CurrentCultureInfoName;
comboBoxLanguage.SelectedValue ??= "en";
}
#if TODO
numericUpDownSizeInPercent.Minimum = 100;
numericUpDownSizeInPercent.Maximum = 200;
numericUpDownSizeInPercent.Increment = 5;
@ -807,7 +795,7 @@ namespace SystemTrayMenu.UserInterface
Log.Warn("DeleteSetFolderByWindowsContextMenu failed", ex);
}
}
#endif
private static bool IsStartupTask()
{
bool useStartupTask = false;
@ -817,6 +805,7 @@ namespace SystemTrayMenu.UserInterface
return useStartupTask;
}
#if TODO
private void SettingsForm_Load(object sender, EventArgs e)
{
AdjustControlMultilineIfNecessary(checkBoxStayOpenWhenFocusLost);
@ -1034,11 +1023,8 @@ namespace SystemTrayMenu.UserInterface
#endif
Close();
}
#if TODO
private void ButtonAddStartup_Click(object sender, EventArgs e)
{
_ = AddStartUpAsync();
async Task AddStartUpAsync()
private async void ButtonAddStartup_Click(object sender, RoutedEventArgs e)
{
// Pass the task ID you specified in the appxmanifest file
StartupTask startupTask = await StartupTask.GetAsync("MyStartupId");
@ -1065,7 +1051,6 @@ namespace SystemTrayMenu.UserInterface
break;
}
}
}
private void UpdateLabelStartupStatus(StartupTaskState newState)
{
@ -1074,44 +1059,59 @@ namespace SystemTrayMenu.UserInterface
case StartupTaskState.Disabled:
case StartupTaskState.DisabledByUser:
case StartupTaskState.DisabledByPolicy:
labelStartupStatus.Text = Translator.GetText("Deactivated");
labelStartupStatus.Content = Translator.GetText("Deactivated");
break;
case StartupTaskState.Enabled:
case StartupTaskState.EnabledByPolicy:
labelStartupStatus.Text = Translator.GetText("Activated");
labelStartupStatus.Content = Translator.GetText("Activated");
break;
default:
break;
}
}
private void ButtonChange_Click(object sender, EventArgs e)
private void ButtonChange_Click(object sender, RoutedEventArgs e)
{
Config.SetFolderByUser(false);
textBoxFolder.Text = Config.Path;
}
private void ButtonOpenFolder_Click(object sender, EventArgs e)
private void ButtonOpenFolder_Click(object sender, RoutedEventArgs e)
{
Log.ProcessStart("explorer.exe", Config.Path, true);
}
private void ButtonChangeRelativeFolder_Click(object sender, EventArgs e)
private void ButtonChangeRelativeFolder_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(Config.Path))
{
Settings.Default.PathDirectory = Path.GetRelativePath(
Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName,
Config.Path);
string? location = Assembly.GetEntryAssembly()?.Location;
if (!string.IsNullOrEmpty(location))
{
string? parentPath = Directory.GetParent(location)?.FullName;
if (!string.IsNullOrEmpty(parentPath))
{
Settings.Default.PathDirectory = Path.GetRelativePath(parentPath, Config.Path);
textBoxFolder.Text = Config.Path;
}
}
private void ButtonOpenAssemblyLocation_Click(object sender, EventArgs e)
{
Log.ProcessStart(Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName);
}
}
private void ButtonOpenAssemblyLocation_Click(object sender, RoutedEventArgs e)
{
string? location = Assembly.GetEntryAssembly()?.Location;
if (!string.IsNullOrEmpty(location))
{
string? parentPath = Directory.GetParent(location)?.FullName;
if (!string.IsNullOrEmpty(parentPath))
{
Log.ProcessStart(parentPath);
}
}
}
#if TODO
private void TextBoxHotkeyEnter(object sender, EventArgs e)
{
UnregisterHotkeys();
@ -1126,21 +1126,24 @@ namespace SystemTrayMenu.UserInterface
RegisterHotkeys();
inHotkey = false;
}
private void ButtonHotkeyDefault_Click(object sender, EventArgs e)
#endif
private void ButtonHotkeyDefault_Click(object sender, RoutedEventArgs e)
{
#if TODO
textBoxHotkey.SetHotkey("Ctrl+LWin");
#endif
}
private void ButtonGeneralDefault_Click(object sender, EventArgs e)
{
checkBoxSetFolderByWindowsContextMenu.Checked = false;
checkBoxSaveConfigInApplicationDirectory.Checked = false;
checkBoxSaveLogFileInApplicationDirectory.Checked = false;
checkBoxAutostart.Checked = false;
checkBoxCheckForUpdates.Checked = false;
checkBoxSetFolderByWindowsContextMenu.IsChecked = false;
checkBoxSaveConfigInApplicationDirectory.IsChecked = false;
checkBoxSaveLogFileInApplicationDirectory.IsChecked = false;
checkBoxAutostart.IsChecked = false;
checkBoxCheckForUpdates.IsChecked = false;
}
#if TODO
private void ButtonChangeIcoFolder_Click(object sender, EventArgs e)
{
Config.SetFolderIcoByUser();