2022-10-23 11:02:31 +13:00
// <copyright file="SettingsWindow.xaml.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.UserInterface
{
2022-10-26 10:30:11 +13:00
using System ;
using System.Collections.Generic ;
2022-10-23 11:02:31 +13:00
using System.IO ;
using System.Reflection ;
2022-11-04 10:17:23 +13:00
using System.Runtime.Versioning ;
2022-10-23 11:02:31 +13:00
using System.Windows ;
2022-11-01 12:57:08 +13:00
using System.Windows.Controls ;
2023-05-22 07:13:18 +12:00
using System.Windows.Input ;
2022-10-23 11:02:31 +13:00
using System.Windows.Media.Imaging ;
2022-11-03 13:07:20 +13:00
using Microsoft.Win32 ;
2022-10-26 10:30:11 +13:00
using SystemTrayMenu.Properties ;
2022-11-01 12:57:08 +13:00
using SystemTrayMenu.UserInterface.FolderBrowseDialog ;
2022-10-26 10:30:11 +13:00
using SystemTrayMenu.Utilities ;
using Windows.ApplicationModel ;
2022-10-23 11:02:31 +13:00
/// <summary>
/// Logic of SettingsWindow.xaml .
/// </summary>
public partial class SettingsWindow : Window
{
private const string MenuName = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder" ;
private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command" ;
2022-11-04 10:17:23 +13:00
2022-10-23 11:02:31 +13:00
private static SettingsWindow ? settingsForm ;
2023-04-17 09:27:27 +12:00
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
private bool inHotkey ;
#endif
public SettingsWindow ( )
{
InitializeComponent ( ) ;
Assembly myassembly = Assembly . GetExecutingAssembly ( ) ;
string myname = myassembly . GetName ( ) . Name ? ? string . Empty ;
using ( Stream ? imgstream = myassembly . GetManifestResourceStream ( myname + ".Resources.SystemTrayMenu.png" ) )
{
if ( imgstream ! = null )
{
2023-04-17 09:27:27 +12:00
BitmapImage imageSource = new ( ) ;
2022-10-23 11:02:31 +13:00
imageSource . BeginInit ( ) ;
imageSource . StreamSource = imgstream ;
imageSource . EndInit ( ) ;
Icon = imageSource ;
}
}
2023-05-22 07:13:18 +12:00
PreviewKeyDown + = HandlePreviewKeyDown ;
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
// Initialize and replace here here, because designer always removes it
InitializeTextBoxHotkeyAndReplacetextBoxHotkeyPlaceholder ( ) ;
void InitializeTextBoxHotkeyAndReplacetextBoxHotkeyPlaceholder ( )
{
textBoxHotkey = new HotkeyTextboxControl . HotkeyControl
{
Hotkey = Keys . None ,
HotkeyModifiers = Keys . None ,
Name = "textBoxHotkey" ,
Size = new Size ( 200 , 20 ) ,
Text = "None" ,
TabStop = false ,
} ;
textBoxHotkey . Enter + = new EventHandler ( TextBoxHotkeyEnter ) ;
textBoxHotkey . Leave + = new EventHandler ( TextBoxHotkey_Leave ) ;
tableLayoutPanelHotkey . Controls . Remove ( textBoxHotkeyPlaceholder ) ;
tableLayoutPanelHotkey . Controls . Add ( textBoxHotkey , 0 , 0 ) ;
}
2022-10-26 10:30:11 +13:00
#endif
2022-10-23 11:02:31 +13:00
Translate ( ) ;
void Translate ( )
{
if ( IsStartupTask ( ) )
{
2022-10-26 10:30:11 +13:00
groupBoxAutostart . Content = $"{(string)groupBoxAutostart.Content} ({Translator.GetText(" Task Manager ")})" ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 13:07:20 +13:00
// TODO: Find a way to escape ' within inline single quotes markup string in XAML
buttonAddSampleStartMenuFolder . Content = Translator . GetText ( "Add sample directory 'Start Menu'" ) ;
checkBoxShowFunctionKeyOpenFolder . Content = Translator . GetText ( "Show function key 'Open Folder'" ) ;
checkBoxShowFunctionKeyPinMenu . Content = Translator . GetText ( "Show function key 'Pin menu'" ) ;
checkBoxShowFunctionKeySettings . Content = Translator . GetText ( "Show function key 'Settings'" ) ;
checkBoxShowFunctionKeyRestart . Content = Translator . GetText ( "Show function key 'Restart'" ) ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 13:07:20 +13:00
2022-10-23 11:02:31 +13:00
textBoxFolder . Text = Config . Path ;
2022-11-03 13:07:20 +13:00
checkBoxSetFolderByWindowsContextMenu . IsChecked = Settings . Default . SetFolderByWindowsContextMenu ;
checkBoxSaveConfigInApplicationDirectory . IsChecked = CustomSettingsProvider . IsActivatedConfigPathAssembly ( ) ;
checkBoxSaveLogFileInApplicationDirectory . IsChecked = Settings . Default . SaveLogFileInApplicationDirectory ;
2022-10-23 11:02:31 +13:00
if ( IsStartupTask ( ) )
{
2022-11-03 13:07:20 +13:00
checkBoxAutostart . Visibility = Visibility . Collapsed ;
labelStartupStatus . Content = string . Empty ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-11-03 13:07:20 +13:00
buttonAddStartup . Visibility = Visibility . Collapsed ;
labelStartupStatus . Visibility = Visibility . Collapsed ;
checkBoxAutostart . IsChecked = Settings . Default . IsAutostartActivated ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 13:07:20 +13:00
checkBoxCheckForUpdates . IsChecked = Settings . Default . CheckForUpdates ;
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
textBoxHotkey . SetHotkey ( Settings . Default . HotKey ) ;
2022-10-26 10:30:11 +13:00
#endif
2022-10-23 11:02:31 +13:00
InitializeLanguage ( ) ;
void InitializeLanguage ( )
{
2022-12-05 11:56:21 +13:00
List < LanguageID > dataSource = new ( )
2022-10-23 11:02:31 +13:00
{
2022-12-05 11:56:21 +13:00
new ( "Afrikaans" , "af" ) ,
new ( "Azərbaycan" , "az" ) ,
new ( "bahasa Indonesia" , "id" ) ,
new ( "català" , "ca" ) ,
new ( "čeština" , "cs" ) ,
new ( "Cymraeg" , "cy" ) ,
new ( "dansk" , "da" ) ,
new ( "Deutsch" , "de" ) ,
new ( "eesti keel" , "et" ) ,
new ( "English" , "en" ) ,
new ( "English (United Kingdom)" , "en-GB" ) ,
new ( "Español" , "es" ) ,
new ( "Esperanto" , "eo" ) ,
new ( "euskara" , "eu" ) ,
new ( "Filipino" , "tl" ) ,
new ( "Français" , "fr" ) ,
new ( "Italian" , "it" ) ,
new ( "galego" , "gl" ) ,
new ( "Hrvatski" , "hr" ) ,
new ( "Gaeilge" , "ga" ) ,
new ( "íslenskur" , "is" ) ,
new ( "kiswahili" , "sw" ) ,
new ( "Kreyòl ayisyen" , "ht" ) ,
new ( "Latinus" , "la" ) ,
new ( "latviski" , "lv" ) ,
new ( "lietuvių" , "lt" ) ,
new ( "Magyar" , "hu" ) ,
new ( "Malti" , "mt" ) ,
new ( "Melayu" , "ms" ) ,
new ( "Nederlands" , "nl" ) ,
new ( "norsk" , "no" ) ,
new ( "Polski" , "pl" ) ,
new ( "Português (Brasil)" , "pt-BR" ) ,
new ( "português (Portugal)" , "pt-PT" ) ,
new ( "Română" , "ro" ) ,
new ( "shqiptare" , "sq" ) ,
new ( "Slovenščina" , "sl" ) ,
new ( "slovenský" , "sk" ) ,
new ( "Suorittaa loppuun" , "fi" ) ,
new ( "svenska" , "sv" ) ,
new ( "Tiếng Việt" , "vi" ) ,
new ( "Türkçe " , "tr" ) ,
new ( "Ελληνικά" , "el" ) ,
new ( "беларуская" , "bg" ) ,
new ( "македонски" , "mk" ) ,
new ( "русский" , "ru" ) ,
new ( "Српски" , "sr" ) ,
new ( "український" , "uk" ) ,
new ( "ქართული" , "ka" ) ,
new ( "հայերեն" , "hy" ) ,
new ( "יידיש" , "yi" ) ,
new ( "עִברִית" , "iw" ) ,
new ( "اردو" , "ur" ) ,
new ( "عربي" , "ar" ) ,
new ( "فارسی" , "fa" ) ,
new ( "हिन्दी" , "hi" ) ,
new ( "ગુજરાતી" , "gu" ) ,
new ( "தமிழ்" , "ta" ) ,
new ( "తెలుగు" , "te" ) ,
new ( "ಕನ್ನಡ" , "kn" ) ,
new ( "ไทย" , "th" ) ,
new ( "ພາສາລາວ" , "lo" ) ,
new ( "ខ្មែរ" , "km" ) ,
new ( "한국어" , "ko" ) ,
new ( "中文(正體)" , "zh-TW" ) ,
new ( "中文(简体)" , "zh-CN" ) ,
new ( "日本語" , "ja" ) ,
2022-10-23 11:02:31 +13:00
} ;
2022-10-26 10:30:11 +13:00
comboBoxLanguage . ItemsSource = dataSource ;
comboBoxLanguage . SelectedValue = Settings . Default . CurrentCultureInfoName ;
2022-10-23 11:02:31 +13:00
comboBoxLanguage . SelectedValue ? ? = "en" ;
}
2022-10-29 10:21:27 +13:00
numericUpDownSizeInPercent . Value = Settings . Default . SizeInPercent ;
numericUpDownIconSizeInPercent . Value = Settings . Default . IconSizeInPercent ;
2022-10-23 11:02:31 +13:00
if ( DllImports . NativeMethods . IsTouchEnabled ( ) )
{
2022-10-29 10:21:27 +13:00
numericUpDownRowHeightInPercentage . Value = Settings . Default . RowHeighteInPercentageTouch ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-29 10:21:27 +13:00
numericUpDownRowHeightInPercentage . Value = Settings . Default . RowHeighteInPercentage ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 10:21:27 +13:00
numericUpDownMenuWidth . Value = Settings . Default . WidthMaxInPercent ;
numericUpDownMenuHeight . Value = Settings . Default . HeightMaxInPercent ;
2022-10-23 11:02:31 +13:00
if ( Settings . Default . UseCustomLocation )
{
2022-10-27 09:30:01 +13:00
radioButtonUseCustomLocation . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
else if ( Settings . Default . AppearAtMouseLocation )
{
2022-10-27 09:30:01 +13:00
radioButtonAppearAtMouseLocation . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
else if ( Settings . Default . AppearAtTheBottomLeft )
{
2022-10-27 09:30:01 +13:00
radioButtonAppearAtTheBottomLeft . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-27 09:30:01 +13:00
radioButtonAppearAtTheBottomRight . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 10:21:27 +13:00
numericUpDownOverlappingOffsetPixels . Value = Settings . Default . OverlappingOffsetPixels ;
2022-10-23 11:02:31 +13:00
if ( Settings . Default . AppearNextToPreviousMenu )
{
2022-10-27 09:30:01 +13:00
radioButtonNextToPreviousMenu . IsChecked = true ;
numericUpDownOverlappingOffsetPixels . IsEnabled = false ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-27 09:30:01 +13:00
radioButtonOverlapping . IsChecked = true ;
numericUpDownOverlappingOffsetPixels . IsEnabled = true ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 11:32:26 +13:00
checkBoxResolveLinksToFolders . IsChecked = Settings . Default . ResolveLinksToFolders ;
checkBoxShowInTaskbar . IsChecked = Settings . Default . ShowInTaskbar ;
checkBoxSendHotkeyInsteadKillOtherInstances . IsChecked = Settings . Default . SendHotkeyInsteadKillOtherInstances ;
checkBoxSupportGamepad . IsChecked = Settings . Default . SupportGamepad ;
checkBoxOpenItemWithOneClick . IsChecked = Settings . Default . OpenItemWithOneClick ;
checkBoxOpenDirectoryWithOneClick . IsChecked = Settings . Default . OpenDirectoryWithOneClick ;
2022-10-23 11:02:31 +13:00
if ( DllImports . NativeMethods . IsTouchEnabled ( ) )
{
2022-10-29 11:32:26 +13:00
checkBoxDragDropItems . IsChecked = Settings . Default . DragDropItemsEnabledTouch ;
checkBoxSwipeScrolling . IsChecked = Settings . Default . SwipeScrollingEnabledTouch ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-29 11:32:26 +13:00
checkBoxDragDropItems . IsChecked = Settings . Default . DragDropItemsEnabled ;
checkBoxSwipeScrolling . IsChecked = Settings . Default . SwipeScrollingEnabled ;
2022-10-23 11:02:31 +13:00
}
textBoxIcoFolder . Text = Settings . Default . PathIcoDirectory ;
2022-10-29 11:32:26 +13:00
if ( Settings . Default . SortByTypeAndNameWindowsExplorerSort )
{
radioButtonSortByTypeAndName . IsChecked = true ;
}
else if ( Settings . Default . SortByTypeAndDate )
{
radioButtonSortByTypeAndDate . IsChecked = true ;
}
else if ( Settings . Default . SortByFileExtensionAndName )
{
radioButtonSortByFileExtensionAndName . IsChecked = true ;
}
else if ( Settings . Default . SortByDate )
{
radioButtonSortByDate . IsChecked = true ;
}
else
{
// default: Settings.Default.SortByName
radioButtonSortByName . IsChecked = true ;
}
2022-10-23 11:02:31 +13:00
2022-10-29 11:32:26 +13:00
if ( Settings . Default . NeverShowHiddenFiles )
{
radioButtonNeverShowHiddenFiles . IsChecked = true ;
}
else if ( Settings . Default . AlwaysShowHiddenFiles )
{
radioButtonAlwaysShowHiddenFiles . IsChecked = true ;
}
else
{
// default: Settings.Default.SystemSettingsShowHiddenFiles
radioButtonSystemSettingsShowHiddenFiles . IsChecked = true ;
}
2022-11-01 12:57:08 +13:00
checkBoxShowOnlyAsSearchResult . IsChecked = Settings . Default . ShowOnlyAsSearchResult ;
2022-10-23 11:02:31 +13:00
try
{
foreach ( string pathAndRecursivString in Settings . Default . PathsAddToMainMenu . Split ( @"|" ) )
{
if ( string . IsNullOrEmpty ( pathAndRecursivString ) )
{
continue ;
}
string pathAddToMainMenu = pathAndRecursivString . Split ( "recursiv:" ) [ 0 ] . Trim ( ) ;
bool recursive = pathAndRecursivString . Split ( "recursiv:" ) [ 1 ] . StartsWith ( "True" ) ;
bool onlyFiles = pathAndRecursivString . Split ( "onlyFiles:" ) [ 1 ] . StartsWith ( "True" ) ;
2022-11-01 12:57:08 +13:00
dataGridViewFolders . Items . Add ( new ListViewItemData ( pathAddToMainMenu , recursive , onlyFiles ) ) ;
2022-10-23 11:02:31 +13:00
}
}
catch ( Exception ex )
{
Log . Warn ( "PathsAddToMainMenu" , ex ) ;
}
2022-12-03 14:14:15 +13:00
EnableButtonAddStartMenu ( ) ;
2022-11-01 12:57:08 +13:00
checkBoxGenerateShortcutsToDrives . IsChecked = Settings . Default . GenerateShortcutsToDrives ;
2022-10-23 11:02:31 +13:00
2022-11-03 09:19:57 +13:00
checkBoxStayOpenWhenItemClicked . IsChecked = Settings . Default . StaysOpenWhenItemClicked ;
checkBoxStayOpenWhenFocusLost . IsChecked = Settings . Default . StaysOpenWhenFocusLost ;
2022-10-23 11:02:31 +13:00
numericUpDownTimeUntilClose . Value = Settings . Default . TimeUntilCloses ;
numericUpDownTimeUntilOpens . Value = Settings . Default . TimeUntilOpens ;
2022-11-03 09:19:57 +13:00
checkBoxStayOpenWhenFocusLostAfterEnterPressed . IsChecked = Settings . Default . StaysOpenWhenFocusLostAfterEnterPressed ;
2022-10-23 11:02:31 +13:00
numericUpDownTimeUntilClosesAfterEnterPressed . Value = Settings . Default . TimeUntilClosesAfterEnterPressed ;
numericUpDownClearCacheIfMoreThanThisNumberOfItems . Value = Settings . Default . ClearCacheIfMoreThanThisNumberOfItems ;
textBoxSearchPattern . Text = Settings . Default . SearchPattern ;
2022-11-03 13:07:20 +13:00
checkBoxUseIconFromRootFolder . IsChecked = Settings . Default . UseIconFromRootFolder ;
checkBoxRoundCorners . IsChecked = Settings . Default . RoundCorners ;
checkBoxDarkModeAlwaysOn . IsChecked = Settings . Default . IsDarkModeAlwaysOn ;
checkBoxUseFading . IsChecked = Settings . Default . UseFading ;
checkBoxShowLinkOverlay . IsChecked = Settings . Default . ShowLinkOverlay ;
checkBoxShowDirectoryTitleAtTop . IsChecked = Settings . Default . ShowDirectoryTitleAtTop ;
checkBoxShowSearchBar . IsChecked = Settings . Default . ShowSearchBar ;
checkBoxShowCountOfElementsBelow . IsChecked = Settings . Default . ShowCountOfElementsBelow ;
checkBoxShowFunctionKeyOpenFolder . IsChecked = Settings . Default . ShowFunctionKeyOpenFolder ;
checkBoxShowFunctionKeyPinMenu . IsChecked = Settings . Default . ShowFunctionKeyPinMenu ;
checkBoxShowFunctionKeySettings . IsChecked = Settings . Default . ShowFunctionKeySettings ;
checkBoxShowFunctionKeyRestart . IsChecked = Settings . Default . ShowFunctionKeyRestart ;
2022-10-23 11:02:31 +13:00
textBoxColorSelectedItem . Text = Settings . Default . ColorSelectedItem ;
2022-11-03 13:07:20 +13:00
textBoxColorSelectedItemDarkMode . Text = Settings . Default . ColorDarkModeSelecetedItem ;
2022-10-23 11:02:31 +13:00
textBoxColorSelectedItemBorder . Text = Settings . Default . ColorSelectedItemBorder ;
textBoxColorSelectedItemBorderDarkMode . Text = Settings . Default . ColorDarkModeSelectedItemBorder ;
textBoxColorOpenFolder . Text = Settings . Default . ColorOpenFolder ;
textBoxColorOpenFolderDarkMode . Text = Settings . Default . ColorDarkModeOpenFolder ;
textBoxColorOpenFolderBorder . Text = Settings . Default . ColorOpenFolderBorder ;
textBoxColorOpenFolderBorderDarkMode . Text = Settings . Default . ColorDarkModeOpenFolderBorder ;
textBoxColorIcons . Text = Settings . Default . ColorIcons ;
textBoxColorIconsDarkMode . Text = Settings . Default . ColorDarkModeIcons ;
textBoxColorBackground . Text = Settings . Default . ColorBackground ;
textBoxColorBackgroundDarkMode . Text = Settings . Default . ColorDarkModeBackground ;
textBoxColorBackgroundBorder . Text = Settings . Default . ColorBackgroundBorder ;
textBoxColorBackgroundBorderDarkMode . Text = Settings . Default . ColorDarkModeBackgroundBorder ;
textBoxColorSearchField . Text = Settings . Default . ColorSearchField ;
textBoxColorSearchFieldDarkMode . Text = Settings . Default . ColorDarkModeSearchField ;
textBoxColorScrollbarBackground . Text = Settings . Default . ColorScrollbarBackground ;
textBoxColorSlider . Text = Settings . Default . ColorSlider ;
textBoxColorSliderDragging . Text = Settings . Default . ColorSliderDragging ;
textBoxColorSliderHover . Text = Settings . Default . ColorSliderHover ;
textBoxColorSliderArrowsAndTrackHover . Text = Settings . Default . ColorSliderArrowsAndTrackHover ;
textBoxColorArrow . Text = Settings . Default . ColorArrow ;
textBoxColorArrowClick . Text = Settings . Default . ColorArrowClick ;
textBoxColorArrowClickBackground . Text = Settings . Default . ColorArrowClickBackground ;
textBoxColorArrowHover . Text = Settings . Default . ColorArrowHover ;
textBoxColorArrowHoverBackground . Text = Settings . Default . ColorArrowHoverBackground ;
textBoxColorScrollbarBackgroundDarkMode . Text = Settings . Default . ColorScrollbarBackgroundDarkMode ;
textBoxColorSliderDarkMode . Text = Settings . Default . ColorSliderDarkMode ;
textBoxColorSliderDraggingDarkMode . Text = Settings . Default . ColorSliderDraggingDarkMode ;
textBoxColorSliderHoverDarkMode . Text = Settings . Default . ColorSliderHoverDarkMode ;
textBoxColorSliderArrowsAndTrackHoverDarkMode . Text = Settings . Default . ColorSliderArrowsAndTrackHoverDarkMode ;
textBoxColorArrowDarkMode . Text = Settings . Default . ColorArrowDarkMode ;
textBoxColorArrowClickDarkMode . Text = Settings . Default . ColorArrowClickDarkMode ;
textBoxColorArrowClickBackgroundDarkMode . Text = Settings . Default . ColorArrowClickBackgroundDarkMode ;
textBoxColorArrowHoverDarkMode . Text = Settings . Default . ColorArrowHoverDarkMode ;
textBoxColorArrowHoverBackgroundDarkMode . Text = Settings . Default . ColorArrowHoverBackgroundDarkMode ;
2022-11-04 10:17:23 +13:00
Closed + = ( _ , _ ) = > settingsForm = null ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 13:07:20 +13:00
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
/// <summary>
/// Gets NewHotKey.
/// </summary>
public string NewHotKey { get ; } = string . Empty ;
/// <summary>
/// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools.
/// </summary>
/// <returns>Whether the hotkeys could be registered to the users content. This also applies if conflicts arise and the user decides to ignore these (i.e. not to register the conflicting hotkey).</returns>
public static bool RegisterHotkeys ( )
{
return RegisterHotkeys ( false ) ;
}
#endif
public static void ShowSingleInstance ( )
{
if ( IsOpen ( ) )
{
2022-12-03 14:14:15 +13:00
settingsForm ! . HandleInvoke ( ( ) = > settingsForm ? . Activate ( ) ) ;
2022-10-23 11:02:31 +13:00
}
else
{
settingsForm = new ( ) ;
settingsForm . Show ( ) ;
}
}
2022-10-26 10:30:11 +13:00
2022-10-23 11:02:31 +13:00
public static bool IsOpen ( )
{
return settingsForm ! = null ;
}
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
/// <summary>
/// Helper method to cleanly register a hotkey.
/// </summary>
/// <param name="failedKeys">failedKeys.</param>
/// <param name="hotkeyString">hotkeyString.</param>
/// <param name="handler">handler.</param>
/// <returns>bool success.</returns>
private static bool RegisterHotkey ( StringBuilder failedKeys , string hotkeyString , HotKeyHandler handler )
{
Keys modifierKeyCode = HotkeyModifiersFromString ( hotkeyString ) ;
Keys virtualKeyCode = HotkeyFromString ( hotkeyString ) ;
if ( ! Keys . None . Equals ( virtualKeyCode ) )
{
if ( RegisterHotKey ( modifierKeyCode , virtualKeyCode , handler ) < 0 )
{
if ( failedKeys . Length > 0 )
{
failedKeys . Append ( ", " ) ;
}
failedKeys . Append ( hotkeyString ) ;
return false ;
}
}
return true ;
}
private static bool RegisterWrapper ( StringBuilder failedKeys , HotKeyHandler handler )
{
bool success = RegisterHotkey (
failedKeys ,
Settings . Default . HotKey ,
handler ) ;
return success ;
}
/// <summary>
/// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools.
/// </summary>
/// <param name="ignoreFailedRegistration">if true, a failed hotkey registration will not be reported to the user - the hotkey will simply not be registered.</param>
/// <returns>Whether the hotkeys could be registered to the users content. This also applies if conflicts arise and the user decides to ignore these (i.e. not to register the conflicting hotkey).</returns>
private static bool RegisterHotkeys ( bool ignoreFailedRegistration )
{
bool success = true ;
StringBuilder failedKeys = new ( ) ;
if ( ! RegisterWrapper ( failedKeys , Handler ) )
{
success = false ;
}
if ( ! success )
{
if ( ! ignoreFailedRegistration )
{
success = HandleFailedHotkeyRegistration ( failedKeys . ToString ( ) ) ;
}
}
return success | | ignoreFailedRegistration ;
}
private static void Handler ( )
{
}
/// <summary>
/// Displays a dialog for the user to choose how to handle hotkey registration failures:
/// retry (allowing to shut down the conflicting application before),
/// ignore (not registering the conflicting hotkey and resetting the respective config to "None", i.e. not trying to register it again on next startup)
/// abort (do nothing about it).
/// </summary>
/// <param name="failedKeys">comma separated list of the hotkeys that could not be registered, for display in dialog text.</param>
/// <returns>bool success.</returns>
private static bool HandleFailedHotkeyRegistration ( string failedKeys )
{
bool success = false ;
string warningTitle = Translator . GetText ( "Warning" ) ;
string message = Translator . GetText ( "Could not register the hot key." ) + failedKeys ;
DialogResult dr = MessageBox . Show ( message , warningTitle , MessageBoxButtons . AbortRetryIgnore , MessageBoxIcon . Exclamation ) ;
if ( dr = = DialogResult . Retry )
{
UnregisterHotkeys ( ) ;
success = RegisterHotkeys ( false ) ;
}
else if ( dr = = DialogResult . Ignore )
{
UnregisterHotkeys ( ) ;
success = RegisterHotkeys ( true ) ;
}
return success ;
}
2022-11-04 10:17:23 +13:00
#endif
2022-10-23 11:02:31 +13:00
2022-11-04 10:17:23 +13:00
[SupportedOSPlatform("windows")]
2022-10-23 11:02:31 +13:00
private static void AddSetFolderByWindowsContextMenu ( )
{
2022-11-04 10:17:23 +13:00
RegistryKey ? registryKeyContextMenu = null ;
RegistryKey ? registryKeyContextMenuCommand = null ;
2022-10-23 11:02:31 +13:00
try
{
registryKeyContextMenu = Registry . CurrentUser . CreateSubKey ( MenuName ) ;
2022-11-04 10:17:23 +13:00
string? binLocation = Environment . ProcessPath ;
if ( ( registryKeyContextMenu ! = null ) & & ( binLocation ! = null ) )
2022-10-23 11:02:31 +13:00
{
registryKeyContextMenu . SetValue ( string . Empty , Translator . GetText ( "Set as directory" ) ) ;
registryKeyContextMenu . SetValue ( "Icon" , binLocation ) ;
}
registryKeyContextMenuCommand = Registry . CurrentUser . CreateSubKey ( Command ) ;
2023-04-16 04:48:53 +12:00
registryKeyContextMenuCommand ? . SetValue ( string . Empty , binLocation + " \"%1\"" ) ;
2022-10-23 11:02:31 +13:00
Settings . Default . SetFolderByWindowsContextMenu = true ;
}
catch ( Exception ex )
{
Log . Warn ( "SaveSetFolderByWindowsContextMenu failed" , ex ) ;
}
finally
{
2023-04-16 04:48:53 +12:00
registryKeyContextMenu ? . Close ( ) ;
registryKeyContextMenuCommand ? . Close ( ) ;
2022-10-23 11:02:31 +13:00
}
}
2022-11-04 10:17:23 +13:00
[SupportedOSPlatform("windows")]
2022-10-23 11:02:31 +13:00
private static void RemoveSetFolderByWindowsContextMenu ( )
{
try
{
2022-11-04 10:17:23 +13:00
RegistryKey ? registryKey = Registry . CurrentUser . OpenSubKey ( Command ) ;
2022-10-23 11:02:31 +13:00
if ( registryKey ! = null )
{
registryKey . Close ( ) ;
Registry . CurrentUser . DeleteSubKey ( Command ) ;
}
registryKey = Registry . CurrentUser . OpenSubKey ( MenuName ) ;
if ( registryKey ! = null )
{
registryKey . Close ( ) ;
Registry . CurrentUser . DeleteSubKey ( MenuName ) ;
}
Settings . Default . SetFolderByWindowsContextMenu = false ;
}
catch ( Exception ex )
{
Log . Warn ( "DeleteSetFolderByWindowsContextMenu failed" , ex ) ;
}
}
2022-11-04 10:17:23 +13:00
2022-10-23 11:02:31 +13:00
private static bool IsStartupTask ( )
{
bool useStartupTask = false ;
#if RELEASEPACKAGE
useStartupTask = true ;
#endif
return useStartupTask ;
}
2023-05-22 07:13:18 +12:00
private void HandlePreviewKeyDown ( object sender , KeyEventArgs e )
{
switch ( e . Key )
{
case Key . Escape :
#if TODO // HOTKEY
if ( ! inHotkey )
{
DialogResult = DialogResult . Cancel ;
}
else
{
return base . ProcessCmdKey ( ref msg , keyData ) ;
}
#endif
break ;
default :
break ;
}
}
2022-10-23 11:02:31 +13:00
private void ButtonOk_Click ( object sender , RoutedEventArgs e )
{
2022-11-03 13:07:20 +13:00
if ( checkBoxSetFolderByWindowsContextMenu . IsChecked ? ? false )
2022-10-23 11:02:31 +13:00
{
AddSetFolderByWindowsContextMenu ( ) ;
}
else
{
RemoveSetFolderByWindowsContextMenu ( ) ;
}
2022-11-04 10:17:23 +13:00
2022-11-03 13:07:20 +13:00
Settings . Default . SaveLogFileInApplicationDirectory = checkBoxSaveLogFileInApplicationDirectory . IsChecked ? ? false ;
2022-10-23 11:02:31 +13:00
if ( Settings . Default . SaveLogFileInApplicationDirectory )
{
try
{
string fileNameToCheckWriteAccess = "CheckWriteAccess" ;
File . WriteAllText ( fileNameToCheckWriteAccess , fileNameToCheckWriteAccess ) ;
File . Delete ( fileNameToCheckWriteAccess ) ;
Settings . Default . SaveLogFileInApplicationDirectory = true ;
}
catch ( Exception ex )
{
Settings . Default . SaveLogFileInApplicationDirectory = false ;
Log . Warn ( $"Failed to save log file in application folder {Log.GetLogFilePath()}" , ex ) ;
}
}
if ( ! IsStartupTask ( ) )
{
2022-11-03 13:07:20 +13:00
if ( checkBoxAutostart . IsChecked ? ? false )
2022-10-23 11:02:31 +13:00
{
2022-11-03 13:07:20 +13:00
RegistryKey ? key = Registry . CurrentUser . OpenSubKey (
2022-10-23 11:02:31 +13:00
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , true ) ;
2023-04-17 09:27:27 +12:00
key ? . SetValue (
2022-11-03 13:07:20 +13:00
Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name ,
Environment . ProcessPath ! ) ;
2022-10-23 11:02:31 +13:00
Settings . Default . IsAutostartActivated = true ;
}
else
{
2022-11-03 13:07:20 +13:00
RegistryKey ? key = Registry . CurrentUser . OpenSubKey (
2022-10-23 11:02:31 +13:00
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , true ) ;
2023-04-17 09:27:27 +12:00
key ? . DeleteValue ( "SystemTrayMenu" , false ) ;
2022-10-23 11:02:31 +13:00
Settings . Default . IsAutostartActivated = false ;
}
}
2022-11-03 13:07:20 +13:00
Settings . Default . CheckForUpdates = checkBoxCheckForUpdates . IsChecked ? ? false ;
2022-10-23 11:02:31 +13:00
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
Settings . Default . HotKey = new KeysConverter ( ) . ConvertToInvariantString ( textBoxHotkey . Hotkey | textBoxHotkey . HotkeyModifiers ) ;
2022-10-29 10:21:27 +13:00
#endif
2022-12-05 11:56:21 +13:00
Settings . Default . CurrentCultureInfoName = comboBoxLanguage . SelectedValue . ToString ( ) ;
2022-10-29 10:21:27 +13:00
Settings . Default . SizeInPercent = numericUpDownSizeInPercent . Value ;
Settings . Default . IconSizeInPercent = numericUpDownIconSizeInPercent . Value ;
2022-10-23 11:02:31 +13:00
if ( DllImports . NativeMethods . IsTouchEnabled ( ) )
{
2022-10-29 10:21:27 +13:00
Settings . Default . RowHeighteInPercentageTouch = numericUpDownRowHeightInPercentage . Value ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-29 10:21:27 +13:00
Settings . Default . RowHeighteInPercentage = numericUpDownRowHeightInPercentage . Value ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 10:21:27 +13:00
Settings . Default . WidthMaxInPercent = numericUpDownMenuWidth . Value ;
Settings . Default . HeightMaxInPercent = numericUpDownMenuHeight . Value ;
2022-10-23 11:02:31 +13:00
2022-11-03 13:07:20 +13:00
if ( radioButtonUseCustomLocation . IsChecked ? ? true )
2022-10-23 11:02:31 +13:00
{
Settings . Default . UseCustomLocation = true ;
Settings . Default . AppearAtMouseLocation = false ;
Settings . Default . AppearAtTheBottomLeft = false ;
}
2022-11-03 13:07:20 +13:00
else if ( radioButtonAppearAtMouseLocation . IsChecked ? ? true )
2022-10-23 11:02:31 +13:00
{
Settings . Default . UseCustomLocation = false ;
Settings . Default . AppearAtMouseLocation = true ;
Settings . Default . AppearAtTheBottomLeft = false ;
}
2022-11-03 13:07:20 +13:00
else if ( radioButtonAppearAtTheBottomLeft . IsChecked ? ? true )
2022-10-23 11:02:31 +13:00
{
Settings . Default . UseCustomLocation = false ;
Settings . Default . AppearAtMouseLocation = false ;
Settings . Default . AppearAtTheBottomLeft = true ;
}
else
{
Settings . Default . UseCustomLocation = false ;
Settings . Default . AppearAtMouseLocation = false ;
Settings . Default . AppearAtTheBottomLeft = false ;
}
2022-11-03 13:07:20 +13:00
2022-10-29 10:21:27 +13:00
Settings . Default . OverlappingOffsetPixels = numericUpDownOverlappingOffsetPixels . Value ;
2022-11-03 13:07:20 +13:00
if ( radioButtonNextToPreviousMenu . IsChecked ? ? true )
2022-10-23 11:02:31 +13:00
{
Settings . Default . AppearNextToPreviousMenu = true ;
}
else
{
Settings . Default . AppearNextToPreviousMenu = false ;
}
2022-11-03 13:07:20 +13:00
2022-10-29 11:32:26 +13:00
Settings . Default . ResolveLinksToFolders = checkBoxResolveLinksToFolders . IsChecked ? ? true ;
Settings . Default . ShowInTaskbar = checkBoxShowInTaskbar . IsChecked ? ? true ;
Settings . Default . SendHotkeyInsteadKillOtherInstances = checkBoxSendHotkeyInsteadKillOtherInstances . IsChecked ? ? false ;
Settings . Default . SupportGamepad = checkBoxSupportGamepad . IsChecked ? ? false ;
Settings . Default . OpenItemWithOneClick = checkBoxOpenItemWithOneClick . IsChecked ? ? true ;
Settings . Default . OpenDirectoryWithOneClick = checkBoxOpenDirectoryWithOneClick . IsChecked ? ? false ;
2022-10-23 11:02:31 +13:00
if ( DllImports . NativeMethods . IsTouchEnabled ( ) )
{
2022-10-29 11:32:26 +13:00
Settings . Default . DragDropItemsEnabledTouch = checkBoxDragDropItems . IsChecked ? ? false ;
Settings . Default . SwipeScrollingEnabledTouch = checkBoxSwipeScrolling . IsChecked ? ? true ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-29 11:32:26 +13:00
Settings . Default . DragDropItemsEnabled = checkBoxDragDropItems . IsChecked ? ? false ;
Settings . Default . SwipeScrollingEnabled = checkBoxSwipeScrolling . IsChecked ? ? true ;
2022-10-23 11:02:31 +13:00
}
Settings . Default . PathIcoDirectory = textBoxIcoFolder . Text ;
2022-10-29 11:32:26 +13:00
Settings . Default . SortByTypeAndNameWindowsExplorerSort = radioButtonSortByTypeAndName . IsChecked ? ? false ;
Settings . Default . SortByTypeAndDate = radioButtonSortByTypeAndDate . IsChecked ? ? false ;
Settings . Default . SortByFileExtensionAndName = radioButtonSortByFileExtensionAndName . IsChecked ? ? false ;
Settings . Default . SortByName = radioButtonSortByName . IsChecked ? ? true ;
Settings . Default . SortByDate = radioButtonSortByDate . IsChecked ? ? false ;
Settings . Default . SystemSettingsShowHiddenFiles = radioButtonSystemSettingsShowHiddenFiles . IsChecked ? ? true ;
Settings . Default . AlwaysShowHiddenFiles = radioButtonAlwaysShowHiddenFiles . IsChecked ? ? false ;
Settings . Default . NeverShowHiddenFiles = radioButtonNeverShowHiddenFiles . IsChecked ? ? false ;
2022-10-23 11:02:31 +13:00
2022-11-01 12:57:08 +13:00
Settings . Default . ShowOnlyAsSearchResult = checkBoxShowOnlyAsSearchResult . IsChecked ? ? false ;
string pathsAddToMainMenu = string . Empty ;
2023-04-25 10:24:48 +12:00
foreach ( ListViewItemData itemData in dataGridViewFolders . Items )
2022-10-23 11:02:31 +13:00
{
2023-04-25 10:24:48 +12:00
pathsAddToMainMenu + = $"{itemData.ColumnFolder} recursiv:{itemData.ColumnRecursiveLevel} onlyFiles:{itemData.ColumnOnlyFiles}|" ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
Settings . Default . PathsAddToMainMenu = pathsAddToMainMenu ;
2022-10-23 11:02:31 +13:00
2022-11-01 12:57:08 +13:00
Settings . Default . GenerateShortcutsToDrives = checkBoxGenerateShortcutsToDrives . IsChecked ? ? false ;
2022-11-03 09:19:57 +13:00
Settings . Default . StaysOpenWhenItemClicked = checkBoxStayOpenWhenItemClicked . IsChecked ? ? true ;
Settings . Default . StaysOpenWhenFocusLost = checkBoxStayOpenWhenFocusLost . IsChecked ? ? true ;
Settings . Default . TimeUntilCloses = numericUpDownTimeUntilClose . Value ;
Settings . Default . TimeUntilOpens = numericUpDownTimeUntilOpens . Value ;
Settings . Default . StaysOpenWhenFocusLostAfterEnterPressed = checkBoxStayOpenWhenFocusLostAfterEnterPressed . IsChecked ? ? true ;
Settings . Default . TimeUntilClosesAfterEnterPressed = numericUpDownTimeUntilClosesAfterEnterPressed . Value ;
Settings . Default . ClearCacheIfMoreThanThisNumberOfItems = numericUpDownClearCacheIfMoreThanThisNumberOfItems . Value ;
2022-10-23 11:02:31 +13:00
Settings . Default . SearchPattern = textBoxSearchPattern . Text ;
2022-11-03 13:07:20 +13:00
Settings . Default . UseIconFromRootFolder = checkBoxUseIconFromRootFolder . IsChecked ? ? false ;
Settings . Default . RoundCorners = checkBoxRoundCorners . IsChecked ? ? false ;
Settings . Default . IsDarkModeAlwaysOn = checkBoxDarkModeAlwaysOn . IsChecked ? ? true ;
Settings . Default . UseFading = checkBoxUseFading . IsChecked ? ? false ;
Settings . Default . ShowLinkOverlay = checkBoxShowLinkOverlay . IsChecked ? ? false ;
Settings . Default . ShowDirectoryTitleAtTop = checkBoxShowDirectoryTitleAtTop . IsChecked ? ? false ;
Settings . Default . ShowSearchBar = checkBoxShowSearchBar . IsChecked ? ? true ;
Settings . Default . ShowCountOfElementsBelow = checkBoxShowCountOfElementsBelow . IsChecked ? ? false ;
Settings . Default . ShowFunctionKeyOpenFolder = checkBoxShowFunctionKeyOpenFolder . IsChecked ? ? false ;
Settings . Default . ShowFunctionKeyPinMenu = checkBoxShowFunctionKeyPinMenu . IsChecked ? ? false ;
Settings . Default . ShowFunctionKeySettings = checkBoxShowFunctionKeySettings . IsChecked ? ? false ;
Settings . Default . ShowFunctionKeyRestart = checkBoxShowFunctionKeyRestart . IsChecked ? ? false ;
if ( checkBoxSaveConfigInApplicationDirectory . IsChecked ? ? false )
2022-10-23 11:02:31 +13:00
{
CustomSettingsProvider . ActivateConfigPathAssembly ( ) ;
TrySettingsDefaultSave ( ) ;
}
else
{
TrySettingsDefaultSave ( ) ;
CustomSettingsProvider . DeactivateConfigPathAssembly ( ) ;
}
static void TrySettingsDefaultSave ( )
{
try
{
Settings . Default . Save ( ) ;
}
catch ( Exception ex )
{
Log . Warn ( $"Failed to save configuration file in application folder {CustomSettingsProvider.ConfigPathAssembly}" , ex ) ;
}
}
AppRestart . ByConfigChange ( ) ;
2022-11-03 13:07:20 +13:00
2022-10-23 11:02:31 +13:00
Close ( ) ;
}
2022-10-26 10:30:11 +13:00
private async void ButtonAddStartup_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-26 10:30:11 +13:00
// Pass the task ID you specified in the appxmanifest file
StartupTask startupTask = await StartupTask . GetAsync ( "MyStartupId" ) ;
Log . Info ( $"Autostart {startupTask.State}." ) ;
2022-10-23 11:02:31 +13:00
2022-10-26 10:30:11 +13:00
switch ( startupTask . State )
{
case StartupTaskState . Enabled :
case StartupTaskState . EnabledByPolicy :
UpdateLabelStartupStatus ( startupTask . State ) ;
break ;
case StartupTaskState . Disabled :
// Task is disabled but can be enabled.
StartupTaskState newState = await startupTask . RequestEnableAsync ( ) ;
UpdateLabelStartupStatus ( newState ) ;
break ;
case StartupTaskState . DisabledByUser :
UpdateLabelStartupStatus ( startupTask . State ) ;
break ;
case StartupTaskState . DisabledByPolicy :
UpdateLabelStartupStatus ( startupTask . State ) ;
break ;
default :
break ;
2022-10-23 11:02:31 +13:00
}
}
private void UpdateLabelStartupStatus ( StartupTaskState newState )
{
switch ( newState )
{
case StartupTaskState . Disabled :
case StartupTaskState . DisabledByUser :
case StartupTaskState . DisabledByPolicy :
2022-10-26 10:30:11 +13:00
labelStartupStatus . Content = Translator . GetText ( "Deactivated" ) ;
2022-10-23 11:02:31 +13:00
break ;
case StartupTaskState . Enabled :
case StartupTaskState . EnabledByPolicy :
2022-10-26 10:30:11 +13:00
labelStartupStatus . Content = Translator . GetText ( "Activated" ) ;
2022-10-23 11:02:31 +13:00
break ;
default :
break ;
}
}
2022-10-26 10:30:11 +13:00
private void ButtonChange_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-14 05:55:24 +13:00
Config . SetFolderByUser ( this , false ) ;
2022-10-23 11:02:31 +13:00
textBoxFolder . Text = Config . Path ;
}
2022-10-26 10:30:11 +13:00
private void ButtonOpenFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
Log . ProcessStart ( "explorer.exe" , Config . Path , true ) ;
}
2022-10-26 10:30:11 +13:00
private void ButtonChangeRelativeFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
if ( ! string . IsNullOrEmpty ( Config . Path ) )
{
2022-10-26 10:30:11 +13:00
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 ;
}
}
2022-10-23 11:02:31 +13:00
}
}
2022-10-26 10:30:11 +13:00
private void ButtonOpenAssemblyLocation_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-26 10:30:11 +13:00
string? location = Assembly . GetEntryAssembly ( ) ? . Location ;
if ( ! string . IsNullOrEmpty ( location ) )
{
string? parentPath = Directory . GetParent ( location ) ? . FullName ;
if ( ! string . IsNullOrEmpty ( parentPath ) )
{
Log . ProcessStart ( parentPath ) ;
}
}
2022-10-23 11:02:31 +13:00
}
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
private void TextBoxHotkeyEnter ( object sender , EventArgs e )
{
UnregisterHotkeys ( ) ;
inHotkey = true ;
}
private void TextBoxHotkey_Leave ( object sender , EventArgs e )
{
Settings . Default . HotKey =
new KeysConverter ( ) . ConvertToInvariantString (
textBoxHotkey . Hotkey | textBoxHotkey . HotkeyModifiers ) ;
RegisterHotkeys ( ) ;
inHotkey = false ;
}
2022-10-26 10:30:11 +13:00
#endif
private void ButtonHotkeyDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-30 10:48:45 +13:00
#if TODO // HOTKEY
2022-10-23 11:02:31 +13:00
textBoxHotkey . SetHotkey ( "Ctrl+LWin" ) ;
2022-10-26 10:30:11 +13:00
#endif
2022-10-23 11:02:31 +13:00
}
2022-10-29 11:32:26 +13:00
private void ButtonGeneralDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-26 10:30:11 +13:00
checkBoxSetFolderByWindowsContextMenu . IsChecked = false ;
checkBoxSaveConfigInApplicationDirectory . IsChecked = false ;
checkBoxSaveLogFileInApplicationDirectory . IsChecked = false ;
checkBoxAutostart . IsChecked = false ;
checkBoxCheckForUpdates . IsChecked = false ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 11:32:26 +13:00
private void ButtonChangeIcoFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-14 05:55:24 +13:00
Config . SetFolderIcoByUser ( this ) ;
2022-10-23 11:02:31 +13:00
textBoxIcoFolder . Text = Settings . Default . PathIcoDirectory ;
}
2022-11-01 12:57:08 +13:00
private void ButtonAddSampleStartMenuFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
string folderPathCommonStartMenu = Environment . GetFolderPath ( Environment . SpecialFolder . CommonStartMenu ) ;
2022-11-01 12:57:08 +13:00
dataGridViewFolders . Items . Add ( new ListViewItemData ( folderPathCommonStartMenu , true , true ) ) ;
EnableButtonAddStartMenu ( ) ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
private void ButtonClearFolders_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-01 12:57:08 +13:00
checkBoxShowOnlyAsSearchResult . IsChecked = false ;
dataGridViewFolders . Items . Clear ( ) ;
EnableButtonAddStartMenu ( ) ;
checkBoxGenerateShortcutsToDrives . IsChecked = false ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
private void ButtonAddFolderToRootFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
using FolderDialog dialog = new ( ) ;
dialog . InitialFolder = Config . Path ;
2022-11-14 05:55:24 +13:00
if ( dialog . ShowDialog ( this ) )
2022-10-23 11:02:31 +13:00
{
2023-04-17 09:27:27 +12:00
if ( ! string . IsNullOrEmpty ( dialog . Folder ) )
{
dataGridViewFolders . Items . Add ( new ListViewItemData ( dialog . Folder , false , true ) ) ;
EnableButtonAddStartMenu ( ) ;
}
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
dataGridViewFolders . SelectedItem = null ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
private void ButtonRemoveFolder_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-01 12:57:08 +13:00
if ( dataGridViewFolders . SelectedItems . Count > 0 )
2022-10-23 11:02:31 +13:00
{
2022-11-01 12:57:08 +13:00
Array items = Array . CreateInstance ( typeof ( object ) , dataGridViewFolders . SelectedItems . Count ) ;
dataGridViewFolders . SelectedItems . CopyTo ( items , 0 ) ;
foreach ( object item in items )
2022-10-23 11:02:31 +13:00
{
2022-11-01 12:57:08 +13:00
dataGridViewFolders . Items . Remove ( item ) ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
EnableButtonAddStartMenu ( ) ;
2022-10-23 11:02:31 +13:00
}
}
2022-11-01 12:57:08 +13:00
private void DataGridViewFolders_SelectionChanged ( object sender , SelectionChangedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-01 12:57:08 +13:00
buttonRemoveFolder . IsEnabled = dataGridViewFolders . SelectedItems . Count > 0 ;
2022-10-23 11:02:31 +13:00
}
private void EnableButtonAddStartMenu ( )
{
bool doesStartMenuFolderExist = false ;
2023-04-25 10:24:48 +12:00
foreach ( ListViewItemData itemData in dataGridViewFolders . Items )
2022-10-23 11:02:31 +13:00
{
string folderPathCommonStartMenu = Environment . GetFolderPath ( Environment . SpecialFolder . CommonStartMenu ) ;
2022-11-01 12:57:08 +13:00
// TODO: Check: Is RecursiveLevel and OnlyFiles really important to be the StartMenu folder entry? (Remove in version 1?)
2023-04-25 10:24:48 +12:00
if ( itemData . ColumnFolder = = folderPathCommonStartMenu )
2022-10-23 11:02:31 +13:00
{
doesStartMenuFolderExist = true ;
2022-11-01 12:57:08 +13:00
break ;
2022-10-23 11:02:31 +13:00
}
}
2022-11-01 12:57:08 +13:00
buttonAddSampleStartMenuFolder . IsEnabled = ! doesStartMenuFolderExist ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
2022-10-27 09:30:01 +13:00
private void ButtonSizeAndLocationDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-29 10:21:27 +13:00
numericUpDownSizeInPercent . Value = 100 ;
numericUpDownIconSizeInPercent . Value = 100 ;
numericUpDownRowHeightInPercentage . Value = 100 ;
numericUpDownMenuWidth . Value = 100 ;
numericUpDownMenuHeight . Value = 100 ;
2022-10-27 09:30:01 +13:00
radioButtonAppearAtTheBottomLeft . IsChecked = true ;
radioButtonNextToPreviousMenu . IsChecked = true ;
2022-10-29 10:21:27 +13:00
numericUpDownOverlappingOffsetPixels . Value = 150 ;
2022-10-23 11:02:31 +13:00
}
2022-10-29 11:32:26 +13:00
private void ButtonAdvancedDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-29 11:32:26 +13:00
checkBoxResolveLinksToFolders . IsChecked = true ;
checkBoxShowInTaskbar . IsChecked = true ;
checkBoxSendHotkeyInsteadKillOtherInstances . IsChecked = false ;
checkBoxSupportGamepad . IsChecked = false ;
checkBoxOpenItemWithOneClick . IsChecked = true ;
checkBoxOpenDirectoryWithOneClick . IsChecked = false ;
2022-10-23 11:02:31 +13:00
if ( DllImports . NativeMethods . IsTouchEnabled ( ) )
{
2022-10-29 11:32:26 +13:00
checkBoxDragDropItems . IsChecked = false ;
checkBoxSwipeScrolling . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
else
{
2022-10-29 11:32:26 +13:00
checkBoxDragDropItems . IsChecked = true ;
checkBoxSwipeScrolling . IsChecked = false ;
2022-10-23 11:02:31 +13:00
}
textBoxIcoFolder . Text = Path . Combine (
2022-10-29 11:32:26 +13:00
Path . Combine (
Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ,
$"SystemTrayMenu" ) ,
"ico" ) ;
2022-10-23 11:02:31 +13:00
if ( ! Directory . Exists ( Settings . Default . PathIcoDirectory ) )
{
Directory . CreateDirectory ( Settings . Default . PathIcoDirectory ) ;
}
2022-10-29 11:32:26 +13:00
radioButtonSortByName . IsChecked = true ;
radioButtonSystemSettingsShowHiddenFiles . IsChecked = true ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 09:19:57 +13:00
private void CheckBoxStayOpenWhenFocusLost_CheckedChanged ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-03 09:19:57 +13:00
numericUpDownTimeUntilClose . IsEnabled = checkBoxStayOpenWhenFocusLost . IsChecked ? ? true ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 09:19:57 +13:00
private void CheckBoxStayOpenWhenFocusLostAfterEnterPressed_CheckedChanged ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-03 09:19:57 +13:00
numericUpDownTimeUntilClosesAfterEnterPressed . IsEnabled = checkBoxStayOpenWhenFocusLostAfterEnterPressed . IsChecked ? ? true ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 09:19:57 +13:00
private void ButtonExpertDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-03 09:19:57 +13:00
checkBoxStayOpenWhenItemClicked . IsChecked = true ;
checkBoxStayOpenWhenFocusLost . IsChecked = true ;
2022-10-23 11:02:31 +13:00
numericUpDownTimeUntilClose . Value = 400 ;
numericUpDownTimeUntilOpens . Value = 100 ;
2022-11-03 09:19:57 +13:00
checkBoxStayOpenWhenFocusLostAfterEnterPressed . IsChecked = true ;
2022-10-23 11:02:31 +13:00
numericUpDownTimeUntilClosesAfterEnterPressed . Value = 200 ;
numericUpDownClearCacheIfMoreThanThisNumberOfItems . Value = 200 ;
textBoxSearchPattern . Text = string . Empty ;
}
2022-11-03 13:07:20 +13:00
private void TextBoxColorsChanged ( ColorSelector sender )
2022-10-23 11:02:31 +13:00
{
SaveColorsTemporarily ( ) ;
}
private void SaveColorsTemporarily ( )
{
2022-11-03 13:07:20 +13:00
if ( Visibility = = Visibility . Visible )
2022-10-23 11:02:31 +13:00
{
Settings . Default . ColorSelectedItem = textBoxColorSelectedItem . Text ;
2022-11-03 13:07:20 +13:00
Settings . Default . ColorDarkModeSelecetedItem = textBoxColorSelectedItemDarkMode . Text ;
2022-10-23 11:02:31 +13:00
Settings . Default . ColorSelectedItemBorder = textBoxColorSelectedItemBorder . Text ;
Settings . Default . ColorDarkModeSelectedItemBorder = textBoxColorSelectedItemBorderDarkMode . Text ;
Settings . Default . ColorOpenFolder = textBoxColorOpenFolder . Text ;
Settings . Default . ColorDarkModeOpenFolder = textBoxColorOpenFolderDarkMode . Text ;
Settings . Default . ColorOpenFolderBorder = textBoxColorOpenFolderBorder . Text ;
Settings . Default . ColorDarkModeOpenFolderBorder = textBoxColorOpenFolderBorderDarkMode . Text ;
Settings . Default . ColorIcons = textBoxColorIcons . Text ;
Settings . Default . ColorDarkModeIcons = textBoxColorIconsDarkMode . Text ;
Settings . Default . ColorBackground = textBoxColorBackground . Text ;
Settings . Default . ColorDarkModeBackground = textBoxColorBackgroundDarkMode . Text ;
Settings . Default . ColorBackgroundBorder = textBoxColorBackgroundBorder . Text ;
Settings . Default . ColorDarkModeBackgroundBorder = textBoxColorBackgroundBorderDarkMode . Text ;
Settings . Default . ColorSearchField = textBoxColorSearchField . Text ;
Settings . Default . ColorDarkModeSearchField = textBoxColorSearchFieldDarkMode . Text ;
Settings . Default . ColorScrollbarBackground = textBoxColorScrollbarBackground . Text ;
Settings . Default . ColorSlider = textBoxColorSlider . Text ;
Settings . Default . ColorSliderDragging = textBoxColorSliderDragging . Text ;
Settings . Default . ColorSliderHover = textBoxColorSliderHover . Text ;
Settings . Default . ColorSliderArrowsAndTrackHover = textBoxColorSliderArrowsAndTrackHover . Text ;
Settings . Default . ColorArrow = textBoxColorArrow . Text ;
Settings . Default . ColorArrowClick = textBoxColorArrowClick . Text ;
Settings . Default . ColorArrowClickBackground = textBoxColorArrowClickBackground . Text ;
Settings . Default . ColorArrowHover = textBoxColorArrowHover . Text ;
Settings . Default . ColorArrowHoverBackground = textBoxColorArrowHoverBackground . Text ;
Settings . Default . ColorScrollbarBackgroundDarkMode = textBoxColorScrollbarBackgroundDarkMode . Text ;
Settings . Default . ColorSliderDarkMode = textBoxColorSliderDarkMode . Text ;
Settings . Default . ColorSliderDraggingDarkMode = textBoxColorSliderDraggingDarkMode . Text ;
Settings . Default . ColorSliderHoverDarkMode = textBoxColorSliderHoverDarkMode . Text ;
Settings . Default . ColorSliderArrowsAndTrackHoverDarkMode = textBoxColorSliderArrowsAndTrackHoverDarkMode . Text ;
Settings . Default . ColorArrowDarkMode = textBoxColorArrowDarkMode . Text ;
Settings . Default . ColorArrowClickDarkMode = textBoxColorArrowClickDarkMode . Text ;
Settings . Default . ColorArrowClickBackgroundDarkMode = textBoxColorArrowClickBackgroundDarkMode . Text ;
Settings . Default . ColorArrowHoverDarkMode = textBoxColorArrowHoverDarkMode . Text ;
Settings . Default . ColorArrowHoverBackgroundDarkMode = textBoxColorArrowHoverBackgroundDarkMode . Text ;
Config . InitializeColors ( false ) ;
}
}
2022-11-03 13:07:20 +13:00
private void CheckBoxDarkModeAlwaysOnCheckedChanged ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-03 13:07:20 +13:00
Settings . Default . IsDarkModeAlwaysOn = checkBoxDarkModeAlwaysOn . IsChecked ? ? true ;
2022-10-23 11:02:31 +13:00
Config . ResetReadDarkModeDone ( ) ;
SaveColorsTemporarily ( ) ;
}
2022-11-03 13:07:20 +13:00
private void ButtonAppearanceDefault_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-11-03 13:07:20 +13:00
checkBoxUseIconFromRootFolder . IsChecked = false ;
checkBoxRoundCorners . IsChecked = false ;
checkBoxUseFading . IsChecked = false ;
checkBoxDarkModeAlwaysOn . IsChecked = true ;
checkBoxShowLinkOverlay . IsChecked = false ;
checkBoxShowDirectoryTitleAtTop . IsChecked = false ;
checkBoxShowSearchBar . IsChecked = true ;
checkBoxShowCountOfElementsBelow . IsChecked = false ;
checkBoxShowFunctionKeyOpenFolder . IsChecked = false ;
checkBoxShowFunctionKeyPinMenu . IsChecked = false ;
checkBoxShowFunctionKeySettings . IsChecked = false ;
checkBoxShowFunctionKeyRestart . IsChecked = false ;
2022-10-23 11:02:31 +13:00
}
2022-11-03 13:07:20 +13:00
private void ButtonDefaultColors_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
textBoxColorIcons . Text = "#95a0a6" ;
textBoxColorOpenFolder . Text = "#C2F5DE" ;
textBoxColorOpenFolderBorder . Text = "#99FFA5" ;
textBoxColorBackground . Text = "#ffffff" ;
textBoxColorBackgroundBorder . Text = "#000000" ;
textBoxColorSearchField . Text = "#ffffff" ;
textBoxColorSelectedItem . Text = "#CCE8FF" ;
textBoxColorSelectedItemBorder . Text = "#99D1FF" ;
textBoxColorArrow . Text = "#606060" ;
textBoxColorArrowHoverBackground . Text = "#dadada" ;
textBoxColorArrowHover . Text = "#000000" ;
textBoxColorArrowClick . Text = "#ffffff" ;
textBoxColorArrowClickBackground . Text = "#606060" ;
textBoxColorSliderArrowsAndTrackHover . Text = "#c0c0c0" ;
textBoxColorSlider . Text = "#cdcdcd" ;
textBoxColorSliderHover . Text = "#a6a6a6" ;
textBoxColorSliderDragging . Text = "#606060" ;
textBoxColorScrollbarBackground . Text = "#f0f0f0" ;
}
2022-11-03 13:07:20 +13:00
private void ButtonDefaultColorsDark_Click ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
textBoxColorIconsDarkMode . Text = "#95a0a6" ;
textBoxColorOpenFolderDarkMode . Text = "#14412A" ;
textBoxColorOpenFolderBorderDarkMode . Text = "#144B55" ;
textBoxColorBackgroundDarkMode . Text = "#202020" ;
textBoxColorBackgroundBorderDarkMode . Text = "#000000" ;
textBoxColorSearchFieldDarkMode . Text = "#191919" ;
2022-11-03 13:07:20 +13:00
textBoxColorSelectedItemDarkMode . Text = "#333333" ;
2022-10-23 11:02:31 +13:00
textBoxColorSelectedItemBorderDarkMode . Text = "#141D4B" ;
textBoxColorArrowDarkMode . Text = "#676767" ;
textBoxColorArrowHoverBackgroundDarkMode . Text = "#373737" ;
textBoxColorArrowHoverDarkMode . Text = "#676767" ;
textBoxColorArrowClickDarkMode . Text = "#171717" ;
textBoxColorArrowClickBackgroundDarkMode . Text = "#a6a6a6" ;
textBoxColorSliderArrowsAndTrackHoverDarkMode . Text = "#4d4d4d" ;
textBoxColorSliderDarkMode . Text = "#4d4d4d" ;
textBoxColorSliderHoverDarkMode . Text = "#7a7a7a" ;
textBoxColorSliderDraggingDarkMode . Text = "#a6a6a6" ;
textBoxColorScrollbarBackgroundDarkMode . Text = "#171717" ;
}
private void ButtonCancel_Click ( object sender , RoutedEventArgs e )
{
Settings . Default . Reload ( ) ;
Close ( ) ;
}
2022-10-27 09:30:01 +13:00
private void RadioButtonOverlapping_Checked ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-27 09:30:01 +13:00
numericUpDownOverlappingOffsetPixels . IsEnabled = true ;
2022-10-23 11:02:31 +13:00
}
2022-10-27 09:30:01 +13:00
private void RadioButtonOverlapping_Unchecked ( object sender , RoutedEventArgs e )
2022-10-23 11:02:31 +13:00
{
2022-10-27 09:30:01 +13:00
numericUpDownOverlappingOffsetPixels . IsEnabled = false ;
2022-10-23 11:02:31 +13:00
}
2022-11-01 12:57:08 +13:00
/// <summary>
/// Type for ListView items.
/// </summary>
private class ListViewItemData
{
public ListViewItemData ( string folder , bool recursiveLevel , bool onlyFiles )
{
ColumnFolder = folder ;
ColumnRecursiveLevel = recursiveLevel ;
ColumnOnlyFiles = onlyFiles ;
}
public string ColumnFolder { get ; set ; }
public bool ColumnRecursiveLevel { get ; set ; }
public bool ColumnOnlyFiles { get ; set ; }
}
2022-12-05 11:56:21 +13:00
/// <summary>
/// Pairs of language display names and their ISO 639-1 standard language codes.
/// </summary>
private class LanguageID
{
public LanguageID ( string displayName , string languageCode )
{
DisplayName = displayName ;
Code = languageCode ;
}
public string DisplayName { get ; set ; }
public string Code { get ; set ; }
}
2022-10-23 11:02:31 +13:00
}
}