optimize<ContextMenu>: do NOT show popup animation

This commit is contained in:
leo 2021-04-29 22:35:02 +08:00
parent ee8efa5c47
commit 50ad4a0278
4 changed files with 28 additions and 30 deletions

View file

@ -104,4 +104,6 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<PopupAnimation x:Key="{x:Static SystemParameters.MenuPopupAnimationKey}">None</PopupAnimation>
</ResourceDictionary> </ResourceDictionary>

View file

@ -80,10 +80,10 @@ namespace SourceGit.Views.Widgets {
return; return;
} }
Diff(repo, opt, false); Diff(repo, opt);
} }
public void Diff(string repo, Option opt, bool clearEditor = true) { public void Diff(string repo, Option opt) {
mask.Visibility = Visibility.Collapsed; mask.Visibility = Visibility.Collapsed;
noChange.Visibility = Visibility.Collapsed; noChange.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Collapsed; sizeChange.Visibility = Visibility.Collapsed;
@ -92,7 +92,6 @@ namespace SourceGit.Views.Widgets {
loading.IsAnimating = true; loading.IsAnimating = true;
SetTitle(opt.Path, opt.OrgPath); SetTitle(opt.Path, opt.OrgPath);
if (clearEditor) ClearEditor();
ClearCache(); ClearCache();
this.repo = repo; this.repo = repo;
@ -390,6 +389,8 @@ namespace SourceGit.Views.Widgets {
private DataGrid CreateTextEditor(string[] lineNumbers) { private DataGrid CreateTextEditor(string[] lineNumbers) {
var grid = new DataGrid(); var grid = new DataGrid();
grid.EnableRowVirtualization = true;
grid.EnableColumnVirtualization = true;
grid.RowHeight = 16.0; grid.RowHeight = 16.0;
grid.FrozenColumnCount = lineNumbers.Length; grid.FrozenColumnCount = lineNumbers.Length;
grid.ContextMenuOpening += OnTextDiffContextMenuOpening; grid.ContextMenuOpening += OnTextDiffContextMenuOpening;

View file

@ -99,6 +99,12 @@ namespace SourceGit.Views.Widgets {
if (e.Target == null) { if (e.Target == null) {
if (e.HasOthers) { if (e.HasOthers) {
if (container.IsUnstaged) {
stagedContainer.UnselectAll();
} else {
unstagedContainer.UnselectAll();
}
mergePanel.Visibility = Visibility.Collapsed; mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset(); diffViewer.Reset();
} }
@ -106,15 +112,14 @@ namespace SourceGit.Views.Widgets {
return; return;
} }
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
var change = e.Target; var change = e.Target;
if (change.IsConflit) { if (change.IsConflit) {
mergePanel.Visibility = Visibility.Visible; mergePanel.Visibility = Visibility.Visible;
return; return;
} }
mergePanel.Visibility = Visibility.Collapsed;
if (change.IsAddedToIndex) { if (change.IsAddedToIndex) {
unstagedContainer.UnselectAll(); unstagedContainer.UnselectAll();

View file

@ -319,11 +319,10 @@ namespace SourceGit.Views.Widgets {
stream.Close(); stream.Close();
} }
private void OpenUnstagedContextMenuByNodes(List<ChangeNode> nodes, List<Models.Change> changes) { private void OpenUnstagedContextMenuByNodes(ContextMenu menu, List<ChangeNode> nodes, List<Models.Change> changes) {
var files = new List<string>(); var files = new List<string>();
foreach (var c in changes) files.Add(c.Path); foreach (var c in changes) files.Add(c.Path);
var menu = new ContextMenu();
if (nodes.Count == 1) { if (nodes.Count == 1) {
var node = nodes[0]; var node = nodes[0];
var path = Path.GetFullPath(Path.Combine(repo, node.Path)); var path = Path.GetFullPath(Path.Combine(repo, node.Path));
@ -441,15 +440,12 @@ namespace SourceGit.Views.Widgets {
menu.Items.Add(stash); menu.Items.Add(stash);
menu.Items.Add(patch); menu.Items.Add(patch);
} }
menu.IsOpen = true;
} }
private void OpenUnstagedContextMenuByChanges(List<Models.Change> changes) { private void OpenUnstagedContextMenuByChanges(ContextMenu menu, List<Models.Change> changes) {
var files = new List<string>(); var files = new List<string>();
foreach (var c in changes) files.Add(c.Path); foreach (var c in changes) files.Add(c.Path);
var menu = new ContextMenu();
if (changes.Count == 1) { if (changes.Count == 1) {
var change = changes[0]; var change = changes[0];
var path = Path.GetFullPath(Path.Combine(repo, change.Path)); var path = Path.GetFullPath(Path.Combine(repo, change.Path));
@ -566,8 +562,6 @@ namespace SourceGit.Views.Widgets {
menu.Items.Add(stash); menu.Items.Add(stash);
menu.Items.Add(patch); menu.Items.Add(patch);
} }
menu.IsOpen = true;
} }
#endregion #endregion
@ -587,11 +581,10 @@ namespace SourceGit.Views.Widgets {
Models.Watcher.Get(repo)?.RefreshWC(); Models.Watcher.Get(repo)?.RefreshWC();
} }
private void OpenStagedContextMenuByNodes(List<ChangeNode> nodes, List<Models.Change> changes) { private void OpenStagedContextMenuByNodes(ContextMenu menu, List<ChangeNode> nodes, List<Models.Change> changes) {
var files = new List<string>(); var files = new List<string>();
foreach (var c in changes) files.Add(c.Path); foreach (var c in changes) files.Add(c.Path);
var menu = new ContextMenu();
if (nodes.Count == 1) { if (nodes.Count == 1) {
var node = nodes[0]; var node = nodes[0];
var path = Path.GetFullPath(Path.Combine(repo, node.Path)); var path = Path.GetFullPath(Path.Combine(repo, node.Path));
@ -628,15 +621,12 @@ namespace SourceGit.Views.Widgets {
menu.Items.Add(unstage); menu.Items.Add(unstage);
} }
menu.IsOpen = true;
} }
private void OpenStagedContextMenuByChanges(List<Models.Change> changes) { private void OpenStagedContextMenuByChanges(ContextMenu menu, List<Models.Change> changes) {
var files = new List<string>(); var files = new List<string>();
foreach (var c in changes) files.Add(c.Path); foreach (var c in changes) files.Add(c.Path);
var menu = new ContextMenu();
if (changes.Count == 1) { if (changes.Count == 1) {
var change = changes[0]; var change = changes[0];
var path = Path.GetFullPath(Path.Combine(repo, change.Path)); var path = Path.GetFullPath(Path.Combine(repo, change.Path));
@ -678,7 +668,6 @@ namespace SourceGit.Views.Widgets {
menu.Items.Add(unstage); menu.Items.Add(unstage);
} }
menu.IsOpen = true;
} }
#endregion #endregion
@ -696,7 +685,6 @@ namespace SourceGit.Views.Widgets {
} else if (modeTree.Selected.Count == 1) { } else if (modeTree.Selected.Count == 1) {
var node = modeTree.Selected[0] as ChangeNode; var node = modeTree.Selected[0] as ChangeNode;
if (node.IsFolder) { if (node.IsFolder) {
if (DiffTarget == null) return;
DiffTarget = null; DiffTarget = null;
hasOthers = true; hasOthers = true;
} else { } else {
@ -760,12 +748,14 @@ namespace SourceGit.Views.Widgets {
GetChangesFromNode(o as ChangeNode, changes); GetChangesFromNode(o as ChangeNode, changes);
} }
var menu = new ContextMenu();
if (IsUnstaged) { if (IsUnstaged) {
OpenUnstagedContextMenuByNodes(nodes, changes); OpenUnstagedContextMenuByNodes(menu, nodes, changes);
} else { } else {
OpenStagedContextMenuByNodes(nodes, changes); OpenStagedContextMenuByNodes(menu, nodes, changes);
} }
menu.IsOpen = true;
ev.Handled = true; ev.Handled = true;
} }
@ -776,28 +766,28 @@ namespace SourceGit.Views.Widgets {
var changes = new List<Models.Change>(); var changes = new List<Models.Change>();
if (Mode == Models.Change.DisplayMode.List) { if (Mode == Models.Change.DisplayMode.List) {
if (!row.IsSelected) { if (!row.IsSelected) {
modeList.SelectedItems.Clear(); modeList.SelectedItem = row.DataContext;
modeList.SelectedItems.Add(row.DataContext);
changes.Add(row.DataContext as Models.Change); changes.Add(row.DataContext as Models.Change);
} else { } else {
foreach (var c in modeList.SelectedItems) changes.Add(c as Models.Change); foreach (var c in modeList.SelectedItems) changes.Add(c as Models.Change);
} }
} else { } else {
if (!row.IsSelected) { if (!row.IsSelected) {
modeGrid.SelectedItems.Clear(); modeGrid.SelectedItem = row.DataContext;
modeGrid.SelectedItems.Add(row.DataContext);
changes.Add(row.DataContext as Models.Change); changes.Add(row.DataContext as Models.Change);
} else { } else {
foreach (var c in modeGrid.SelectedItems) changes.Add(c as Models.Change); foreach (var c in modeGrid.SelectedItems) changes.Add(c as Models.Change);
} }
} }
var menu = new ContextMenu();
if (IsUnstaged) { if (IsUnstaged) {
OpenUnstagedContextMenuByChanges(changes); OpenUnstagedContextMenuByChanges(menu, changes);
} else { } else {
OpenStagedContextMenuByChanges(changes); OpenStagedContextMenuByChanges(menu, changes);
} }
menu.IsOpen = true;
ev.Handled = true; ev.Handled = true;
} }