mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 03:34:59 +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,7 +4,7 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -276,6 +276,12 @@ namespace SourceGit.Views
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue