mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-29 16:14:59 +00:00
refactor: code cleanup
This commit is contained in:
parent
04f4293421
commit
fa3a3b2dad
25 changed files with 174 additions and 233 deletions
|
@ -92,9 +92,7 @@
|
|||
<DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Classes="icon_button"
|
||||
Command="{Binding $parent[v:AssumeUnchangedManager].DataContext.(vm:AssumeUnchangedManager).Remove}"
|
||||
CommandParameter="{Binding}">
|
||||
<Button Classes="icon_button" Click="OnRemoveButtonClicked">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Clear}"/>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -20,5 +20,12 @@ namespace SourceGit.Views
|
|||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnRemoveButtonClicked(object sender, RoutedEventArgs e) {
|
||||
if (DataContext is ViewModels.AssumeUnchangedManager vm && sender is Button button)
|
||||
vm.Remove(button.DataContext as string);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
<Button Classes="caption_button" Click="MinimizeWindow">
|
||||
<Path Data="{StaticResource Icons.Window.Minimize}"/>
|
||||
</Button>
|
||||
<Button Classes="caption_button" Click="MaximizeOrRestoreWindow">
|
||||
<Path Data="{Binding $parent[Window].WindowState, Converter={x:Static c:WindowStateConverters.ToMaxOrRestoreIcon}}"/>
|
||||
<Button Classes="caption_button max_or_restore_btn" Click="MaximizeOrRestoreWindow">
|
||||
<Path/>
|
||||
</Button>
|
||||
<Button Classes="caption_button" Click="CloseWindow">
|
||||
<Path Data="{StaticResource Icons.Window.Close}" Width="9" Height="9"/>
|
||||
|
|
|
@ -12,11 +12,7 @@
|
|||
<DataTemplate DataType="m:Commit">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<!-- Author & Committer -->
|
||||
<Grid Margin="0,8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding IsCommitterVisible, Converter={x:Static c:BoolConverters.ToStarOrAutoGridLength}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<UniformGrid Rows="1" Margin="0,8">
|
||||
<!-- Author -->
|
||||
<Grid Grid.Column="0" ColumnDefinitions="96,*">
|
||||
<v:Avatar Grid.Column="0" Width="64" Height="64" HorizontalAlignment="Right" User="{Binding Author}"/>
|
||||
|
@ -26,9 +22,9 @@
|
|||
<SelectableTextBlock Text="{Binding Author.Name}" Margin="2,0,8,0"/>
|
||||
<SelectableTextBlock Text="{Binding Author.Email}" ToolTip.Tip="{Binding Author.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
|
||||
</DockPanel>
|
||||
<SelectableTextBlock Text="{Binding AuthorTimeStr}"
|
||||
<SelectableTextBlock Text="{Binding AuthorTimeStr}"
|
||||
Margin="2,0,0,0"
|
||||
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Decrease}}"
|
||||
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Decrease}}"
|
||||
Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
@ -42,13 +38,13 @@
|
|||
<SelectableTextBlock Text="{Binding Committer.Name}" Margin="2,0,8,0"/>
|
||||
<SelectableTextBlock Text="{Binding Committer.Email}" ToolTip.Tip="{Binding Committer.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
|
||||
</DockPanel>
|
||||
<SelectableTextBlock Text="{Binding CommitterTimeStr}"
|
||||
Margin="2,0,0,0"
|
||||
<SelectableTextBlock Text="{Binding CommitterTimeStr}"
|
||||
Margin="2,0,0,0"
|
||||
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Decrease}}"
|
||||
Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UniformGrid>
|
||||
|
||||
<!-- Line -->
|
||||
<Rectangle Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}" VerticalAlignment="Center"/>
|
||||
|
|
|
@ -213,7 +213,8 @@
|
|||
|
||||
<!-- Text Diff -->
|
||||
<DataTemplate DataType="m:TextDiff">
|
||||
<v:TextDiffView TextDiff="{Binding}" UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/>
|
||||
<v:TextDiffView TextDiff="{Binding}"
|
||||
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<!-- No or only EOL changes -->
|
||||
|
|
|
@ -129,7 +129,6 @@
|
|||
</DataGrid>
|
||||
|
||||
<v:CommitGraph x:Name="commitGraph"
|
||||
BindingDataGrid="{Binding #commitDataGrid}"
|
||||
Graph="{Binding Graph}"
|
||||
DotBrush="{DynamicResource Brush.Contents}"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
|
|
|
@ -3,7 +3,6 @@ using System;
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
|
@ -90,15 +89,6 @@ namespace SourceGit.Views
|
|||
set => SetValue(GraphProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<DataGrid> BindingDataGridProperty =
|
||||
AvaloniaProperty.Register<CommitGraph, DataGrid>(nameof(BindingDataGrid));
|
||||
|
||||
public DataGrid BindingDataGrid
|
||||
{
|
||||
get => GetValue(BindingDataGridProperty);
|
||||
set => SetValue(BindingDataGridProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IBrush> DotBrushProperty =
|
||||
AvaloniaProperty.Register<CommitGraph, IBrush>(nameof(DotBrush), Brushes.Transparent);
|
||||
|
||||
|
@ -108,17 +98,13 @@ namespace SourceGit.Views
|
|||
set => SetValue(DotBrushProperty, value);
|
||||
}
|
||||
|
||||
static CommitGraph()
|
||||
{
|
||||
AffectsRender<CommitGraph>(BindingDataGridProperty, GraphProperty, DotBrushProperty);
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
|
||||
var parent = this.FindAncestorOfType<Histories>();
|
||||
var graph = Graph;
|
||||
var grid = BindingDataGrid;
|
||||
var grid = parent.commitDataGrid;
|
||||
if (graph == null || grid == null)
|
||||
return;
|
||||
|
||||
|
@ -277,8 +263,6 @@ namespace SourceGit.Views
|
|||
public Histories()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Bind(NavigationIdProperty, new Binding("NavigationId", BindingMode.OneWay));
|
||||
}
|
||||
|
||||
private void OnCommitDataGridLayoutUpdated(object sender, EventArgs e)
|
||||
|
|
|
@ -166,7 +166,7 @@
|
|||
</ContextMenu>
|
||||
</Border.ContextMenu>
|
||||
|
||||
<v:LauncherTab UseFixedTabWidth="{Binding Source={x:Static vm:Preference.Instance}, Path=UseFixedTabWidth}" Height="30" ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center">
|
||||
<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}}"
|
||||
|
@ -219,7 +219,7 @@
|
|||
</MultiBinding>
|
||||
</Rectangle.IsVisible>
|
||||
</Rectangle>
|
||||
</v:LauncherTab>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
@ -253,7 +253,17 @@
|
|||
</Grid>
|
||||
|
||||
<!-- Page body -->
|
||||
<v:LauncherBody Grid.Row="1" Background="{DynamicResource Brush.ToolBar}" Data="{Binding ActivePage.Data}"/>
|
||||
<ContentControl Grid.Row="1" Background="{DynamicResource Brush.ToolBar}" Content="{Binding ActivePage.Data}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:Welcome">
|
||||
<v:Welcome/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:Repository">
|
||||
<v:Repository/>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
|
||||
<!-- Popup container -->
|
||||
<Grid Grid.Row="1" Margin="0,36,0,0" IsVisible="{Binding ActivePage.Popup, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
|
|
|
@ -7,67 +7,6 @@ using Avalonia.Interactivity;
|
|||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class LauncherTab : Grid
|
||||
{
|
||||
public static readonly StyledProperty<bool> UseFixedTabWidthProperty =
|
||||
AvaloniaProperty.Register<LauncherTab, bool>(nameof(UseFixedTabWidth), false);
|
||||
|
||||
public bool UseFixedTabWidth
|
||||
{
|
||||
get => GetValue(UseFixedTabWidthProperty);
|
||||
set => SetValue(UseFixedTabWidthProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(Grid);
|
||||
|
||||
static LauncherTab()
|
||||
{
|
||||
UseFixedTabWidthProperty.Changed.AddClassHandler<LauncherTab>((tab, ev) =>
|
||||
{
|
||||
tab.Width = tab.UseFixedTabWidth ? 200.0 : double.NaN;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class LauncherBody : Border
|
||||
{
|
||||
public static readonly StyledProperty<object> DataProperty =
|
||||
AvaloniaProperty.Register<LauncherBody, object>(nameof(Data), false);
|
||||
|
||||
public object Data
|
||||
{
|
||||
get => GetValue(DataProperty);
|
||||
set => SetValue(DataProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(Border);
|
||||
|
||||
static LauncherBody()
|
||||
{
|
||||
DataProperty.Changed.AddClassHandler<LauncherBody>((body, ev) =>
|
||||
{
|
||||
var data = body.Data;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
body.Child = null;
|
||||
}
|
||||
else if (data is ViewModels.Welcome)
|
||||
{
|
||||
body.Child = new Welcome { DataContext = data };
|
||||
}
|
||||
else if (data is ViewModels.Repository)
|
||||
{
|
||||
body.Child = new Repository { DataContext = data };
|
||||
}
|
||||
else
|
||||
{
|
||||
body.Child = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Launcher : Window, Models.INotificationReceiver
|
||||
{
|
||||
public Launcher()
|
||||
|
|
|
@ -589,7 +589,21 @@
|
|||
<Button Grid.Column="3" Classes="flat" FontWeight="Regular" Content="{DynamicResource Text.Repository.Abort}" Height="20" Padding="8,0" Margin="4,0" Command="{Binding AbortMerge}"/>
|
||||
</Grid>
|
||||
|
||||
<v:RepositorySubView Grid.Row="1" Data="{Binding SelectedView}"/>
|
||||
<ContentControl Grid.Row="1" Content="{Binding SelectedView}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:Histories">
|
||||
<v:Histories NavigationId="{Binding NavigationId}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:WorkingCopy">
|
||||
<v:WorkingCopy/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:StashesPage">
|
||||
<v:StashesPage/>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
@ -11,51 +11,6 @@ using Avalonia.VisualTree;
|
|||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class RepositorySubView : Border
|
||||
{
|
||||
public static readonly StyledProperty<object> DataProperty =
|
||||
AvaloniaProperty.Register<RepositorySubView, object>(nameof(Data), false);
|
||||
|
||||
public object Data
|
||||
{
|
||||
get => GetValue(DataProperty);
|
||||
set => SetValue(DataProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(Border);
|
||||
|
||||
static RepositorySubView()
|
||||
{
|
||||
DataProperty.Changed.AddClassHandler<RepositorySubView>((view, ev) =>
|
||||
{
|
||||
var data = view.Data;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
view.Child = null;
|
||||
}
|
||||
else if (data is ViewModels.Histories)
|
||||
{
|
||||
view.Child = new Histories { DataContext = data };
|
||||
}
|
||||
else if (data is ViewModels.WorkingCopy)
|
||||
{
|
||||
view.Child = new WorkingCopy { DataContext = data };
|
||||
}
|
||||
else if (data is ViewModels.StashesPage)
|
||||
{
|
||||
view.Child = new StashesPage { DataContext = data };
|
||||
}
|
||||
else
|
||||
{
|
||||
view.Child = null;
|
||||
}
|
||||
|
||||
GC.Collect();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Repository : UserControl
|
||||
{
|
||||
public Repository()
|
||||
|
|
|
@ -54,15 +54,7 @@
|
|||
<DataGridTemplateColumn Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate DataType="m:Stash">
|
||||
<Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1" Padding="4" Background="Transparent">
|
||||
<Border.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="{DynamicResource Text.StashCM.Apply}" Command="{Binding $parent[v:StashesPage].DataContext.(vm:StashesPage).Apply}" CommandParameter="{Binding}"/>
|
||||
<MenuItem Header="{DynamicResource Text.StashCM.Pop}" Command="{Binding $parent[v:StashesPage].DataContext.(vm:StashesPage).Pop}" CommandParameter="{Binding}"/>
|
||||
<MenuItem Header="{DynamicResource Text.StashCM.Drop}" Command="{Binding $parent[v:StashesPage].DataContext.(vm:StashesPage).Drop}" CommandParameter="{Binding}"/>
|
||||
</ContextMenu>
|
||||
</Border.ContextMenu>
|
||||
|
||||
<Border BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1" Padding="4" Background="Transparent" ContextRequested="OnStashContextRequested">
|
||||
<Grid RowDefinitions="Auto,*" >
|
||||
<Grid Grid.Row="0" ColumnDefinitions="*,Auto">
|
||||
<TextBlock Grid.Column="0" Classes="monospace" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" TextDecorations="Underline" Cursor="Hand"/>
|
||||
|
|
|
@ -8,5 +8,15 @@ namespace SourceGit.Views
|
|||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnStashContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.StashesPage vm && sender is Border border)
|
||||
{
|
||||
var menu = vm.MakeContextMenu(border.DataContext as Models.Stash);
|
||||
border.OpenContextMenu(menu);
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<Grid RowDefinitions="36,*,36" Background="{DynamicResource Brush.Window}">
|
||||
<Border Grid.Row="0" BorderBrush="{DynamicResource Brush.Border0}" BorderThickness="0,0,0,1" Background="{DynamicResource Brush.ToolBar}">
|
||||
<StackPanel Orientation="Horizontal" Margin="4,0,0,0">
|
||||
<Button Classes="icon_button" Width="32" Command="{Binding Clone}" CommandParameter="{Binding $parent[v:Launcher].DataContext}" ToolTip.Tip="{DynamicResource Text.Welcome.Clone}">
|
||||
<Button Classes="icon_button" Width="32" Command="{Binding Clone}" ToolTip.Tip="{DynamicResource Text.Welcome.Clone}">
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.Pull}"/>
|
||||
</Button>
|
||||
|
||||
|
|
|
@ -211,14 +211,8 @@
|
|||
Height="28"
|
||||
Margin="8,0,0,0"
|
||||
Padding="8,0"
|
||||
Command="{Binding CommitWithPush}">
|
||||
<Button.IsVisible>
|
||||
<MultiBinding Converter="{x:Static BoolConverters.And}">
|
||||
<Binding Path="$parent[v:Repository].DataContext.(vm:Repository).CanCommitWithPush"/>
|
||||
<Binding Path="!UseAmend"/>
|
||||
</MultiBinding>
|
||||
</Button.IsVisible>
|
||||
</Button>
|
||||
Command="{Binding CommitWithPush}"
|
||||
IsVisible="{Binding IsCommitWithPushVisible}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue