Skip to content

Commit a545180

Browse files
committed
Workaround for when clicking a button outside TreeView while renaming
1 parent 54da08a commit a545180

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/SQLScriptsExplorer.Addin/Controls/FileExplorerTreeView.xaml.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ private void TreeViewMain_PreviewMouseLeftButtonDown(object sender, MouseButtonE
8989
currentTreeViewItem.DataContext as TreeNode : null;
9090

9191
// 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+
}
9396
}
9497

9598
private void TreeViewMain_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
@@ -333,12 +336,15 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
333336
{
334337
if (string.IsNullOrWhiteSpace(txtRename.Text))
335338
{
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+
}
339346
}
340-
341-
if (currentTreeViewItem != null && renamingNodeFileName != txtRename.Text)
347+
else if (currentTreeViewItem != null && renamingNodeFileName != txtRename.Text)
342348
{
343349
var renamingTreeNode = DataSourceDictionary[renamingNodeId];
344350

@@ -403,13 +409,5 @@ private void txtRename_LostFocus(object sender, RoutedEventArgs e)
403409
MessageBox.Show(ex.Message);
404410
}
405411
}
406-
407-
private void ApplyRenaming()
408-
{
409-
if (currentTreeNode != null && isEditMode && currentTreeNode.Id != renamingNodeId)
410-
{
411-
txtRename_LostFocus(null, null);
412-
}
413-
}
414412
}
415413
}

0 commit comments

Comments
 (0)