Add tray icon and start deveopment of menu handling

This commit is contained in:
Vladimir Eremeev 2024-12-20 12:24:43 +03:00
parent c9b00d7bfe
commit dce6db3a13
5 changed files with 35 additions and 2 deletions

View file

@ -37,7 +37,7 @@ namespace SourceGit
}
}
public static readonly Command OpenPreferenceCommand = new Command(_ => OpenDialog(new Views.Preference()));
public static readonly Command OpenPreferenceCommand = new Command(_ => { OpenDialog(new Views.Preference()); });
public static readonly Command OpenHotkeysCommand = new Command(_ => OpenDialog(new Views.Hotkeys()));
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
public static readonly Command OpenAboutCommand = new Command(_ => OpenDialog(new Views.About()));

View file

@ -41,4 +41,5 @@
<NativeMenuItem Header="{DynamicResource Text.Quit}" Command="{x:Static s:App.QuitCommand}" Gesture="⌘+Q"/>
</NativeMenu>
</NativeMenu.Menu>
</Application>

View file

@ -14,6 +14,8 @@ using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Media.Fonts;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Styling;
using Avalonia.Threading;
@ -85,6 +87,7 @@ namespace SourceGit
SetLocale(pref.Locale);
SetTheme(pref.Theme, pref.ThemeOverrides);
SetFonts(pref.DefaultFontFamily, pref.MonospaceFontFamily, pref.OnlyUseMonoFontInEditor);
SetupTrayIcon(pref.SystemTrayIcon);
}
public override void OnFrameworkInitializationCompleted()
@ -192,6 +195,26 @@ namespace SourceGit
}
}
public static void SetupTrayIcon(bool enable)
{
if (enable)
{
var icons = new TrayIcons {
new TrayIcon {
Icon = new WindowIcon(new Bitmap(AssetLoader.Open(new Uri("avares://SourceGit/App.ico")))),
Menu = [
new NativeMenuItem(Text("Open")),
new NativeMenuItem(Text("Preference")) {Command = OpenPreferenceCommand},
new NativeMenuItemSeparator(),
new NativeMenuItem(Text("Quit")) {Command = QuitCommand},
]
}
};
TrayIcon.SetIcons(Current, icons);
}
}
public static void SetFonts(string defaultFont, string monospaceFont, bool onlyUseMonospaceFontInEditor)
{
var app = Current as App;

View file

@ -420,7 +420,8 @@
<x:String x:Key="Text.MoveRepositoryNode.Target" xml:space="preserve">Select parent node for:</x:String>
<x:String x:Key="Text.Name" xml:space="preserve">Name:</x:String>
<x:String x:Key="Text.NotConfigured" xml:space="preserve">Git has NOT been configured. Please to go [Preference] and configure it first.</x:String>
<x:String x:Key="Text.OpenAppDataDir" xml:space="preserve">Open Data Storage Directory</x:String>
<x:String x:Key="Text.Open" xml:space="preserve">Open SourceGit</x:String>
<x:String x:Key="Text.OpenAppDataDir" xml:space="preserve">Open Storage Directory</x:String>
<x:String x:Key="Text.OpenWith" xml:space="preserve">Open with...</x:String>
<x:String x:Key="Text.Optional" xml:space="preserve">Optional.</x:String>
<x:String x:Key="Text.PageTabBar.New" xml:space="preserve">Create New Page</x:String>

View file

@ -333,6 +333,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _lastCheckUpdateTime, value);
}
public bool SystemTrayIcon
{
get => _systemTrayIcon;
set => SetProperty(ref _systemTrayIcon, value);
}
public bool IsGitConfigured()
{
var path = GitInstallPath;
@ -663,5 +669,7 @@ namespace SourceGit.ViewModels
private string _externalMergeToolPath = string.Empty;
private uint _statisticsSampleColor = 0xFF00FF00;
private bool _systemTrayIcon = false;
}
}