Skip to content

Commit

Permalink
Merge branch 'release/v8.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
love-linger committed May 13, 2024
2 parents 56780f9 + 146f33b commit 283c681
Show file tree
Hide file tree
Showing 29 changed files with 314 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ This app supports open repository in external tools listed in the table below.
Thanks to all the people who contribute.

<a href="https://github.com/sourcegit-scm/sourcegit/graphs/contributors">
<img src="https://contrib.rocks/image?repo=sourcegit-scm/sourcegit&t=2" />
<img src="https://contrib.rocks/image?repo=sourcegit-scm/sourcegit&columns=10&t=3" />
</a>
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.11
8.12
2 changes: 2 additions & 0 deletions build/resources/_common/usr/bin/sourcegit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec /opt/sourcegit/sourcegit
13 changes: 13 additions & 0 deletions src/App.axaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="using:SourceGit"
x:Class="SourceGit.App"
Name="SourceGit"
RequestedThemeVariant="Dark">
Expand All @@ -21,4 +22,16 @@
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="/Resources/Styles.axaml"/>
</Application.Styles>

<NativeMenu.Menu>
<NativeMenu>
<NativeMenuItem Header="{DynamicResource Text.About.Menu}" Command="{x:Static s:App.OpenAboutCommand}"/>
<NativeMenuItem Header="{DynamicResource Text.Hotkeys.Menu}" Command="{x:Static s:App.OpenHotkeysCommand}"/>
<NativeMenuItem Header="{DynamicResource Text.SelfUpdate}" Command="{x:Static s:App.CheckForUpdateCommand}"/>
<NativeMenuItemSeparator/>
<NativeMenuItem Header="{DynamicResource Text.Preference}" Command="{x:Static s:App.OpenPreferenceCommand}" Gesture="⌘+,"/>
<NativeMenuItemSeparator/>
<NativeMenuItem Header="{DynamicResource Text.Quit}" Command="{x:Static s:App.QuitCommand}"/>
</NativeMenu>
</NativeMenu.Menu>
</Application>
46 changes: 45 additions & 1 deletion src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Input;

using Avalonia;
using Avalonia.Controls;
Expand All @@ -18,9 +19,27 @@

namespace SourceGit
{
public partial class App : Application
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)
{
Expand Down Expand Up @@ -67,6 +86,31 @@ public static AppBuilder BuildAvaloniaApp()
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)
Expand Down
27 changes: 22 additions & 5 deletions src/Commands/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,30 @@ protected override void OnReadline(string line)

public class AutoFetch
{
private const double INTERVAL = 10 * 60;

public static bool IsEnabled
{
get;
set;
} = false;

public static int Interval
{
get => _interval;
set
{
if (value < 1)
return;
_interval = value;
lock (_lock)
{
foreach (var job in _jobs)
{
job.Value.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(_interval));
}
}
}
}

class Job
{
public Fetch Cmd = null;
Expand Down Expand Up @@ -104,7 +120,7 @@ static AutoFetch()
foreach (var job in uptodate)
{
job.Cmd.Exec();
job.NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL);
job.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval));
}
Thread.Sleep(2000);
Expand All @@ -117,7 +133,7 @@ public static void AddRepository(string repo)
var job = new Job
{
Cmd = new Fetch(repo, "--all", true, null) { RaiseError = false },
NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL),
NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval)),
};

lock (_lock)
Expand Down Expand Up @@ -147,12 +163,13 @@ public static void MarkFetched(string repo)
{
if (_jobs.TryGetValue(repo, out var value))
{
value.NextRunTimepoint = DateTime.Now.AddSeconds(INTERVAL);
value.NextRunTimepoint = DateTime.Now.AddMinutes(Convert.ToDouble(Interval));
}
}
}

private static readonly Dictionary<string, Job> _jobs = new Dictionary<string, Job>();
private static readonly object _lock = new object();
private static int _interval = 10;
}
}
6 changes: 3 additions & 3 deletions src/Models/User.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace SourceGit.Models
{
Expand Down Expand Up @@ -36,11 +36,11 @@ public static User FindOrAdd(string data)
var email = data.Substring(nameEndIdx + 1);

User user = new User() { Name = name, Email = email };
_caches.Add(data, user);
_caches.TryAdd(data, user);
return user;
}
}

