mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
feature: move main menu to macOS system menu bar
This commit is contained in:
parent
764cf24284
commit
e0d35409b4
7 changed files with 66 additions and 34 deletions
|
@ -1,5 +1,6 @@
|
||||||
<Application xmlns="https://github.com/avaloniaui"
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:s="using:SourceGit"
|
||||||
x:Class="SourceGit.App"
|
x:Class="SourceGit.App"
|
||||||
Name="SourceGit"
|
Name="SourceGit"
|
||||||
RequestedThemeVariant="Dark">
|
RequestedThemeVariant="Dark">
|
||||||
|
@ -21,4 +22,16 @@
|
||||||
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
||||||
<StyleInclude Source="/Resources/Styles.axaml"/>
|
<StyleInclude Source="/Resources/Styles.axaml"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|
||||||
|
<NativeMenu.Menu>
|
||||||
|
<NativeMenu>
|
||||||
|
<NativeMenuItem Header="{DynamicResource Text.About}" Command="{x:Static s:App.OpenAboutCommand}"/>
|
||||||
|
<NativeMenuItem Header="{DynamicResource Text.Hotkeys}" Command="{x:Static s:App.OpenHotkeysCommand}"/>
|
||||||
|
<NativeMenuItem Header="{DynamicResource Text.SelfUpdate}" Command="{x:Static s:App.CheckForUpdateCommand}"/>
|
||||||
|
<NativeMenuItem Header="-"/>
|
||||||
|
<NativeMenuItem Header="{DynamicResource Text.Preference}" Command="{x:Static s:App.OpenPreferenceCommand}"/>
|
||||||
|
<NativeMenuItem Header="-"/>
|
||||||
|
<NativeMenuItem Header="{DynamicResource Text.Quit}" Command="{x:Static s:App.QuitCommand}"/>
|
||||||
|
</NativeMenu>
|
||||||
|
</NativeMenu.Menu>
|
||||||
</Application>
|
</Application>
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
@ -18,9 +19,27 @@ using Avalonia.Threading;
|
||||||
|
|
||||||
namespace SourceGit
|
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
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
@ -67,6 +86,31 @@ namespace SourceGit
|
||||||
return builder;
|
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)
|
public static void RaiseException(string context, string message)
|
||||||
{
|
{
|
||||||
if (Current is App app && app._notificationReceiver != null)
|
if (Current is App app && app._notificationReceiver != null)
|
||||||
|
|
|
@ -22,7 +22,6 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
builder.With(new MacOSPlatformOptions()
|
builder.With(new MacOSPlatformOptions()
|
||||||
{
|
{
|
||||||
DisableNativeMenus = true,
|
|
||||||
DisableDefaultApplicationMenuItems = true,
|
DisableDefaultApplicationMenuItems = true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,6 +310,7 @@
|
||||||
<x:String x:Key="Text.PushTag" xml:space="preserve">Push Tag To Remote</x:String>
|
<x:String x:Key="Text.PushTag" xml:space="preserve">Push Tag To Remote</x:String>
|
||||||
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">Remote :</x:String>
|
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">Remote :</x:String>
|
||||||
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">Tag :</x:String>
|
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">Tag :</x:String>
|
||||||
|
<x:String x:Key="Text.Quit" xml:space="preserve">Quit</x:String>
|
||||||
<x:String x:Key="Text.Rebase" xml:space="preserve">Rebase Current Branch</x:String>
|
<x:String x:Key="Text.Rebase" xml:space="preserve">Rebase Current Branch</x:String>
|
||||||
<x:String x:Key="Text.Rebase.AutoStash" xml:space="preserve">Stash & reapply local changes</x:String>
|
<x:String x:Key="Text.Rebase.AutoStash" xml:space="preserve">Stash & reapply local changes</x:String>
|
||||||
<x:String x:Key="Text.Rebase.On" xml:space="preserve">On :</x:String>
|
<x:String x:Key="Text.Rebase.On" xml:space="preserve">On :</x:String>
|
||||||
|
|
|
@ -310,6 +310,7 @@
|
||||||
<x:String x:Key="Text.PushTag" xml:space="preserve">推送标签到远程仓库</x:String>
|
<x:String x:Key="Text.PushTag" xml:space="preserve">推送标签到远程仓库</x:String>
|
||||||
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">远程仓库 :</x:String>
|
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">远程仓库 :</x:String>
|
||||||
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">标签 :</x:String>
|
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">标签 :</x:String>
|
||||||
|
<x:String x:Key="Text.Quit" xml:space="preserve">退出</x:String>
|
||||||
<x:String x:Key="Text.Rebase" xml:space="preserve">变基(rebase)操作</x:String>
|
<x:String x:Key="Text.Rebase" xml:space="preserve">变基(rebase)操作</x:String>
|
||||||
<x:String x:Key="Text.Rebase.AutoStash" xml:space="preserve">自动贮藏并恢复本地变更</x:String>
|
<x:String x:Key="Text.Rebase.AutoStash" xml:space="preserve">自动贮藏并恢复本地变更</x:String>
|
||||||
<x:String x:Key="Text.Rebase.On" xml:space="preserve">目标提交 :</x:String>
|
<x:String x:Key="Text.Rebase.On" xml:space="preserve">目标提交 :</x:String>
|
||||||
|
|
|
@ -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:s="using:SourceGit"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
xmlns:m="using:SourceGit.Models"
|
xmlns:m="using:SourceGit.Models"
|
||||||
xmlns:c="using:SourceGit.Converters"
|
xmlns:c="using:SourceGit.Converters"
|
||||||
|
@ -49,31 +50,31 @@
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Menu -->
|
<!-- Menu -->
|
||||||
<Button Grid.Column="{OnPlatform 0, macOS=2}" Classes="icon_button" VerticalAlignment="Bottom">
|
<Button Grid.Column="0" Classes="icon_button" VerticalAlignment="Bottom" IsVisible="{OnPlatform True, macOS=False}">
|
||||||
<Button.Margin>
|
<Button.Margin>
|
||||||
<OnPlatform Default="4,0,2,3" macOS="4,0,6,3"/>
|
<OnPlatform Default="4,0,2,3" macOS="4,0,6,3"/>
|
||||||
</Button.Margin>
|
</Button.Margin>
|
||||||
|
|
||||||
<Button.Flyout>
|
<Button.Flyout>
|
||||||
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
|
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
|
||||||
<MenuItem Header="{DynamicResource Text.Preference}" Click="OpenPreference">
|
<MenuItem Header="{DynamicResource Text.Preference}" Command="{x:Static s:App.OpenPreferenceCommand}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Settings2}"/>
|
<Path Width="14" Height="14" Data="{StaticResource Icons.Settings2}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{DynamicResource Text.Hotkeys}" Click="OpenHotkeys">
|
<MenuItem Header="{DynamicResource Text.Hotkeys}" Command="{x:Static s:App.OpenHotkeysCommand}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Hotkeys}"/>
|
<Path Width="14" Height="14" Data="{StaticResource Icons.Hotkeys}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="-"/>
|
<MenuItem Header="-"/>
|
||||||
<MenuItem Header="{DynamicResource Text.SelfUpdate}" Click="Check4Update">
|
<MenuItem Header="{DynamicResource Text.SelfUpdate}" Command="{x:Static s:App.CheckForUpdateCommand}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="14" Height="14" Data="{StaticResource Icons.SoftwareUpdate}"/>
|
<Path Width="14" Height="14" Data="{StaticResource Icons.SoftwareUpdate}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="-"/>
|
<MenuItem Header="-"/>
|
||||||
<MenuItem Header="{DynamicResource Text.About}" Click="OpenAboutDialog">
|
<MenuItem Header="{DynamicResource Text.About}" Command="{x:Static s:App.OpenAboutCommand}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}"/>
|
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
|
|
|
@ -337,33 +337,6 @@ namespace SourceGit.Views
|
||||||
OnPopupCancel(sender, e);
|
OnPopupCancel(sender, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenPreference(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var dialog = new Preference();
|
|
||||||
await dialog.ShowDialog(this);
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OpenHotkeys(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var dialog = new Hotkeys();
|
|
||||||
await dialog.ShowDialog(this);
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Check4Update(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
App.Check4Update(true);
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OpenAboutDialog(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
var dialog = new About();
|
|
||||||
await dialog.ShowDialog(this);
|
|
||||||
e.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _pressedTab = false;
|
private bool _pressedTab = false;
|
||||||
private Point _pressedTabPosition = new Point();
|
private Point _pressedTabPosition = new Point();
|
||||||
private bool _startDrag = false;
|
private bool _startDrag = false;
|
||||||
|
|
Loading…
Reference in a new issue