Skip to content

Commit

Permalink
Merge pull request #31 from Freeesia/feature/partial
Browse files Browse the repository at this point in the history
自動生成される`PresentationService` を部分クラスに変更
  • Loading branch information
nuitsjp authored Feb 11, 2025
2 parents bb953e4 + 7207a43 commit da6e076
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand All @@ -67,7 +68,11 @@
<TextBlock Grid.Row="4" Grid.Column="1" Text="with Safe Parameter."/>
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding WindowName3}" Cursor="Arrow"/>

<StackPanel Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal" Margin="20">
<Button Grid.Row="5" Grid.Column="0" Content="Open" Command="{Binding OpenSingletonCommand}" CommandParameter="{kamishibai:Window}"/>
<TextBlock Grid.Row="5" Grid.Column="1" Text="App-specific Singleton." Cursor=""/>
<TextBox Grid.Row="5" Grid.Column="2" Text="{Binding WindowName4}" Cursor="Arrow"/>

<StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal" Margin="20">
<Button Content="Activate" Command="{Binding ActivateCommand}"/>
<Button Content="Hide" Command="{Binding HideCommand}"/>
<Button Content="Show" Command="{Binding ShowCommand}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public OpenWindowViewModel(IPresentationService presentationService)
new(owner => _presentationService.OpenWindowWithArgumentsWindowAsync(WindowName3, owner, new OpenWindowOptions { WindowStartupLocation = SelectedWindowStartupLocation })
.AddTo(_disposable));

public string WindowName4 { get; set; } = "Hello, Singleton (App-specific)";

public AsyncRelayCommand<object> OpenSingletonCommand =>
new(owner => _presentationService.OpenSingletonWindowWithArgumentsWindowAsync(WindowName4, owner, new OpenWindowOptions { WindowStartupLocation = SelectedWindowStartupLocation })
.AddTo(_disposable));

public RelayCommand ActivateCommand => new(() => InvokeWindowAction(x => x.Activate()));
public RelayCommand HideCommand => new(() => InvokeWindowAction(x => x.Hide()));
public RelayCommand ShowCommand => new(() => InvokeWindowAction(x => x.Show()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Kamishibai;

namespace SampleBrowser.ViewModel;

partial interface IPresentationService
{
Task<IWindow> OpenSingletonWindowWithArgumentsWindowAsync(string windowName, object? owner = null, OpenWindowOptions? options = null);
}


partial class PresentationService
{
private IWindow? singletonWindow;

public async Task<IWindow> OpenSingletonWindowWithArgumentsWindowAsync(string windowName, object? owner = null, OpenWindowOptions? options = null)
{
if (this.singletonWindow is null || this.singletonWindow.IsClosed)
{
return this.singletonWindow = await OpenWindowWithArgumentsWindowAsync(windowName, owner, options);
}
this.singletonWindow.Activate();
return this.singletonWindow;
}
}
16 changes: 8 additions & 8 deletions Source/Kamishibai.CodeAnalysis.Test/GenerateNavigateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToFooAsync(string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -82,7 +82,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToFooAsync(string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -133,7 +133,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToFooAsync(string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -192,7 +192,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToBarAsync(int number, Foo.Argument argument, string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -252,7 +252,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToBarAsync(int number, string frameName, Foo.Argument argument);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -314,7 +314,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToBarAsync(int number, Foo.Argument argument, string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -375,7 +375,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToBarAsync(int? number, Foo.Argument argument, string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -432,7 +432,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> NavigateToBarAsync(int number, Foo.Argument argument, string frameName = """");
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down
14 changes: 7 additions & 7 deletions Source/Kamishibai.CodeAnalysis.Test/GenerateOpenDialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenFooDialogAsync(object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -83,7 +83,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenFooDialogAsync(object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -136,7 +136,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenFooDialogAsync(object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -196,7 +196,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenBarDialogAsync(int number, Foo.Argument argument, object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -258,7 +258,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenBarDialogAsync(int number, Foo.Argument argument, object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -320,7 +320,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenBarDialogAsync(int? number, Foo.Argument argument, object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -379,7 +379,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<bool> OpenBarDialogAsync(int number, Foo.Argument argument, object? owner = null, OpenDialogOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down
14 changes: 7 additions & 7 deletions Source/Kamishibai.CodeAnalysis.Test/GenerateOpenWindowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenFooWindowAsync(object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -83,7 +83,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenFooWindowAsync(object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -136,7 +136,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenFooWindowAsync(object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -196,7 +196,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenBarWindowAsync(int number, Foo.Argument argument, object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -258,7 +258,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenBarWindowAsync(int number, Foo.Argument argument, object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -320,7 +320,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenBarWindowAsync(int? number, Foo.Argument argument, object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -379,7 +379,7 @@ public partial interface IPresentationService : IPresentationServiceBase
Task<IWindow> OpenBarWindowAsync(int? number, Foo.Argument argument, object? owner = null, OpenWindowOptions? options = null);
}
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override string TransformText()

this.Write(@" }
public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ foreach(var openDialogInfo in OpenDialogInfos)
#>
}

public class PresentationService : PresentationServiceBase, IPresentationService
public partial class PresentationService : PresentationServiceBase, IPresentationService
{
private readonly IServiceProvider _serviceProvider;

Expand Down

0 comments on commit da6e076

Please sign in to comment.