[PowerRename] Add row highlighting (#14746)

* Add Highlight property to ExplorerItem

* Change property type

* Initialize property

* Update MainWindow.xaml

* Update MainWindow.xaml

* Update MainWindow.xaml

* Updated brush

Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
This commit is contained in:
Niels Laute
2021-12-02 13:02:12 +01:00
committed by GitHub
parent 0e61f41e31
commit a018e0493b
4 changed files with 68 additions and 23 deletions

View File

@@ -13,6 +13,7 @@ namespace winrt::PowerRenameUILib::implementation
m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_depth{ depth }, m_checked{ checked } m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_depth{ depth }, m_checked{ checked }
{ {
m_imagePath = (m_type == static_cast<UINT>(ExplorerItemType::Folder)) ? folderImagePath : fileImagePath; m_imagePath = (m_type == static_cast<UINT>(ExplorerItemType::Folder)) ? folderImagePath : fileImagePath;
m_highlight = m_checked && !m_renamed.empty() ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
} }
int32_t ExplorerItem::Id() int32_t ExplorerItem::Id()
@@ -50,6 +51,13 @@ namespace winrt::PowerRenameUILib::implementation
{ {
m_renamed = value; m_renamed = value;
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Renamed" }); m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Renamed" });
auto visibility = m_checked && !m_renamed.empty() ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
if (m_highlight != visibility)
{
m_highlight = visibility;
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Highlight" });
}
} }
} }
@@ -87,9 +95,21 @@ namespace winrt::PowerRenameUILib::implementation
{ {
m_checked = value; m_checked = value;
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Checked" }); m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Checked" });
auto visibility = m_checked && !m_renamed.empty() ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
if (m_highlight != visibility)
{
m_highlight = visibility;
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Highlight" });
}
} }
} }
winrt::Windows::UI::Xaml::Visibility ExplorerItem::Highlight()
{
return m_highlight;
}
winrt::event_token ExplorerItem::PropertyChanged(winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) winrt::event_token ExplorerItem::PropertyChanged(winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
{ {
return m_propertyChanged.add(handler); return m_propertyChanged.add(handler);

View File

@@ -26,6 +26,7 @@ namespace winrt::PowerRenameUILib::implementation
void Type(int32_t value); void Type(int32_t value);
bool Checked(); bool Checked();
void Checked(bool value); void Checked(bool value);
winrt::Windows::UI::Xaml::Visibility Highlight();
Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> Children(); Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> Children();
void Children(Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> const& value); void Children(Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> const& value);
winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler); winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler);
@@ -41,6 +42,7 @@ namespace winrt::PowerRenameUILib::implementation
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> m_children; winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> m_children;
int32_t m_type; int32_t m_type;
bool m_checked; bool m_checked;
winrt::Windows::UI::Xaml::Visibility m_highlight;
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged; winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
}; };
} }

View File

@@ -12,5 +12,6 @@ namespace PowerRenameUILib
String ImagePath { get; }; String ImagePath { get; };
Int32 Type; Int32 Type;
Boolean Checked; Boolean Checked;
Windows.UI.Xaml.Visibility Highlight { get; };
} }
} }

View File

@@ -77,7 +77,7 @@
<ControlTemplate TargetType="ListViewItem"> <ControlTemplate TargetType="ListViewItem">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<ContentPresenter /> <ContentPresenter />
<Rectangle Height="1" Margin="0,4,0,0" Opacity="0.8" Grid.ColumnSpan="5" Fill="{ThemeResource CardStrokeColorDefaultBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" /> <Rectangle Height="1" Margin="0,0,0,0" Opacity="0.8" Grid.ColumnSpan="5" Fill="{ThemeResource CardStrokeColorDefaultBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
</StackPanel> </StackPanel>
</ControlTemplate> </ControlTemplate>
@@ -87,33 +87,55 @@
</ListView.ItemContainerStyle> </ListView.ItemContainerStyle>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate x:Name="ExplorerItemTemplate" x:DataType="local:ExplorerItem"> <DataTemplate x:Name="ExplorerItemTemplate" x:DataType="local:ExplorerItem">
<Grid Height="20" Margin="10,4,0,0"> <Grid Height="28" Padding="0,0,0,0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="0"> <Border HorizontalAlignment="Stretch" Grid.ColumnSpan="2" BorderThickness="0,0,0,1" Margin="0,0,0,-1" BorderBrush="{ThemeResource SystemAccentColor}" VerticalAlignment="Stretch" Background="{ThemeResource AccentTextFillColorPrimaryBrush}" Opacity="0.1" Visibility="{x:Bind Highlight, Mode=OneWay}" />
<StackPanel MinWidth="{x:Bind Indentation}"/>
<CheckBox TabIndex="0" <Grid Grid.Column="0" HorizontalAlignment="Left" Margin="10,4,0,4">
MinWidth="0" <Grid.ColumnDefinitions>
XYFocusKeyboardNavigation="Enabled" <ColumnDefinition MinWidth="{x:Bind Indentation}"/>
Checked="Checked_ids" <ColumnDefinition Width="Auto"/>
IsTabStop="True" <ColumnDefinition Width="Auto"/>
Unchecked="Checked_ids" <ColumnDefinition Width="Auto"/>
Content="" </Grid.ColumnDefinitions>
Name="{x:Bind IdStr}"
AutomationProperties.Name="{x:Bind Original}"
AutomationProperties.HelpText="{x:Bind Renamed}" <CheckBox TabIndex="0"
IsChecked="{x:Bind Checked, Mode=TwoWay}" /> MinWidth="0"
<Image Width="16" Margin="4,0,0,0" Source="{x:Bind ImagePath}" HorizontalAlignment="Left" /> Width="28"
<TextBlock Margin="6,0,0,0" Height="28"
Text="{x:Bind Original, Mode=OneWay}" Grid.Column="1"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" XYFocusKeyboardNavigation="Enabled"
VerticalAlignment="Center" Checked="Checked_ids"
FontSize="12" /> IsTabStop="True"
</StackPanel> Unchecked="Checked_ids"
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}" Grid.Column="1" FontWeight="Bold" VerticalAlignment="Center" FontSize="12" /> Content=""
Name="{x:Bind IdStr}"
AutomationProperties.Name="{x:Bind Original}"
AutomationProperties.HelpText="{x:Bind Renamed}"
IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16"
Grid.Column="2"
Margin="4,0,0,0"
Source="{x:Bind ImagePath}"
HorizontalAlignment="Left" />
<TextBlock Margin="6,0,0,0"
Grid.Column="3"
Text="{x:Bind Original, Mode=OneWay}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
VerticalAlignment="Center"
FontSize="12" />
</Grid>
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}"
Grid.Column="1"
FontWeight="Bold"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
VerticalAlignment="Center"
FontSize="12" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>