11using System . Collections . Generic ;
2- using System . IO ;
32using System . Windows ;
43using Microsoft . Win32 ;
54using Flow . Launcher . Core . Plugin ;
@@ -15,6 +14,7 @@ public partial class SearchSourceSettingWindow
1514 private PluginInitContext _context ;
1615 private IPublicAPI _api ;
1716 private SearchSourceViewModel _viewModel ;
17+ private string selectedNewIconImageFullPath ;
1818
1919
2020 public SearchSourceSettingWindow ( IList < SearchSource > sources , PluginInitContext context , SearchSource old )
@@ -39,6 +39,10 @@ private void Initilize(IList<SearchSource> sources, PluginInitContext context, A
3939 _action = action ;
4040 _context = context ;
4141 _api = _context . API ;
42+
43+ _viewModel . SetupCustomImagesDirectory ( ) ;
44+
45+ imgPreviewIcon . Source = _viewModel . LoadPreviewIcon ( _searchSource . IconPath ) ;
4246 }
4347
4448 private void OnCancelButtonClick ( object sender , RoutedEventArgs e )
@@ -111,26 +115,32 @@ private void EditSearchSource()
111115 var warning = _api . GetTranslation ( "newActionKeywordsHasBeenAssigned" ) ;
112116 MessageBox . Show ( warning ) ;
113117 }
118+
119+ if ( ! string . IsNullOrEmpty ( selectedNewIconImageFullPath ) )
120+ {
121+ _viewModel . UpdateIconAttributes ( _searchSource , selectedNewIconImageFullPath ) ;
122+
123+ _viewModel . CopyNewImageToUserDataDirectoryIfRequired (
124+ _searchSource , selectedNewIconImageFullPath , _oldSearchSource . IconPath ) ;
125+ }
114126 }
115127
116128 private void OnSelectIconClick ( object sender , RoutedEventArgs e )
117129 {
118- var directory = Main . ImagesDirectory ;
119130 const string filter = "Image files (*.jpg, *.jpeg, *.gif, *.png, *.bmp) |*.jpg; *.jpeg; *.gif; *.png; *.bmp" ;
120- var dialog = new OpenFileDialog { InitialDirectory = directory , Filter = filter } ;
131+ var dialog = new OpenFileDialog { InitialDirectory = Main . CustomImagesDirectory , Filter = filter } ;
121132
122133 var result = dialog . ShowDialog ( ) ;
123134 if ( result == true )
124135 {
125- var fullpath = dialog . FileName ;
126- if ( ! string . IsNullOrEmpty ( fullpath ) )
136+ selectedNewIconImageFullPath = dialog . FileName ;
137+
138+ if ( ! string . IsNullOrEmpty ( selectedNewIconImageFullPath ) )
127139 {
128- _searchSource . Icon = Path . GetFileName ( fullpath ) ;
129- if ( ! File . Exists ( _searchSource . IconPath ) )
130- {
131- _searchSource . Icon = SearchSource . DefaultIcon ;
132- MessageBox . Show ( $ "The file should be put under { directory } ") ;
133- }
140+ if ( _viewModel . ShouldProvideHint ( selectedNewIconImageFullPath ) )
141+ MessageBox . Show ( _api . GetTranslation ( "flowlauncher_plugin_websearch_iconpath_hint" ) ) ;
142+
143+ imgPreviewIcon . Source = _viewModel . LoadPreviewIcon ( selectedNewIconImageFullPath ) ;
134144 }
135145 }
136146 }
0 commit comments