diff --git a/Flow.Launcher/Converters/DateTimeFormatToNowConverter.cs b/Flow.Launcher/Converters/DateTimeFormatToNowConverter.cs
new file mode 100644
index 000000000..3c46fd01a
--- /dev/null
+++ b/Flow.Launcher/Converters/DateTimeFormatToNowConverter.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace Flow.Launcher.Converters
+{
+ public class DateTimeFormatToNowConverter : IValueConverter
+ {
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return value is not string format ? null : DateTime.Now.ToString(format);
+ }
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml
index bc0ff1ce4..e078cb6e2 100644
--- a/Flow.Launcher/SettingWindow.xaml
+++ b/Flow.Launcher/SettingWindow.xaml
@@ -44,6 +44,7 @@
+
@@ -2179,9 +2180,14 @@
Margin="0,0,18,0"
VerticalAlignment="Center"
FontSize="14"
- ItemsSource="{Binding TimeFormatDisplayList}"
- SelectedIndex="{Binding TimeFormatIndex, Mode=OneWayToSource}"
- DropDownOpened="RefreshTimeList"/>
+ ItemsSource="{Binding TimeFormatList}"
+ SelectedIndex="{Binding TimeFormat}">
+
+
+
+
+
+
+ ItemsSource="{Binding DateFormatList}"
+ SelectedIndex="{Binding DateFormat}">
+
+
+
+
+
+
x.Equals(Settings.TimeFormat))) >= 0 ? tmp : 0;
- DateFormatIndex = (tmp = DateFormatList.FindIndex(x => x.Equals(Settings.DateFormat))) >= 0 ? tmp : 0;
- // TODO: CurrentCulture may not equal to settings.language when this is constructed
- TimeFormatDisplayList = TimeFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
- DateFormatDisplayList = DateFormatList.Select(x => DateTime.Now.ToString(x, CultureInfo.CurrentCulture)).ToList();
}
public Settings Settings { get; set; }
@@ -164,7 +158,10 @@ namespace Flow.Launcher.ViewModel
{
var key = $"LastQuery{e}";
var display = _translater.GetTranslation(key);
- var m = new LastQueryMode { Display = display, Value = e, };
+ var m = new LastQueryMode
+ {
+ Display = display, Value = e,
+ };
modes.Add(m);
}
return modes;
@@ -355,7 +352,6 @@ namespace Flow.Launcher.ViewModel
App.API.ShowMainWindow();
}
-
#endregion
#region theme
@@ -420,8 +416,7 @@ namespace Flow.Launcher.ViewModel
var display = _translater.GetTranslation(key);
var m = new ColorScheme
{
- Display = display,
- Value = e,
+ Display = display, Value = e,
};
modes.Add(m);
}
@@ -445,14 +440,17 @@ namespace Flow.Launcher.ViewModel
{
var key = $"SearchWindowPosition{e}";
var display = _translater.GetTranslation(key);
- var m = new SearchWindowPosition { Display = display, Value = e, };
+ var m = new SearchWindowPosition
+ {
+ Display = display, Value = e,
+ };
modes.Add(m);
}
return modes;
}
}
- public List TimeFormatList { get; set; } = new List()
+ public List TimeFormatList { get; } = new()
{
"h:mm",
"hh:mm",
@@ -464,7 +462,7 @@ namespace Flow.Launcher.ViewModel
"hh:mm tt"
};
- public List DateFormatList { get; set; } = new List()
+ public List DateFormatList { get; } = new()
{
"MM'/'dd dddd",
"MM'/'dd ddd",
@@ -482,33 +480,23 @@ namespace Flow.Launcher.ViewModel
"dd', 'MMMM"
};
- private int timeFormatIndex = 0;
- public int TimeFormatIndex
+ public string TimeFormat
{
- get => timeFormatIndex;
+ get { return Settings.TimeFormat; }
set
{
- if (value != -1)
- {
- timeFormatIndex = value;
- Settings.TimeFormat = TimeFormatList[value];
- ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
- }
+ Settings.TimeFormat = value;
+ OnPropertyChanged();
}
}
- private int dateFormatIndex = 0;
- public int DateFormatIndex
+ public string DateFormat
{
- get => dateFormatIndex;
- set
- {
- if (value != -1)
- {
- dateFormatIndex = value;
- Settings.DateFormat = DateFormatList[value];
- DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
- }
+ get { return Settings.DateFormat; }
+ set
+ {
+ Settings.DateFormat = value;
+ OnPropertyChanged();
}
}
@@ -516,31 +504,6 @@ namespace Flow.Launcher.ViewModel
public string DateText { get; private set; }
- public List TimeFormatDisplayList { get; set; } = null;
-
- public List DateFormatDisplayList { get; set; } = null;
-
- public void UpdateDateDisplayList()
- {
- for (int i = 0; i < DateFormatList.Count; ++i)
- {
- DateFormatDisplayList[i] = DateTime.Now.ToString(DateFormatList[i], CultureInfo.CurrentCulture);
- }
- // TODO: CurrentCulture may not equal to settings.language
- // Cross thread issue?
- DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
- }
-
- public void UpdateTimeDisplayList()
- {
- for (int i = 0; i < TimeFormatList.Count; ++i)
- {
- TimeFormatDisplayList[i] = DateTime.Now.ToString(TimeFormatList[i], CultureInfo.CurrentCulture);
- }
- // TODO: CurrentCulture may not equal to settings.language
- // Cross thread issue?
- ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
- }
public double WindowWidthSize
{
@@ -783,7 +746,7 @@ namespace Flow.Launcher.ViewModel
string deleteWarning = string.Format(
InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"),
- item.Key, item.Value);
+ item.Key, item.Value);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
@@ -864,19 +827,22 @@ namespace Flow.Launcher.ViewModel
internal void ClearLogFolder()
{
var directory = new DirectoryInfo(
- Path.Combine(
- DataLocation.DataDirectory(),
- Constant.Logs,
- Constant.Version));
+ Path.Combine(
+ DataLocation.DataDirectory(),
+ Constant.Logs,
+ Constant.Version));
directory.EnumerateFiles()
- .ToList()
- .ForEach(x => x.Delete());
+ .ToList()
+ .ForEach(x => x.Delete());
}
internal string FormatBytes(long bytes)
{
const int scale = 1024;
- string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
+ string[] orders = new string[]
+ {
+ "GB", "MB", "KB", "Bytes"
+ };
long max = (long)Math.Pow(scale, orders.Length - 1);
foreach (string order in orders)
@@ -888,6 +854,7 @@ namespace Flow.Launcher.ViewModel
}
return "0 Bytes";
}
+
#endregion
}
}