44using System ;
55using System . Collections . Generic ;
66using System . Collections . ObjectModel ;
7+ using System . ComponentModel ;
78using System . IO ;
89using System . Linq ;
910using System . Windows ;
1314using System . Windows . Media ;
1415using System . Windows . Media . Animation ;
1516using System . Windows . Media . Imaging ;
17+ using FindDuplicateFiles . Model ;
18+ using FindDuplicateFiles . ViewModel ;
1619
1720namespace FindDuplicateFiles
1821{
@@ -21,21 +24,13 @@ namespace FindDuplicateFiles
2124 /// </summary>
2225 public partial class MainWindow : Window
2326 {
24- /// <summary>
25- /// 已选取的要搜索的文件夹
26- /// </summary>
27- public ObservableCollection < string > SearchFolders { get ; set ; }
2827 /// <summary>
2928 /// 是否正在进行搜索
3029 /// </summary>
3130 private bool _isSearching ;
32- private readonly SearchFilesJob _searchFilesJob = new ( ) ;
33-
34- /// <summary>
35- /// 重复文件集合
36- /// </summary>
37- public ObservableCollection < DuplicateFileInfo > DuplicateFiles { get ; set ; }
3831
32+ private readonly SearchFilesJob _searchFilesJob = new ( ) ;
33+ private readonly MainWindowViewModel _myModel = new ( ) ;
3934 public MainWindow ( )
4035 {
4136 InitializeComponent ( ) ;
@@ -70,7 +65,7 @@ private void InitializeSearchCondition()
7065 ChkIgnoreSmallFile . IsChecked = false ;
7166 RdoAllFile . IsChecked = true ;
7267
73- SearchFolders . Clear ( ) ;
68+ _myModel . SearchFolders . Clear ( ) ;
7469 }
7570 private void InitializeLoadingBlock ( )
7671 {
@@ -84,20 +79,15 @@ private void InitializeLoadingBlock()
8479 RotateTransform rt = new RotateTransform ( ) ;
8580 ImgLoading . RenderTransform = rt ;
8681 rt . BeginAnimation ( RotateTransform . AngleProperty , da ) ;
87- PanelLoading . Height = 0 ;
88- PanelLoading . Margin = new Thickness ( 0 , 0 , 0 , 0 ) ;
8982 }
9083
9184 /// <summary>
9285 /// UI数据绑定
9386 /// </summary>
9487 private void BindingItemsSource ( )
9588 {
96- SearchFolders = new ObservableCollection < string > ( ) ;
97- ListBoxSearchFolders . ItemsSource = SearchFolders ;
98-
99- DuplicateFiles = new ObservableCollection < DuplicateFileInfo > ( ) ;
100- ListViewDuplicateFile . ItemsSource = DuplicateFiles ;
89+ ListBoxSearchFolders . ItemsSource = _myModel . SearchFolders ;
90+ ListViewDuplicateFile . ItemsSource = _myModel . DuplicateFiles ;
10191
10292 CollectionView view = ( CollectionView ) CollectionViewSource . GetDefaultView ( ListViewDuplicateFile . ItemsSource ) ;
10393 PropertyGroupDescription groupDescription = new PropertyGroupDescription ( "Key" ) ;
@@ -106,6 +96,7 @@ private void BindingItemsSource()
10696 RdoOnlyImageFile . ToolTip = $ "仅支持:{ GlobalArgs . AppConfig . ImageExtension } 文件";
10797 RdoOnlyMediaFile . ToolTip = $ "仅支持:{ GlobalArgs . AppConfig . MediaExtension } 文件";
10898 RdoOnlyDocumentFile . ToolTip = $ "仅支持:{ GlobalArgs . AppConfig . DocumentExtension } 文件";
99+ DataContext = _myModel ;
109100 }
110101
111102 /// <summary>
@@ -136,7 +127,7 @@ private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
136127 if ( GridImage . Visibility == Visibility )
137128 {
138129 ImgSelected . Source = null ;
139- GridImage . Visibility = Visibility . Hidden ;
130+ GridImage . Visibility = Visibility . Collapsed ;
140131 }
141132 }
142133
@@ -174,12 +165,11 @@ private void BtnAddSearchFolder_Click(object sender, RoutedEventArgs e)
174165 return ;
175166 }
176167
177- if ( SearchFolders . Contains ( path ) )
168+ if ( _myModel . SearchFolders . Contains ( path ) )
178169 {
179170 return ;
180171 }
181-
182- SearchFolders . Add ( path ) ;
172+ _myModel . SearchFolders . Add ( path ) ;
183173 }
184174
185175 private void BtnRemoveSearchFolder_Click ( object sender , RoutedEventArgs e )
@@ -190,7 +180,7 @@ private void BtnRemoveSearchFolder_Click(object sender, RoutedEventArgs e)
190180 return ;
191181 }
192182
193- SearchFolders . Remove ( tag . ToString ( ) ) ;
183+ _myModel . SearchFolders . Remove ( tag . ToString ( ) ) ;
194184 }
195185
196186 private void BtnSearch_Click ( object sender , RoutedEventArgs e )
@@ -211,7 +201,7 @@ private void BtnSearch_Click(object sender, RoutedEventArgs e)
211201
212202 private void BeginSearch ( )
213203 {
214- if ( SearchFolders . Count == 0 )
204+ if ( _myModel . SearchFolders . Count == 0 )
215205 {
216206 MessageBox . Show ( "请选择要查找的文件夹" , "重复文件查找" , MessageBoxButton . OK , MessageBoxImage . Stop ) ;
217207 return ;
@@ -265,10 +255,10 @@ private void BeginSearch()
265255 }
266256
267257 SetBeginSearchStyle ( ) ;
268- DuplicateFiles . Clear ( ) ;
258+ _myModel . DuplicateFiles . Clear ( ) ;
269259 var config = new SearchConfigs ( )
270260 {
271- Folders = new List < string > ( SearchFolders . ToList ( ) ) ,
261+ Folders = new List < string > ( _myModel . SearchFolders . ToList ( ) ) ,
272262 SearchMatch = searchMatch ,
273263 SearchOption = searchOption
274264 } ;
@@ -280,11 +270,10 @@ private void BeginSearch()
280270 /// </summary>
281271 private void SetBeginSearchStyle ( )
282272 {
283- PanelLoading . Height = 25 ;
284- PanelLoading . Margin = new Thickness ( 5 , 8 , 5 , 8 ) ;
285273 TxtSearch . Text = "停止" ;
286274 ImgSearch . Source = new BitmapImage ( new Uri ( "pack://application:,,,/Images/stop.png" ) ) ;
287275 _isSearching = true ;
276+ _myModel . IsShowLoading = _isSearching ;
288277 }
289278
290279 private void EndSearch ( )
@@ -298,11 +287,10 @@ private void EndSearch()
298287 /// </summary>
299288 private void SetEndSearchStyle ( )
300289 {
301- PanelLoading . Height = 0 ;
302- PanelLoading . Margin = new Thickness ( 0 , 0 , 0 , 0 ) ;
303290 TxtSearch . Text = "开始" ;
304291 ImgSearch . Source = new BitmapImage ( new Uri ( "pack://application:,,,/Images/search.png" ) ) ;
305292 _isSearching = false ;
293+ _myModel . IsShowLoading = _isSearching ;
306294 }
307295
308296 private void BtnReset_Click ( object sender , RoutedEventArgs e )
@@ -354,7 +342,7 @@ private void DuplicateFilesFound(string key, SimpleFileInfo simpleFile)
354342 {
355343 Application . Current . Dispatcher . Invoke ( ( ) =>
356344 {
357- DuplicateFiles . Add ( new DuplicateFileInfo ( )
345+ _myModel . DuplicateFiles . Add ( new DuplicateFileInfo ( )
358346 {
359347 Key = key ,
360348 Name = simpleFile . Name ,
@@ -397,5 +385,15 @@ private void BtnAbout_Click(object sender, RoutedEventArgs e)
397385 } ;
398386 about . Show ( ) ;
399387 }
388+
389+ private void BtnChooseFile_Click ( object sender , RoutedEventArgs e )
390+ {
391+ MessageBox . Show ( "抱歉,该功能暂不可用" , "重复文件查找" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
392+ }
393+
394+ private void BtnDeleteFile_Click ( object sender , RoutedEventArgs e )
395+ {
396+ MessageBox . Show ( "抱歉,该功能暂不可用" , "重复文件查找" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
397+ }
400398 }
401399}
0 commit comments