Skip to content

Commit ce74fd8

Browse files
authored
Merge pull request #41 from NeverMorewd/master
release 2.0.8-beta
2 parents e677525 + 49cbc2d commit ce74fd8

7 files changed

Lines changed: 51 additions & 9 deletions

File tree

src/Lemon.ModuleNavigation.Avaloniaui/Core/NavigationExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private static void SetBinding(Control control,
213213
{
214214
return null;
215215
}
216-
return navigationHandler.ModuleManager.CreateView(m) as Control;
216+
return navigationHandler.ModuleManager.GetOrCreateView(m, regionName) as Control;
217217
});
218218
}
219219
else if (control is ItemsControl itemsControl)
@@ -248,7 +248,7 @@ private static void SetBinding(Control control,
248248
{
249249
return null;
250250
}
251-
return navigationHandler.ModuleManager.CreateView(m) as Control;
251+
return navigationHandler.ModuleManager.GetOrCreateView(m, regionName) as Control;
252252
});
253253
}
254254
else if (control is ContentControl contentControl)

src/Lemon.ModuleNavigation.Sample.DesktopHosting/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static void Main(string[] args)
3636
// views
3737
hostBuilder.Services.AddView<ViewAlpha, ViewAlphaViewModel>(nameof(ViewAlpha));
3838
hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewBeta));
39+
hostBuilder.Services.AddAvaDialogWindow<CustomDialogWindow>(nameof(CustomDialogWindow));
3940

4041
hostBuilder.Services.AddAvaloniauiDesktopApplication<App>(BuildAvaloniaApp);
4142
hostBuilder.Services.AddMainWindow<MainWindow, MainViewModel>();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"profiles": {
3+
"Lemon.ModuleNavigation.Sample.DesktopHosting": {
4+
"commandName": "Project"
5+
},
6+
"WSL": {
7+
"commandName": "WSL2",
8+
"distributionName": ""
9+
}
10+
}
11+
}

src/Lemon.ModuleNavigation.Sample/ViewModels/SampleViewModelBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Lemon.ModuleNavigation.Sample.ViewModels;
55

66
public class SampleViewModelBase : ReactiveObject, IDisposable
77
{
8-
public virtual string Greeting => $"Welcome to {GetType().Name}{Environment.NewLine}{DateTime.Now:yyyy-MM-dd HH-mm-ss.ffff}";
8+
public virtual string Greeting => $"Welcome to {GetType().Name}[{Environment.ProcessId}][{Environment.CurrentManagedThreadId}]{Environment.NewLine}{DateTime.Now:yyyy-MM-dd HH-mm-ss.ffff}";
99
public virtual void Dispose()
1010
{
1111

src/Lemon.ModuleNavigation/Abstracts/IModule.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public Type ViewModelType
3939
{
4040
get;
4141
}
42+
public IView? View
43+
{
44+
get;
45+
}
46+
public IModuleNavigationAware? ViewModel
47+
{
48+
get;
49+
}
4250
public void Initialize();
4351
}
4452
}

src/Lemon.ModuleNavigation/Core/ModuleManager.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Lemon.ModuleNavigation.Abstracts;
22
using Microsoft.Extensions.DependencyInjection;
3-
using System;
43
using System.Collections.Concurrent;
54
using System.Collections.ObjectModel;
65
using System.ComponentModel;
@@ -11,11 +10,15 @@ namespace Lemon.ModuleNavigation.Core
1110
public class ModuleManager : IModuleManager, INotifyPropertyChanged
1211
{
1312
private readonly ConcurrentDictionary<string, IModule> _modulesCache;
14-
private readonly ConcurrentDictionary<(string, string), IView> _regionCache;
13+
private readonly ConcurrentDictionary<(string RegionName, string ModuleKey), IView> _regionCache;
1514
private readonly IServiceProvider _serviceProvider;
16-
public ModuleManager(IEnumerable<IModule> modules, IServiceProvider serviceProvider)
15+
private readonly IRegionManager _regionManager;
16+
public ModuleManager(IEnumerable<IModule> modules,
17+
IRegionManager regionManager,
18+
IServiceProvider serviceProvider)
1719
{
1820
_serviceProvider = serviceProvider;
21+
_regionManager = regionManager;
1922
_regionCache = [];
2023
_modulesCache = new ConcurrentDictionary<string, IModule>(modules.ToDictionary(m => m.Key, m => m));
2124
Modules = _modulesCache.Values;
@@ -85,7 +88,6 @@ public void RequestNavigate(IModule module, NavigationParameters parameters)
8588
ActiveModules.Add(module);
8689
}
8790
}
88-
8991
///TODO:Consider an async implementation
9092
module.Initialize();
9193
module.IsActivated = true;
@@ -111,10 +113,30 @@ public IView GetOrCreateView(IModule module, string regionName)
111113
}
112114
else
113115
{
114-
var view = CreateView(module);
116+
IView view;
117+
if (!IsRenderedOnAnyRegion(module.Key))
118+
{
119+
view = module.View!;
120+
}
121+
else
122+
{
123+
view = CreateView(module);
124+
}
115125
_regionCache.TryAdd((regionName, module.Key), view);
116126
return view;
117127
}
118128
}
129+
130+
private bool IsRenderedOnAnyRegion(string moduleKey)
131+
{
132+
if (!_regionCache.IsEmpty)
133+
{
134+
foreach (var item in _regionCache)
135+
{
136+
return (item.Key.ModuleKey == moduleKey);
137+
}
138+
}
139+
return false;
140+
}
119141
}
120142
}

src/Package.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>2.0.7-beta</Version>
3+
<Version>2.0.8-beta</Version>
44
<Authors>Easley</Authors>
55
<RepositoryUrl>https://github.com/NeverMorewd/Lemon.ModuleNavigation</RepositoryUrl>
66
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)