Skip to content

Commit

Permalink
chore(project): upgrade to UIComponents v1.0.0-beta.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jonisavo committed Sep 22, 2023
1 parent b3a1580 commit 8c1e9c0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
19 changes: 2 additions & 17 deletions Packages/io.savolainen.unitygit/Core/Services/Service.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
using System.Collections.Generic;
using UIComponents;
using UIComponents;
using UIComponents.DependencyInjection;
using ILogger = UIComponents.ILogger;

namespace UnityGit.Core.Services
{
[Dependency(typeof(ILogger), provide: typeof(DebugLogger))]
public abstract class Service : IDependencyConsumer
public abstract class Service : DependencyConsumer
{
protected readonly ILogger Logger;

private readonly DependencyInjector _dependencyInjector;

protected Service()
{
DiContext.Current.RegisterConsumer(this);
_dependencyInjector = DiContext.Current.GetInjector(GetType());
Logger = Provide<ILogger>();
UIC_PopulateProvideFields();
}

protected T Provide<T>() where T : class
{
return _dependencyInjector.Provide<T>();
}

public abstract IEnumerable<IDependency> GetDependencies();

protected abstract void UIC_PopulateProvideFields();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,15 @@ static Styles()
};
}
}

private static readonly IStatusService StatusService;
private static readonly ICheckoutService CheckoutService;
private static readonly IBranchService BranchService;

private static readonly BranchToolbarButtonServices Services;

private static readonly GUIContent BranchButtonContent;

static BranchToolbarButton()
{
ToolbarExtender.LeftToolbarGUI.Add(DoBranchToolbarItem);
var injector = DiContext.Current.GetInjector(typeof(BranchToolbarButton));
var services = new BranchToolbarButtonServices();
DiContext.Current.RegisterConsumer(services);
injector.SetConsumer(services);
StatusService = injector.Provide<IStatusService>();
CheckoutService = injector.Provide<ICheckoutService>();
BranchService = injector.Provide<IBranchService>();
Services = new BranchToolbarButtonServices();

var texture = Icons.GetIcon(Icons.Name.Merge);

Expand All @@ -62,20 +54,20 @@ private static void DoBranchToolbarItem()

GUILayout.Space(6);

using (new EditorGUI.DisabledScope(!StatusService.HasProjectRepository()))
using (new EditorGUI.DisabledScope(!Services.StatusService.HasProjectRepository()))
DoBranchToolbarButton();
}

private static string GetToolbarButtonText()
{
var hasRepo = StatusService.HasProjectRepository();
var hasRepo = Services.StatusService.HasProjectRepository();

if (!hasRepo)
return "No repository";

var head = StatusService.ProjectRepository.Head;
var head = Services.StatusService.ProjectRepository.Head;

return BranchService.GetBranchName(head);
return Services.BranchService.GetBranchName(head);
}

private static void AddBranchButtonsToMenu(GenericMenu menu, IEnumerable<Branch> branches)
Expand All @@ -92,9 +84,9 @@ private static void AddBranchButtonsToMenu(GenericMenu menu, IEnumerable<Branch>
if (itemAsBranch == null || itemAsBranch.IsCurrentRepositoryHead)
return;
var repository = StatusService.ProjectRepository;
var repository = Services.StatusService.ProjectRepository;
CheckoutService.CheckoutBranch(repository, itemAsBranch);
Services.CheckoutService.CheckoutBranch(repository, itemAsBranch);
}, branch);
}
}
Expand All @@ -106,7 +98,7 @@ private static void DoBranchToolbarButton()

var menu = new GenericMenu();
var branchPartitions =
StatusService.ProjectRepository.Branches.GroupBy((branch) => branch.IsRemote);
Services.StatusService.ProjectRepository.Branches.GroupBy((branch) => branch.IsRemote);

foreach (var partition in branchPartitions)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using System.Collections.Generic;
using UIComponents;
using UIComponents.DependencyInjection;
using UnityGit.Core.Services;

namespace UnityGit.Editor.Toolbar
{
internal class BranchToolbarButtonServices : IDependencyConsumer
[Dependency(typeof(IStatusService), provide: typeof(StatusService))]
[Dependency(typeof(ICheckoutService), provide: typeof(CheckoutService))]
[Dependency(typeof(IBranchService), provide: typeof(BranchService))]
internal partial class BranchToolbarButtonServices : DependencyConsumer
{
public IEnumerable<IDependency> GetDependencies()
{
return new IDependency[]
{
Dependency.SingletonFor<IStatusService, StatusService>(),
Dependency.SingletonFor<ICheckoutService, CheckoutService>(),
Dependency.SingletonFor<IBranchService, BranchService>()
};
}
[Provide]
public IStatusService StatusService;

[Provide]
public ICheckoutService CheckoutService;

[Provide]
public IBranchService BranchService;
}

}
8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"dependencies": {
"com.marijnzwemmer.unity-toolbar-extender": "1.4.2",
"com.unity.collab-proxy": "2.0.5",
"com.unity.ide.rider": "3.0.24",
"com.unity.ide.visualstudio": "2.0.18",
"com.unity.collab-proxy": "2.0.7",
"com.unity.ide.rider": "3.0.25",
"com.unity.ide.visualstudio": "2.0.21",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.33",
"com.unity.testtools.codecoverage": "1.2.4",
"com.unity.textmeshpro": "3.0.6",
"com.unity.ugui": "1.0.0",
"io.savolainen.uicomponents": "1.0.0-beta.4",
"io.savolainen.uicomponents": "1.0.0-beta.6",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
14 changes: 10 additions & 4 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://package.openupm.com"
},
"com.unity.collab-proxy": {
"version": "2.0.5",
"version": "2.0.7",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand All @@ -22,7 +22,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.24",
"version": "3.0.25",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -31,7 +31,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.18",
"version": "2.0.21",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -92,8 +92,14 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"io.savolainen.test": {
"version": "file:io.savolainen.test",
"depth": 0,
"source": "embedded",
"dependencies": {}
},
"io.savolainen.uicomponents": {
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.6",
"depth": 0,
"source": "registry",
"dependencies": {},
Expand Down

0 comments on commit 8c1e9c0

Please sign in to comment.