feat(01-07): add ProfileManagementDialog with DI factory wiring

- Create Views/Dialogs/ProfileManagementDialog.xaml (modal Window with Name/TenantUrl/ClientId fields and TranslationSource bindings)
- Create Views/Dialogs/ProfileManagementDialog.xaml.cs (DI constructor injection, LoadAsync on Loaded)
- Add OpenProfileManagementDialog factory delegate to MainWindowViewModel
- Wire ManageProfilesCommand to open dialog via factory, reload profiles after close
- Register ProfileManagementDialog as Transient in DI (App.xaml.cs)
- Inject IServiceProvider into MainWindow constructor for DI-resolved dialog factory
This commit is contained in:
Dev
2026-04-02 12:38:31 +02:00
parent b41599d95a
commit cb7cf93c52
5 changed files with 105 additions and 2 deletions

View File

@@ -8,6 +8,8 @@ using SharepointToolbox.Infrastructure.Logging;
using SharepointToolbox.Services; using SharepointToolbox.Services;
using SharepointToolbox.ViewModels; using SharepointToolbox.ViewModels;
using SharepointToolbox.ViewModels.Tabs; using SharepointToolbox.ViewModels.Tabs;
using SharepointToolbox.Views.Dialogs;
using SharepointToolbox.Views.Tabs;
using System.Windows; using System.Windows;
namespace SharepointToolbox; namespace SharepointToolbox;
@@ -74,6 +76,8 @@ public partial class App : Application
services.AddSingleton<MainWindowViewModel>(); services.AddSingleton<MainWindowViewModel>();
services.AddTransient<ProfileManagementViewModel>(); services.AddTransient<ProfileManagementViewModel>();
services.AddTransient<SettingsViewModel>(); services.AddTransient<SettingsViewModel>();
services.AddTransient<ProfileManagementDialog>();
services.AddTransient<SettingsView>();
services.AddSingleton<MainWindow>(); services.AddSingleton<MainWindow>();
} }
} }

View File

@@ -1,6 +1,9 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Microsoft.Extensions.DependencyInjection;
using SharepointToolbox.ViewModels; using SharepointToolbox.ViewModels;
using SharepointToolbox.Views.Dialogs;
using SharepointToolbox.Views.Tabs;
namespace SharepointToolbox; namespace SharepointToolbox;
@@ -8,11 +11,18 @@ public partial class MainWindow : Window
{ {
private readonly MainWindowViewModel _viewModel; private readonly MainWindowViewModel _viewModel;
public MainWindow(MainWindowViewModel viewModel) public MainWindow(MainWindowViewModel viewModel, IServiceProvider serviceProvider)
{ {
InitializeComponent(); InitializeComponent();
_viewModel = viewModel; _viewModel = viewModel;
DataContext = viewModel; DataContext = viewModel;
// Wire profile management dialog factory
viewModel.OpenProfileManagementDialog = () => serviceProvider.GetRequiredService<ProfileManagementDialog>();
// Replace Settings tab placeholder with the DI-resolved SettingsView
SettingsTabItem.Content = serviceProvider.GetRequiredService<SettingsView>();
Loaded += OnLoaded; Loaded += OnLoaded;
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging;
@@ -15,6 +16,9 @@ public partial class MainWindowViewModel : ObservableRecipient
private readonly SessionManager _sessionManager; private readonly SessionManager _sessionManager;
private readonly ILogger<MainWindowViewModel> _logger; private readonly ILogger<MainWindowViewModel> _logger;
// Set by the view layer (MainWindow.xaml.cs) to open the dialog using DI
public Func<Window>? OpenProfileManagementDialog { get; set; }
[ObservableProperty] [ObservableProperty]
private TenantProfile? _selectedProfile; private TenantProfile? _selectedProfile;
@@ -122,6 +126,12 @@ public partial class MainWindowViewModel : ObservableRecipient
private void OpenProfileManagement() private void OpenProfileManagement()
{ {
// Profile management dialog opened by View layer (plan 01-07) if (OpenProfileManagementDialog == null) return;
var dialog = OpenProfileManagementDialog();
dialog.Owner = Application.Current.MainWindow;
dialog.ShowDialog();
// Reload profiles after dialog closes (modal — ShowDialog blocks until closed)
_ = LoadProfilesAsync();
} }
} }

View File

@@ -0,0 +1,60 @@
<Window x:Class="SharepointToolbox.Views.Dialogs.ProfileManagementDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="clr-namespace:SharepointToolbox.Localization"
Title="Manage Profiles" Width="500" Height="480"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
ResizeMode="NoResize">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Profile list -->
<Label Content="Profiles" Grid.Row="0" />
<ListBox Grid.Row="1" Margin="0,0,0,8"
ItemsSource="{Binding Profiles}"
SelectedItem="{Binding SelectedProfile}"
DisplayMemberPath="Name" />
<!-- Input fields -->
<Grid Grid.Row="2" Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.name]}"
Grid.Row="0" Grid.Column="0" />
<TextBox Text="{Binding NewName, UpdateSourceTrigger=PropertyChanged}"
Grid.Row="0" Grid.Column="1" Margin="0,2" />
<Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.url]}"
Grid.Row="1" Grid.Column="0" />
<TextBox Text="{Binding NewTenantUrl, UpdateSourceTrigger=PropertyChanged}"
Grid.Row="1" Grid.Column="1" Margin="0,2" />
<Label Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.clientid]}"
Grid.Row="2" Grid.Column="0" />
<TextBox Text="{Binding NewClientId, UpdateSourceTrigger=PropertyChanged}"
Grid.Row="2" Grid.Column="1" Margin="0,2" />
</Grid>
<!-- Buttons -->
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.add]}"
Command="{Binding AddCommand}" Width="60" Margin="4,0" />
<Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.rename]}"
Command="{Binding RenameCommand}" Width="60" Margin="4,0" />
<Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[profile.delete]}"
Command="{Binding DeleteCommand}" Width="60" Margin="4,0" />
<Button Content="Close" Width="60" Margin="4,0"
Click="CloseButton_Click" IsCancel="True" />
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,19 @@
using System.Windows;
using SharepointToolbox.ViewModels;
namespace SharepointToolbox.Views.Dialogs;
public partial class ProfileManagementDialog : Window
{
public ProfileManagementDialog(ProfileManagementViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
Loaded += async (_, _) => await viewModel.LoadAsync();
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}