diff --git a/src/Views/Widgets/WorkingCopyChanges.xaml.cs b/src/Views/Widgets/WorkingCopyChanges.xaml.cs index b95698d1..99389b2b 100644 --- a/src/Views/Widgets/WorkingCopyChanges.xaml.cs +++ b/src/Views/Widgets/WorkingCopyChanges.xaml.cs @@ -122,20 +122,20 @@ namespace SourceGit.Views.Widgets { } public void StageSelected() { - var files = new List(); + var changes = new List(); switch (Mode) { case Models.Change.DisplayMode.Tree: - var changes = new List(); foreach (var node in modeTree.Selected) GetChangesFromNode(node as ChangeNode, changes); - foreach (var c in changes) files.Add(c.Path); break; case Models.Change.DisplayMode.List: - foreach (var c in modeList.SelectedItems) files.Add((c as Models.Change).Path); + foreach (var c in modeList.SelectedItems) changes.Add(c as Models.Change); break; case Models.Change.DisplayMode.Grid: - foreach (var c in modeGrid.SelectedItems) files.Add((c as Models.Change).Path); + foreach (var c in modeGrid.SelectedItems) changes.Add(c as Models.Change); break; } + + var files = GetPathsFromChanges(changes); if (files.Count > 0) DoStage(files); } @@ -144,20 +144,20 @@ namespace SourceGit.Views.Widgets { } public void UnstageSelected() { - var files = new List(); + var changes = new List(); switch (Mode) { case Models.Change.DisplayMode.Tree: - var changes = new List(); foreach (var node in modeTree.Selected) GetChangesFromNode(node as ChangeNode, changes); - foreach (var c in changes) files.Add(c.Path); break; case Models.Change.DisplayMode.List: - foreach (var c in modeList.SelectedItems) files.Add((c as Models.Change).Path); + foreach (var c in modeList.SelectedItems) changes.Add(c as Models.Change); break; case Models.Change.DisplayMode.Grid: - foreach (var c in modeGrid.SelectedItems) files.Add((c as Models.Change).Path); + foreach (var c in modeGrid.SelectedItems) changes.Add(c as Models.Change); break; } + + var files = GetPathsFromChanges(changes); if (files.Count > 0) DoUnstage(files); } @@ -285,6 +285,15 @@ namespace SourceGit.Views.Widgets { foreach (var sub in node.Children) GetChangesFromNode(sub, changes); } } + + private List GetPathsFromChanges(List changes) { + var files = new List(); + foreach (var c in changes) { + files.Add(c.Path); + if (!string.IsNullOrEmpty(c.OriginalPath)) files.Add(c.OriginalPath); + } + return files; + } #endregion #region UNSTAGED @@ -582,8 +591,7 @@ namespace SourceGit.Views.Widgets { } private void OpenStagedContextMenuByNodes(ContextMenu menu, List nodes, List changes) { - var files = new List(); - foreach (var c in changes) files.Add(c.Path); + var files = GetPathsFromChanges(changes); if (nodes.Count == 1) { var node = nodes[0]; @@ -624,8 +632,7 @@ namespace SourceGit.Views.Widgets { } private void OpenStagedContextMenuByChanges(ContextMenu menu, List changes) { - var files = new List(); - foreach (var c in changes) files.Add(c.Path); + var files = GetPathsFromChanges(changes); if (changes.Count == 1) { var change = changes[0];