Skip to content

Commit dc590ad

Browse files
committed
Add Icon theme preview
1 parent 9e879a8 commit dc590ad

File tree

5 files changed

+73
-17
lines changed

5 files changed

+73
-17
lines changed

Flow.Launcher.Plugin.OneNote/Icons/IconConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ public static class IconConstants
55
public const string ImagesDirectory = "Images/";
66
public const string GeneratedImagesDirectory = $"{ImagesDirectory}Generated/";
77

8+
public const string Logo = "logo";
9+
810
public const string Notebook = "notebook";
911
public const string SectionGroup = "section_group";
1012
public const string RecycleBin = "recycle_bin";
1113
public const string Section = "section";
1214
public const string Page = "page";
1315

14-
public const string Logo = "logo";
1516
public const string Sync = "sync";
1617
public const string Search = "search";
1718
public const string Recent = "page_recent";

Flow.Launcher.Plugin.OneNote/Icons/IconProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void OnIconThemeChanged(object sender, PropertyChangedEventArgs args)
7676
}
7777
}
7878

79-
private string GetIconLocal(string icon) => $"Images/{icon}.{GetIconThemeString(settings.IconTheme)}.png";
79+
private string GetIconLocal(string icon) => $"{IC.ImagesDirectory}{icon}.{GetIconThemeString(settings.IconTheme)}.png";
8080

8181
private string GetIconThemeString(IconTheme iconTheme)
8282
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Linq;
3+
using Flow.Launcher.Plugin.OneNote.Icons;
4+
5+
namespace Flow.Launcher.Plugin.OneNote.UI.ViewModels
6+
{
7+
public class IconThemeViewModel
8+
{
9+
private IconThemeViewModel(IconTheme iconTheme, PluginInitContext context)
10+
{
11+
IconTheme = iconTheme;
12+
string iconThemeString;
13+
if (iconTheme == IconTheme.System)
14+
{
15+
//TODO: Implement this
16+
iconThemeString = Enum.GetName(IconTheme.Light).ToLower();
17+
//ThemeManager.Current.ActualApplicationTheme
18+
Tooltip = "Match the system theme";
19+
}
20+
else
21+
{
22+
iconThemeString = Enum.GetName(iconTheme).ToLower();
23+
}
24+
ImageUri = new Uri(
25+
$"{context.CurrentPluginMetadata.PluginDirectory}/{IconConstants.ImagesDirectory}{IconConstants.Notebook}.{iconThemeString}.png");
26+
}
27+
28+
public IconTheme IconTheme { get; }
29+
public Uri ImageUri { get; }
30+
public string Tooltip { get; }
31+
32+
public static IconThemeViewModel[] GetIconThemeViewModels(PluginInitContext context) =>
33+
Enum.GetValues<IconTheme>().Select(iconTheme => new IconThemeViewModel(iconTheme, context)).ToArray();
34+
}
35+
36+
}

Flow.Launcher.Plugin.OneNote/UI/ViewModels/SettingsViewModel.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Linq;
2+
using System.Threading.Tasks;
23
using System.Windows.Input;
34
using Flow.Launcher.Plugin.OneNote.Icons;
45
using Modern = ModernWpf.Controls;
@@ -12,9 +13,10 @@ public class SettingsViewModel : Model
1213

1314
public SettingsViewModel(PluginInitContext context, Settings settings, IconProvider iconProvider)
1415
{
15-
Settings = settings;
16-
Keywords = KeywordViewModel.GetKeywordViewModels(settings.Keywords);
1716
this.iconProvider = iconProvider;
17+
Settings = settings;
18+
Keywords = KeywordViewModel.GetKeywordViewModels(settings.Keywords);
19+
IconThemes = IconThemeViewModel.GetIconThemeViewModels(context);
1820

1921
EditCommand = new RelayCommand(
2022
_ => new Views.ChangeKeywordWindow(this, context).ShowDialog(), //Avert your eyes! This is not MVVM!
@@ -42,14 +44,15 @@ public SettingsViewModel(PluginInitContext context, Settings settings, IconProvi
4244
public ICommand ClearCachedIconsCommand { get; }
4345
public Settings Settings { get; }
4446
public KeywordViewModel[] Keywords { get; }
47+
public IconThemeViewModel[] IconThemes { get; }
4548
public string CachedIconsFileSize => iconProvider.GetCachedIconsMemorySize();
4649

4750
public KeywordViewModel SelectedKeyword
4851
{
4952
get => selectedKeyword;
5053
set => SetProperty(ref selectedKeyword, value);
5154
}
52-
55+
5356
//quick and dirty non MVVM stuffs
5457
private async Task ClearCachedIcons()
5558
{

Flow.Launcher.Plugin.OneNote/UI/Views/SettingsView.xaml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:icon="clr-namespace:Flow.Launcher.Plugin.OneNote.Icons"
76
xmlns:linq="clr-namespace:System.Linq;assembly=System.Core"
87
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
98
xmlns:sys="clr-namespace:System;assembly=mscorlib"
@@ -20,14 +19,6 @@
2019
<ui:ThemeResources />
2120
<ResourceDictionary Source="/Flow.Launcher.Plugin.OneNote;component/UI/Styles.xaml" />
2221
</ResourceDictionary.MergedDictionaries>
23-
<ObjectDataProvider
24-
x:Key="IconThemeEnumDataSource"
25-
MethodName="GetValues"
26-
ObjectType="{x:Type sys:Enum}">
27-
<ObjectDataProvider.MethodParameters>
28-
<x:Type TypeName="icon:IconTheme" />
29-
</ObjectDataProvider.MethodParameters>
30-
</ObjectDataProvider>
3122
<ObjectDataProvider
3223
x:Key="DefaultRecentCountOptions"
3324
MethodName="Range"
@@ -126,8 +117,33 @@
126117
Width="100"
127118
Margin="10,0,18,0"
128119
HorizontalContentAlignment="Center"
129-
ItemsSource="{Binding Source={StaticResource IconThemeEnumDataSource}}"
130-
SelectedItem="{Binding Settings.IconTheme}" />
120+
ItemsSource="{Binding IconThemes}"
121+
SelectedValue="{Binding Settings.IconTheme}"
122+
SelectedValuePath="IconTheme">
123+
<ComboBox.ItemTemplate>
124+
<DataTemplate DataType="{x:Type vm:IconThemeViewModel}">
125+
<StackPanel Orientation="Horizontal" ToolTip="{Binding Tooltip}">
126+
<Image
127+
x:Name="ImageIcon"
128+
Width="32"
129+
UseLayoutRounding="True"
130+
SnapsToDevicePixels="True"
131+
Height="32"
132+
Source="{Binding ImageUri}" />
133+
<TextBlock
134+
x:Name="TextBlockIconTheme"
135+
Margin="8,0,0,0"
136+
VerticalAlignment="Center"
137+
Text="{Binding IconTheme}" />
138+
</StackPanel>
139+
<DataTemplate.Triggers>
140+
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBoxItem}}" Value="{x:Null}">
141+
<Setter TargetName="ImageIcon" Property="Visibility" Value="Collapsed" />
142+
</DataTrigger>
143+
</DataTemplate.Triggers>
144+
</DataTemplate>
145+
</ComboBox.ItemTemplate>
146+
</ComboBox>
131147
<ui:FontIcon Glyph="&#xe790;" Style="{StaticResource Glyph}" />
132148
</ItemsControl>
133149
</Border>

0 commit comments

Comments
 (0)