mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-19 19:34:58 +00:00
enhance: cleanup unused resources
Some checks are pending
Some checks are pending
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
b78f6b0ea8
commit
aff003fd6d
8 changed files with 51 additions and 26 deletions
|
@ -44,10 +44,10 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Switcher
|
public IDisposable Switcher
|
||||||
{
|
{
|
||||||
get => _switcher;
|
get => _switcher;
|
||||||
set => SetProperty(ref _switcher, value);
|
private set => SetProperty(ref _switcher, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Launcher(string startupRepo)
|
public Launcher(string startupRepo)
|
||||||
|
@ -148,12 +148,13 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void CancelSwitcher()
|
public void CancelSwitcher()
|
||||||
{
|
{
|
||||||
|
Switcher?.Dispose();
|
||||||
Switcher = null;
|
Switcher = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchWorkspace(Workspace to)
|
public void SwitchWorkspace(Workspace to)
|
||||||
{
|
{
|
||||||
if (to.IsActive)
|
if (to == null || to.IsActive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var one in Pages)
|
foreach (var one in Pages)
|
||||||
|
@ -623,6 +624,6 @@ namespace SourceGit.ViewModels
|
||||||
private LauncherPage _activePage = null;
|
private LauncherPage _activePage = null;
|
||||||
private bool _ignoreIndexChange = false;
|
private bool _ignoreIndexChange = false;
|
||||||
private string _title = string.Empty;
|
private string _title = string.Empty;
|
||||||
private object _switcher = null;
|
private IDisposable _switcher = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class LauncherPageSwitcher : ObservableObject
|
public class LauncherPageSwitcher : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public List<LauncherPage> VisiblePages
|
public List<LauncherPage> VisiblePages
|
||||||
{
|
{
|
||||||
get => _visiblePages;
|
get => _visiblePages;
|
||||||
private set => SetProperty(ref _visiblePages, value);
|
private set => SetProperty(ref _visiblePages, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SearchFilter
|
public string SearchFilter
|
||||||
{
|
{
|
||||||
get => _searchFilter;
|
get => _searchFilter;
|
||||||
|
@ -27,13 +27,13 @@ namespace SourceGit.ViewModels
|
||||||
get => _selectedPage;
|
get => _selectedPage;
|
||||||
set => SetProperty(ref _selectedPage, value);
|
set => SetProperty(ref _selectedPage, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LauncherPageSwitcher(Launcher launcher)
|
public LauncherPageSwitcher(Launcher launcher)
|
||||||
{
|
{
|
||||||
_launcher = launcher;
|
_launcher = launcher;
|
||||||
UpdateVisiblePages();
|
UpdateVisiblePages();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearFilter()
|
public void ClearFilter()
|
||||||
{
|
{
|
||||||
SearchFilter = string.Empty;
|
SearchFilter = string.Empty;
|
||||||
|
@ -41,12 +41,17 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void Switch()
|
public void Switch()
|
||||||
{
|
{
|
||||||
if (_selectedPage is { })
|
_launcher.ActivePage = _selectedPage ?? _launcher.ActivePage;
|
||||||
_launcher.ActivePage = _selectedPage;
|
|
||||||
|
|
||||||
_launcher.CancelSwitcher();
|
_launcher.CancelSwitcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_visiblePages.Clear();
|
||||||
|
_selectedPage = null;
|
||||||
|
_searchFilter = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateVisiblePages()
|
private void UpdateVisiblePages()
|
||||||
{
|
{
|
||||||
var visible = new List<LauncherPage>();
|
var visible = new List<LauncherPage>();
|
||||||
|
|
|
@ -4,7 +4,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class WorkspaceSwitcher : ObservableObject
|
public class WorkspaceSwitcher : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
public List<Workspace> VisibleWorkspaces
|
public List<Workspace> VisibleWorkspaces
|
||||||
{
|
{
|
||||||
|
@ -41,12 +41,17 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void Switch()
|
public void Switch()
|
||||||
{
|
{
|
||||||
if (_selectedWorkspace is { })
|
_launcher.SwitchWorkspace(_selectedWorkspace);
|
||||||
_launcher.SwitchWorkspace(_selectedWorkspace);
|
|
||||||
|
|
||||||
_launcher.CancelSwitcher();
|
_launcher.CancelSwitcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_visibleWorkspaces.Clear();
|
||||||
|
_selectedWorkspace = null;
|
||||||
|
_searchFilter = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateVisibleWorkspaces()
|
private void UpdateVisibleWorkspaces()
|
||||||
{
|
{
|
||||||
var visible = new List<Workspace>();
|
var visible = new List<Workspace>();
|
||||||
|
|
|
@ -104,9 +104,10 @@
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
|
||||||
<!-- Workspace/Pages Switcher -->
|
<!-- Workspace/Pages Switcher -->
|
||||||
<Border Grid.Row="1"
|
<Border Grid.Row="0" Grid.RowSpan="2"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
IsVisible="{Binding Switcher, Converter={x:Static ObjectConverters.IsNotNull}}">
|
IsVisible="{Binding Switcher, Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||||
|
PointerPressed="OnCancelSwitcher">
|
||||||
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
|
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
|
||||||
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
|
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
|
||||||
<ContentControl Margin="16,10,16,12" Content="{Binding Switcher}">
|
<ContentControl Margin="16,10,16,12" Content="{Binding Switcher}">
|
||||||
|
|
|
@ -322,6 +322,13 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCancelSwitcher(object sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Source == sender)
|
||||||
|
(DataContext as ViewModels.Launcher)?.CancelSwitcher();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private KeyModifiers _unhandledModifiers = KeyModifiers.None;
|
private KeyModifiers _unhandledModifiers = KeyModifiers.None;
|
||||||
private WindowState _lastWindowState = WindowState.Normal;
|
private WindowState _lastWindowState = WindowState.Normal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
|
|
||||||
<Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0">
|
<Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0">
|
||||||
<Button.Flyout>
|
<Button.Flyout>
|
||||||
<Flyout Opened="OnTabsDropdownOpened">
|
<Flyout Opened="OnTabsDropdownOpened" Closed="OnTabsDropdownClosed">
|
||||||
<Grid RowDefinitions="28,Auto" KeyDown="OnTabsDropdownKeyDown" LostFocus="OnTabsDropdownLostFocus">
|
<Grid RowDefinitions="28,Auto" KeyDown="OnTabsDropdownKeyDown" LostFocus="OnTabsDropdownLostFocus">
|
||||||
<TextBox Grid.Row="0"
|
<TextBox Grid.Row="0"
|
||||||
Height="24"
|
Height="24"
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace SourceGit.Views
|
||||||
get => GetValue(IsScrollerVisibleProperty);
|
get => GetValue(IsScrollerVisibleProperty);
|
||||||
set => SetValue(IsScrollerVisibleProperty, value);
|
set => SetValue(IsScrollerVisibleProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<string> SearchFilterProperty =
|
public static readonly StyledProperty<string> SearchFilterProperty =
|
||||||
AvaloniaProperty.Register<LauncherTabBar, string>(nameof(SearchFilter));
|
AvaloniaProperty.Register<LauncherTabBar, string>(nameof(SearchFilter));
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ namespace SourceGit.Views
|
||||||
var stroke = new Pen(this.FindResource("Brush.Border0") as IBrush);
|
var stroke = new Pen(this.FindResource("Brush.Border0") as IBrush);
|
||||||
context.DrawGeometry(fill, stroke, geo);
|
context.DrawGeometry(fill, stroke, geo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||||
{
|
{
|
||||||
base.OnPropertyChanged(change);
|
base.OnPropertyChanged(change);
|
||||||
|
@ -148,7 +148,7 @@ namespace SourceGit.Views
|
||||||
if (change.Property == SearchFilterProperty)
|
if (change.Property == SearchFilterProperty)
|
||||||
UpdateSelectablePages();
|
UpdateSelectablePages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollTabs(object _, PointerWheelEventArgs e)
|
private void ScrollTabs(object _, PointerWheelEventArgs e)
|
||||||
{
|
{
|
||||||
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||||
|
@ -270,12 +270,18 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTabsDropdownOpened(object sender, EventArgs e)
|
private void OnTabsDropdownOpened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UpdateSelectablePages();
|
UpdateSelectablePages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTabsDropdownClosed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectablePages.Clear();
|
||||||
|
SearchFilter = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTabsDropdownKeyDown(object sender, KeyEventArgs e)
|
private void OnTabsDropdownKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Escape)
|
if (e.Key == Key.Escape)
|
||||||
|
@ -294,7 +300,7 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTabsDropdownSearchBoxKeyDown(object sender, KeyEventArgs e)
|
private void OnTabsDropdownSearchBoxKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Down && TabsDropdownList.ItemCount > 0)
|
if (e.Key == Key.Down && TabsDropdownList.ItemCount > 0)
|
||||||
|
@ -355,7 +361,7 @@ namespace SourceGit.Views
|
||||||
SelectablePages.Add(page);
|
SelectablePages.Add(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _pressedTab = false;
|
private bool _pressedTab = false;
|
||||||
private Point _pressedTabPosition = new Point();
|
private Point _pressedTabPosition = new Point();
|
||||||
private bool _startDragTab = false;
|
private bool _startDragTab = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue