feature(Launcher): enable drag-drop on title bar

This commit is contained in:
leo 2020-08-03 18:29:48 +08:00
parent c6e094b95c
commit a4d1617c5a
2 changed files with 35 additions and 2 deletions

View file

@ -5,7 +5,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:source="clr-namespace:SourceGit"
xmlns:local="clr-namespace:SourceGit.UI"
mc:Ignorable="d"
MinWidth="800" MinHeight="600"
Title="Source Git"
@ -76,6 +75,7 @@
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="AllowDrop" Value="True"/>
<Setter Property="IsSelected" Value="{Binding IsActive, Mode=TwoWay}"/>
<Setter Property="Template">
<Setter.Value>
@ -113,6 +113,9 @@
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter Event="PreviewMouseMove" Handler="TabsPreviewMouseMove"/>
<EventSetter Event="Drop" Handler="TabsDrop"/>
</Style>
</TabControl.ItemContainerStyle>

View file

@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace SourceGit.UI {
@ -177,5 +178,34 @@ namespace SourceGit.UI {
App.Current.Shutdown();
}
#endregion
#region DRAG_DROP
private void TabsPreviewMouseMove(object sender, MouseEventArgs e) {
var tab = e.Source as TabItem;
if (tab == null || (tab.DataContext as Tab).Repo == null) return;
if (Mouse.LeftButton == MouseButtonState.Pressed) {
DragDrop.DoDragDrop(tab, tab, DragDropEffects.All);
}
}
private void TabsDrop(object sender, DragEventArgs e) {
var tabItemSrc = e.Data.GetData(typeof(TabItem)) as TabItem;
var tabItemDst = e.Source as TabItem;
if (tabItemSrc.Equals(tabItemDst)) return;
var tabSrc = tabItemSrc.DataContext as Tab;
var tabDst = tabItemDst.DataContext as Tab;
if (tabDst.Repo == null) {
Tabs.Remove(tabSrc);
Tabs.Insert(1, tabSrc);
} else {
int dstIdx = Tabs.IndexOf(tabDst);
Tabs.Remove(tabSrc);
Tabs.Insert(dstIdx, tabSrc);
}
}
#endregion
}
}