-
Notifications
You must be signed in to change notification settings - Fork 7.5k
CmdPal: Plain text viewer and image viewer IContent [Experiment] #43964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jiripolasek
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
jiripolasek:feature/41038-cmdpal-moar-content
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
95 changes: 95 additions & 0 deletions
95
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentImageViewModel.cs
This file contains hidden or 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,95 @@ | ||
| // 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.Core.ViewModels; | ||
| using Microsoft.CmdPal.Core.ViewModels.Models; | ||
| using Microsoft.CommandPalette.Extensions; | ||
|
|
||
| namespace Microsoft.CmdPal.UI.ViewModels; | ||
|
|
||
| public partial class ContentImageViewModel : ContentViewModel | ||
| { | ||
| public ExtensionObject<IImageContent> Model { get; } | ||
|
|
||
| public IconInfoViewModel Image { get; protected set; } = new(null); | ||
|
|
||
| public double MaxWidth { get; protected set; } = double.PositiveInfinity; | ||
|
|
||
| public double MaxHeight { get; protected set; } = double.PositiveInfinity; | ||
|
|
||
| public ContentImageViewModel(IImageContent content, WeakReference<IPageContext> context) | ||
| : base(context) | ||
| { | ||
| Model = new ExtensionObject<IImageContent>(content); | ||
| } | ||
|
|
||
| public override void InitializeProperties() | ||
| { | ||
| var model = Model.Unsafe; | ||
| if (model is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| Image = new IconInfoViewModel(model.Image); | ||
| Image.InitializeProperties(); | ||
|
|
||
| MaxWidth = model.MaxWidth <= 0 ? double.PositiveInfinity : model.MaxWidth; | ||
| MaxHeight = model.MaxHeight <= 0 ? double.PositiveInfinity : model.MaxHeight; | ||
|
|
||
| UpdateProperty(nameof(Image), nameof(MaxWidth), nameof(MaxHeight)); | ||
| model.PropChanged += Model_PropChanged; | ||
| } | ||
|
|
||
| private void Model_PropChanged(object sender, IPropChangedEventArgs args) | ||
| { | ||
| try | ||
| { | ||
| var propName = args.PropertyName; | ||
| FetchProperty(propName); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ShowException(ex); | ||
| } | ||
| } | ||
|
|
||
| private void FetchProperty(string propertyName) | ||
| { | ||
| var model = Model.Unsafe; | ||
| if (model is null) | ||
| { | ||
| return; // throw? | ||
| } | ||
|
|
||
| switch (propertyName) | ||
| { | ||
| case nameof(Image): | ||
| Image = new IconInfoViewModel(model.Image); | ||
| Image.InitializeProperties(); | ||
| UpdateProperty(propertyName); | ||
| break; | ||
|
|
||
| case nameof(IImageContent.MaxWidth): | ||
| MaxWidth = model.MaxWidth <= 0 ? double.PositiveInfinity : model.MaxWidth; | ||
| UpdateProperty(propertyName); | ||
| break; | ||
|
|
||
| case nameof(IImageContent.MaxHeight): | ||
| MaxHeight = model.MaxHeight <= 0 ? double.PositiveInfinity : model.MaxHeight; | ||
| UpdateProperty(propertyName); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| protected override void UnsafeCleanup() | ||
| { | ||
| base.UnsafeCleanup(); | ||
| var model = Model.Unsafe; | ||
| if (model is not null) | ||
| { | ||
| model.PropChanged -= Model_PropChanged; | ||
| } | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ContentPlainTextViewModel.cs
This file contains hidden or 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,75 @@ | ||
| // 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.Core.ViewModels; | ||
| using Microsoft.CmdPal.Core.ViewModels.Models; | ||
| using Microsoft.CommandPalette.Extensions; | ||
|
|
||
| namespace Microsoft.CmdPal.UI.ViewModels; | ||
|
|
||
| public partial class ContentPlainTextViewModel : ContentViewModel | ||
| { | ||
| public ExtensionObject<IPlainTextContent> Model { get; } | ||
|
|
||
| public string? Text { get; protected set; } | ||
|
|
||
| public ContentPlainTextViewModel(IPlainTextContent content, WeakReference<IPageContext> context) | ||
| : base(context) | ||
| { | ||
| Model = new ExtensionObject<IPlainTextContent>(content); | ||
| } | ||
|
|
||
| public override void InitializeProperties() | ||
| { | ||
| var model = Model.Unsafe; | ||
| if (model is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| Text = model.Text; | ||
| UpdateProperty(nameof(Text)); | ||
| model.PropChanged += Model_PropChanged; | ||
| } | ||
|
|
||
| private void Model_PropChanged(object sender, IPropChangedEventArgs args) | ||
| { | ||
| try | ||
| { | ||
| var propName = args.PropertyName; | ||
| FetchProperty(propName); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ShowException(ex); | ||
| } | ||
| } | ||
|
|
||
| private void FetchProperty(string propertyName) | ||
| { | ||
| var model = Model.Unsafe; | ||
| if (model is null) | ||
| { | ||
| return; // throw? | ||
| } | ||
|
|
||
| Text = propertyName switch | ||
| { | ||
| nameof(Text) => model.Text, | ||
| _ => Text, | ||
| }; | ||
|
|
||
| UpdateProperty(propertyName); | ||
| } | ||
|
|
||
| protected override void UnsafeCleanup() | ||
| { | ||
| base.UnsafeCleanup(); | ||
| var model = Model.Unsafe; | ||
| if (model is not null) | ||
| { | ||
| model.PropChanged -= Model_PropChanged; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ImageViewer.xaml
This file contains hidden or 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,62 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <UserControl | ||
| x:Class="Microsoft.CmdPal.UI.Controls.ImageViewer" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:controls="using:Microsoft.CmdPal.UI.Controls" | ||
| xmlns:help="using:Microsoft.CmdPal.UI.Helpers" | ||
| mc:Ignorable="d"> | ||
| <Grid Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> | ||
| <controls:IconBox x:Name="ZoomImage" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| IsTabStop="False" | ||
| RenderTransformOrigin="0.5,0.5" | ||
| SourceRequested="{x:Bind help:IconCacheProvider.SourceRequested}"> | ||
| <controls:IconBox.RenderTransform> | ||
| <TransformGroup> | ||
| <ScaleTransform x:Name="ScaleTransform" ScaleX="1" ScaleY="1" /> | ||
| <TranslateTransform x:Name="TranslateTransform" X="0" Y="0" /> | ||
| </TransformGroup> | ||
| </controls:IconBox.RenderTransform> | ||
| </controls:IconBox> | ||
|
|
||
| <Border x:Name="ToolbarHost" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Bottom" | ||
| Margin="0,0,0,12" | ||
| Padding="8" | ||
| CornerRadius="8" | ||
| BorderThickness="1" | ||
| BorderBrush="{ThemeResource ControlStrokeColorDefaultBrush}" | ||
| Background="{ThemeResource SystemControlAcrylicWindowBrush}"> | ||
| <StackPanel x:Name="Toolbar" | ||
| Orientation="Horizontal" | ||
| Spacing="8" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Background="Transparent"> | ||
| <Button Padding="8,6" Click="OnZoomInClick"> | ||
| <ToolTipService.ToolTip> | ||
| <ToolTip Content="Zoom in"/> | ||
| </ToolTipService.ToolTip> | ||
| <SymbolIcon Symbol="ZoomIn" /> | ||
| </Button> | ||
| <Button Padding="8,6" Click="OnZoomOutClick"> | ||
| <ToolTipService.ToolTip> | ||
| <ToolTip Content="Zoom out"/> | ||
| </ToolTipService.ToolTip> | ||
| <SymbolIcon Symbol="ZoomOut" /> | ||
| </Button> | ||
| <Button Padding="8,6" Click="OnZoomToFitClick"> | ||
| <ToolTipService.ToolTip> | ||
| <ToolTip Content="Zoom to fit"/> | ||
| </ToolTipService.ToolTip> | ||
| <FontIcon Glyph="" /> | ||
| </Button> | ||
| </StackPanel> | ||
| </Border> | ||
| </Grid> | ||
| </UserControl> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more resources to localize. I think this can be done just by giving the button an
x:Uidala: