mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<*>: remove dragdrop adorner; redesign bookmark style on welcome page
This commit is contained in:
parent
bdd147f737
commit
787cf5bb02
9 changed files with 36 additions and 151 deletions
|
@ -24,7 +24,6 @@
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="{x:Type Window}">
|
<ControlTemplate TargetType="{x:Type Window}">
|
||||||
<AdornerDecorator>
|
|
||||||
<Border
|
<Border
|
||||||
Padding="{TemplateBinding Padding}"
|
Padding="{TemplateBinding Padding}"
|
||||||
Background="{TemplateBinding Background}"
|
Background="{TemplateBinding Background}"
|
||||||
|
@ -32,7 +31,6 @@
|
||||||
BorderBrush="{TemplateBinding BorderBrush}">
|
BorderBrush="{TemplateBinding BorderBrush}">
|
||||||
<ContentPresenter/>
|
<ContentPresenter/>
|
||||||
</Border>
|
</Border>
|
||||||
</AdornerDecorator>
|
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace SourceGit.Views.Controls {
|
|
||||||
/// <summary>
|
|
||||||
/// 展示正在拖拽的视图
|
|
||||||
/// </summary>
|
|
||||||
public class DragDropAdorner : Adorner {
|
|
||||||
private FrameworkElement renderElem;
|
|
||||||
|
|
||||||
public struct PInPoint {
|
|
||||||
public int X;
|
|
||||||
public int Y;
|
|
||||||
|
|
||||||
public PInPoint(int x, int y) { X = x; Y = y; }
|
|
||||||
public PInPoint(double x, double y) { X = (int)x; Y = (int)y; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
static extern void GetCursorPos(ref PInPoint p);
|
|
||||||
|
|
||||||
public DragDropAdorner(FrameworkElement elem) : base(elem) {
|
|
||||||
renderElem = elem;
|
|
||||||
IsHitTestVisible = false;
|
|
||||||
Window.AddAdorner(elem, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove() {
|
|
||||||
Window.RemoveAdorner(renderElem, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnRender(DrawingContext dc) {
|
|
||||||
base.OnRender(dc);
|
|
||||||
|
|
||||||
PInPoint p = new PInPoint();
|
|
||||||
GetCursorPos(ref p);
|
|
||||||
|
|
||||||
Point pos = PointFromScreen(new Point(p.X, p.Y));
|
|
||||||
Rect rect = new Rect(pos.X, pos.Y, renderElem.RenderSize.Width, renderElem.RenderSize.Height);
|
|
||||||
|
|
||||||
dc.PushOpacity(1);
|
|
||||||
dc.DrawRectangle(FindResource("Brush.Window") as Brush, null, rect);
|
|
||||||
dc.DrawRectangle(new VisualBrush(renderElem), null, rect);
|
|
||||||
dc.DrawRectangle(null, new Pen(Brushes.DeepSkyBlue, 2), rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,37 +20,9 @@ namespace SourceGit.Views.Controls {
|
||||||
set { SetValue(IsMaximizedProperty, value); }
|
set { SetValue(IsMaximizedProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdornerLayer adornerLayer = null;
|
|
||||||
private List<Adorner> adorners = new List<Adorner>();
|
|
||||||
|
|
||||||
public Window() {
|
public Window() {
|
||||||
Style = FindResource("Style.Window") as Style;
|
Style = FindResource("Style.Window") as Style;
|
||||||
|
Loaded += (_, __) => OnStateChanged(null);
|
||||||
Loaded += (_, __) => {
|
|
||||||
adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement);
|
|
||||||
OnStateChanged(null);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddAdorner(FrameworkElement windowContext, Adorner adorner) {
|
|
||||||
var wnd = GetWindow(windowContext) as Window;
|
|
||||||
if (wnd != null && wnd.adornerLayer != null) {
|
|
||||||
wnd.adorners.Add(adorner);
|
|
||||||
wnd.adornerLayer.Add(adorner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveAdorner(FrameworkElement windowContext, Adorner adorner) {
|
|
||||||
var wnd = GetWindow(windowContext) as Window;
|
|
||||||
if (wnd != null && wnd.adornerLayer != null) {
|
|
||||||
wnd.adorners.Remove(adorner);
|
|
||||||
wnd.adornerLayer.Remove(adorner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPreviewGiveFeedback(GiveFeedbackEventArgs e) {
|
|
||||||
base.OnPreviewGiveFeedback(e);
|
|
||||||
if (adornerLayer != null && adorners.Count > 0) adornerLayer.Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStateChanged(EventArgs e) {
|
protected override void OnStateChanged(EventArgs e) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace SourceGit.Views.Converters {
|
||||||
|
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||||
var index = (int)value;
|
var index = (int)value;
|
||||||
return index == 0 ? (App.Current.FindResource("Brush.FG1") as Brush) : COLORS[index];
|
return COLORS[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||||
|
|
|
@ -144,7 +144,6 @@ namespace SourceGit.Views {
|
||||||
#region TAB_OPERATION
|
#region TAB_OPERATION
|
||||||
private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
||||||
var page = new Widgets.Welcome();
|
var page = new Widgets.Welcome();
|
||||||
page.OnBookmarkChanged += repo => tabs.Update(repo.Path, repo.Bookmark, repo.Name);
|
|
||||||
container.Add(e.TabId, page);
|
container.Add(e.TabId, page);
|
||||||
Controls.PopupWidget.RegisterContainer(e.TabId, page);
|
Controls.PopupWidget.RegisterContainer(e.TabId, page);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,11 @@
|
||||||
<ListBox.ItemContainerStyle>
|
<ListBox.ItemContainerStyle>
|
||||||
<Style TargetType="{x:Type ListBoxItem}">
|
<Style TargetType="{x:Type ListBoxItem}">
|
||||||
<EventSetter Event="ContextMenuOpening" Handler="OnTabContextMenuOpening" />
|
<EventSetter Event="ContextMenuOpening" Handler="OnTabContextMenuOpening" />
|
||||||
|
<EventSetter Event="MouseMove" Handler="OnMouseMove"/>
|
||||||
|
<EventSetter Event="DragOver" Handler="OnDragOver"/>
|
||||||
|
<EventSetter Event="Drop" Handler="OnDrop"/>
|
||||||
|
<EventSetter Event="GiveFeedback" Handler="OnGiveFeedback"/>
|
||||||
|
|
||||||
<Setter Property="AllowDrop" Value="True"/>
|
<Setter Property="AllowDrop" Value="True"/>
|
||||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
|
@ -125,9 +130,6 @@
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|
||||||
<EventSetter Event="MouseMove" Handler="OnMouseMove"/>
|
|
||||||
<EventSetter Event="Drop" Handler="OnDrop"/>
|
|
||||||
</Style>
|
</Style>
|
||||||
</ListBox.ItemContainerStyle>
|
</ListBox.ItemContainerStyle>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
|
@ -269,12 +269,25 @@ namespace SourceGit.Views.Widgets {
|
||||||
if (tab == null || tab != container.SelectedItem) return;
|
if (tab == null || tab != container.SelectedItem) return;
|
||||||
|
|
||||||
if (e.LeftButton == MouseButtonState.Pressed) {
|
if (e.LeftButton == MouseButtonState.Pressed) {
|
||||||
var dragging = new Controls.DragDropAdorner(item);
|
|
||||||
DragDrop.DoDragDrop(item, item.DataContext, DragDropEffects.Move);
|
DragDrop.DoDragDrop(item, item.DataContext, DragDropEffects.Move);
|
||||||
dragging.Remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnGiveFeedback(object sender, GiveFeedbackEventArgs e) {
|
||||||
|
if (e.Effects == DragDropEffects.Move) {
|
||||||
|
e.UseDefaultCursors = false;
|
||||||
|
Mouse.SetCursor(Cursors.Hand);
|
||||||
|
} else {
|
||||||
|
e.UseDefaultCursors = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDragOver(object sender, DragEventArgs e) {
|
||||||
|
OnDrop(sender, e);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDrop(object sender, DragEventArgs e) {
|
private void OnDrop(object sender, DragEventArgs e) {
|
||||||
var tabSrc = e.Data.GetData(typeof(Tab)) as Tab;
|
var tabSrc = e.Data.GetData(typeof(Tab)) as Tab;
|
||||||
if (tabSrc == null) return;
|
if (tabSrc == null) return;
|
||||||
|
@ -323,13 +336,12 @@ namespace SourceGit.Views.Widgets {
|
||||||
menu.Items.Add(closeRight);
|
menu.Items.Add(closeRight);
|
||||||
|
|
||||||
if (tab.IsRepository) {
|
if (tab.IsRepository) {
|
||||||
var iconBookmark = FindResource("Icon.Git") as Geometry;
|
|
||||||
var bookmark = new MenuItem();
|
var bookmark = new MenuItem();
|
||||||
bookmark.Header = App.Text("PageTabBar.Tab.Bookmark");
|
bookmark.Header = App.Text("PageTabBar.Tab.Bookmark");
|
||||||
for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) {
|
for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) {
|
||||||
var icon = new System.Windows.Shapes.Path();
|
var icon = new System.Windows.Shapes.Path();
|
||||||
icon.Data = iconBookmark;
|
icon.Data = new EllipseGeometry(new Point(0, 0), 12, 12);
|
||||||
icon.Fill = i == 0 ? (FindResource("Brush.FG1") as Brush) : Converters.IntToBookmarkBrush.COLORS[i];
|
icon.Fill = Converters.IntToBookmarkBrush.COLORS[i];
|
||||||
icon.Width = 12;
|
icon.Width = 12;
|
||||||
|
|
||||||
var mark = new MenuItem();
|
var mark = new MenuItem();
|
||||||
|
|
|
@ -124,25 +124,20 @@
|
||||||
Height="36" Margin="0,2"
|
Height="36" Margin="0,2"
|
||||||
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
|
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
|
||||||
Background="{DynamicResource Brush.Contents}">
|
Background="{DynamicResource Brush.Contents}">
|
||||||
<Grid Margin="8,0">
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="8"/>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="32"/>
|
<ColumnDefinition Width="32"/>
|
||||||
<ColumnDefinition Width="32"/>
|
<ColumnDefinition Width="32"/>
|
||||||
<ColumnDefinition Width="32"/>
|
<ColumnDefinition Width="32"/>
|
||||||
<ColumnDefinition Width="32"/>
|
<ColumnDefinition Width="32"/>
|
||||||
|
<ColumnDefinition Width="8"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Button Grid.Column="0" Background="Transparent" Width="16" BorderThickness="0" ToolTip="{DynamicResource Text.RepoCM.Bookmark}" Click="OnChangeRepositoryBookmark">
|
<Border Grid.Column="0" Background="{Binding Bookmark, Converter={StaticResource IntToBookmarkBrush}}"/>
|
||||||
<Path Width="8" Fill="{Binding Bookmark, Converter={StaticResource IntToBookmarkBrush}}">
|
|
||||||
<Path.Data>
|
|
||||||
<EllipseGeometry Center="0,0" RadiusX="14" RadiusY="14"/>
|
|
||||||
</Path.Data>
|
|
||||||
</Path>
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<StackPanel Grid.Column="1" Margin="8,0" Orientation="Horizontal">
|
<StackPanel Grid.Column="1" Margin="4,0" Orientation="Horizontal">
|
||||||
<TextBlock Text="{Binding Name}" FontSize="12pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}"/>
|
<TextBlock Text="{Binding Name}" FontSize="12pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}"/>
|
||||||
<TextBlock Text="{Binding Path}" FontSize="10pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" Margin="8,0" Foreground="{DynamicResource Brush.FG2}"/>
|
<TextBlock Text="{Binding Path}" FontSize="10pt" FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}" Margin="8,0" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
|
@ -16,11 +16,6 @@ namespace SourceGit.Views.Widgets {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Welcome : UserControl, Controls.IPopupContainer {
|
public partial class Welcome : UserControl, Controls.IPopupContainer {
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 修改仓库标签颜色的回调
|
|
||||||
/// </summary>
|
|
||||||
public event Action<Models.Repository> OnBookmarkChanged;
|
|
||||||
|
|
||||||
public Welcome() {
|
public Welcome() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
UpdateVisibles();
|
UpdateVisibles();
|
||||||
|
@ -135,45 +130,6 @@ namespace SourceGit.Views.Widgets {
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChangeRepositoryBookmark(object sender, RoutedEventArgs e) {
|
|
||||||
var btn = (sender as Button);
|
|
||||||
var repo = btn.DataContext as Models.Repository;
|
|
||||||
if (repo == null) return;
|
|
||||||
|
|
||||||
var menu = new ContextMenu();
|
|
||||||
menu.Placement = PlacementMode.Bottom;
|
|
||||||
menu.PlacementTarget = btn;
|
|
||||||
menu.StaysOpen = false;
|
|
||||||
menu.Focusable = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) {
|
|
||||||
var icon = new System.Windows.Shapes.Path();
|
|
||||||
icon.Data = new EllipseGeometry(new Point(0, 0), 8, 8);
|
|
||||||
icon.Fill = i == 0 ? (FindResource("Brush.FG1") as Brush) : Converters.IntToBookmarkBrush.COLORS[i];
|
|
||||||
icon.Width = 12;
|
|
||||||
|
|
||||||
var mark = new MenuItem();
|
|
||||||
mark.Icon = icon;
|
|
||||||
mark.Header = $"{i}";
|
|
||||||
|
|
||||||
var refIdx = i;
|
|
||||||
mark.Click += (o, ev) => {
|
|
||||||
if (repo != null) {
|
|
||||||
repo.Bookmark = refIdx;
|
|
||||||
UpdateVisibles();
|
|
||||||
OnBookmarkChanged?.Invoke(repo);
|
|
||||||
}
|
|
||||||
ev.Handled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.Items.Add(mark);
|
|
||||||
}
|
|
||||||
|
|
||||||
btn.ContextMenu = menu;
|
|
||||||
btn.ContextMenu.IsOpen = true;
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnOpenRepositoryTerminal(object sender, RoutedEventArgs e) {
|
private void OnOpenRepositoryTerminal(object sender, RoutedEventArgs e) {
|
||||||
var repo = (sender as Button).DataContext as Models.Repository;
|
var repo = (sender as Button).DataContext as Models.Repository;
|
||||||
if (repo == null) return;
|
if (repo == null) return;
|
||||||
|
|
Loading…
Reference in a new issue