mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
Merge branch 'master' into feature/resx
This commit is contained in:
commit
14550655f3
235 changed files with 8625 additions and 4381 deletions
111
src/App.axaml.cs
111
src/App.axaml.cs
|
@ -1,3 +1,12 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
@ -6,22 +15,21 @@ using Avalonia.Markup.Xaml;
|
|||
using Avalonia.Media;
|
||||
using Avalonia.Media.Fonts;
|
||||
using Avalonia.Styling;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace SourceGit {
|
||||
public partial class App : Application {
|
||||
namespace SourceGit
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args) {
|
||||
try {
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("Crash: ");
|
||||
builder.Append(ex.Message);
|
||||
|
@ -39,40 +47,48 @@ namespace SourceGit {
|
|||
"SourceGit",
|
||||
$"crash_{time}.log");
|
||||
File.WriteAllText(file, builder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AppBuilder BuildAvaloniaApp() {
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
{
|
||||
var builder = AppBuilder.Configure<App>();
|
||||
builder.UsePlatformDetect();
|
||||
builder.LogToTrace();
|
||||
builder.ConfigureFonts(manager => {
|
||||
builder.ConfigureFonts(manager =>
|
||||
{
|
||||
var monospace = new EmbeddedFontCollection(
|
||||
new Uri("fonts:SourceGit", UriKind.Absolute),
|
||||
new Uri("avares://SourceGit/Resources/Fonts", UriKind.Absolute));
|
||||
manager.AddFontCollection(monospace);
|
||||
});
|
||||
|
||||
Native.OS.SetupFonts(builder);
|
||||
Native.OS.SetupApp(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void RaiseException(string context, string message) {
|
||||
if (Current is App app && app._notificationReceiver != null) {
|
||||
public static void RaiseException(string context, string message)
|
||||
{
|
||||
if (Current is App app && app._notificationReceiver != null)
|
||||
{
|
||||
var notice = new Models.Notification() { IsError = true, Message = message };
|
||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendNotification(string context, string message) {
|
||||
if (Current is App app && app._notificationReceiver != null) {
|
||||
public static void SendNotification(string context, string message)
|
||||
{
|
||||
if (Current is App app && app._notificationReceiver != null)
|
||||
{
|
||||
var notice = new Models.Notification() { IsError = false, Message = message };
|
||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetLocale(string localeKey) {
|
||||
public static void SetLocale(string localeKey)
|
||||
{
|
||||
var app = Current as App;
|
||||
|
||||
localeKey = localeKey.Replace("_", "-");
|
||||
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(localeKey);
|
||||
|
@ -92,7 +108,8 @@ namespace SourceGit {
|
|||
return;
|
||||
}
|
||||
|
||||
if (app._activeLocale != null) {
|
||||
if (app._activeLocale != null)
|
||||
{
|
||||
app.Resources.MergedDictionaries.Remove(app._activeLocale);
|
||||
}
|
||||
|
||||
|
@ -100,31 +117,42 @@ namespace SourceGit {
|
|||
app._activeLocale = targetLocale;
|
||||
}
|
||||
|
||||
public static void SetTheme(string theme) {
|
||||
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase)) {
|
||||
public static void SetTheme(string theme)
|
||||
{
|
||||
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Current.RequestedThemeVariant = ThemeVariant.Light;
|
||||
} else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase)) {
|
||||
}
|
||||
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Current.RequestedThemeVariant = ThemeVariant.Dark;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Current.RequestedThemeVariant = ThemeVariant.Default;
|
||||
}
|
||||
}
|
||||
|
||||
public static async void CopyText(string data) {
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||
if (desktop.MainWindow.Clipboard is { } clipbord) {
|
||||
public static async void CopyText(string data)
|
||||
{
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.MainWindow.Clipboard is { } clipbord)
|
||||
{
|
||||
await clipbord.SetTextAsync(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Text(string key, params object[] args) {
|
||||
public static string Text(string key, params object[] args)
|
||||
{
|
||||
var fmt = Current.FindResource($"Text.{key}") as string;
|
||||
if (string.IsNullOrWhiteSpace(fmt)) return $"Text.{key}";
|
||||
return string.Format(fmt, args);
|
||||
}
|
||||
|
||||
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) {
|
||||
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
|
||||
{
|
||||
var icon = new Avalonia.Controls.Shapes.Path();
|
||||
icon.Width = 12;
|
||||
icon.Height = 12;
|
||||
|
@ -133,29 +161,36 @@ namespace SourceGit {
|
|||
return icon;
|
||||
}
|
||||
|
||||
public static TopLevel GetTopLevel() {
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||
public static TopLevel GetTopLevel()
|
||||
{
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
return desktop.MainWindow;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Quit() {
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||
public static void Quit()
|
||||
{
|
||||
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow.Close();
|
||||
desktop.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize() {
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
SetLocale(ViewModels.Preference.Instance.Locale);
|
||||
SetTheme(ViewModels.Preference.Instance.Theme);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted() {
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
BindingPlugins.DataValidators.RemoveAt(0);
|
||||
|
||||
var launcher = new Views.Launcher();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue