mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2749 from Flow-Launcher/binding
Use binding for values introduced in Resizable PR
This commit is contained in:
commit
9b9ebfc861
3 changed files with 31 additions and 98 deletions
|
|
@ -22,6 +22,7 @@ namespace Flow.Launcher.SettingPages.ViewModels;
|
|||
|
||||
public partial class SettingsPaneThemeViewModel : BaseModel
|
||||
{
|
||||
private const string DefaultFont = "Segoe UI";
|
||||
public Settings Settings { get; }
|
||||
|
||||
public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme";
|
||||
|
|
@ -82,6 +83,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
get => Settings.QueryBoxFontSize;
|
||||
set => Settings.QueryBoxFontSize = value;
|
||||
}
|
||||
|
||||
public double ResultItemFontSize
|
||||
{
|
||||
get => Settings.ResultItemFontSize;
|
||||
|
|
@ -97,30 +99,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
private List<Theme.ThemeData> _themes;
|
||||
public List<Theme.ThemeData> Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes();
|
||||
|
||||
public class ColorSchemeData : DropdownDataGeneric<ColorSchemes> { }
|
||||
|
||||
public class ColorScheme
|
||||
{
|
||||
public string Display { get; set; }
|
||||
public ColorSchemes Value { get; set; }
|
||||
}
|
||||
|
||||
public List<ColorScheme> ColorSchemes
|
||||
{
|
||||
get
|
||||
{
|
||||
List<ColorScheme> modes = new List<ColorScheme>();
|
||||
var enums = (ColorSchemes[])Enum.GetValues(typeof(ColorSchemes));
|
||||
foreach (var e in enums)
|
||||
{
|
||||
var key = $"ColorScheme{e}";
|
||||
var display = InternationalizationManager.Instance.GetTranslation(key);
|
||||
var m = new ColorScheme { Display = display, Value = e, };
|
||||
modes.Add(m);
|
||||
}
|
||||
|
||||
return modes;
|
||||
}
|
||||
}
|
||||
public List<ColorSchemeData> ColorSchemes { get; } = DropdownDataGeneric<ColorSchemes>.GetValues<ColorSchemeData>("ColorScheme");
|
||||
|
||||
public List<string> TimeFormatList { get; } = new()
|
||||
{
|
||||
|
|
@ -167,11 +148,13 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
}
|
||||
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
|
||||
public bool KeepMaxResults
|
||||
{
|
||||
get => Settings.KeepMaxResults;
|
||||
set => Settings.KeepMaxResults = value;
|
||||
}
|
||||
|
||||
public string ClockText => DateTime.Now.ToString(TimeFormat, CultureInfo.CurrentCulture);
|
||||
|
||||
public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture);
|
||||
|
|
@ -188,29 +171,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
set => Settings.UseAnimation = value;
|
||||
}
|
||||
|
||||
public class AnimationSpeed
|
||||
{
|
||||
public string Display { get; set; }
|
||||
public AnimationSpeeds Value { get; set; }
|
||||
}
|
||||
public class AnimationSpeedData : DropdownDataGeneric<AnimationSpeeds> { }
|
||||
public List<AnimationSpeedData> AnimationSpeeds { get; } = DropdownDataGeneric<AnimationSpeeds>.GetValues<AnimationSpeedData>("AnimationSpeed");
|
||||
|
||||
public List<AnimationSpeed> AnimationSpeeds
|
||||
{
|
||||
get
|
||||
{
|
||||
List<AnimationSpeed> speeds = new List<AnimationSpeed>();
|
||||
var enums = (AnimationSpeeds[])Enum.GetValues(typeof(AnimationSpeeds));
|
||||
foreach (var e in enums)
|
||||
{
|
||||
var key = $"AnimationSpeed{e}";
|
||||
var display = InternationalizationManager.Instance.GetTranslation(key);
|
||||
var m = new AnimationSpeed { Display = display, Value = e, };
|
||||
speeds.Add(m);
|
||||
}
|
||||
|
||||
return speeds;
|
||||
}
|
||||
}
|
||||
public bool UseSound
|
||||
{
|
||||
get => Settings.UseSound;
|
||||
|
|
@ -329,7 +292,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
return fontExists switch
|
||||
{
|
||||
true => new FontFamily(Settings.QueryBoxFont),
|
||||
_ => new FontFamily("Segoe UI")
|
||||
_ => new FontFamily(DefaultFont)
|
||||
};
|
||||
}
|
||||
set
|
||||
|
|
@ -373,7 +336,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
return fontExists switch
|
||||
{
|
||||
true => new FontFamily(Settings.ResultFont),
|
||||
_ => new FontFamily("Segoe UI")
|
||||
_ => new FontFamily(DefaultFont)
|
||||
};
|
||||
}
|
||||
set
|
||||
|
|
@ -418,7 +381,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
}
|
||||
else
|
||||
{
|
||||
var font = new FontFamily("Segoe UI");
|
||||
var font = new FontFamily(DefaultFont);
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
|
@ -449,6 +412,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
ThemeManager.Instance.ChangeTheme(Settings.Theme);
|
||||
}
|
||||
}
|
||||
|
||||
public string ThemeImage => Constant.QueryTextBoxIconImagePath;
|
||||
|
||||
[RelayCommand]
|
||||
|
|
@ -473,4 +437,22 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
Settings = settings;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Reset()
|
||||
{
|
||||
SelectedQueryBoxFont = new FontFamily(DefaultFont);
|
||||
SelectedQueryBoxFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
|
||||
QueryBoxFontSize = 20;
|
||||
|
||||
SelectedResultFont = new FontFamily(DefaultFont);
|
||||
SelectedResultFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
|
||||
ResultItemFontSize = 16;
|
||||
|
||||
SelectedResultSubFont = new FontFamily(DefaultFont);
|
||||
SelectedResultSubFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
|
||||
ResultSubItemFontSize = 13;
|
||||
|
||||
WindowHeightSize = 42;
|
||||
ItemHeightSize = 58;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,9 +255,8 @@
|
|||
<Button
|
||||
Margin="8"
|
||||
HorizontalAlignment="Stretch"
|
||||
Click="Reset_Click"
|
||||
Command="{Binding ResetCommand}"
|
||||
Content="{DynamicResource resetCustomize}" />
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
|
|
|||
|
|
@ -30,52 +30,4 @@ public partial class SettingsPaneTheme : Page
|
|||
{
|
||||
_viewModel.UpdateColorScheme();
|
||||
}
|
||||
|
||||
private void Reset_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*The FamilyTypeface should initialize all of its various properties.*/
|
||||
FamilyTypeface targetTypeface = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
|
||||
|
||||
QueryBoxFontSize.Value = 20;
|
||||
QueryBoxFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", QueryBoxFontComboBox);
|
||||
QueryBoxFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, QueryBoxFontStyleComboBox);
|
||||
|
||||
ResultItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultItemFontComboBox);
|
||||
ResultItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultItemFontStyleComboBox);
|
||||
ResultItemFontSize.Value = 16;
|
||||
|
||||
ResultSubItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultSubItemFontComboBox);
|
||||
ResultSubItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultSubItemFontStyleComboBox);
|
||||
ResultSubItemFontSize.Value = 13;
|
||||
|
||||
WindowHeightValue.Value = 42;
|
||||
ItemHeightValue.Value = 58;
|
||||
}
|
||||
|
||||
private int SearchFontIndex(string targetFont, ComboBox combo)
|
||||
{
|
||||
for (int i = 0; i < combo.Items.Count; i++)
|
||||
{
|
||||
if (combo.Items[i]?.ToString() == targetFont)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo)
|
||||
{
|
||||
for (int i = 0; i < combo.Items.Count; i++)
|
||||
{
|
||||
if (combo.Items[i] is FamilyTypeface typefaceItem &&
|
||||
typefaceItem.Stretch == targetTypeface.Stretch &&
|
||||
typefaceItem.Weight == targetTypeface.Weight &&
|
||||
typefaceItem.Style == targetTypeface.Style)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue