@@ -52,19 +52,21 @@ void DataGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
52
52
53
53
void DataGrid_MouseRightButtonUp ( object sender , MouseButtonEventArgs e )
54
54
{
55
- DataGrid grid = sender as DataGrid ;
55
+ ShowMenu ( PointToScreen ( Mouse . GetPosition ( this ) ) ) ;
56
+ }
56
57
57
- if ( grid . SelectedItem != null )
58
+ void ShowMenu ( Point screenPos )
59
+ {
60
+ if ( DG . SelectedItem != null )
58
61
{
59
- Item item = grid . SelectedItem as Item ;
62
+ Item item = DG . SelectedItem as Item ;
60
63
string file = Path . Combine ( item . Directory , item . Name ) ;
61
64
62
65
if ( File . Exists ( file ) )
63
66
{
64
67
ShellContextMenu menu = new ShellContextMenu ( ) ;
65
68
FileInfo [ ] files = { new FileInfo ( file ) } ;
66
69
IntPtr handle = new WindowInteropHelper ( this ) . Handle ;
67
- Point screenPos = PointToScreen ( Mouse . GetPosition ( this ) ) ;
68
70
System . Drawing . Point screenPos2 = new System . Drawing . Point ( ( int ) screenPos . X , ( int ) screenPos . Y ) ;
69
71
menu . ShowContextMenu ( handle , files , screenPos2 ) ;
70
72
Task . Run ( ( ) => {
@@ -103,15 +105,9 @@ protected override void OnClosing(CancelEventArgs e)
103
105
RegistryHelp . SetValue ( RegistryHelp . ApplicationKey , "LastText" , ViewModel . SearchText ) ;
104
106
}
105
107
106
- protected override void OnStateChanged ( EventArgs e )
107
- {
108
- base . OnStateChanged ( e ) ;
109
-
110
- }
111
-
112
108
void SearchTextBox_PreviewKeyDown ( object sender , KeyEventArgs e )
113
109
{
114
- if ( e . Key == Key . Up )
110
+ if ( e . Key == Key . Up && SearchTextBox . Text == "" )
115
111
{
116
112
string last = RegistryHelp . GetString ( RegistryHelp . ApplicationKey , "LastText" ) ;
117
113
@@ -121,6 +117,50 @@ void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
121
117
SearchTextBox . CaretIndex = 1000 ;
122
118
}
123
119
}
120
+
121
+ if ( DG . Items . Count > 0 )
122
+ {
123
+ if ( e . Key == Key . Up )
124
+ {
125
+ int index = DG . SelectedIndex ;
126
+ index -- ;
127
+
128
+ if ( index < 0 )
129
+ index = 0 ;
130
+
131
+ DG . SelectedIndex = index ;
132
+ }
133
+
134
+ if ( e . Key == Key . Down )
135
+ {
136
+ int index = DG . SelectedIndex ;
137
+ index ++ ;
138
+
139
+ if ( index > DG . Items . Count - 1 )
140
+ index = DG . Items . Count - 1 ;
141
+
142
+ DG . SelectedIndex = index ;
143
+ }
144
+ }
145
+
146
+ if ( e . Key == Key . Apps )
147
+ {
148
+ Application . Current . Dispatcher . InvokeAsync ( ( ) => {
149
+ ShowMenu ( PointToScreen ( new Point ( 0d , 0d ) ) ) ;
150
+ } ) ;
151
+ }
152
+ }
153
+
154
+ IntPtr WndProc ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
155
+ {
156
+ if ( msg == 0x104 && ( Keyboard . IsKeyDown ( Key . LeftShift ) || Keyboard . IsKeyDown ( Key . RightShift ) ) )
157
+ {
158
+ Application . Current . Dispatcher . InvokeAsync ( ( ) => {
159
+ ShowMenu ( PointToScreen ( new Point ( 0d , 0d ) ) ) ;
160
+ } ) ;
161
+ }
162
+
163
+ return IntPtr . Zero ;
124
164
}
125
165
126
166
void Window_Activated ( object sender , EventArgs e )
@@ -134,5 +174,11 @@ void Window_SizeChanged(object sender, SizeChangedEventArgs e)
134
174
NameColumn . Width = ActualWidth * 0.25 ;
135
175
DirectoryColumn . Width = ActualWidth * 0.5 ;
136
176
}
177
+
178
+ void Window_Loaded ( object sender , RoutedEventArgs e )
179
+ {
180
+ HwndSource source = HwndSource . FromHwnd ( new WindowInteropHelper ( this ) . Handle ) ;
181
+ source . AddHook ( new HwndSourceHook ( WndProc ) ) ;
182
+ }
137
183
}
138
184
}
0 commit comments