From e0d35409b49bb1441caab56cb3cd6e7ac084ba56 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 11 May 2024 11:31:14 +0800 Subject: [PATCH] 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 @@ -