mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
111
src/Views/Controls/ChangeStatusIcon.cs
Normal file
111
src/Views/Controls/ChangeStatusIcon.cs
Normal file
|
@ -0,0 +1,111 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SourceGit.Views.Controls {
|
||||
/// <summary>
|
||||
/// 变更状态图标
|
||||
/// </summary>
|
||||
class ChangeStatusIcon : FrameworkElement {
|
||||
|
||||
public static readonly DependencyProperty ChangeProperty = DependencyProperty.Register(
|
||||
"Change",
|
||||
typeof(Models.Change),
|
||||
typeof(ChangeStatusIcon),
|
||||
new PropertyMetadata(null, ForceDirty));
|
||||
|
||||
public Models.Change Change {
|
||||
get { return (Models.Change)GetValue(ChangeProperty); }
|
||||
set { SetValue(ChangeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsLocalChangeProperty = DependencyProperty.Register(
|
||||
"IsLocalChange",
|
||||
typeof(bool),
|
||||
typeof(ChangeStatusIcon),
|
||||
new PropertyMetadata(false, ForceDirty));
|
||||
|
||||
public bool IsLocalChange {
|
||||
get { return (bool)GetValue(IsLocalChangeProperty); }
|
||||
set { SetValue(IsLocalChangeProperty, value); }
|
||||
}
|
||||
|
||||
private Brush background;
|
||||
private FormattedText label;
|
||||
|
||||
public ChangeStatusIcon() {
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc) {
|
||||
if (background == null || label == null) return;
|
||||
var corner = Math.Max(2, Width / 16);
|
||||
dc.DrawRoundedRectangle(background, null, new Rect(0, 0, Width, Height), corner, corner);
|
||||
dc.DrawText(label, new Point((Width - label.Width) * 0.5, 0));
|
||||
}
|
||||
|
||||
private static void ForceDirty(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var icon = d as ChangeStatusIcon;
|
||||
if (icon == null) return;
|
||||
|
||||
if (icon.Change == null) {
|
||||
icon.background = null;
|
||||
icon.label = null;
|
||||
return;
|
||||
}
|
||||
|
||||
string txt;
|
||||
if (icon.IsLocalChange) {
|
||||
if (icon.Change.IsConflit) {
|
||||
icon.background = Brushes.OrangeRed;
|
||||
txt = "!";
|
||||
} else {
|
||||
icon.background = GetBackground(icon.Change.WorkTree);
|
||||
txt = GetLabel(icon.Change.WorkTree);
|
||||
}
|
||||
} else {
|
||||
icon.background = GetBackground(icon.Change.Index);
|
||||
txt = GetLabel(icon.Change.Index);
|
||||
}
|
||||
|
||||
icon.label = new FormattedText(
|
||||
txt,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
|
||||
icon.Width * 0.8,
|
||||
new SolidColorBrush(Color.FromRgb(241,241,241)),
|
||||
VisualTreeHelper.GetDpi(icon).PixelsPerDip);
|
||||
|
||||
icon.InvalidateVisual();
|
||||
}
|
||||
|
||||
private static Brush GetBackground(Models.Change.Status status) {
|
||||
switch (status) {
|
||||
case Models.Change.Status.Modified: return new LinearGradientBrush(Colors.Orange, Color.FromRgb(255, 213, 134), 90);
|
||||
case Models.Change.Status.Added: return new LinearGradientBrush(Colors.LimeGreen, Color.FromRgb(124, 241, 124), 90);
|
||||
case Models.Change.Status.Deleted: return new LinearGradientBrush(Colors.Tomato, Color.FromRgb(252, 165, 150), 90);
|
||||
case Models.Change.Status.Renamed: return new LinearGradientBrush(Colors.Orchid, Color.FromRgb(248, 161, 245), 90);
|
||||
case Models.Change.Status.Copied: return new LinearGradientBrush(Colors.Orange, Color.FromRgb(255, 213, 134), 90);
|
||||
case Models.Change.Status.Unmerged: return new LinearGradientBrush(Colors.Orange, Color.FromRgb(255, 213, 134), 90);
|
||||
case Models.Change.Status.Untracked: return new LinearGradientBrush(Colors.LimeGreen, Color.FromRgb(124, 241, 124), 90);
|
||||
default: return Brushes.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetLabel(Models.Change.Status status) {
|
||||
switch (status) {
|
||||
case Models.Change.Status.Modified: return "±";
|
||||
case Models.Change.Status.Added: return "✚";
|
||||
case Models.Change.Status.Deleted: return "▬";
|
||||
case Models.Change.Status.Renamed: return "➔";
|
||||
case Models.Change.Status.Copied: return "❏";
|
||||
case Models.Change.Status.Unmerged: return "U";
|
||||
case Models.Change.Status.Untracked: return "?";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue