feat(04-10): create TemplatesViewModel and TemplatesView
- TemplatesViewModel: list, capture with 5 options, apply, rename, delete, refresh - TemplatesView: capture section with checkboxes, apply section, template DataGrid - RenameInputDialog: simple WPF dialog (no Microsoft.VisualBasic dependency) - Capture/Apply are separate async commands from RunCommand
This commit is contained in:
71
SharepointToolbox/Views/Tabs/TemplatesView.xaml.cs
Normal file
71
SharepointToolbox/Views/Tabs/TemplatesView.xaml.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SharepointToolbox.Views.Tabs;
|
||||
|
||||
public partial class TemplatesView : UserControl
|
||||
{
|
||||
public TemplatesView(ViewModels.Tabs.TemplatesViewModel viewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
|
||||
// Wire rename dialog factory using a simple WPF input dialog
|
||||
viewModel.RenameDialogFactory = currentName =>
|
||||
{
|
||||
var dialog = new RenameInputDialog(currentName) { Owner = Window.GetWindow(this) };
|
||||
return dialog.ShowDialog() == true ? dialog.InputText : null;
|
||||
};
|
||||
|
||||
// Load templates on first display
|
||||
viewModel.RefreshCommand.ExecuteAsync(null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple WPF input dialog for renaming templates (replaces Microsoft.VisualBasic.Interaction.InputBox).
|
||||
/// </summary>
|
||||
internal class RenameInputDialog : Window
|
||||
{
|
||||
private readonly TextBox _inputBox;
|
||||
|
||||
public string InputText => _inputBox.Text;
|
||||
|
||||
public RenameInputDialog(string currentName)
|
||||
{
|
||||
Title = "Rename Template";
|
||||
Width = 360;
|
||||
Height = 140;
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||||
ResizeMode = ResizeMode.NoResize;
|
||||
|
||||
var panel = new StackPanel { Margin = new Thickness(12) };
|
||||
panel.Children.Add(new TextBlock { Text = "Enter new template name:", Margin = new Thickness(0, 0, 0, 6) });
|
||||
|
||||
_inputBox = new TextBox { Text = currentName };
|
||||
_inputBox.SelectAll();
|
||||
_inputBox.Focus();
|
||||
_inputBox.KeyDown += (s, e) =>
|
||||
{
|
||||
if (e.Key == System.Windows.Input.Key.Enter) { DialogResult = true; Close(); }
|
||||
if (e.Key == System.Windows.Input.Key.Escape) { DialogResult = false; Close(); }
|
||||
};
|
||||
panel.Children.Add(_inputBox);
|
||||
|
||||
var buttons = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
Margin = new Thickness(0, 10, 0, 0),
|
||||
};
|
||||
var ok = new Button { Content = "OK", Width = 75, Margin = new Thickness(0, 0, 8, 0), IsDefault = true };
|
||||
ok.Click += (s, e) => { DialogResult = true; Close(); };
|
||||
var cancel = new Button { Content = "Cancel", Width = 75, IsCancel = true };
|
||||
cancel.Click += (s, e) => { DialogResult = false; Close(); };
|
||||
buttons.Children.Add(ok);
|
||||
buttons.Children.Add(cancel);
|
||||
panel.Children.Add(buttons);
|
||||
|
||||
Content = panel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user