@@ -89,7 +89,10 @@ private void TreeViewMain_PreviewMouseLeftButtonDown(object sender, MouseButtonE
89
89
currentTreeViewItem . DataContext as TreeNode : null ;
90
90
91
91
// In case changing focus to a different node while renaming file
92
- ApplyRenaming ( ) ;
92
+ if ( currentTreeNode != null && isEditMode && currentTreeNode . Id != renamingNodeId )
93
+ {
94
+ txtRename_LostFocus ( null , null ) ;
95
+ }
93
96
}
94
97
95
98
private void TreeViewMain_PreviewMouseRightButtonDown ( object sender , MouseButtonEventArgs e )
@@ -333,12 +336,15 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
333
336
{
334
337
if ( string . IsNullOrWhiteSpace ( txtRename . Text ) )
335
338
{
336
- MessageBox . Show ( "Please enter a file name." ) ;
337
- txtRename . Text = lblRename . Text = renamingNodeFileName ;
338
- return ;
339
+ // TODO: Workaround for when clicking a button outside TreeView
340
+ if ( currentTreeViewItem != null && ! currentTreeViewItem . DataContext . ToString ( ) . Equals ( "{DisconnectedItem}" ) )
341
+ {
342
+ MessageBox . Show ( "Please enter a file name." ) ;
343
+ txtRename . Text = lblRename . Text = renamingNodeFileName ;
344
+ return ;
345
+ }
339
346
}
340
-
341
- if ( currentTreeViewItem != null && renamingNodeFileName != txtRename . Text )
347
+ else if ( currentTreeViewItem != null && renamingNodeFileName != txtRename . Text )
342
348
{
343
349
var renamingTreeNode = DataSourceDictionary [ renamingNodeId ] ;
344
350
@@ -403,13 +409,5 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
403
409
MessageBox . Show ( ex . Message ) ;
404
410
}
405
411
}
406
-
407
- private void ApplyRenaming ( )
408
- {
409
- if ( currentTreeNode != null && isEditMode && currentTreeNode . Id != renamingNodeId )
410
- {
411
- txtRename_LostFocus ( null , null ) ;
412
- }
413
- }
414
412
}
415
413
}
0 commit comments