From 0e0d3d64b46f2887b738cd0fc7899b25c89cdd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A5=9D=E7=AB=8B?= Date: Tue, 7 May 2024 10:29:24 +0800 Subject: [PATCH 01/24] fix: Fixed the problem that the switching branch of the worktree repo is not displayed --- src/Models/Watcher.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index e6e30fb0..e4eb6851 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -180,7 +180,8 @@ namespace SourceGit.Models } else if (name.Equals("HEAD", StringComparison.Ordinal) || name.StartsWith("refs/heads/", StringComparison.Ordinal) || - name.StartsWith("refs/remotes/", StringComparison.Ordinal)) + name.StartsWith("refs/remotes/", StringComparison.Ordinal) || + (name.StartsWith("worktrees/", StringComparison.Ordinal) && name.EndsWith("/HEAD", StringComparison.Ordinal))) { _updateBranch = DateTime.Now.AddSeconds(.5).ToFileTime(); } From 37b5f5c083ebf76a4fa06b3a42e99fdf462d798a Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 10:34:04 +0800 Subject: [PATCH 02/24] feature: enhance the behaviour of closing the last tab * If the last tab is an opened repository, go back to the welcome page * If the last tab is welcome page, quit this app --- src/ViewModels/Launcher.cs | 17 ++++++++++++++++- src/ViewModels/LauncherPage.cs | 8 +------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 3d1fc1c1..e8bace1e 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -107,7 +107,22 @@ namespace SourceGit.ViewModels { if (Pages.Count == 1) { - App.Quit(); + var last = Pages[0]; + if (last.Data is Repository repo) + { + Commands.AutoFetch.RemoveRepository(repo.FullPath); + repo.Close(); + + last.Node = new RepositoryNode() { Id = Guid.NewGuid().ToString() }; + last.Data = new Welcome(); + + GC.Collect(); + } + else + { + App.Quit(); + } + return; } diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index c8765c0d..00c145b3 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -26,13 +26,7 @@ namespace SourceGit.ViewModels public LauncherPage() { - _node = new RepositoryNode() - { - Id = Guid.NewGuid().ToString(), - Name = "WelcomePage", - Bookmark = 0, - IsRepository = false, - }; + _node = new RepositoryNode() { Id = Guid.NewGuid().ToString() }; _data = new Welcome(); } From 06ca29b2b2f1128acc4b7a177ef007677a7f9d16 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 11:19:50 +0800 Subject: [PATCH 03/24] localization: update copyright --- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 563809eb..32b077d6 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -1,7 +1,7 @@ About • Build with - Copyright © 2024 sourcegit-scm. + © 2024 sourcegit-scm • TextEditor from • Monospace fonts come from • Source code can be found at diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 76385fe0..9175a125 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -1,7 +1,7 @@ 关于软件 • 项目依赖于 - Copyright © 2024 sourcegit-scm. + © 2024 sourcegit-scm • 文本编辑器使用 • 等宽字体来自于 • 项目源代码地址 From 4af8cc18d27062b9f83d91ce6a6046f2617f1f6c Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 14:12:33 +0800 Subject: [PATCH 04/24] fix: welcome page should use a shared singleton instance to manage and filter repositories (#117) --- src/ViewModels/Launcher.cs | 2 +- src/ViewModels/LauncherPage.cs | 2 +- src/ViewModels/Repository.cs | 1 - src/ViewModels/Welcome.cs | 9 ++------- src/Views/Welcome.axaml | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index e8bace1e..1fdc8d54 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -114,7 +114,7 @@ namespace SourceGit.ViewModels repo.Close(); last.Node = new RepositoryNode() { Id = Guid.NewGuid().ToString() }; - last.Data = new Welcome(); + last.Data = Welcome.Instance; GC.Collect(); } diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 00c145b3..5fce2bf3 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -27,7 +27,7 @@ namespace SourceGit.ViewModels public LauncherPage() { _node = new RepositoryNode() { Id = Guid.NewGuid().ToString() }; - _data = new Welcome(); + _data = Welcome.Instance; } public LauncherPage(RepositoryNode node, Repository repo) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 73a500b5..bff80053 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -8,7 +8,6 @@ using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Media; using Avalonia.Media.Imaging; -using Avalonia.Platform; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index a6fa1a8a..d4569d05 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -9,10 +9,7 @@ namespace SourceGit.ViewModels { public class Welcome : ObservableObject { - public bool IsClearSearchVisible - { - get => !string.IsNullOrEmpty(_searchFilter); - } + public static Welcome Instance => _instance; public AvaloniaList RepositoryNodes { @@ -25,10 +22,7 @@ namespace SourceGit.ViewModels set { if (SetProperty(ref _searchFilter, value)) - { Referesh(); - OnPropertyChanged(nameof(IsClearSearchVisible)); - } } } @@ -205,6 +199,7 @@ namespace SourceGit.ViewModels } } + private static Welcome _instance = new Welcome(); private string _searchFilter = string.Empty; } } diff --git a/src/Views/Welcome.axaml b/src/Views/Welcome.axaml index 96e6bb14..fef229a2 100644 --- a/src/Views/Welcome.axaml +++ b/src/Views/Welcome.axaml @@ -42,7 +42,7 @@ - From 15456f0deebf9aefd65ca8a5c58bb01807740266 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 14:28:34 +0800 Subject: [PATCH 05/24] code_style: use `?:` operator instead of `if...else` --- src/ViewModels/Launcher.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 1fdc8d54..7d0c9197 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -134,15 +134,7 @@ namespace SourceGit.ViewModels var activeIdx = Pages.IndexOf(_activePage); if (removeIdx == activeIdx) { - if (removeIdx == Pages.Count - 1) - { - ActivePage = Pages[removeIdx - 1]; - } - else - { - ActivePage = Pages[removeIdx + 1]; - } - + ActivePage = Pages[removeIdx == Pages.Count - 1 ? removeIdx - 1 : removeIdx + 1]; CloseRepositoryInTab(page); Pages.RemoveAt(removeIdx); OnPropertyChanged(nameof(Pages)); From 207e82b39173cf68c6b70f89eac340add14e7c61 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 15:28:54 +0800 Subject: [PATCH 06/24] enhance: keep repository tree sorted by name --- src/ViewModels/EditRepositoryNode.cs | 8 ++++-- src/ViewModels/Preference.cs | 39 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/EditRepositoryNode.cs b/src/ViewModels/EditRepositoryNode.cs index 99567c13..4877ca9b 100644 --- a/src/ViewModels/EditRepositoryNode.cs +++ b/src/ViewModels/EditRepositoryNode.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace SourceGit.ViewModels @@ -50,8 +49,13 @@ namespace SourceGit.ViewModels public override Task Sure() { + bool needSort = _node.Name != _name; _node.Name = _name; _node.Bookmark = _bookmark; + + if (needSort) + Preference.SortByRenamedNode(_node); + return null; } diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index cf488328..075ec172 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -362,6 +362,30 @@ namespace SourceGit.ViewModels RemoveNodeRecursive(node, _instance._repositoryNodes); } + public static void SortByRenamedNode(RepositoryNode node) + { + var container = FindNodeContainer(node, _instance._repositoryNodes); + if (container == null) + return; + + var list = new List(); + list.AddRange(container); + list.Sort((l, r) => + { + if (l.IsRepository != r.IsRepository) + { + return l.IsRepository ? 1 : -1; + } + else + { + return l.Name.CompareTo(r.Name); + } + }); + + container.Clear(); + foreach (var one in list) container.Add(one); + } + public static Repository FindRepository(string path) { foreach (var repo in _instance.Repositories) @@ -417,6 +441,21 @@ namespace SourceGit.ViewModels return null; } + private static AvaloniaList FindNodeContainer(RepositoryNode node, AvaloniaList collection) + { + foreach (var sub in collection) + { + if (node == sub) + return collection; + + var subCollection = FindNodeContainer(node, sub.SubNodes); + if (subCollection != null) + return subCollection; + } + + return null; + } + private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList collection) { if (collection.Contains(node)) From eeb6abb560b3e81942dd4c029b7daa33e68c004d Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 15:49:57 +0800 Subject: [PATCH 07/24] fix: avoid duplicated nodes being added into the repository tree --- src/ViewModels/Clone.cs | 13 ++----------- src/ViewModels/Init.cs | 10 +--------- src/ViewModels/Preference.cs | 23 +++++++++++++++++++++++ src/Views/Welcome.axaml.cs | 9 +-------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index d1702860..103f0505 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.IO; using System.Threading.Tasks; @@ -114,15 +113,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { var repo = Preference.AddRepository(path, Path.Combine(path, ".git")); - var node = new RepositoryNode() - { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), - Bookmark = 0, - IsRepository = true, - }; - Preference.AddNode(node); - + var node = Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, null); _launcher.OpenRepositoryInTab(node, _page); }); diff --git a/src/ViewModels/Init.cs b/src/ViewModels/Init.cs index 5f1e846e..b2c48fc7 100644 --- a/src/ViewModels/Init.cs +++ b/src/ViewModels/Init.cs @@ -28,18 +28,10 @@ namespace SourceGit.ViewModels return false; var gitDir = Path.GetFullPath(Path.Combine(_targetPath, ".git")); - CallUIThread(() => { var repo = Preference.AddRepository(_targetPath, gitDir); - var node = new RepositoryNode() - { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), - Bookmark = 0, - IsRepository = true, - }; - Preference.AddNode(node); + Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, null); }); return true; diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 075ec172..a9360e96 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -346,6 +346,29 @@ namespace SourceGit.ViewModels return FindNodeRecursive(id, _instance.RepositoryNodes); } + public static RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent) + { + var node = FindNodeRecursive(repo, _instance.RepositoryNodes); + if (node == null) + { + node = new RepositoryNode() + { + Id = Guid.NewGuid().ToString(), + Name = Path.GetFileName(repo), + Bookmark = 0, + IsRepository = true, + }; + + AddNode(node, parent); + } + else + { + MoveNode(node, parent); + } + + return node; + } + public static void MoveNode(RepositoryNode node, RepositoryNode to = null) { if (to == null && _instance._repositoryNodes.Contains(node)) diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index 53ef2b5a..f0e3a1fc 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -257,14 +257,7 @@ namespace SourceGit.Views Dispatcher.UIThread.Invoke(() => { var repo = ViewModels.Preference.AddRepository(root, gitDir); - var node = new ViewModels.RepositoryNode() - { - Id = repo.FullPath, - Name = Path.GetFileName(repo.FullPath), - Bookmark = 0, - IsRepository = true, - }; - ViewModels.Preference.AddNode(node, parent); + var node = ViewModels.Preference.FindOrAddNodeByRepositoryPath(repo.FullPath, parent); launcher.OpenRepositoryInTab(node, page); }); }); From cebe07695a8a25c25d08f0c2e6e7a30830f20385 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 7 May 2024 15:52:04 +0800 Subject: [PATCH 08/24] fix: issue cause by commit eeb6abb560b3e81942dd4c029b7daa33e68c004d --- src/ViewModels/Preference.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index a9360e96..a9cb6277 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -353,7 +353,7 @@ namespace SourceGit.ViewModels { node = new RepositoryNode() { - Id = Guid.NewGuid().ToString(), + Id = repo, Name = Path.GetFileName(repo), Bookmark = 0, IsRepository = true, From b07b96baeaed6c3ddc6b79b6e01de5ab5b1b467b Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 9 May 2024 11:16:05 +0800 Subject: [PATCH 09/24] readme: force update contributors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8188c579..e2cf9da2 100644 --- a/README.md +++ b/README.md @@ -91,5 +91,5 @@ This app supports open repository in external tools listed in the table below. Thanks to all the people who contribute. - + From 65ccc9fc7b813b7dd6a28dfa1341cc330acf84ce Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 10 May 2024 09:53:20 +0800 Subject: [PATCH 10/24] fix: add missing script to start from commandline on linux --- build/resources/_common/usr/bin/sourcegit | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 build/resources/_common/usr/bin/sourcegit diff --git a/build/resources/_common/usr/bin/sourcegit b/build/resources/_common/usr/bin/sourcegit new file mode 100644 index 00000000..f056d708 --- /dev/null +++ b/build/resources/_common/usr/bin/sourcegit @@ -0,0 +1,2 @@ +#!/bin/bash +exec /opt/sourcegit/sourcegit From 37f5472186e2279a95d8421ddc370b59cb321270 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 10 May 2024 16:01:20 +0800 Subject: [PATCH 11/24] ux: do not show `/dev/null` in DiffView for new file --- src/ViewModels/DiffContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 18c03936..3400b5ea 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -133,7 +133,7 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Post(() => { - if (string.IsNullOrEmpty(_option.OrgPath)) + if (string.IsNullOrEmpty(_option.OrgPath) || _option.OrgPath == "/dev/null") Title = _option.Path; else Title = $"{_option.OrgPath} → {_option.Path}"; From 592d087e0507c8351a63a35cd3a056531003c340 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Fri, 10 May 2024 16:04:03 +0800 Subject: [PATCH 12/24] fix: update search filter selected commit after Histories selected commit changed --- src/ViewModels/Histories.cs | 12 ++++++++++++ src/ViewModels/Repository.cs | 15 +++++++++++++++ src/Views/Histories.axaml.cs | 1 + src/Views/Repository.axaml | 1 + 4 files changed, 29 insertions(+) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index a9f62516..47ca8e10 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -369,6 +369,18 @@ namespace SourceGit.ViewModels return menu; } + public void NotifyAutoSelectedCommitChanged() + { + if (DetailContext is CommitDetail detail) + { + _repo.HandleSelectedCommitChanged(detail.Commit); + } + else + { + _repo.HandleSelectedCommitChanged(null); + } + } + private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) { var submenu = new MenuItem(); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index bff80053..89807206 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -221,6 +221,12 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _hasUnsolvedConflicts, value); } + public Models.Commit SearchResultSelectedCommit + { + get => _searchResultSelectedCommit; + set => SetProperty(ref _searchResultSelectedCommit, value); + } + public void Open() { _watcher = new Models.Watcher(this); @@ -1348,6 +1354,14 @@ namespace SourceGit.ViewModels return menu; } + public void HandleSelectedCommitChanged(Models.Commit commit) + { + if (SearchedCommits.Count > 0) + { + SearchResultSelectedCommit = commit; + } + } + private string _fullpath = string.Empty; private string _gitDir = string.Empty; private Models.GitFlow _gitflow = new Models.GitFlow(); @@ -1377,5 +1391,6 @@ namespace SourceGit.ViewModels private InProgressContext _inProgressContext = null; private bool _hasUnsolvedConflicts = false; + private Models.Commit _searchResultSelectedCommit = null; } } diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 13f05aff..cbed193b 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -291,6 +291,7 @@ namespace SourceGit.Views if (DataContext is ViewModels.Histories histories) { histories.Select(commitDataGrid.SelectedItems); + histories.NotifyAutoSelectedCommitChanged(); } e.Handled = true; } diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 1423807d..c854faa2 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -403,6 +403,7 @@ Date: Fri, 10 May 2024 16:30:34 +0800 Subject: [PATCH 13/24] code_review: PR #120 * remove unnecessary code. The `SetProperty` function takes care of set same property in a loop --- src/ViewModels/Histories.cs | 18 ++++++------------ src/ViewModels/Repository.cs | 8 -------- src/Views/Histories.axaml.cs | 1 - 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 47ca8e10..8cab66c1 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -134,11 +134,14 @@ namespace SourceGit.ViewModels { if (commits.Count == 0) { + _repo.SearchResultSelectedCommit = null; DetailContext = null; } else if (commits.Count == 1) { var commit = commits[0] as Models.Commit; + _repo.SearchResultSelectedCommit = commit; + AutoSelectedCommit = commit; NavigationId = _navigationId + 1; @@ -155,12 +158,15 @@ namespace SourceGit.ViewModels } else if (commits.Count == 2) { + _repo.SearchResultSelectedCommit = null; + var end = commits[0] as Models.Commit; var start = commits[1] as Models.Commit; DetailContext = new RevisionCompare(_repo.FullPath, start, end); } else { + _repo.SearchResultSelectedCommit = null; DetailContext = new CountSelectedCommits() { Count = commits.Count }; } } @@ -369,18 +375,6 @@ namespace SourceGit.ViewModels return menu; } - public void NotifyAutoSelectedCommitChanged() - { - if (DetailContext is CommitDetail detail) - { - _repo.HandleSelectedCommitChanged(detail.Commit); - } - else - { - _repo.HandleSelectedCommitChanged(null); - } - } - private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) { var submenu = new MenuItem(); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 89807206..0e67f11b 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1354,14 +1354,6 @@ namespace SourceGit.ViewModels return menu; } - public void HandleSelectedCommitChanged(Models.Commit commit) - { - if (SearchedCommits.Count > 0) - { - SearchResultSelectedCommit = commit; - } - } - private string _fullpath = string.Empty; private string _gitDir = string.Empty; private Models.GitFlow _gitflow = new Models.GitFlow(); diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index cbed193b..13f05aff 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -291,7 +291,6 @@ namespace SourceGit.Views if (DataContext is ViewModels.Histories histories) { histories.Select(commitDataGrid.SelectedItems); - histories.NotifyAutoSelectedCommitChanged(); } e.Handled = true; } From e0d35409b49bb1441caab56cb3cd6e7ac084ba56 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 11 May 2024 11:31:14 +0800 Subject: [PATCH 14/24] feature: move main menu to macOS system menu bar --- src/App.axaml | 13 +++++++++ src/App.axaml.cs | 46 ++++++++++++++++++++++++++++++- src/Native/MacOS.cs | 1 - src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Views/Launcher.axaml | 11 ++++---- src/Views/Launcher.axaml.cs | 27 ------------------ 7 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/App.axaml b/src/App.axaml index 768ff267..a1225c6d 100644 --- a/src/App.axaml +++ b/src/App.axaml @@ -1,5 +1,6 @@ @@ -21,4 +22,16 @@ + + + + + + + + + + + + diff --git a/src/App.axaml.cs b/src/App.axaml.cs index eb4655c4..ed92b621 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Text; using System.Text.Json; using System.Threading.Tasks; +using System.Windows.Input; using Avalonia; using Avalonia.Controls; @@ -18,9 +19,27 @@ using Avalonia.Threading; namespace SourceGit { + public class SimpleCommand : ICommand + { + public event EventHandler CanExecuteChanged + { + add { } + remove { } + } + + public SimpleCommand(Action action) + { + _action = action; + } + + public bool CanExecute(object parameter) => _action != null; + public void Execute(object parameter) => _action?.Invoke(); + + private Action _action = null; + } + public partial class App : Application { - [STAThread] public static void Main(string[] args) { @@ -67,6 +86,31 @@ namespace SourceGit return builder; } + public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() => + { + var dialog = new Views.Preference(); + dialog.ShowDialog(GetTopLevel() as Window); + }); + + public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() => + { + var dialog = new Views.Hotkeys(); + dialog.ShowDialog(GetTopLevel() as Window); + }); + + public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() => + { + var dialog = new Views.About(); + dialog.ShowDialog(GetTopLevel() as Window); + }); + + public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() => + { + Check4Update(true); + }); + + public static readonly SimpleCommand QuitCommand = new SimpleCommand(Quit); + public static void RaiseException(string context, string message) { if (Current is App app && app._notificationReceiver != null) diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index 465dcdf9..d5b58fb3 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -22,7 +22,6 @@ namespace SourceGit.Native builder.With(new MacOSPlatformOptions() { - DisableNativeMenus = true, DisableDefaultApplicationMenuItems = true, }); } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 32b077d6..28f8b6b0 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -310,6 +310,7 @@ Push Tag To Remote Remote : Tag : + Quit Rebase Current Branch Stash & reapply local changes On : diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 9175a125..591c1a6a 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -310,6 +310,7 @@ 推送标签到远程仓库 远程仓库 : 标签 : + 退出 变基(rebase)操作 自动贮藏并恢复本地变更 目标提交 : diff --git a/src/Views/Launcher.axaml b/src/Views/Launcher.axaml index 861fec09..60812305 100644 --- a/src/Views/Launcher.axaml +++ b/src/Views/Launcher.axaml @@ -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:s="using:SourceGit" xmlns:vm="using:SourceGit.ViewModels" xmlns:m="using:SourceGit.Models" xmlns:c="using:SourceGit.Converters" @@ -49,31 +50,31 @@ - + - + From 146f33b531edf204fc25530602a87aef29858c5b Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 13 May 2024 09:19:37 +0800 Subject: [PATCH 24/24] version: Release 8.12 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3578724f..9c57ca32 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.11 \ No newline at end of file +8.12 \ No newline at end of file