1
1
using System . Collections . Generic ;
2
- using System . IO ;
3
2
using System . Windows ;
4
3
using Microsoft . Win32 ;
5
4
using Flow . Launcher . Core . Plugin ;
@@ -15,6 +14,7 @@ public partial class SearchSourceSettingWindow
15
14
private PluginInitContext _context ;
16
15
private IPublicAPI _api ;
17
16
private SearchSourceViewModel _viewModel ;
17
+ private string selectedNewIconImageFullPath ;
18
18
19
19
20
20
public SearchSourceSettingWindow ( IList < SearchSource > sources , PluginInitContext context , SearchSource old )
@@ -39,6 +39,10 @@ private void Initilize(IList<SearchSource> sources, PluginInitContext context, A
39
39
_action = action ;
40
40
_context = context ;
41
41
_api = _context . API ;
42
+
43
+ _viewModel . SetupCustomImagesDirectory ( ) ;
44
+
45
+ imgPreviewIcon . Source = _viewModel . LoadPreviewIcon ( _searchSource . IconPath ) ;
42
46
}
43
47
44
48
private void OnCancelButtonClick ( object sender , RoutedEventArgs e )
@@ -111,26 +115,32 @@ private void EditSearchSource()
111
115
var warning = _api . GetTranslation ( "newActionKeywordsHasBeenAssigned" ) ;
112
116
MessageBox . Show ( warning ) ;
113
117
}
118
+
119
+ if ( ! string . IsNullOrEmpty ( selectedNewIconImageFullPath ) )
120
+ {
121
+ _viewModel . UpdateIconAttributes ( _searchSource , selectedNewIconImageFullPath ) ;
122
+
123
+ _viewModel . CopyNewImageToUserDataDirectoryIfRequired (
124
+ _searchSource , selectedNewIconImageFullPath , _oldSearchSource . IconPath ) ;
125
+ }
114
126
}
115
127
116
128
private void OnSelectIconClick ( object sender , RoutedEventArgs e )
117
129
{
118
- var directory = Main . ImagesDirectory ;
119
130
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 } ;
121
132
122
133
var result = dialog . ShowDialog ( ) ;
123
134
if ( result == true )
124
135
{
125
- var fullpath = dialog . FileName ;
126
- if ( ! string . IsNullOrEmpty ( fullpath ) )
136
+ selectedNewIconImageFullPath = dialog . FileName ;
137
+
138
+ if ( ! string . IsNullOrEmpty ( selectedNewIconImageFullPath ) )
127
139
{
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 ) ;
134
144
}
135
145
}
136
146
}
0 commit comments