private static Dictionary<string, User> _caches = new Dictionary<string, User>();
private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
}
}
3 changes: 2 additions & 1 deletion src/Models/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ private void OnRepositoryChanged(object o, FileSystemEventArgs e)
}
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();
}
Expand Down
1 change: 0 additions & 1 deletion src/Native/MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void SetupApp(AppBuilder builder)

builder.With(new MacOSPlatformOptions()
{
DisableNativeMenus = true,
DisableDefaultApplicationMenuItems = true,
});
}
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:String x:Key="Text.About" xml:space="preserve">About</x:String>
<x:String x:Key="Text.About.Menu" xml:space="preserve">About SourceGit</x:String>
<x:String x:Key="Text.About.BuildWith" xml:space="preserve">• Build with </x:String>
<x:String x:Key="Text.About.Copyright" xml:space="preserve">Copyright © 2024 sourcegit-scm.</x:String>
<x:String x:Key="Text.About.Copyright" xml:space="preserve">© 2024 sourcegit-scm</x:String>
<x:String x:Key="Text.About.Editor" xml:space="preserve">• TextEditor from </x:String>
<x:String x:Key="Text.About.Fonts" xml:space="preserve">• Monospace fonts come from </x:String>
<x:String x:Key="Text.About.SourceCode" xml:space="preserve">• Source code can be found at </x:String>
Expand Down Expand Up @@ -210,12 +211,14 @@
<x:String x:Key="Text.Histories.SearchClear" xml:space="preserve">CLEAR</x:String>
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">SELECTED {0} COMMITS</x:String>
<x:String x:Key="Text.Hotkeys" xml:space="preserve">HotKeys</x:String>
<x:String x:Key="Text.Hotkeys.Menu" xml:space="preserve">About HotKeys</x:String>
<x:String x:Key="Text.Hotkeys.Global" xml:space="preserve">GLOBAL</x:String>
<x:String x:Key="Text.Hotkeys.Global.CancelPopup" xml:space="preserve">Cancel current popup</x:String>
<x:String x:Key="Text.Hotkeys.Global.CloseTab" xml:space="preserve">Close current page</x:String>
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">Go to previous page</x:String>
<x:String x:Key="Text.Hotkeys.Global.GotoNextTab" xml:space="preserve">Go to next page</x:String>
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">Create new page</x:String>
<x:String x:Key="Text.Hotkeys.Global.OpenPreference" xml:space="preserve">Open preference dialog</x:String>
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">REPOSITORY</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">Force to reload this repository</x:String>
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">Stage/Unstage selected changes</x:String>
Expand Down Expand Up @@ -272,6 +275,8 @@
<x:String x:Key="Text.Preference.General.UseFixedTabWidth" xml:space="preserve">Use fixed tab width in titlebar</x:String>
<x:String x:Key="Text.Preference.Git" xml:space="preserve">GIT</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetch" xml:space="preserve">Fetch remotes automatically</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetchInterval" xml:space="preserve">Auto Fetch Interval</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
<x:String x:Key="Text.Preference.Git.CRLF" xml:space="preserve">Enable Auto CRLF</x:String>
<x:String x:Key="Text.Preference.Git.DefaultCloneDir" xml:space="preserve">Default Clone Dir</x:String>
<x:String x:Key="Text.Preference.Git.Email" xml:space="preserve">User Email</x:String>
Expand Down Expand Up @@ -310,6 +315,7 @@
<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.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.AutoStash" xml:space="preserve">Stash &amp; reapply local changes</x:String>
<x:String x:Key="Text.Rebase.On" xml:space="preserve">On :</x:String>
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:String x:Key="Text.About" xml:space="preserve">关于软件</x:String>
<x:String x:Key="Text.About.Menu" xml:space="preserve">关于本软件</x:String>
<x:String x:Key="Text.About.BuildWith" xml:space="preserve">• 项目依赖于 </x:String>
<x:String x:Key="Text.About.Copyright" xml:space="preserve">Copyright © 2024 sourcegit-scm.</x:String>
<x:String x:Key="Text.About.Copyright" xml:space="preserve">© 2024 sourcegit-scm</x:String>
<x:String x:Key="Text.About.Editor" xml:space="preserve">• 文本编辑器使用 </x:String>
<x:String x:Key="Text.About.Fonts" xml:space="preserve">• 等宽字体来自于 </x:String>
<x:String x:Key="Text.About.SourceCode" xml:space="preserve">• 项目源代码地址 </x:String>
Expand Down Expand Up @@ -210,12 +211,14 @@
<x:String x:Key="Text.Histories.SearchClear" xml:space="preserve">清空</x:String>
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已选中 {0} 项提交</x:String>
<x:String x:Key="Text.Hotkeys" xml:space="preserve">快捷键</x:String>
<x:String x:Key="Text.Hotkeys.Menu" xml:space="preserve">显示快捷键</x:String>
<x:String x:Key="Text.Hotkeys.Global" xml:space="preserve">全局快捷键</x:String>
<x:String x:Key="Text.Hotkeys.Global.CancelPopup" xml:space="preserve">取消弹出面板</x:String>
<x:String x:Key="Text.Hotkeys.Global.CloseTab" xml:space="preserve">关闭当前页面</x:String>
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">切换到上一个页面</x:String>
<x:String x:Key="Text.Hotkeys.Global.GotoNextTab" xml:space="preserve">切换到下一个页面</x:String>
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">新建页面</x:String>
<x:String x:Key="Text.Hotkeys.Global.OpenPreference" xml:space="preserve">打开偏好设置面板</x:String>
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">仓库页面快捷键</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">重新加载仓库状态</x:String>
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">将选中的变更暂存或从暂存列表中移除</x:String>
Expand Down Expand Up @@ -272,6 +275,8 @@
<x:String x:Key="Text.Preference.General.UseFixedTabWidth" xml:space="preserve">使用固定宽度的标题栏标签</x:String>
<x:String x:Key="Text.Preference.Git" xml:space="preserve">GIT配置</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetch" xml:space="preserve">启用定时自动拉取远程更新</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetchInterval" xml:space="preserve">自动拉取间隔</x:String>
<x:String x:Key="Text.Preference.Git.AutoFetchIntervalSuffix" xml:space="preserve">分钟</x:String>
<x:String x:Key="Text.Preference.Git.CRLF" xml:space="preserve">自动换行转换</x:String>
<x:String x:Key="Text.Preference.Git.DefaultCloneDir" xml:space="preserve">默认克隆路径</x:String>
<x:String x:Key="Text.Preference.Git.Email" xml:space="preserve">邮箱</x:String>
Expand Down Expand Up @@ -310,6 +315,7 @@
<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.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.AutoStash" xml:space="preserve">自动贮藏并恢复本地变更</x:String>
<x:String x:Key="Text.Rebase.On" xml:space="preserve">目标提交 :</x:String>
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@
<Setter Property="Background" Value="Red"/>
</Style>

<Style Selector="Button.icon_button">
<Style Selector="Button.icon_button, RepeatButton.icon_button">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Button.icon_button /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="Button.icon_button /template/ ContentPresenter#PART_ContentPresenter, RepeatButton.icon_button /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Opacity" Value="0.8"/>
</Style>
<Style Selector="Button.icon_button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="Button.icon_button:pointerover /template/ ContentPresenter#PART_ContentPresenter, RepeatButton.icon_button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Opacity" Value="1"/>
</Style>

Expand Down
13 changes: 2 additions & 11 deletions src/ViewModels/Clone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;

Expand Down Expand Up @@ -114,15 +113,7 @@ public override Task<bool> Sure()
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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/DiffContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
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}";
Expand Down
8 changes: 6 additions & 2 deletions src/ViewModels/EditRepositoryNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;

namespace SourceGit.ViewModels
Expand Down Expand Up @@ -50,8 +49,13 @@ public EditRepositoryNode(RepositoryNode node)

public override Task<bool> Sure()
{
bool needSort = _node.Name != _name;
_node.Name = _name;
_node.Bookmark = _bookmark;

if (needSort)
Preference.SortByRenamedNode(_node);

return null;
}

Expand Down

0 comments on commit 283c681

Please sign in to comment.