mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
refactor: move non-observable object from ViewModels
to Models
* ViewModels.MergeMode -> Models.MergeMode * ViewModels.Notification -> Models.Notification * ViewModels.ResetMode -> Models.ResetMode * use `int` instead of `ViewModels.CountSelectedCommits`
This commit is contained in:
parent
0dee3a1969
commit
9e048751ae
13 changed files with 74 additions and 82 deletions
24
src/Models/MergeMode.cs
Normal file
24
src/Models/MergeMode.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
namespace SourceGit.Models
|
||||
{
|
||||
public class MergeMode
|
||||
{
|
||||
public static readonly MergeMode[] Supported =
|
||||
[
|
||||
new MergeMode("Default", "Fast-forward if possible", ""),
|
||||
new MergeMode("No Fast-forward", "Always create a merge commit", "--no-ff"),
|
||||
new MergeMode("Squash", "Use '--squash'", "--squash"),
|
||||
new MergeMode("Don't commit", "Merge without commit", "--no-commit"),
|
||||
];
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
|
||||
public MergeMode(string n, string d, string a)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace SourceGit.ViewModels
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class Notification
|
||||
{
|
27
src/Models/ResetMode.cs
Normal file
27
src/Models/ResetMode.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class ResetMode
|
||||
{
|
||||
public static readonly ResetMode[] Supported =
|
||||
[
|
||||
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
|
||||
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
|
||||
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
|
||||
];
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
public IBrush Color { get; set; }
|
||||
|
||||
public ResetMode(string n, string d, string a, IBrush b)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
Color = b;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,11 +9,6 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class CountSelectedCommits
|
||||
{
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
public class Histories : ObservableObject
|
||||
{
|
||||
public bool IsLoading
|
||||
|
@ -143,7 +138,7 @@ namespace SourceGit.ViewModels
|
|||
else
|
||||
{
|
||||
_repo.SearchResultSelectedCommit = null;
|
||||
DetailContext = new CountSelectedCommits() { Count = commits.Count };
|
||||
DetailContext = commits.Count;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace SourceGit.ViewModels
|
|||
var root = new Commands.QueryRepositoryRootPath(startupRepo).Result();
|
||||
if (string.IsNullOrEmpty(root))
|
||||
{
|
||||
Pages[0].Notifications.Add(new Notification
|
||||
Pages[0].Notifications.Add(new Models.Notification
|
||||
{
|
||||
IsError = true,
|
||||
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
|
||||
|
@ -272,7 +272,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void DispatchNotification(string pageId, string message, bool isError)
|
||||
{
|
||||
var notification = new Notification()
|
||||
var notification = new Models.Notification()
|
||||
{
|
||||
IsError = isError,
|
||||
Message = message,
|
||||
|
|
|
@ -18,11 +18,11 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _data, value);
|
||||
}
|
||||
|
||||
public AvaloniaList<Notification> Notifications
|
||||
public AvaloniaList<Models.Notification> Notifications
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new AvaloniaList<Notification>();
|
||||
} = new AvaloniaList<Models.Notification>();
|
||||
|
||||
public LauncherPage()
|
||||
{
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class MergeMode
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
|
||||
public MergeMode(string n, string d, string a)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
}
|
||||
}
|
||||
|
||||
public class Merge : Popup
|
||||
{
|
||||
public string Source
|
||||
|
@ -31,13 +16,7 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public List<MergeMode> Modes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public MergeMode SelectedMode
|
||||
public Models.MergeMode SelectedMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -48,13 +27,7 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Source = source;
|
||||
Into = into;
|
||||
Modes = new List<MergeMode>() {
|
||||
new MergeMode("Default", "Fast-forward if possible", ""),
|
||||
new MergeMode("No Fast-forward", "Always create a merge commit", "--no-ff"),
|
||||
new MergeMode("Squash", "Use '--squash'", "--squash"),
|
||||
new MergeMode("Don't commit", "Merge without commit", "--no-commit"),
|
||||
};
|
||||
SelectedMode = Modes[0];
|
||||
SelectedMode = Models.MergeMode.Supported[0];
|
||||
View = new Views.Merge() { DataContext = this };
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Media;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class ResetMode
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Desc { get; set; }
|
||||
public string Arg { get; set; }
|
||||
public IBrush Color { get; set; }
|
||||
|
||||
public ResetMode(string n, string d, string a, IBrush b)
|
||||
{
|
||||
Name = n;
|
||||
Desc = d;
|
||||
Arg = a;
|
||||
Color = b;
|
||||
}
|
||||
}
|
||||
|
||||
public class Reset : Popup
|
||||
{
|
||||
public Models.Branch Current
|
||||
|
@ -35,13 +16,7 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public List<ResetMode> Modes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ResetMode SelectedMode
|
||||
public Models.ResetMode SelectedMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -52,12 +27,7 @@ namespace SourceGit.ViewModels
|
|||
_repo = repo;
|
||||
Current = current;
|
||||
To = to;
|
||||
Modes = new List<ResetMode>() {
|
||||
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
|
||||
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
|
||||
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
|
||||
};
|
||||
SelectedMode = Modes[0];
|
||||
SelectedMode = Models.ResetMode.Supported[0];
|
||||
View = new Views.Reset() { DataContext = this };
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@
|
|||
<v:RevisionCompare/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:CountSelectedCommits">
|
||||
<DataTemplate DataType="x:Int32">
|
||||
<Grid Background="{DynamicResource Brush.Window}">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Path Width="128" Height="128"
|
||||
|
@ -227,7 +227,7 @@
|
|||
Margin="0,16"
|
||||
FontSize="24" FontWeight="Bold"
|
||||
Foreground="{DynamicResource Brush.FG2}"
|
||||
Text="{Binding Count, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Histories.Selected'}"/>
|
||||
Text="{Binding Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Histories.Selected'}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
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:m="using:SourceGit.Models"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
@ -86,7 +87,7 @@
|
|||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl ItemsSource="{Binding Notifications}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="vm:Notification">
|
||||
<DataTemplate DataType="m:Notification">
|
||||
<Border Margin="10,6" HorizontalAlignment="Stretch" VerticalAlignment="Top" Effect="drop-shadow(0 0 12 #A0000000)">
|
||||
<Border Padding="8" CornerRadius="6" Background="{DynamicResource Brush.Popup}">
|
||||
<Grid RowDefinitions="26,Auto,32">
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnDismissNotification(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button { DataContext: ViewModels.Notification notice } &&
|
||||
if (sender is Button { DataContext: Models.Notification notice } &&
|
||||
DataContext is ViewModels.LauncherPage page)
|
||||
page.Notifications.Remove(notice);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
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:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.Merge"
|
||||
|
@ -36,10 +37,10 @@
|
|||
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||
Height="28" Padding="8,0"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Modes}"
|
||||
ItemsSource="{Binding Source={x:Static m:MergeMode.Supported}}"
|
||||
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:MergeMode">
|
||||
<DataTemplate DataType="m:MergeMode">
|
||||
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
<TextBlock Text="{Binding Desc}" Margin="8,0,0,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
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:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
@ -38,10 +39,10 @@
|
|||
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||
Height="28" Padding="8,0"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Modes}"
|
||||
ItemsSource="{Binding Source={x:Static m:ResetMode.Supported}}"
|
||||
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:ResetMode">
|
||||
<DataTemplate DataType="m:ResetMode">
|
||||
<Grid ColumnDefinitions="16,60,*">
|
||||
<Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="4,0,0,0"/>
|
||||
|
|
Loading…
Reference in a new issue