Skip to content

Commit 6cb2cc3

Browse files
committed
update to WebSearch's custom icon image save behaviour
Load icon image preview on select and only save changes on confirm
1 parent 203df8f commit 6cb2cc3

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSource.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public string IconPath
3434
}
3535
}
3636

37-
[JsonIgnore]
38-
public ImageSource Image => ImageLoader.Load(IconPath);
39-
40-
internal void NotifyImageChange() => OnPropertyChanged(nameof(Image));
41-
4237
public string Url { get; set; }
4338
public bool Enabled { get; set; }
4439

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<TextBlock Margin="10" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center"
4848
HorizontalAlignment="Right" Text="{DynamicResource flowlauncher_plugin_websearch_icon}" />
4949
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" Margin="10">
50-
<Image Source="{Binding SearchSource.Image ,IsAsync=True}" Width="24" Height="24" Margin="0 0 20 0" />
50+
<Image Name="imgPreviewIcon" Width="24" Height="24" Margin="0 0 20 0" />
5151
<Button Click="OnSelectIconClick" Height="35"
5252
Content="{DynamicResource flowlauncher_plugin_websearch_select_icon}" />
5353
</StackPanel>

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class SearchSourceSettingWindow
1414
private PluginInitContext _context;
1515
private IPublicAPI _api;
1616
private SearchSourceViewModel _viewModel;
17+
private string selectedNewIconImageFullPath;
1718

1819

1920
public SearchSourceSettingWindow(IList<SearchSource> sources, PluginInitContext context, SearchSource old)
@@ -40,6 +41,8 @@ private void Initilize(IList<SearchSource> sources, PluginInitContext context, A
4041
_api = _context.API;
4142

4243
_viewModel.SetupCustomImagesDirectory();
44+
45+
imgPreviewIcon.Source = _viewModel.LoadPreviewIcon(_searchSource.IconPath);
4346
}
4447

4548
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
@@ -112,6 +115,14 @@ private void EditSearchSource()
112115
var warning = _api.GetTranslation("newActionKeywordsHasBeenAssigned");
113116
MessageBox.Show(warning);
114117
}
118+
119+
if (!string.IsNullOrEmpty(selectedNewIconImageFullPath))
120+
{
121+
_viewModel.UpdateIconAttributes(_searchSource, selectedNewIconImageFullPath);
122+
123+
_viewModel.CopyNewImageToUserDataDirectoryIfRequired(
124+
_searchSource, selectedNewIconImageFullPath, _oldSearchSource.IconPath);
125+
}
115126
}
116127

117128
private void OnSelectIconClick(object sender, RoutedEventArgs e)
@@ -122,17 +133,14 @@ private void OnSelectIconClick(object sender, RoutedEventArgs e)
122133
var result = dialog.ShowDialog();
123134
if (result == true)
124135
{
125-
var fullpathToSelectedImage = dialog.FileName;
126-
127-
if (_viewModel.ShouldProvideHint(fullpathToSelectedImage))
128-
MessageBox.Show(_api.GetTranslation("flowlauncher_plugin_websearch_iconpath_hint"));
136+
selectedNewIconImageFullPath = dialog.FileName;
129137

130-
if (!string.IsNullOrEmpty(fullpathToSelectedImage))
138+
if (!string.IsNullOrEmpty(selectedNewIconImageFullPath))
131139
{
132-
var fullPathToOriginalImage = _searchSource.IconPath;
133-
_viewModel.UpdateIconAttributes(_searchSource, fullpathToSelectedImage);
134-
_viewModel.CopyNewImageToUserDataDirectoryIfRequired(
135-
_searchSource, fullpathToSelectedImage, fullPathToOriginalImage);
140+
if (_viewModel.ShouldProvideHint(selectedNewIconImageFullPath))
141+
MessageBox.Show(_api.GetTranslation("flowlauncher_plugin_websearch_iconpath_hint"));
142+
143+
imgPreviewIcon.Source = _viewModel.LoadPreviewIcon(selectedNewIconImageFullPath);
136144
}
137145
}
138146
}

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using Flow.Launcher.Infrastructure.Image;
12
using System;
3+
using System.Drawing;
24
using System.IO;
5+
using System.Windows.Media;
36

47
namespace Flow.Launcher.Plugin.WebSearch
58
{
@@ -40,8 +43,6 @@ public void CopyNewImageToUserDataDirectoryIfRequired(
4043
#endif
4144
}
4245
}
43-
44-
selectedSearchSource.NotifyImageChange();
4546
}
4647

4748
internal void SetupCustomImagesDirectory()
@@ -54,5 +55,10 @@ internal bool ShouldProvideHint(string fullPathToSelectedImage)
5455
{
5556
return Directory.GetParent(fullPathToSelectedImage).ToString() == Main.DefaultImagesDirectory;
5657
}
58+
59+
internal ImageSource LoadPreviewIcon(string pathToPreviewIconImage)
60+
{
61+
return ImageLoader.Load(pathToPreviewIconImage);
62+
}
5763
}
5864
}

0 commit comments

Comments
 (0)