This works!

This commit is contained in:
Mike Griese
2025-11-18 06:59:51 -06:00
parent d547a6f613
commit 38dfee0234
5 changed files with 77 additions and 11 deletions

View File

@@ -11,16 +11,25 @@ namespace Microsoft.CmdPal.Core.Common.Helpers;
public partial class WrappedDockItem : CommandItem
{
public override string Title => string.Empty;
public override string Title => $"{_itemTitle} (Pinned)";
public override IIconInfo? Icon => _icon;
private readonly string _itemTitle;
private readonly IIconInfo? _icon;
public WrappedDockItem(ICommand command)
{
Command = new WrappedDockList(command);
_itemTitle = command.Name;
_icon = command.Icon;
}
public WrappedDockItem(ICommandItem item, string id)
{
Command = new WrappedDockList(item, id);
_itemTitle = item.Title;
_icon = item.Icon;
}
}

View File

@@ -168,21 +168,62 @@ public sealed partial class DockViewModel : IDisposable,
// }
public partial class DockBandSettingsViewModel : ObservableObject
{
private readonly DockBandSettings _settingsModel;
private readonly SettingsModel _settingsModel;
private readonly DockBandSettings _dockSettingsModel;
private readonly TopLevelViewModel _adapter;
public string Title => _adapter.Title;
public string Description
{
get
{
// TODO! we should have a way of saying "pinned from {extension}" vs
// just a band that's from an extension
return $"{_adapter.ExtensionName}";
}
}
public string ProviderId => _adapter.CommandProviderId;
public IconInfoViewModel Icon => _adapter.ItemViewModel.Icon;
public IconInfoViewModel Icon => _adapter.IconViewModel;
public bool ShowLabels => _settingsModel.ShowLabels ?? true; // TODO! deal with the fact it might be null
public DockBandSettingsViewModel(DockBandSettings settingsModel, TopLevelViewModel adapter)
public bool ShowLabels
{
_settingsModel = settingsModel;
get => _dockSettingsModel.ShowLabels ?? true; // TODO! deal with the fact it might be null
set => _dockSettingsModel.ShowLabels = value; // TODO! save settings
}
public string PinSide
{
// returns "Start", "End" or "None"
get
{
var dockSettings = _settingsModel.DockSettings;
var inStart = dockSettings.StartBands.Any(b => b.Id == _dockSettingsModel.Id);
if (inStart)
{
return "Start";
}
var inEnd = dockSettings.EndBands.Any(b => b.Id == _dockSettingsModel.Id);
if (inEnd)
{
return "End";
}
return "None";
}
}
public DockBandSettingsViewModel(
DockBandSettings dockSettingsModel,
TopLevelViewModel adapter,
SettingsModel settingsModel)
{
_dockSettingsModel = dockSettingsModel;
_adapter = adapter;
_settingsModel = settingsModel;
}
}
#pragma warning restore SA1402 // File may only contain a single type

View File

@@ -48,18 +48,22 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
public CommandPaletteHost ExtensionHost { get; private set; }
public string ExtensionName => ExtensionHost.Extension?.ExtensionDisplayName ?? "Built-in"; // TODO! loc
public CommandViewModel CommandViewModel => _commandItemViewModel.Command;
public CommandItemViewModel ItemViewModel => _commandItemViewModel;
public string CommandProviderId => _commandProviderId;
public IconInfoViewModel IconViewModel => _commandItemViewModel.Icon;
////// ICommandItem
public string Title => _commandItemViewModel.Title;
public string Subtitle => _commandItemViewModel.Subtitle;
public IIconInfo Icon => _commandItemViewModel.Icon;
public IIconInfo Icon => (IIconInfo)IconViewModel;
public IIconInfo InitialIcon => _initialIcon ?? _commandItemViewModel.Icon;
@@ -258,7 +262,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
return;
}
_initialIcon = _commandItemViewModel.Icon;
_initialIcon = (IIconInfo?)_commandItemViewModel.Icon;
if (raiseNotification)
{

View File

@@ -94,7 +94,7 @@
<ItemsRepeater ItemsSource="{x:Bind AllDockBandItems, Mode=OneWay}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="dockVm:DockBandSettingsViewModel">
<controls:SettingsCard Description="{x:Bind ProviderId, Mode=OneWay}" Header="{x:Bind Title, Mode=OneWay}">
<controls:SettingsCard Description="{x:Bind Description, Mode=OneWay}" Header="{x:Bind Title, Mode=OneWay}">
<controls:SettingsCard.HeaderIcon>
<cpControls:ContentIcon>
<cpControls:ContentIcon.Content>
@@ -107,6 +107,17 @@
</cpControls:ContentIcon.Content>
</cpControls:ContentIcon>
</controls:SettingsCard.HeaderIcon>
<StackPanel
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="8">
<TextBlock VerticalAlignment="Center" Text="{x:Bind PinSide, Mode=OneWay}" />
<ToggleSwitch
IsOn="{x:Bind ShowLabels, Mode=TwoWay}"
OffContent="Hide labels"
OnContent="Show Labels" />
</StackPanel>
</controls:SettingsCard>
</DataTemplate>
</ItemsRepeater.ItemTemplate>

View File

@@ -130,13 +130,14 @@ public sealed partial class DockSettingsPage : Page
// var allBands = GetAllBands();
var tlcManager = App.Current.Services.GetService<TopLevelCommandManager>()!;
var settingsModel = App.Current.Services.GetService<SettingsModel>()!;
var allBands = tlcManager.DockBands;
foreach (var band in allBands)
{
var setting = band.DockBandSettings;
if (setting is not null)
{
allSettings.Add(new(setting, band));
allSettings.Add(new(setting, band, settingsModel));
}
}