mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
refactor: code cleanup
This commit is contained in:
parent
04f4293421
commit
fa3a3b2dad
25 changed files with 174 additions and 233 deletions
|
@ -24,9 +24,9 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
}
|
||||
|
||||
public void Remove(object param)
|
||||
public void Remove(string file)
|
||||
{
|
||||
if (param is string file)
|
||||
if (!string.IsNullOrEmpty(file))
|
||||
{
|
||||
new Commands.AssumeUnchanged(_repo).Remove(file);
|
||||
Files.Remove(file);
|
||||
|
|
|
@ -50,10 +50,10 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _extraArgs, value);
|
||||
}
|
||||
|
||||
public Clone(Launcher launcher, LauncherPage page)
|
||||
public Clone(Launcher launcher)
|
||||
{
|
||||
_launcher = launcher;
|
||||
_page = page;
|
||||
_page = launcher.ActivePage;
|
||||
|
||||
View = new Views.Clone() { DataContext = this };
|
||||
}
|
||||
|
|
|
@ -158,13 +158,6 @@ namespace SourceGit.ViewModels
|
|||
get => _stashesPage == null ? 0 : _stashesPage.Count;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool CanCommitWithPush
|
||||
{
|
||||
get => _canCommitWithPush;
|
||||
private set => SetProperty(ref _canCommitWithPush, value);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IncludeUntracked
|
||||
{
|
||||
|
@ -172,9 +165,7 @@ namespace SourceGit.ViewModels
|
|||
set
|
||||
{
|
||||
if (SetProperty(ref _includeUntracked, value))
|
||||
{
|
||||
Task.Run(RefreshWorkingCopyChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -567,8 +558,11 @@ namespace SourceGit.ViewModels
|
|||
LocalBranchTrees = builder.Locals;
|
||||
RemoteBranchTrees = builder.Remotes;
|
||||
|
||||
var cur = Branches.Find(x => x.IsCurrent);
|
||||
CanCommitWithPush = cur != null && !string.IsNullOrEmpty(cur.Upstream);
|
||||
if (_workingCopy != null)
|
||||
{
|
||||
var cur = Branches.Find(x => x.IsCurrent);
|
||||
_workingCopy.CanCommitWithPush = cur != null && !string.IsNullOrEmpty(cur.Upstream);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1520,7 +1514,6 @@ namespace SourceGit.ViewModels
|
|||
private List<BranchTreeNode> _remoteBranchTrees = new List<BranchTreeNode>();
|
||||
private List<Models.Tag> _tags = new List<Models.Tag>();
|
||||
private List<string> _submodules = new List<string>();
|
||||
private bool _canCommitWithPush = false;
|
||||
private bool _includeUntracked = true;
|
||||
|
||||
private InProgressContext _inProgressContext = null;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
@ -106,34 +106,42 @@ namespace SourceGit.ViewModels
|
|||
_diffContext = null;
|
||||
}
|
||||
|
||||
public void Apply(object param)
|
||||
public ContextMenu MakeContextMenu(Models.Stash stash)
|
||||
{
|
||||
if (param is Models.Stash stash)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
new Commands.Stash(_repo.FullPath).Apply(stash.Name);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (stash == null)
|
||||
return null;
|
||||
|
||||
public void Pop(object param)
|
||||
{
|
||||
if (param is Models.Stash stash)
|
||||
var apply = new MenuItem();
|
||||
apply.Header = App.Text("StashCM.Apply");
|
||||
apply.Click += (o, ev) =>
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
new Commands.Stash(_repo.FullPath).Pop(stash.Name);
|
||||
});
|
||||
}
|
||||
}
|
||||
Task.Run(() => new Commands.Stash(_repo.FullPath).Apply(stash.Name));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
public void Drop(object param)
|
||||
{
|
||||
if (param is Models.Stash stash && PopupHost.CanCreatePopup())
|
||||
var pop = new MenuItem();
|
||||
pop.Header = App.Text("StashCM.Pop");
|
||||
pop.Click += (o, ev) =>
|
||||
{
|
||||
PopupHost.ShowPopup(new DropStash(_repo.FullPath, stash));
|
||||
}
|
||||
Task.Run(() => new Commands.Stash(_repo.FullPath).Pop(stash.Name));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var drop = new MenuItem();
|
||||
drop.Header = App.Text("StashCM.Drop");
|
||||
drop.Click += (o, ev) =>
|
||||
{
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowPopup(new DropStash(_repo.FullPath, stash));
|
||||
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(apply);
|
||||
menu.Items.Add(pop);
|
||||
menu.Items.Add(drop);
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
|
@ -40,20 +41,21 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public void Clone(object param)
|
||||
public void Clone()
|
||||
{
|
||||
var launcher = param as Launcher;
|
||||
var page = launcher.ActivePage;
|
||||
|
||||
if (!Preference.Instance.IsGitConfigured)
|
||||
{
|
||||
App.RaiseException(page.GetId(), App.Text("NotConfigured"));
|
||||
App.RaiseException(string.Empty, App.Text("NotConfigured"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PopupHost.CanCreatePopup())
|
||||
{
|
||||
PopupHost.ShowPopup(new Clone(launcher, page));
|
||||
if (App.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var launcher = desktop.MainWindow.DataContext as Launcher;
|
||||
PopupHost.ShowPopup(new Clone(launcher));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,29 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public class WorkingCopy : ObservableObject
|
||||
{
|
||||
public bool IncludeUntracked
|
||||
{
|
||||
get => _repo.IncludeUntracked;
|
||||
set
|
||||
{
|
||||
if (_repo.IncludeUntracked != value)
|
||||
{
|
||||
_repo.IncludeUntracked = value;
|
||||
OnPropertyChanged(nameof(IncludeUntracked));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanCommitWithPush
|
||||
{
|
||||
get => _canCommitWithPush;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _canCommitWithPush, value))
|
||||
OnPropertyChanged(nameof(IsCommitWithPushVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsStaging
|
||||
{
|
||||
get => _isStaging;
|
||||
|
@ -74,9 +97,16 @@ namespace SourceGit.ViewModels
|
|||
CommitMessage = commits[0].FullMessage;
|
||||
}
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(IsCommitWithPushVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCommitWithPushVisible
|
||||
{
|
||||
get => !UseAmend && CanCommitWithPush;
|
||||
}
|
||||
|
||||
public List<Models.Change> Unstaged
|
||||
{
|
||||
get => _unstaged;
|
||||
|
@ -161,14 +191,31 @@ namespace SourceGit.ViewModels
|
|||
public void Cleanup()
|
||||
{
|
||||
_repo = null;
|
||||
if (_unstaged != null)
|
||||
_unstaged.Clear();
|
||||
if (_staged != null)
|
||||
_staged.Clear();
|
||||
|
||||
if (_selectedUnstaged != null)
|
||||
{
|
||||
_selectedUnstaged.Clear();
|
||||
OnPropertyChanged(nameof(SelectedUnstaged));
|
||||
}
|
||||
|
||||
if (_selectedStaged != null)
|
||||
{
|
||||
_selectedStaged.Clear();
|
||||
OnPropertyChanged(nameof(SelectedStaged));
|
||||
}
|
||||
|
||||
if (_unstaged != null)
|
||||
{
|
||||
_unstaged.Clear();
|
||||
OnPropertyChanged(nameof(Unstaged));
|
||||
}
|
||||
|
||||
if (_staged != null)
|
||||
{
|
||||
_staged.Clear();
|
||||
OnPropertyChanged(nameof(Staged));
|
||||
}
|
||||
|
||||
_detailContext = null;
|
||||
_commitMessage = string.Empty;
|
||||
}
|
||||
|
@ -1016,6 +1063,7 @@ namespace SourceGit.ViewModels
|
|||
private bool _isUnstaging = false;
|
||||
private bool _isCommitting = false;
|
||||
private bool _useAmend = false;
|
||||
private bool _canCommitWithPush = false;
|
||||
private List<Models.Change> _unstaged = null;
|
||||
private List<Models.Change> _staged = null;
|
||||
private List<Models.Change> _selectedUnstaged = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue