Skip to content

Commit

Permalink
AdditionalTools validation & feedback (#3108)
Browse files Browse the repository at this point in the history
* AdditionalTools validation & feedback

* Updates per feedback

* More updates per feedback

* More feedback, another update

* Second half of the pin icon fix I missed last time.

* Updates per feedback.
  • Loading branch information
andreww-msft authored Jun 4, 2024
1 parent 7f92aeb commit 0c4fb00
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 107 deletions.
2 changes: 1 addition & 1 deletion tools/PI/DevHome.PI/BarWindowHorizontal.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
HorizontalAlignment="Center"
Click="ManageExternalToolsButton_Click">
<Button.ContextFlyout>
<MenuFlyout x:Name="ExternalToolsMenu">
<MenuFlyout x:Name="ExternalToolsMenu" Opening="ExternalToolsMenu_Opening">
<!-- We can't databind to MenuFlyout, so we'll add a MenuFlyoutItem
for each external tool in codebehind here. -->
</MenuFlyout>
Expand Down
15 changes: 15 additions & 0 deletions tools/PI/DevHome.PI/BarWindowHorizontal.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public partial class BarWindowHorizontal : WindowEx
private readonly string _pinMenuItemText = CommonHelper.GetLocalizedString("PinMenuItemText");
private readonly string _unpinMenuItemText = CommonHelper.GetLocalizedString("UnpinMenuItemText");
private readonly BarWindowViewModel _viewModel;
private readonly FontIcon _pinIcon = new() { Glyph = "\uE718" };
private readonly FontIcon _unpinIcon = new() { Glyph = "\uE77A" };

private ExternalTool? _selectedExternalTool;
private INotifyCollectionChanged? _externalTools;
Expand Down Expand Up @@ -227,6 +229,15 @@ private void ManageExternalToolsButton_Click(object sender, RoutedEventArgs e)
ExpandedViewControl.NavigateToSettings(typeof(AdditionalToolsViewModel).FullName!);
}

private void ExternalToolsMenu_Opening(object sender, object e)
{
// Cancel the opening of the menu if there are no items.
if (sender is MenuFlyout flyout && flyout?.Items?.Count == 0)
{
flyout.Hide();
}
}

