mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
refactor: rewrite Launcher
* move main tabbar to a standalone control * simpfy notification
This commit is contained in:
parent
1ce0d0f7bf
commit
e330862ec9
8 changed files with 406 additions and 349 deletions
|
@ -112,20 +112,14 @@ namespace SourceGit
|
||||||
|
|
||||||
public static void RaiseException(string context, string message)
|
public static void RaiseException(string context, string message)
|
||||||
{
|
{
|
||||||
if (Current is App app && app._notificationReceiver != null)
|
if (Current is App app && app._launcher != null)
|
||||||
{
|
app._launcher.DispatchNotification(context, message, true);
|
||||||
var notice = new Models.Notification() { IsError = true, Message = message };
|
|
||||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendNotification(string context, string message)
|
public static void SendNotification(string context, string message)
|
||||||
{
|
{
|
||||||
if (Current is App app && app._notificationReceiver != null)
|
if (Current is App app && app._launcher != null)
|
||||||
{
|
app._launcher.DispatchNotification(context, message, false);
|
||||||
var notice = new Models.Notification() { IsError = false, Message = message };
|
|
||||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetLocale(string localeKey)
|
public static void SetLocale(string localeKey)
|
||||||
|
@ -285,9 +279,8 @@ namespace SourceGit
|
||||||
BindingPlugins.DataValidators.RemoveAt(0);
|
BindingPlugins.DataValidators.RemoveAt(0);
|
||||||
Native.OS.SetupEnternalTools();
|
Native.OS.SetupEnternalTools();
|
||||||
|
|
||||||
var launcher = new Views.Launcher();
|
_launcher = new ViewModels.Launcher();
|
||||||
_notificationReceiver = launcher;
|
desktop.MainWindow = new Views.Launcher() { DataContext = _launcher };
|
||||||
desktop.MainWindow = launcher;
|
|
||||||
|
|
||||||
if (ViewModels.Preference.Instance.ShouldCheck4UpdateOnStartup)
|
if (ViewModels.Preference.Instance.ShouldCheck4UpdateOnStartup)
|
||||||
{
|
{
|
||||||
|
@ -330,8 +323,8 @@ namespace SourceGit
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ViewModels.Launcher _launcher = null;
|
||||||
private ResourceDictionary _activeLocale = null;
|
private ResourceDictionary _activeLocale = null;
|
||||||
private ResourceDictionary _colorOverrides = null;
|
private ResourceDictionary _colorOverrides = null;
|
||||||
private Models.INotificationReceiver _notificationReceiver = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Media;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
@ -40,7 +43,7 @@ namespace SourceGit.ViewModels
|
||||||
var root = new Commands.QueryRepositoryRootPath(path).Result();
|
var root = new Commands.QueryRepositoryRootPath(path).Result();
|
||||||
if (string.IsNullOrEmpty(root))
|
if (string.IsNullOrEmpty(root))
|
||||||
{
|
{
|
||||||
Pages[0].Notifications.Add(new Models.Notification
|
Pages[0].Notifications.Add(new Notification
|
||||||
{
|
{
|
||||||
IsError = true,
|
IsError = true,
|
||||||
Message = $"Given path: '{path}' is NOT a valid repository!"
|
Message = $"Given path: '{path}' is NOT a valid repository!"
|
||||||
|
@ -124,7 +127,7 @@ namespace SourceGit.ViewModels
|
||||||
ActivePage = Pages[prevIdx];
|
ActivePage = Pages[prevIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseTab(object param)
|
public void CloseTab(LauncherPage page)
|
||||||
{
|
{
|
||||||
if (Pages.Count == 1)
|
if (Pages.Count == 1)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +151,6 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherPage page = param as LauncherPage;
|
|
||||||
if (page == null)
|
if (page == null)
|
||||||
page = _activePage;
|
page = _activePage;
|
||||||
|
|
||||||
|
@ -250,6 +252,108 @@ namespace SourceGit.ViewModels
|
||||||
ActivePage = page;
|
ActivePage = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DispatchNotification(string pageId, string message, bool isError)
|
||||||
|
{
|
||||||
|
var notification = new Notification() {
|
||||||
|
IsError = isError,
|
||||||
|
Message = message,
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var page in Pages)
|
||||||
|
{
|
||||||
|
var id = page.Node.Id.Replace("\\", "/");
|
||||||
|
if (id == pageId)
|
||||||
|
{
|
||||||
|
page.Notifications.Add(notification);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_activePage != null)
|
||||||
|
_activePage.Notifications.Add(notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DismissNotification(Notification notice)
|
||||||
|
{
|
||||||
|
if (notice != null)
|
||||||
|
ActivePage?.Notifications.Remove(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContextMenu CreateContextForPageTab(LauncherPage page)
|
||||||
|
{
|
||||||
|
if (page == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var menu = new ContextMenu();
|
||||||
|
var close = new MenuItem();
|
||||||
|
close.Header = App.Text("PageTabBar.Tab.Close");
|
||||||
|
close.InputGesture = KeyGesture.Parse(OperatingSystem.IsMacOS() ? "⌘+W" : "Ctrl+W");
|
||||||
|
close.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
CloseTab(page);
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(close);
|
||||||
|
|
||||||
|
var closeOthers = new MenuItem();
|
||||||
|
closeOthers.Header = App.Text("PageTabBar.Tab.CloseOther");
|
||||||
|
closeOthers.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
CloseOtherTabs();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(closeOthers);
|
||||||
|
|
||||||
|
var closeRight = new MenuItem();
|
||||||
|
closeRight.Header = App.Text("PageTabBar.Tab.CloseRight");
|
||||||
|
closeRight.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
CloseRightTabs();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(closeRight);
|
||||||
|
|
||||||
|
if (page.Node.IsRepository)
|
||||||
|
{
|
||||||
|
var bookmark = new MenuItem();
|
||||||
|
bookmark.Header = App.Text("PageTabBar.Tab.Bookmark");
|
||||||
|
bookmark.Icon = App.CreateMenuIcon("Icons.Bookmark");
|
||||||
|
|
||||||
|
for (int i = 0; i < Models.Bookmarks.Supported.Count; i++)
|
||||||
|
{
|
||||||
|
var icon = App.CreateMenuIcon("Icons.Bookmark");
|
||||||
|
icon.Fill = Models.Bookmarks.Brushes[i];
|
||||||
|
icon.Stroke = App.Current.FindResource("Brush.FG1") as Brush;
|
||||||
|
icon.StrokeThickness = i == 0 ? 1.0 : 0;
|
||||||
|
|
||||||
|
var dupIdx = i;
|
||||||
|
var setter = new MenuItem();
|
||||||
|
setter.Header = icon;
|
||||||
|
setter.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
page.Node.Bookmark = dupIdx;
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
bookmark.Items.Add(setter);
|
||||||
|
}
|
||||||
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
|
menu.Items.Add(bookmark);
|
||||||
|
|
||||||
|
var copyPath = new MenuItem();
|
||||||
|
copyPath.Header = App.Text("PageTabBar.Tab.CopyPath");
|
||||||
|
copyPath.Icon = App.CreateMenuIcon("Icons.Copy");
|
||||||
|
copyPath.Click += (o, e) =>
|
||||||
|
{
|
||||||
|
page.CopyPath();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||||
|
menu.Items.Add(copyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
private void CloseRepositoryInTab(LauncherPage page)
|
private void CloseRepositoryInTab(LauncherPage page)
|
||||||
{
|
{
|
||||||
if (page.Data is Repository repo)
|
if (page.Data is Repository repo)
|
||||||
|
|
|
@ -24,11 +24,11 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _isTabSplitterVisible, value);
|
set => SetProperty(ref _isTabSplitterVisible, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AvaloniaList<Models.Notification> Notifications
|
public AvaloniaList<Notification> Notifications
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new AvaloniaList<Models.Notification>();
|
} = new AvaloniaList<Notification>();
|
||||||
|
|
||||||
public LauncherPage()
|
public LauncherPage()
|
||||||
{
|
{
|
||||||
|
@ -53,12 +53,6 @@ namespace SourceGit.ViewModels
|
||||||
App.CopyText(_node.Id);
|
App.CopyText(_node.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DismissNotification(object param)
|
|
||||||
{
|
|
||||||
if (param is Models.Notification notice)
|
|
||||||
Notifications.Remove(notice);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RepositoryNode _node = null;
|
private RepositoryNode _node = null;
|
||||||
private object _data = null;
|
private object _data = null;
|
||||||
private bool _isTabSplitterVisible = true;
|
private bool _isTabSplitterVisible = true;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace SourceGit.Models
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class Notification
|
public class Notification
|
||||||
{
|
{
|
||||||
|
@ -10,9 +10,4 @@
|
||||||
App.CopyText(Message);
|
App.CopyText(Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface INotificationReceiver
|
|
||||||
{
|
|
||||||
void OnReceiveNotification(string ctx, Notification notice);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.Launcher"
|
x:Class="SourceGit.Views.Launcher"
|
||||||
x:DataType="vm:Launcher"
|
x:DataType="vm:Launcher"
|
||||||
x:Name="me"
|
|
||||||
Icon="/App.ico"
|
Icon="/App.ico"
|
||||||
Title="SourceGit"
|
Title="SourceGit"
|
||||||
MinWidth="1280" MinHeight="720"
|
MinWidth="1280" MinHeight="720"
|
||||||
|
@ -18,9 +17,9 @@
|
||||||
Height="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.LauncherHeight, Mode=TwoWay}"
|
Height="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.LauncherHeight, Mode=TwoWay}"
|
||||||
WindowState="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.LauncherWindowState, Mode=TwoWay}"
|
WindowState="{Binding Source={x:Static vm:Preference.Instance}, Path=Layout.LauncherWindowState, Mode=TwoWay}"
|
||||||
WindowStartupLocation="CenterScreen">
|
WindowStartupLocation="CenterScreen">
|
||||||
<Grid>
|
<Grid x:Name="MainLayout">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="{Binding #me.TitleBarHeight}"/>
|
<RowDefinition Height="38"/>
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@
|
||||||
<v:CaptionButtonsMacOS VerticalAlignment="Bottom"/>
|
<v:CaptionButtonsMacOS VerticalAlignment="Bottom"/>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Menu -->
|
<!-- Menu (Windows/Linux) -->
|
||||||
<Button Grid.Column="0" Classes="icon_button" VerticalAlignment="Bottom" IsVisible="{OnPlatform True, macOS=False}">
|
<Button Grid.Column="0" Classes="icon_button" VerticalAlignment="Bottom" IsVisible="{OnPlatform True, macOS=False}">
|
||||||
<Button.Margin>
|
<Button.Margin>
|
||||||
<OnPlatform Default="4,0,2,3" macOS="4,0,6,3"/>
|
<OnPlatform Default="4,0,2,3" macOS="4,0,6,3"/>
|
||||||
|
@ -76,160 +75,7 @@
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Pages Tabs-->
|
<!-- Pages Tabs-->
|
||||||
<Grid x:Name="launcherTabsContainer" Grid.Column="1" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Bottom" SizeChanged="UpdateScrollIndicator">
|
<v:LauncherTabBar Grid.Column="1" Height="30" VerticalAlignment="Bottom"/>
|
||||||
<RepeatButton x:Name="leftScrollIndicator" Grid.Column="0" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsLeft">
|
|
||||||
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleLeft}"/>
|
|
||||||
</RepeatButton>
|
|
||||||
|
|
||||||
<ScrollViewer Grid.Column="1"
|
|
||||||
x:Name="launcherTabsScroller"
|
|
||||||
HorizontalAlignment="Left"
|
|
||||||
HorizontalScrollBarVisibility="Hidden"
|
|
||||||
VerticalScrollBarVisibility="Disabled"
|
|
||||||
PointerWheelChanged="ScrollTabs"
|
|
||||||
ScrollChanged="OnTabsScrollChanged">
|
|
||||||
<StackPanel x:Name="launcherTabsBar" Orientation="Horizontal" SizeChanged="UpdateScrollIndicator">
|
|
||||||
<ListBox Classes="launcher_page_tabbar"
|
|
||||||
ItemsSource="{Binding Pages}"
|
|
||||||
SelectionMode="AlwaysSelected"
|
|
||||||
SelectedItem="{Binding ActivePage, Mode=TwoWay}">
|
|
||||||
<ListBox.ItemsPanel>
|
|
||||||
<ItemsPanelTemplate>
|
|
||||||
<VirtualizingStackPanel Orientation="Horizontal" Height="30"/>
|
|
||||||
</ItemsPanelTemplate>
|
|
||||||
</ListBox.ItemsPanel>
|
|
||||||
|
|
||||||
<ListBox.ItemTemplate>
|
|
||||||
<DataTemplate DataType="{x:Type vm:LauncherPage}">
|
|
||||||
<Border Classes="launcher_pagetab"
|
|
||||||
Height="30"
|
|
||||||
BorderThickness="1,1,1,0"
|
|
||||||
CornerRadius="6,6,0,0"
|
|
||||||
PointerPressed="OnPointerPressedTab"
|
|
||||||
PointerMoved="OnPointerMovedOverTab"
|
|
||||||
PointerReleased="OnPointerReleasedTab"
|
|
||||||
Loaded="SetupDragAndDrop">
|
|
||||||
<Border.ContextMenu>
|
|
||||||
<ContextMenu>
|
|
||||||
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.Close}"
|
|
||||||
Command="{Binding #me.((vm:Launcher)DataContext).CloseTab}"
|
|
||||||
CommandParameter="{Binding}"
|
|
||||||
InputGesture="{OnPlatform Ctrl+W, macOS=⌘+W}"/>
|
|
||||||
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.CloseOther}"
|
|
||||||
Command="{Binding #me.((vm:Launcher)DataContext).CloseOtherTabs}"/>
|
|
||||||
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.CloseRight}"
|
|
||||||
Command="{Binding #me.((vm:Launcher)DataContext).CloseRightTabs}"/>
|
|
||||||
<MenuItem Header="-" IsVisible="{Binding Node.IsRepository}"/>
|
|
||||||
<MenuItem IsVisible="{Binding Node.IsRepository}">
|
|
||||||
<MenuItem.Header>
|
|
||||||
<Grid Height="20" ColumnDefinitions="Auto,*">
|
|
||||||
<TextBlock Grid.Column="0" Text="{DynamicResource Text.PageTabBar.Tab.Bookmark}"/>
|
|
||||||
<ComboBox Grid.Column="1"
|
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
|
||||||
BorderThickness=".5" Margin="8,0,0,0"
|
|
||||||
ItemsSource="{x:Static m:Bookmarks.Supported}"
|
|
||||||
SelectedIndex="{Binding Node.Bookmark, Mode=TwoWay}">
|
|
||||||
<ComboBox.Resources>
|
|
||||||
<Thickness x:Key="ComboBoxPadding">12,2,0,2</Thickness>
|
|
||||||
<Thickness x:Key="ComboBoxEditableTextPadding">11,2,32,2</Thickness>
|
|
||||||
<x:Double x:Key="ComboBoxMinHeight">22</x:Double>
|
|
||||||
</ComboBox.Resources>
|
|
||||||
<ComboBox.ItemTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<Border Height="20" VerticalAlignment="Center">
|
|
||||||
<Path Width="12" Height="12"
|
|
||||||
Fill="{Binding Converter={x:Static c:BookmarkConverters.ToBrush}}"
|
|
||||||
StrokeThickness="{Binding Converter={x:Static c:BookmarkConverters.ToStrokeThickness}}"
|
|
||||||
Stroke="{DynamicResource Brush.FG1}"
|
|
||||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
|
||||||
Data="{StaticResource Icons.Bookmark}"/>
|
|
||||||
</Border>
|
|
||||||
</DataTemplate>
|
|
||||||
</ComboBox.ItemTemplate>
|
|
||||||
</ComboBox>
|
|
||||||
</Grid>
|
|
||||||
</MenuItem.Header>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="-" IsVisible="{Binding Node.IsRepository}"/>
|
|
||||||
<MenuItem Header="{DynamicResource Text.PageTabBar.Tab.CopyPath}" Command="{Binding CopyPath}" IsVisible="{Binding Node.IsRepository}"/>
|
|
||||||
</ContextMenu>
|
|
||||||
</Border.ContextMenu>
|
|
||||||
|
|
||||||
<Grid Width="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth, Converter={x:Static c:BoolConverters.ToPageTabWidth}}" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
|
|
||||||
<Path Grid.Column="0"
|
|
||||||
Width="12" Height="12" Margin="12,0"
|
|
||||||
Fill="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToBrush}}"
|
|
||||||
StrokeThickness="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToStrokeThickness}}"
|
|
||||||
Stroke="{DynamicResource Brush.FG1}"
|
|
||||||
Data="{StaticResource Icons.Bookmark}"
|
|
||||||
IsVisible="{Binding Node.IsRepository}"
|
|
||||||
IsHitTestVisible="False"/>
|
|
||||||
<Path Grid.Column="0"
|
|
||||||
Width="12" Height="12" Margin="12,0"
|
|
||||||
Fill="{DynamicResource Brush.FG1}"
|
|
||||||
Data="{StaticResource Icons.Repositories}"
|
|
||||||
IsVisible="{Binding !Node.IsRepository}"
|
|
||||||
IsHitTestVisible="False"/>
|
|
||||||
<TextBlock Grid.Column="1"
|
|
||||||
Classes="monospace"
|
|
||||||
FontSize="12"
|
|
||||||
HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
|
||||||
TextAlignment="Center"
|
|
||||||
Text="{Binding Node.Name}"
|
|
||||||
IsVisible="{Binding Node.IsRepository}"
|
|
||||||
IsHitTestVisible="False"/>
|
|
||||||
<TextBlock Grid.Column="1"
|
|
||||||
Classes="monospace"
|
|
||||||
FontSize="12"
|
|
||||||
HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
|
||||||
TextAlignment="Center"
|
|
||||||
Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
|
|
||||||
IsVisible="{Binding !Node.IsRepository}"
|
|
||||||
IsHitTestVisible="False"/>
|
|
||||||
<Button Grid.Column="2"
|
|
||||||
Classes="icon_button"
|
|
||||||
Width="16" Height="16" Margin="12,0"
|
|
||||||
Command="{Binding #me.((vm:Launcher)DataContext).CloseTab}"
|
|
||||||
CommandParameter="{Binding}">
|
|
||||||
<ToolTip.Tip>
|
|
||||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
|
||||||
<TextBlock Text="{DynamicResource Text.PageTabBar.Tab.Close}" VerticalAlignment="Center"/>
|
|
||||||
<TextBlock Margin="16,0,0,0" Text="{OnPlatform Ctrl+W, macOS=⌘+W}" Opacity=".6" FontSize="11" VerticalAlignment="Center"/>
|
|
||||||
</StackPanel>
|
|
||||||
</ToolTip.Tip>
|
|
||||||
<Path Width="8" Height="8" Data="{StaticResource Icons.Window.Close}"/>
|
|
||||||
</Button>
|
|
||||||
<Rectangle Grid.Column="2"
|
|
||||||
Width=".5" Height="20"
|
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
|
||||||
Fill="{DynamicResource Brush.FG2}"
|
|
||||||
IsVisible="{Binding IsTabSplitterVisible}"/>
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
</DataTemplate>
|
|
||||||
</ListBox.ItemTemplate>
|
|
||||||
</ListBox>
|
|
||||||
|
|
||||||
<Button Classes="icon_button"
|
|
||||||
Width="16" Height="16"
|
|
||||||
Margin="8,0"
|
|
||||||
Command="{Binding AddNewTab}">
|
|
||||||
<ToolTip.Tip>
|
|
||||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
|
||||||
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>
|
|
||||||
<TextBlock Margin="16,0,0,0" Text="{OnPlatform Ctrl+T, macOS=⌘+T}" Opacity=".6" FontSize="11" VerticalAlignment="Center"/>
|
|
||||||
</StackPanel>
|
|
||||||
</ToolTip.Tip>
|
|
||||||
|
|
||||||
<Path Width="12" Height="12" Data="{StaticResource Icons.Plus}"/>
|
|
||||||
</Button>
|
|
||||||
</StackPanel>
|
|
||||||
</ScrollViewer>
|
|
||||||
|
|
||||||
<RepeatButton x:Name="rightScrollIndicator" Grid.Column="2" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsRight">
|
|
||||||
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
|
|
||||||
</RepeatButton>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<!-- Caption Buttons (Windows/Linux)-->
|
<!-- Caption Buttons (Windows/Linux)-->
|
||||||
<Border Grid.Column="2" Margin="32,0,0,0" IsVisible="{OnPlatform True, macOS=False}">
|
<Border Grid.Column="2" Margin="32,0,0,0" IsVisible="{OnPlatform True, macOS=False}">
|
||||||
|
@ -298,7 +144,7 @@
|
||||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||||
<ItemsControl ItemsSource="{Binding ActivePage.Notifications}">
|
<ItemsControl ItemsSource="{Binding ActivePage.Notifications}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate DataType="m:Notification">
|
<DataTemplate DataType="vm:Notification">
|
||||||
<Border Margin="10,6" HorizontalAlignment="Stretch" VerticalAlignment="Top" Effect="drop-shadow(0 0 12 #A0000000)">
|
<Border Margin="10,6" HorizontalAlignment="Stretch" VerticalAlignment="Top" Effect="drop-shadow(0 0 12 #A0000000)">
|
||||||
<Border Padding="8" CornerRadius="6" Background="{DynamicResource Brush.Popup}">
|
<Border Padding="8" CornerRadius="6" Background="{DynamicResource Brush.Popup}">
|
||||||
<Grid RowDefinitions="26,Auto,32">
|
<Grid RowDefinitions="26,Auto,32">
|
||||||
|
@ -330,9 +176,8 @@
|
||||||
|
|
||||||
<Button Classes="flat primary"
|
<Button Classes="flat primary"
|
||||||
Margin="0,0"
|
Margin="0,0"
|
||||||
Command="{Binding #me.((vm:Launcher)DataContext).ActivePage.DismissNotification}"
|
Content="{DynamicResource Text.Close}"
|
||||||
CommandParameter="{Binding}"
|
Click="OnDismissNotification"/>
|
||||||
Content="{DynamicResource Text.Close}"/>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
|
@ -7,42 +7,13 @@ using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
public partial class Launcher : ChromelessWindow, Models.INotificationReceiver
|
public partial class Launcher : ChromelessWindow
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<GridLength> TitleBarHeightProperty =
|
|
||||||
AvaloniaProperty.Register<Launcher, GridLength>(nameof(TitleBarHeight), new GridLength(38, GridUnitType.Pixel));
|
|
||||||
|
|
||||||
public GridLength TitleBarHeight
|
|
||||||
{
|
|
||||||
get => GetValue(TitleBarHeightProperty);
|
|
||||||
set => SetValue(TitleBarHeightProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Launcher()
|
public Launcher()
|
||||||
{
|
{
|
||||||
DataContext = new ViewModels.Launcher();
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReceiveNotification(string ctx, Models.Notification notice)
|
|
||||||
{
|
|
||||||
if (DataContext is ViewModels.Launcher vm)
|
|
||||||
{
|
|
||||||
foreach (var page in vm.Pages)
|
|
||||||
{
|
|
||||||
var pageId = page.Node.Id.Replace("\\", "/");
|
|
||||||
if (pageId == ctx)
|
|
||||||
{
|
|
||||||
page.Notifications.Add(notice);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.ActivePage != null)
|
|
||||||
vm.ActivePage.Notifications.Add(notice);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||||
{
|
{
|
||||||
base.OnPropertyChanged(change);
|
base.OnPropertyChanged(change);
|
||||||
|
@ -51,9 +22,9 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
var state = (WindowState)change.NewValue;
|
var state = (WindowState)change.NewValue;
|
||||||
if (state == WindowState.Maximized)
|
if (state == WindowState.Maximized)
|
||||||
SetCurrentValue(TitleBarHeightProperty, new GridLength(OperatingSystem.IsMacOS() ? 34 : 30));
|
MainLayout.RowDefinitions[0].Height = new GridLength(OperatingSystem.IsMacOS() ? 34 : 30);
|
||||||
else
|
else
|
||||||
SetCurrentValue(TitleBarHeightProperty, new GridLength(38, GridUnitType.Pixel));
|
MainLayout.RowDefinitions[0].Height = new GridLength(38);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,139 +167,21 @@ namespace SourceGit.Views
|
||||||
private void EndMoveWindow(object sender, PointerReleasedEventArgs e)
|
private void EndMoveWindow(object sender, PointerReleasedEventArgs e)
|
||||||
{
|
{
|
||||||
_pressedTitleBar = false;
|
_pressedTitleBar = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollTabs(object sender, PointerWheelEventArgs e)
|
|
||||||
{
|
|
||||||
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
|
||||||
{
|
|
||||||
if (e.Delta.Y < 0)
|
|
||||||
launcherTabsScroller.LineRight();
|
|
||||||
else if (e.Delta.Y > 0)
|
|
||||||
launcherTabsScroller.LineLeft();
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ScrollTabsLeft(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
launcherTabsScroller.LineLeft();
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ScrollTabsRight(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
launcherTabsScroller.LineRight();
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateScrollIndicator(object sender, SizeChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (launcherTabsBar.Bounds.Width > launcherTabsContainer.Bounds.Width)
|
|
||||||
{
|
|
||||||
leftScrollIndicator.IsVisible = true;
|
|
||||||
rightScrollIndicator.IsVisible = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
leftScrollIndicator.IsVisible = false;
|
|
||||||
rightScrollIndicator.IsVisible = false;
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTabsScrollChanged(object sender, ScrollChangedEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender is ScrollViewer scrollViewer)
|
|
||||||
{
|
|
||||||
leftScrollIndicator.IsEnabled = scrollViewer.Offset.X > 0;
|
|
||||||
rightScrollIndicator.IsEnabled = scrollViewer.Offset.X < scrollViewer.Extent.Width - scrollViewer.Viewport.Width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupDragAndDrop(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender is Border border)
|
|
||||||
{
|
|
||||||
DragDrop.SetAllowDrop(border, true);
|
|
||||||
border.AddHandler(DragDrop.DropEvent, DropTab);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPointerPressedTab(object sender, PointerPressedEventArgs e)
|
|
||||||
{
|
|
||||||
var border = sender as Border;
|
|
||||||
var point = e.GetCurrentPoint(border);
|
|
||||||
if (point.Properties.IsMiddleButtonPressed)
|
|
||||||
{
|
|
||||||
var vm = DataContext as ViewModels.Launcher;
|
|
||||||
vm.CloseTab(border.DataContext as ViewModels.LauncherPage);
|
|
||||||
e.Handled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_pressedTab = true;
|
|
||||||
_startDragTab = false;
|
|
||||||
_pressedTabPosition = e.GetPosition(sender as Border);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPointerReleasedTab(object sender, PointerReleasedEventArgs e)
|
|
||||||
{
|
|
||||||
_pressedTab = false;
|
|
||||||
_startDragTab = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPointerMovedOverTab(object sender, PointerEventArgs e)
|
|
||||||
{
|
|
||||||
if (_pressedTab && !_startDragTab && sender is Border border)
|
|
||||||
{
|
|
||||||
var delta = e.GetPosition(border) - _pressedTabPosition;
|
|
||||||
var sizeSquired = delta.X * delta.X + delta.Y * delta.Y;
|
|
||||||
if (sizeSquired < 64)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_startDragTab = true;
|
|
||||||
|
|
||||||
var data = new DataObject();
|
|
||||||
data.Set("MovedTab", border.DataContext);
|
|
||||||
DragDrop.DoDragDrop(e, data, DragDropEffects.Move);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DropTab(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Data.Contains("MovedTab") && sender is Border border)
|
|
||||||
{
|
|
||||||
var to = border.DataContext as ViewModels.LauncherPage;
|
|
||||||
var moved = e.Data.Get("MovedTab") as ViewModels.LauncherPage;
|
|
||||||
if (to != null && moved != null && to != moved && DataContext is ViewModels.Launcher vm)
|
|
||||||
{
|
|
||||||
vm.MoveTab(moved, to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_pressedTab = false;
|
|
||||||
_startDragTab = false;
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPopupSure(object sender, RoutedEventArgs e)
|
private void OnPopupSure(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Launcher vm)
|
if (DataContext is ViewModels.Launcher vm)
|
||||||
{
|
|
||||||
vm.ActivePage.ProcessPopup();
|
vm.ActivePage.ProcessPopup();
|
||||||
}
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPopupCancel(object sender, RoutedEventArgs e)
|
private void OnPopupCancel(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Launcher vm)
|
if (DataContext is ViewModels.Launcher vm)
|
||||||
{
|
|
||||||
vm.ActivePage.CancelPopup();
|
vm.ActivePage.CancelPopup();
|
||||||
}
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,9 +190,14 @@ namespace SourceGit.Views
|
||||||
OnPopupCancel(sender, e);
|
OnPopupCancel(sender, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDismissNotification(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Button btn && DataContext is ViewModels.Launcher vm)
|
||||||
|
vm.DismissNotification(btn.DataContext as ViewModels.Notification);
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool _pressedTitleBar = false;
|
private bool _pressedTitleBar = false;
|
||||||
private bool _pressedTab = false;
|
|
||||||
private Point _pressedTabPosition = new Point();
|
|
||||||
private bool _startDragTab = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
120
src/Views/LauncherTabBar.axaml
Normal file
120
src/Views/LauncherTabBar.axaml
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
|
xmlns:c="using:SourceGit.Converters"
|
||||||
|
xmlns:v="using:SourceGit.Views"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.LauncherTabBar"
|
||||||
|
x:DataType="vm:Launcher">
|
||||||
|
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||||
|
<RepeatButton x:Name="LeftScrollIndicator" Grid.Column="0" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsLeft">
|
||||||
|
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleLeft}"/>
|
||||||
|
</RepeatButton>
|
||||||
|
|
||||||
|
<ScrollViewer Grid.Column="1"
|
||||||
|
x:Name="LauncherTabsScroller"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
HorizontalScrollBarVisibility="Hidden"
|
||||||
|
VerticalScrollBarVisibility="Disabled"
|
||||||
|
PointerWheelChanged="ScrollTabs"
|
||||||
|
LayoutUpdated="OnTabsLayoutUpdated">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<ListBox Classes="launcher_page_tabbar"
|
||||||
|
ItemsSource="{Binding Pages}"
|
||||||
|
SelectionMode="AlwaysSelected"
|
||||||
|
SelectedItem="{Binding ActivePage, Mode=TwoWay}">
|
||||||
|
<ListBox.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" Height="30"/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ListBox.ItemsPanel>
|
||||||
|
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate DataType="{x:Type vm:LauncherPage}">
|
||||||
|
<Border Classes="launcher_pagetab"
|
||||||
|
Height="30"
|
||||||
|
BorderThickness="1,1,1,0"
|
||||||
|
CornerRadius="6,6,0,0"
|
||||||
|
PointerPressed="OnPointerPressedTab"
|
||||||
|
PointerMoved="OnPointerMovedOverTab"
|
||||||
|
PointerReleased="OnPointerReleasedTab"
|
||||||
|
Loaded="SetupDragAndDrop"
|
||||||
|
ContextRequested="OnTabContextRequested">
|
||||||
|
<Grid Width="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth, Converter={x:Static c:BoolConverters.ToPageTabWidth}}" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
|
||||||
|
<Path Grid.Column="0"
|
||||||
|
Width="12" Height="12" Margin="12,0"
|
||||||
|
Fill="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToBrush}}"
|
||||||
|
StrokeThickness="{Binding Node.Bookmark, Converter={x:Static c:BookmarkConverters.ToStrokeThickness}}"
|
||||||
|
Stroke="{DynamicResource Brush.FG1}"
|
||||||
|
Data="{StaticResource Icons.Bookmark}"
|
||||||
|
IsVisible="{Binding Node.IsRepository}"
|
||||||
|
IsHitTestVisible="False"/>
|
||||||
|
<Path Grid.Column="0"
|
||||||
|
Width="12" Height="12" Margin="12,0"
|
||||||
|
Fill="{DynamicResource Brush.FG1}"
|
||||||
|
Data="{StaticResource Icons.Repositories}"
|
||||||
|
IsVisible="{Binding !Node.IsRepository}"
|
||||||
|
IsHitTestVisible="False"/>
|
||||||
|
<TextBlock Grid.Column="1"
|
||||||
|
Classes="monospace"
|
||||||
|
FontSize="12"
|
||||||
|
HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||||
|
TextAlignment="Center"
|
||||||
|
Text="{Binding Node.Name}"
|
||||||
|
IsVisible="{Binding Node.IsRepository}"
|
||||||
|
IsHitTestVisible="False"/>
|
||||||
|
<TextBlock Grid.Column="1"
|
||||||
|
Classes="monospace"
|
||||||
|
FontSize="12"
|
||||||
|
HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||||
|
TextAlignment="Center"
|
||||||
|
Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
|
||||||
|
IsVisible="{Binding !Node.IsRepository}"
|
||||||
|
IsHitTestVisible="False"/>
|
||||||
|
<Button Grid.Column="2"
|
||||||
|
Classes="icon_button"
|
||||||
|
Width="16" Height="16" Margin="12,0"
|
||||||
|
Click="OnCloseTab">
|
||||||
|
<ToolTip.Tip>
|
||||||
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="{DynamicResource Text.PageTabBar.Tab.Close}" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock Margin="16,0,0,0" Text="{OnPlatform Ctrl+W, macOS=⌘+W}" Opacity=".6" FontSize="11" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</ToolTip.Tip>
|
||||||
|
<Path Width="8" Height="8" Data="{StaticResource Icons.Window.Close}"/>
|
||||||
|
</Button>
|
||||||
|
<Rectangle Grid.Column="2"
|
||||||
|
Width=".5" Height="20"
|
||||||
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
Fill="{DynamicResource Brush.FG2}"
|
||||||
|
IsVisible="{Binding IsTabSplitterVisible}"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
|
|
||||||
|
<Button Classes="icon_button"
|
||||||
|
Width="16" Height="16"
|
||||||
|
Margin="8,0"
|
||||||
|
Command="{Binding AddNewTab}">
|
||||||
|
<ToolTip.Tip>
|
||||||
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>
|
||||||
|
<TextBlock Margin="16,0,0,0" Text="{OnPlatform Ctrl+T, macOS=⌘+T}" Opacity=".6" FontSize="11" VerticalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</ToolTip.Tip>
|
||||||
|
|
||||||
|
<Path Width="12" Height="12" Data="{StaticResource Icons.Plus}"/>
|
||||||
|
</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
<RepeatButton x:Name="RightScrollIndicator" Grid.Column="2" Classes="icon_button" Width="18" Height="30" Click="ScrollTabsRight">
|
||||||
|
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
|
||||||
|
</RepeatButton>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
148
src/Views/LauncherTabBar.axaml.cs
Normal file
148
src/Views/LauncherTabBar.axaml.cs
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class LauncherTabBar : UserControl
|
||||||
|
{
|
||||||
|
public LauncherTabBar()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScrollTabs(object sender, PointerWheelEventArgs e)
|
||||||
|
{
|
||||||
|
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||||
|
{
|
||||||
|
if (e.Delta.Y < 0)
|
||||||
|
LauncherTabsScroller.LineRight();
|
||||||
|
else if (e.Delta.Y > 0)
|
||||||
|
LauncherTabsScroller.LineLeft();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScrollTabsLeft(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
LauncherTabsScroller.LineLeft();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScrollTabsRight(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
LauncherTabsScroller.LineRight();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTabsLayoutUpdated(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (LauncherTabsScroller.Extent.Width > LauncherTabsScroller.Viewport.Width)
|
||||||
|
{
|
||||||
|
LeftScrollIndicator.IsVisible = true;
|
||||||
|
LeftScrollIndicator.IsEnabled = LauncherTabsScroller.Offset.X > 0;
|
||||||
|
RightScrollIndicator.IsVisible = true;
|
||||||
|
RightScrollIndicator.IsEnabled = LauncherTabsScroller.Offset.X < LauncherTabsScroller.Extent.Width - LauncherTabsScroller.Viewport.Width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LeftScrollIndicator.IsVisible = false;
|
||||||
|
RightScrollIndicator.IsVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupDragAndDrop(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Border border)
|
||||||
|
{
|
||||||
|
DragDrop.SetAllowDrop(border, true);
|
||||||
|
border.AddHandler(DragDrop.DropEvent, DropTab);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPointerPressedTab(object sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
var border = sender as Border;
|
||||||
|
var point = e.GetCurrentPoint(border);
|
||||||
|
if (point.Properties.IsMiddleButtonPressed)
|
||||||
|
{
|
||||||
|
var vm = DataContext as ViewModels.Launcher;
|
||||||
|
vm.CloseTab(border.DataContext as ViewModels.LauncherPage);
|
||||||
|
e.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_pressedTab = true;
|
||||||
|
_startDragTab = false;
|
||||||
|
_pressedTabPosition = e.GetPosition(sender as Border);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPointerReleasedTab(object sender, PointerReleasedEventArgs e)
|
||||||
|
{
|
||||||
|
_pressedTab = false;
|
||||||
|
_startDragTab = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPointerMovedOverTab(object sender, PointerEventArgs e)
|
||||||
|
{
|
||||||
|
if (_pressedTab && !_startDragTab && sender is Border border)
|
||||||
|
{
|
||||||
|
var delta = e.GetPosition(border) - _pressedTabPosition;
|
||||||
|
var sizeSquired = delta.X * delta.X + delta.Y * delta.Y;
|
||||||
|
if (sizeSquired < 64)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_startDragTab = true;
|
||||||
|
|
||||||
|
var data = new DataObject();
|
||||||
|
data.Set("MovedTab", border.DataContext);
|
||||||
|
DragDrop.DoDragDrop(e, data, DragDropEffects.Move);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DropTab(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Data.Contains("MovedTab") && sender is Border border)
|
||||||
|
{
|
||||||
|
var to = border.DataContext as ViewModels.LauncherPage;
|
||||||
|
var moved = e.Data.Get("MovedTab") as ViewModels.LauncherPage;
|
||||||
|
if (to != null && moved != null && to != moved && DataContext is ViewModels.Launcher vm)
|
||||||
|
{
|
||||||
|
vm.MoveTab(moved, to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_pressedTab = false;
|
||||||
|
_startDragTab = false;
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTabContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Border border && DataContext is ViewModels.Launcher vm)
|
||||||
|
{
|
||||||
|
var menu = vm.CreateContextForPageTab(border.DataContext as ViewModels.LauncherPage);
|
||||||
|
border.OpenContextMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCloseTab(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Button btn && DataContext is ViewModels.Launcher vm)
|
||||||
|
vm.CloseTab(btn.DataContext as ViewModels.LauncherPage);
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _pressedTab = false;
|
||||||
|
private Point _pressedTabPosition = new Point();
|
||||||
|
private bool _startDragTab = false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue