11
11
using System . Windows . Media ;
12
12
using System . Windows . Media . Animation ;
13
13
using System . Windows . Media . Imaging ;
14
+ using Newtonsoft . Json . Linq ;
15
+ using System . Xml . Linq ;
14
16
using SoftwareHelper . Helpers ;
17
+ using SoftwareHelper . Models ;
15
18
using SoftwareHelper . ViewModels ;
16
19
using WPFDevelopers . Controls ;
20
+ using static System . Windows . Forms . LinkLabel ;
21
+ using System . IO ;
17
22
18
23
namespace SoftwareHelper . Views
19
24
{
@@ -28,6 +33,8 @@ public partial class EmbedDeasktopView : Window
28
33
private Point anchorPoint ;
29
34
private bool inDrag ;
30
35
private readonly MainVM mainVM ;
36
+ private string filePath ;
37
+ private BitmapSource fileIcon ;
31
38
32
39
public EmbedDeasktopView ( )
33
40
{
@@ -133,6 +140,8 @@ private void EmbedDeasktopView_Loaded(object sender, RoutedEventArgs e)
133
140
private void EmbedDeasktopView_Closing ( object sender , CancelEventArgs e )
134
141
{
135
142
Win32Api . UnRegisterDesktop ( true ) ;
143
+ string json = JsonHelper . Serialize ( mainVM . ApplicationList . Where ( x=> x . IsDrag == true ) . OrderBy ( x => x . Group ) ) ;
144
+ FileHelper . WriteFile ( Common . ConvertJsonString ( json ) , Common . LocalTemporaryApplicationJson ) ;
136
145
}
137
146
138
147
protected override void OnSourceInitialized ( EventArgs e )
@@ -294,16 +303,28 @@ private void UnToggleButtonMini_Checked(object sender, RoutedEventArgs e)
294
303
#endregion
295
304
296
305
297
- private void Grid_DragOver ( object sender , DragEventArgs e )
306
+ private void DragCanvas_DragOver ( object sender , DragEventArgs e )
298
307
{
299
- if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
308
+ try
300
309
{
301
- var msg = ( ( System . Array ) e . Data . GetData ( DataFormats . FileDrop ) ) . GetValue ( 0 ) . ToString ( ) ;
302
- DragTextBlock . Text = System . IO . Path . GetFileName ( msg ) ;
303
- DragImage . Source = ( BitmapSource ) Common . GetIcon ( msg ) ;
304
- var point = e . GetPosition ( this ) ;
305
- Canvas . SetLeft ( DragStackPanel , point . X - DragStackPanel . ActualWidth / 2 ) ;
306
- Canvas . SetTop ( DragStackPanel , point . Y - DragStackPanel . ActualHeight / 2 ) ;
310
+ if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
311
+ {
312
+ var msg = ( ( System . Array ) e . Data . GetData ( DataFormats . FileDrop ) ) . GetValue ( 0 ) . ToString ( ) ;
313
+ filePath = msg ;
314
+ DragTextBlock . Text = System . IO . Path . GetFileName ( filePath ) ;
315
+ var icon = ( BitmapSource ) Common . GetIcon ( filePath ) ;
316
+ fileIcon = icon ;
317
+ DragImage . Source = fileIcon ;
318
+ var point = e . GetPosition ( this ) ;
319
+ var x = point . X - DragStackPanel . ActualWidth / 2 ;
320
+ var y = point . Y - DragStackPanel . ActualHeight / 2 ;
321
+ Canvas . SetLeft ( DragStackPanel , x ) ;
322
+ Canvas . SetTop ( DragStackPanel , y ) ;
323
+ }
324
+ }
325
+ catch ( Exception ex )
326
+ {
327
+ Log . Error ( "DragCanvas_DragOver:" + ex . Message ) ;
307
328
}
308
329
309
330
}
@@ -312,14 +333,26 @@ private void embedDeasktopView_DragEnter(object sender, DragEventArgs e)
312
333
{
313
334
AppSwitchListEmbedded . IsHitTestVisible = false ;
314
335
AppSwitchList . IsHitTestVisible = false ;
315
- DragScaleTransform . ScaleX = 1 ;
316
- DragScaleTransform . ScaleY = 1 ;
336
+ var doubleXAnimation = new DoubleAnimation
337
+ {
338
+ From = 0 ,
339
+ To = 1 ,
340
+ Duration = new Duration ( TimeSpan . FromSeconds ( 0 ) ) ,
341
+ } ;
342
+ DragScaleTransform . BeginAnimation ( ScaleTransform . ScaleXProperty , doubleXAnimation ) ;
343
+ var doubleYAnimation = new DoubleAnimation
344
+ {
345
+ From = 0 ,
346
+ To = 1 ,
347
+ Duration = new Duration ( TimeSpan . FromSeconds ( 0 ) ) ,
348
+ } ;
349
+ DragScaleTransform . BeginAnimation ( ScaleTransform . ScaleYProperty , doubleXAnimation ) ;
317
350
DragCanvas . Visibility = Visibility . Visible ;
318
351
}
319
352
320
353
private void embedDeasktopView_DragLeave ( object sender , DragEventArgs e )
321
354
{
322
- // DragInitial();
355
+ DragInitial ( ) ;
323
356
}
324
357
void DisposeDrag ( )
325
358
{
@@ -329,6 +362,7 @@ void DisposeDrag()
329
362
From = 1 ,
330
363
To = 0 ,
331
364
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
365
+ EasingFunction = new BackEase { EasingMode = EasingMode . EaseIn } ,
332
366
} ;
333
367
Storyboard . SetTargetName ( doubleXAnimation , "DragStackPanel" ) ;
334
368
Storyboard . SetTargetProperty ( doubleXAnimation , new PropertyPath ( "(StackPanel.RenderTransform).(ScaleTransform.ScaleX)" ) ) ;
@@ -337,6 +371,7 @@ void DisposeDrag()
337
371
From = 1 ,
338
372
To = 0 ,
339
373
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
374
+ EasingFunction = new BackEase { EasingMode = EasingMode . EaseIn } ,
340
375
} ;
341
376
Storyboard . SetTargetName ( doubleYAnimation , "DragStackPanel" ) ;
342
377
Storyboard . SetTargetProperty ( doubleYAnimation , new PropertyPath ( "(StackPanel.RenderTransform).(ScaleTransform.ScaleY)" ) ) ;
@@ -345,18 +380,58 @@ void DisposeDrag()
345
380
storyboard . Completed += delegate
346
381
{
347
382
DragInitial ( ) ;
383
+ var model = new ApplicationModel ( ) ;
384
+ model . ExePath = filePath ;
385
+ model . Name = DragTextBlock . Text ;
386
+ var iconPath = System . IO . Path . Combine ( Common . TemporaryIconFile , model . Name ) ;
387
+ iconPath = iconPath + ".png" ;
388
+ model . IconPath = iconPath ;
389
+ model . IsDrag = true ;
390
+ var firstModel = mainVM . ApplicationList . FirstOrDefault ( x => x . Name == model . Name && x . ExePath == model . ExePath ) ;
391
+ if ( firstModel != null ) return ;
392
+ string first = model . Name . Substring ( 0 , 1 ) ;
393
+ if ( ! Common . IsChinese ( first ) )
394
+ {
395
+ if ( char . IsUpper ( first . ToCharArray ( ) [ 0 ] ) )
396
+ model . Group = first ;
397
+ model . Group = model . Name . Substring ( 0 , 1 ) . ToUpper ( ) ;
398
+ }
399
+ else
400
+ {
401
+ model . Group = Common . GetCharSpellCode ( first ) ;
402
+ }
403
+ mainVM . ApplicationList . Insert ( 0 , model ) ;
404
+ if ( File . Exists ( iconPath ) )
405
+ return ;
406
+ Common . SaveImage ( fileIcon , iconPath ) ;
348
407
} ;
349
408
storyboard . Begin ( DragStackPanel ) ;
350
409
}
351
410
void DragInitial ( )
352
411
{
353
- DragCanvas . Visibility = Visibility . Collapsed ;
354
- AppSwitchListEmbedded . IsHitTestVisible = true ;
355
- AppSwitchList . IsHitTestVisible = true ;
412
+ try
413
+ {
414
+ DragCanvas . Visibility = Visibility . Collapsed ;
415
+ AppSwitchListEmbedded . IsHitTestVisible = true ;
416
+ AppSwitchList . IsHitTestVisible = true ;
417
+ }
418
+ catch ( Exception ex )
419
+ {
420
+
421
+ Log . Error ( "DragInitial:" + ex . Message ) ;
422
+ }
356
423
}
357
424
private void DragCanvas_Drop ( object sender , DragEventArgs e )
358
425
{
426
+ if ( string . IsNullOrWhiteSpace ( filePath ) )
427
+ {
428
+ DragInitial ( ) ;
429
+ return ;
430
+ }
359
431
DisposeDrag ( ) ;
360
432
}
433
+
434
+
435
+
361
436
}
362
437
}
0 commit comments