mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
style: add .editorconfig for code formatting. see issu #25
This commit is contained in:
parent
a8eeea4f78
commit
18aaa0a143
225 changed files with 7781 additions and 3911 deletions
|
@ -1,30 +1,41 @@
|
|||
using Avalonia.Collections;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SourceGit.ViewModels {
|
||||
public class Launcher : ObservableObject {
|
||||
public AvaloniaList<LauncherPage> Pages {
|
||||
using Avalonia.Collections;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class Launcher : ObservableObject
|
||||
{
|
||||
public AvaloniaList<LauncherPage> Pages
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public LauncherPage ActivePage {
|
||||
public LauncherPage ActivePage
|
||||
{
|
||||
get => _activePage;
|
||||
set {
|
||||
if (SetProperty(ref _activePage, value)) {
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _activePage, value))
|
||||
{
|
||||
PopupHost.Active = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Launcher() {
|
||||
public Launcher()
|
||||
{
|
||||
Pages = new AvaloniaList<LauncherPage>();
|
||||
AddNewTab();
|
||||
|
||||
if (Preference.Instance.RestoreTabs) {
|
||||
foreach (var id in Preference.Instance.OpenedTabs) {
|
||||
if (Preference.Instance.RestoreTabs)
|
||||
{
|
||||
foreach (var id in Preference.Instance.OpenedTabs)
|
||||
{
|
||||
var node = Preference.FindNode(id);
|
||||
if (node == null) continue;
|
||||
|
||||
|
@ -32,17 +43,21 @@ namespace SourceGit.ViewModels {
|
|||
}
|
||||
|
||||
var lastActiveIdx = Preference.Instance.LastActiveTabIdx;
|
||||
if (lastActiveIdx >= 0 && lastActiveIdx < Pages.Count) {
|
||||
if (lastActiveIdx >= 0 && lastActiveIdx < Pages.Count)
|
||||
{
|
||||
ActivePage = Pages[lastActiveIdx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Quit() {
|
||||
public void Quit()
|
||||
{
|
||||
Preference.Instance.OpenedTabs.Clear();
|
||||
|
||||
if (Preference.Instance.RestoreTabs) {
|
||||
foreach (var page in Pages) {
|
||||
if (Preference.Instance.RestoreTabs)
|
||||
{
|
||||
foreach (var page in Pages)
|
||||
{
|
||||
if (page.Node.IsRepository) Preference.Instance.OpenedTabs.Add(page.Node.Id);
|
||||
}
|
||||
}
|
||||
|
@ -51,20 +66,23 @@ namespace SourceGit.ViewModels {
|
|||
Preference.Save();
|
||||
}
|
||||
|
||||
public void AddNewTab() {
|
||||
public void AddNewTab()
|
||||
{
|
||||
var page = new LauncherPage();
|
||||
Pages.Add(page);
|
||||
ActivePage = page;
|
||||
}
|
||||
|
||||
public void MoveTab(LauncherPage from, LauncherPage to) {
|
||||
public void MoveTab(LauncherPage from, LauncherPage to)
|
||||
{
|
||||
var fromIdx = Pages.IndexOf(from);
|
||||
var toIdx = Pages.IndexOf(to);
|
||||
Pages.Move(fromIdx, toIdx);
|
||||
ActivePage = from;
|
||||
}
|
||||
|
||||
public void GotoNextTab() {
|
||||
public void GotoNextTab()
|
||||
{
|
||||
if (Pages.Count == 1) return;
|
||||
|
||||
var activeIdx = Pages.IndexOf(_activePage);
|
||||
|
@ -72,8 +90,10 @@ namespace SourceGit.ViewModels {
|
|||
ActivePage = Pages[nextIdx];
|
||||
}
|
||||
|
||||
public void CloseTab(object param) {
|
||||
if (Pages.Count == 1) {
|
||||
public void CloseTab(object param)
|
||||
{
|
||||
if (Pages.Count == 1)
|
||||
{
|
||||
App.Quit();
|
||||
return;
|
||||
}
|
||||
|
@ -83,21 +103,29 @@ namespace SourceGit.ViewModels {
|
|||
|
||||
var removeIdx = Pages.IndexOf(page);
|
||||
var activeIdx = Pages.IndexOf(_activePage);
|
||||
if (removeIdx == activeIdx) {
|
||||
if (removeIdx == Pages.Count - 1) {
|
||||
if (removeIdx == activeIdx)
|
||||
{
|
||||
if (removeIdx == Pages.Count - 1)
|
||||
{
|
||||
ActivePage = Pages[removeIdx - 1];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivePage = Pages[removeIdx + 1];
|
||||
}
|
||||
|
||||
CloseRepositoryInTab(page);
|
||||
Pages.RemoveAt(removeIdx);
|
||||
OnPropertyChanged(nameof(Pages));
|
||||
} else if (removeIdx + 1 == activeIdx) {
|
||||
}
|
||||
else if (removeIdx + 1 == activeIdx)
|
||||
{
|
||||
CloseRepositoryInTab(page);
|
||||
Pages.RemoveAt(removeIdx);
|
||||
OnPropertyChanged(nameof(Pages));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseRepositoryInTab(page);
|
||||
Pages.RemoveAt(removeIdx);
|
||||
}
|
||||
|
@ -105,7 +133,8 @@ namespace SourceGit.ViewModels {
|
|||
GC.Collect();
|
||||
}
|
||||
|
||||
public void CloseOtherTabs(object param) {
|
||||
public void CloseOtherTabs(object param)
|
||||
{
|
||||
if (Pages.Count == 1) return;
|
||||
|
||||
var page = param as LauncherPage;
|
||||
|
@ -113,7 +142,8 @@ namespace SourceGit.ViewModels {
|
|||
|
||||
ActivePage = page;
|
||||
|
||||
foreach (var one in Pages) {
|
||||
foreach (var one in Pages)
|
||||
{
|
||||
if (one.Node.Id != page.Node.Id) CloseRepositoryInTab(one);
|
||||
}
|
||||
|
||||
|
@ -123,17 +153,20 @@ namespace SourceGit.ViewModels {
|
|||
GC.Collect();
|
||||
}
|
||||
|
||||
public void CloseRightTabs(object param) {
|
||||
public void CloseRightTabs(object param)
|
||||
{
|
||||
LauncherPage page = param as LauncherPage;
|
||||
if (page == null) page = _activePage;
|
||||
|
||||
var endIdx = Pages.IndexOf(page);
|
||||
var activeIdx = Pages.IndexOf(_activePage);
|
||||
if (endIdx < activeIdx) {
|
||||
if (endIdx < activeIdx)
|
||||
{
|
||||
ActivePage = page;
|
||||
}
|
||||
|
||||
for (var i = Pages.Count - 1; i > endIdx; i--) {
|
||||
for (var i = Pages.Count - 1; i > endIdx; i--)
|
||||
{
|
||||
CloseRepositoryInTab(Pages[i]);
|
||||
Pages.Remove(Pages[i]);
|
||||
}
|
||||
|
@ -141,16 +174,20 @@ namespace SourceGit.ViewModels {
|
|||
GC.Collect();
|
||||
}
|
||||
|
||||
public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page) {
|
||||
foreach (var one in Pages) {
|
||||
if (one.Node.Id == node.Id) {
|
||||
public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
|
||||
{
|
||||
foreach (var one in Pages)
|
||||
{
|
||||
if (one.Node.Id == node.Id)
|
||||
{
|
||||
ActivePage = one;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var repo = Preference.FindRepository(node.Id);
|
||||
if (repo == null || !Path.Exists(repo.FullPath)) {
|
||||
if (repo == null || !Path.Exists(repo.FullPath))
|
||||
{
|
||||
var ctx = page == null ? ActivePage.Node.Id : page.Node.Id;
|
||||
App.RaiseException(ctx, "Repository does NOT exists any more. Please remove it.");
|
||||
return;
|
||||
|
@ -159,16 +196,22 @@ namespace SourceGit.ViewModels {
|
|||
repo.Open();
|
||||
Commands.AutoFetch.AddRepository(repo.FullPath);
|
||||
|
||||
if (page == null) {
|
||||
if (ActivePage == null || ActivePage.Node.IsRepository) {
|
||||
if (page == null)
|
||||
{
|
||||
if (ActivePage == null || ActivePage.Node.IsRepository)
|
||||
{
|
||||
page = new LauncherPage(node, repo);
|
||||
Pages.Add(page);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
page = ActivePage;
|
||||
page.Node = node;
|
||||
page.Data = repo;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
page.Node = node;
|
||||
page.Data = repo;
|
||||
}
|
||||
|
@ -176,8 +219,10 @@ namespace SourceGit.ViewModels {
|
|||
ActivePage = page;
|
||||
}
|
||||
|
||||
private void CloseRepositoryInTab(LauncherPage page) {
|
||||
if (page.Data is Repository repo) {
|
||||
private void CloseRepositoryInTab(LauncherPage page)
|
||||
{
|
||||
if (page.Data is Repository repo)
|
||||
{
|
||||
Commands.AutoFetch.RemoveRepository(repo.FullPath);
|
||||
repo.Close();
|
||||
}
|
||||
|
@ -187,4 +232,4 @@ namespace SourceGit.ViewModels {
|
|||
|
||||
private LauncherPage _activePage = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue