-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bunch more ListItem viewmodel properties, namely tags (#192)
Doesn't use all these everywhere, but starts plumbing them into ViewModel's so that @niels9001 can start using more things in more places. ![image](https://github.com/user-attachments/assets/f1c7c0c4-c4b2-49a4-889f-2c2e5f595f63) I didn't actually colorize the tags, because that requires a Brush, and I don't think I'm supposed to put brushes in the viewmodels ref #73
- Loading branch information
1 parent
186d411
commit 8d8c8c6
Showing
3 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TagViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.CmdPal.Extensions; | ||
using Microsoft.CmdPal.UI.ViewModels.Models; | ||
using Windows.UI; | ||
|
||
namespace Microsoft.CmdPal.UI.ViewModels; | ||
|
||
public partial class TagViewModel(ITag _tag, TaskScheduler Scheduler) : ExtensionObjectViewModel | ||
{ | ||
private readonly ExtensionObject<ITag> _tagModel = new(_tag); | ||
|
||
// Remember - "observable" properties from the model (via PropChanged) | ||
// cannot be marked [ObservableProperty] | ||
public string Text { get; private set; } = string.Empty; | ||
|
||
public string Tooltip { get; private set; } = string.Empty; | ||
|
||
public Color Color { get; private set; } | ||
|
||
// TODO Icon | ||
public ExtensionObject<ICommand> Command { get; private set; } = new(null); | ||
|
||
public override void InitializeProperties() | ||
{ | ||
var model = _tagModel.Unsafe; | ||
if (model == null) | ||
{ | ||
return; | ||
} | ||
|
||
Command = new(model.Command); | ||
Text = model.Text; | ||
Color = model.Color; | ||
Tooltip = model.ToolTip; | ||
|
||
UpdateProperty(nameof(Text)); | ||
UpdateProperty(nameof(Color)); | ||
UpdateProperty(nameof(Tooltip)); | ||
} | ||
|
||
protected void UpdateProperty(string propertyName) => Task.Factory.StartNew(() => { OnPropertyChanged(propertyName); }, CancellationToken.None, TaskCreationOptions.None, Scheduler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters