11
2- using Shell ;
32using System ;
3+ using System . ComponentModel ;
44using System . Diagnostics ;
55using System . IO ;
6+ using System . Threading ;
7+ using System . Threading . Tasks ;
68using System . Windows ;
79using System . Windows . Controls ;
810using System . Windows . Input ;
11+ using System . Windows . Interop ;
912using System . Windows . Media ;
1013
14+ using Shell ;
15+
1116namespace EverythingNET
1217{
1318 public partial class View : Window
1419 {
20+ ViewModel ViewModel ;
21+
1522 public View ( )
1623 {
1724 InitializeComponent ( ) ;
18- DataContext = new ViewModel ( ) ;
25+ ViewModel = new ViewModel ( ) ;
26+ DataContext = ViewModel ;
1927 }
2028
2129 void DataGrid_MouseDoubleClick ( object sender , MouseButtonEventArgs e )
@@ -42,7 +50,7 @@ void DataGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
4250 row . IsSelected = true ;
4351 }
4452
45- private void DataGrid_MouseRightButtonUp ( object sender , MouseButtonEventArgs e )
53+ void DataGrid_MouseRightButtonUp ( object sender , MouseButtonEventArgs e )
4654 {
4755 DataGrid grid = sender as DataGrid ;
4856
@@ -55,12 +63,76 @@ private void DataGrid_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
5563 {
5664 ShellContextMenu menu = new ShellContextMenu ( ) ;
5765 FileInfo [ ] files = { new FileInfo ( file ) } ;
58- IntPtr handle = new System . Windows . Interop . WindowInteropHelper ( this ) . Handle ;
66+ IntPtr handle = new WindowInteropHelper ( this ) . Handle ;
5967 Point screenPos = PointToScreen ( Mouse . GetPosition ( this ) ) ;
6068 System . Drawing . Point screenPos2 = new System . Drawing . Point ( ( int ) screenPos . X , ( int ) screenPos . Y ) ;
6169 menu . ShowContextMenu ( handle , files , screenPos2 ) ;
70+ Task . Run ( ( ) => {
71+ Thread . Sleep ( 2000 ) ;
72+ ViewModel . Update ( ) ;
73+ } ) ;
74+ }
75+ }
76+ }
77+
78+ protected override void OnKeyDown ( KeyEventArgs e )
79+ {
80+ base . OnKeyDown ( e ) ;
81+
82+ if ( e . Key == Key . Escape )
83+ Close ( ) ;
84+
85+ if ( e . Key == Key . F1 )
86+ {
87+ using ( var proc = Process . GetCurrentProcess ( ) )
88+ {
89+ string txt = "Everything.NET\n \n Copyright (C) 2020 Frank Skare (stax76)\n \n Version " +
90+ FileVersionInfo . GetVersionInfo ( proc . MainModule . FileName ) . FileVersion . ToString ( ) +
91+ "\n \n " + "MIT License" ;
92+
93+ MessageBox . Show ( txt ) ;
94+ }
95+ }
96+ }
97+
98+ protected override void OnClosing ( CancelEventArgs e )
99+ {
100+ base . OnClosing ( e ) ;
101+
102+ if ( ! string . IsNullOrEmpty ( ViewModel . SearchText ) )
103+ RegistryHelp . SetValue ( RegistryHelp . ApplicationKey , "LastText" , ViewModel . SearchText ) ;
104+ }
105+
106+ protected override void OnStateChanged ( EventArgs e )
107+ {
108+ base . OnStateChanged ( e ) ;
109+
110+ }
111+
112+ void SearchTextBox_PreviewKeyDown ( object sender , KeyEventArgs e )
113+ {
114+ if ( e . Key == Key . Up )
115+ {
116+ string last = RegistryHelp . GetString ( RegistryHelp . ApplicationKey , "LastText" ) ;
117+
118+ if ( ! string . IsNullOrEmpty ( last ) )
119+ {
120+ SearchTextBox . Text = last ;
121+ SearchTextBox . CaretIndex = 1000 ;
62122 }
63123 }
64124 }
125+
126+ void Window_Activated ( object sender , EventArgs e )
127+ {
128+ if ( ! string . IsNullOrEmpty ( ViewModel . SearchText ) )
129+ ViewModel . Update ( ) ;
130+ }
131+
132+ void Window_SizeChanged ( object sender , SizeChangedEventArgs e )
133+ {
134+ NameColumn . Width = ActualWidth * 0.25 ;
135+ DirectoryColumn . Width = ActualWidth * 0.5 ;
136+ }
65137 }
66138}
0 commit comments