private void ExternalToolMenuItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
var menuItem = sender as MenuFlyoutItem;
Expand All @@ -236,10 +247,12 @@ private void ExternalToolMenuItem_RightTapped(object sender, RightTappedRoutedEv
if (_selectedExternalTool.IsPinned)
{
PinUnpinMenuItem.Text = _unpinMenuItemText;
PinUnpinMenuItem.Icon = _unpinIcon;
}
else
{
PinUnpinMenuItem.Text = _pinMenuItemText;
PinUnpinMenuItem.Icon = _pinIcon;
}

ToolContextMenu.ShowAt(menuItem, e.GetPosition(menuItem));
Expand Down Expand Up @@ -291,10 +304,12 @@ private void ExternalToolButton_PointerPressed(object sender, PointerRoutedEvent
if (_selectedExternalTool.IsPinned)
{
PinUnpinMenuItem.Text = _unpinMenuItemText;
PinUnpinMenuItem.Icon = _unpinIcon;
}
else
{
PinUnpinMenuItem.Text = _pinMenuItemText;
PinUnpinMenuItem.Icon = _pinIcon;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/PI/DevHome.PI/BarWindowVertical.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
x:Uid="ManageExternalToolsButton"
HorizontalAlignment="Center">
<Button.ContextFlyout>
<MenuFlyout x:Name="ExternalToolsMenu">
<MenuFlyout x:Name="ExternalToolsMenu" Opening="ExternalToolsMenu_Opening">
<!-- We can't databind to MenuFlyout, so we'll add a MenuFlyoutItem
for each external tool in codebehind here. -->
</MenuFlyout>
Expand Down
10 changes: 10 additions & 0 deletions tools/PI/DevHome.PI/BarWindowVertical.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ private void MainPanel_Loaded(object sender, RoutedEventArgs e)
Width = 70;
}

private void ExternalToolsMenu_Opening(object sender, object e)
{
// Cancel the opening of the menu if there are no items.
var flyout = sender as MenuFlyout;
if (flyout is not null && flyout.Items is not null && flyout.Items.Count == 0)
{
flyout.Hide();
}
}

private void ExternalToolButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Button clickedButton)
Expand Down
154 changes: 71 additions & 83 deletions tools/PI/DevHome.PI/Controls/AddToolControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,83 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Border>
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock
x:Uid="ToolPathHeaderTextBlock"
VerticalAlignment="Center" />
<TextBox
x:Name="ToolPathTextBox" Grid.Column="1" MinWidth="800"
TextChanged="UpdateSampleCommandline"/>
<Button
x:Uid="ToolBrowseButton" Name="BrowseButton" Grid.Column="2"
Width="100" Margin="8,0,0,0" HorizontalAlignment="Left"
Click="BrowseButton_Click"/>
</Grid>
<Grid Margin="0,6,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<TextBlock x:Uid="ToolNameHeaderTextBlock" VerticalAlignment="Center"/>
<TextBox x:Name="ToolNameTextBox" Grid.Column="1" HorizontalAlignment="Stretch"/>
</Grid>
</StackPanel>
</Border>

<Border Grid.Row="1" Margin="0,12,0,0">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="BasicArgumentsTextBlock"/>
<Grid Grid.Row="1" Margin="0,6,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton
x:Uid="NoneRadio" x:Name="NoneRadio" IsChecked="True" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
<RadioButton
x:Uid="HwndRadio" x:Name="HwndRadio" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
<RadioButton
x:Uid="ProcessIdRadio" x:Name="ProcessIdRadio" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
</StackPanel>
<TextBlock
x:Uid="PrefixTextBlock" Grid.Column="1" Margin="0,0,8,0"
VerticalAlignment="Center" HorizontalAlignment="Right"/>
<TextBox
x:Name="PrefixTextBox" Grid.Column="2" Width="100" HorizontalAlignment="Right"
TextChanged="UpdateSampleCommandline"/>
</Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button
x:Name="ToolBrowseButton" x:Uid="ToolBrowseButton"
HorizontalAlignment="Left" MinWidth="100"
Click="ToolBrowseButton_Click"/>
<TextBox
x:Name="ToolPathTextBox" Grid.Column="1" MinWidth="800" Margin="8,0,0,0"
IsReadOnly="True"/>
</Grid>
<Grid Margin="0,6,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<TextBlock x:Uid="ToolNameHeaderTextBlock" VerticalAlignment="Center" MinWidth="100"/>
<TextBox x:Name="ToolNameTextBox" Grid.Column="1" HorizontalAlignment="Stretch" Margin="8,0,0,0" />
</Grid>
</Border>
</StackPanel>

<Border Grid.Row="2" Margin="0,12,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="OtherArgumentsTextBlock"/>
<TextBox
x:Name="OtherArgsTextBox" Grid.Row="1" TextWrapping="Wrap" MinHeight="60"
<Grid Grid.Row="1" Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="BasicArgumentsTextBlock"/>
<Grid Grid.Row="1" Margin="0,6,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton
x:Uid="NoneRadio" x:Name="NoneRadio" IsChecked="True" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
<RadioButton
x:Uid="HwndRadio" x:Name="HwndRadio" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
<RadioButton
x:Uid="ProcessIdRadio" x:Name="ProcessIdRadio" GroupName="SwitchGroup"
Checked="UpdateSampleCommandline"/>
</StackPanel>
<TextBlock
x:Uid="PrefixTextBlock" Grid.Column="1" Margin="0,0,8,0"
VerticalAlignment="Center" HorizontalAlignment="Right"/>
<TextBox
x:Name="PrefixTextBox" Grid.Column="2" MinWidth="150" HorizontalAlignment="Right"
TextChanged="UpdateSampleCommandline"/>
</Grid>
</Border>
</Grid>

<Border Grid.Row="3" Margin="0,12,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="SampleCommandLineTextBlock"/>
<TextBox
x:Name="SampleCommandTextBox" Grid.Row="1" MinHeight="60"
TextWrapping="Wrap" IsReadOnly="True"/>
</Grid>
</Border>
<Grid Grid.Row="2" Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="OtherArgumentsTextBlock"/>
<TextBox
x:Name="OtherArgsTextBox" Grid.Row="1" TextWrapping="Wrap" MinHeight="60"
TextChanged="UpdateSampleCommandline"/>
</Grid>

<Grid Grid.Row="3" Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Uid="SampleCommandLineTextBlock"/>
<TextBox
x:Name="SampleCommandTextBox" Grid.Row="1" MinHeight="60"
TextWrapping="Wrap" IsReadOnly="True"/>
</Grid>

<ToggleSwitch
x:Uid="IsPinnedToggleSwitch" x:Name="IsPinnedToggleSwitch"
Expand Down
29 changes: 26 additions & 3 deletions tools/PI/DevHome.PI/Controls/AddToolControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Runtime.InteropServices;
using DevHome.Common;
using DevHome.Common.Extensions;
using DevHome.PI.Helpers;
using Microsoft.UI.Xaml;
Expand All @@ -13,12 +15,15 @@ namespace DevHome.PI.Controls;

public sealed partial class AddToolControl : UserControl
{
private readonly string invalidToolInfo = CommonHelper.GetLocalizedString("InvalidToolInfoMessage");
private readonly string messageCloseText = CommonHelper.GetLocalizedString("MessageCloseText");

public AddToolControl()
{
InitializeComponent();
}

private void BrowseButton_Click(object sender, RoutedEventArgs e)
private void ToolBrowseButton_Click(object sender, RoutedEventArgs e)
{
HandleBrowseButton();
}
Expand Down Expand Up @@ -68,7 +73,15 @@ private void HandleBrowseButton()

private void OkButton_Click(object sender, RoutedEventArgs e)
{
ExternalToolsHelper.Instance.AddExternalTool(GetCurrentToolDefinition());
var tool = GetCurrentToolDefinition();
if (tool is null)
{
return;
}

ExternalToolsHelper.Instance.AddExternalTool(tool);
var toolRegisteredMessage = CommonHelper.GetLocalizedString("ToolRegisteredMessage", ToolNameTextBox.Text);
WindowHelper.ShowTimedMessageDialog(this, toolRegisteredMessage, messageCloseText);
ClearValues();
}

Expand All @@ -82,8 +95,14 @@ private void ClearValues()
IsPinnedToggleSwitch.IsOn = true;
}

private ExternalTool GetCurrentToolDefinition()
private ExternalTool? GetCurrentToolDefinition()
{
if (string.IsNullOrEmpty(ToolNameTextBox.Text) || string.IsNullOrEmpty(ToolPathTextBox.Text))
{
WindowHelper.ShowTimedMessageDialog(this, invalidToolInfo, messageCloseText);
return null;
}

var argType = ExternalToolArgType.None;

if (HwndRadio.IsChecked ?? false)
Expand Down Expand Up @@ -123,6 +142,10 @@ private void UpdateSampleCommandline()
}

var tool = GetCurrentToolDefinition();
if (tool is null)
{
return;
}

SampleCommandTextBox.Text = tool.CreateFullCommandLine(123, (Windows.Win32.Foundation.HWND)123);
}
Expand Down
18 changes: 14 additions & 4 deletions tools/PI/DevHome.PI/Controls/EditToolsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:local="using:DevHome.PI.Helpers"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Expand All @@ -15,6 +16,7 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<controls:DataGrid
x:Name="ToolsDataGrid"
VerticalScrollBarVisibility="Visible"
Expand All @@ -27,17 +29,25 @@
CanUserReorderColumns="True"
CanUserResizeColumns="True"
ColumnHeaderHeight="32"
MaxColumnWidth="400"
FrozenColumnCount="0"
GridLinesVisibility="None"
HeadersVisibility="Column">
HeadersVisibility="Column"
ItemsSource="{x:Bind local:ExternalToolsHelper.Instance.AllExternalTools}"
SelectionChanged="ToolsDataGrid_SelectionChanged">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn x:Uid="EditToolsNameColumn" Binding="{Binding Name}" Width="150"/>
<controls:DataGridTextColumn x:Uid="EditToolsNameColumn" Binding="{Binding Name}" MinWidth="150"/>
<controls:DataGridTextColumn x:Uid="EditToolsNameColumn" Binding="{Binding Executable}" Width="*"/>
</controls:DataGrid.Columns>
</controls:DataGrid>

<StackPanel x:Name="GridButtonPanel" Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="0,4,0,8">
<Button x:Uid="DeleteToolButton" x:Name="DeleteToolButton" Width="120" Height="36" Margin="4,0,0,0" Click="DeleteToolButton_Click"/>
<Button
x:Uid="UnregisterToolButton"
x:Name="UnregisterToolButton"
Width="120"
Height="36"
Margin="4,0,0,0"
Click="UnregisterToolButton_Click"/>
</StackPanel>
</Grid>
</UserControl>
Loading

0 comments on commit 0c4fb00

Please sign in to comment.