mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -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
|
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
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class CountSelectedCommits
|
|
||||||
{
|
|
||||||
public int Count { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Histories : ObservableObject
|
public class Histories : ObservableObject
|
||||||
{
|
{
|
||||||
public bool IsLoading
|
public bool IsLoading
|
||||||
|
@ -143,7 +138,7 @@ namespace SourceGit.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_repo.SearchResultSelectedCommit = null;
|
_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();
|
var root = new Commands.QueryRepositoryRootPath(startupRepo).Result();
|
||||||
if (string.IsNullOrEmpty(root))
|
if (string.IsNullOrEmpty(root))
|
||||||
{
|
{
|
||||||
Pages[0].Notifications.Add(new Notification
|
Pages[0].Notifications.Add(new Models.Notification
|
||||||
{
|
{
|
||||||
IsError = true,
|
IsError = true,
|
||||||
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
|
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)
|
public void DispatchNotification(string pageId, string message, bool isError)
|
||||||
{
|
{
|
||||||
var notification = new Notification()
|
var notification = new Models.Notification()
|
||||||
{
|
{
|
||||||
IsError = isError,
|
IsError = isError,
|
||||||
Message = message,
|
Message = message,
|
||||||
|
|
|
@ -18,11 +18,11 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _data, value);
|
set => SetProperty(ref _data, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AvaloniaList<Notification> Notifications
|
public AvaloniaList<Models.Notification> Notifications
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
} = new AvaloniaList<Notification>();
|
} = new AvaloniaList<Models.Notification>();
|
||||||
|
|
||||||
public LauncherPage()
|
public LauncherPage()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,22 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
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 class Merge : Popup
|
||||||
{
|
{
|
||||||
public string Source
|
public string Source
|
||||||
|
@ -31,13 +16,7 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MergeMode> Modes
|
public Models.MergeMode SelectedMode
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MergeMode SelectedMode
|
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -48,13 +27,7 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
Source = source;
|
Source = source;
|
||||||
Into = into;
|
Into = into;
|
||||||
Modes = new List<MergeMode>() {
|
SelectedMode = Models.MergeMode.Supported[0];
|
||||||
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];
|
|
||||||
View = new Views.Merge() { DataContext = this };
|
View = new Views.Merge() { DataContext = this };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
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 class Reset : Popup
|
||||||
{
|
{
|
||||||
public Models.Branch Current
|
public Models.Branch Current
|
||||||
|
@ -35,13 +16,7 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResetMode> Modes
|
public Models.ResetMode SelectedMode
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResetMode SelectedMode
|
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -52,12 +27,7 @@ namespace SourceGit.ViewModels
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
Current = current;
|
Current = current;
|
||||||
To = to;
|
To = to;
|
||||||
Modes = new List<ResetMode>() {
|
SelectedMode = Models.ResetMode.Supported[0];
|
||||||
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];
|
|
||||||
View = new Views.Reset() { DataContext = this };
|
View = new Views.Reset() { DataContext = this };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@
|
||||||
<v:RevisionCompare/>
|
<v:RevisionCompare/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:CountSelectedCommits">
|
<DataTemplate DataType="x:Int32">
|
||||||
<Grid Background="{DynamicResource Brush.Window}">
|
<Grid Background="{DynamicResource Brush.Window}">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Path Width="128" Height="128"
|
<Path Width="128" Height="128"
|
||||||
|
@ -227,7 +227,7 @@
|
||||||
Margin="0,16"
|
Margin="0,16"
|
||||||
FontSize="24" FontWeight="Bold"
|
FontSize="24" FontWeight="Bold"
|
||||||
Foreground="{DynamicResource Brush.FG2}"
|
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>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
@ -86,7 +87,7 @@
|
||||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||||
<ItemsControl ItemsSource="{Binding Notifications}">
|
<ItemsControl ItemsSource="{Binding Notifications}">
|
||||||
<ItemsControl.ItemTemplate>
|
<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 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">
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnDismissNotification(object sender, RoutedEventArgs e)
|
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)
|
DataContext is ViewModels.LauncherPage page)
|
||||||
page.Notifications.Remove(notice);
|
page.Notifications.Remove(notice);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.Merge"
|
x:Class="SourceGit.Views.Merge"
|
||||||
|
@ -36,10 +37,10 @@
|
||||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||||
Height="28" Padding="8,0"
|
Height="28" Padding="8,0"
|
||||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||||
ItemsSource="{Binding Modes}"
|
ItemsSource="{Binding Source={x:Static m:MergeMode.Supported}}"
|
||||||
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:MergeMode">
|
<DataTemplate DataType="m:MergeMode">
|
||||||
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||||
<TextBlock Text="{Binding Name}"/>
|
<TextBlock Text="{Binding Name}"/>
|
||||||
<TextBlock Text="{Binding Desc}" Margin="8,0,0,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
|
<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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
xmlns:c="using:SourceGit.Converters"
|
xmlns:c="using:SourceGit.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
@ -38,10 +39,10 @@
|
||||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||||
Height="28" Padding="8,0"
|
Height="28" Padding="8,0"
|
||||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||||
ItemsSource="{Binding Modes}"
|
ItemsSource="{Binding Source={x:Static m:ResetMode.Supported}}"
|
||||||
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:ResetMode">
|
<DataTemplate DataType="m:ResetMode">
|
||||||
<Grid ColumnDefinitions="16,60,*">
|
<Grid ColumnDefinitions="16,60,*">
|
||||||
<Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/>
|
<Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/>
|
||||||
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="4,0,0,0"/>
|
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="4,0,0,0"/>
|
||||||
|
|
Loading…
Reference in a new issue