Skip to content

Commit

Permalink
[PowerRename] Add row highlighting (#14746)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
niels9001 and stefansjfw committed Dec 2, 2021
1 parent 0e61f41 commit a018e04
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 23 deletions.
20 changes: 20 additions & 0 deletions src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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()
Expand Down Expand Up @@ -50,6 +51,13 @@ namespace winrt::PowerRenameUILib::implementation
{
m_renamed = value;
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" });
}
}
}

Expand Down Expand Up @@ -87,9 +95,21 @@ namespace winrt::PowerRenameUILib::implementation
{
m_checked = value;
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)
{
return m_propertyChanged.add(handler);
Expand Down
2 changes: 2 additions & 0 deletions src/modules/powerrename/PowerRenameUILib/ExplorerItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace winrt::PowerRenameUILib::implementation
void Type(int32_t value);
bool Checked();
void Checked(bool value);
winrt::Windows::UI::Xaml::Visibility Highlight();
Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> Children();
void Children(Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> const& value);
winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler);
Expand All @@ -41,6 +42,7 @@ namespace winrt::PowerRenameUILib::implementation
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> m_children;
int32_t m_type;
bool m_checked;
winrt::Windows::UI::Xaml::Visibility m_highlight;
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
};
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ namespace PowerRenameUILib
String ImagePath { get; };
Int32 Type;
Boolean Checked;
Windows.UI.Xaml.Visibility Highlight { get; };
}
}
68 changes: 45 additions & 23 deletions src/modules/powerrename/PowerRenameUILib/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<ControlTemplate TargetType="ListViewItem">
<StackPanel Orientation="Vertical">
<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>
</ControlTemplate>
Expand All @@ -87,33 +87,55 @@
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<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>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<StackPanel Orientation="Horizontal" Grid.Column="0">
<StackPanel MinWidth="{x:Bind Indentation}"/>
<CheckBox TabIndex="0"
MinWidth="0"
XYFocusKeyboardNavigation="Enabled"
Checked="Checked_ids"
IsTabStop="True"
Unchecked="Checked_ids"
Content=""
Name="{x:Bind IdStr}"
AutomationProperties.Name="{x:Bind Original}"
AutomationProperties.HelpText="{x:Bind Renamed}"
IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16" Margin="4,0,0,0" Source="{x:Bind ImagePath}" HorizontalAlignment="Left" />
<TextBlock Margin="6,0,0,0"
Text="{x:Bind Original, Mode=OneWay}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
VerticalAlignment="Center"
FontSize="12" />
</StackPanel>
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}" Grid.Column="1" FontWeight="Bold" VerticalAlignment="Center" FontSize="12" />
<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}" />

<Grid Grid.Column="0" HorizontalAlignment="Left" Margin="10,4,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="{x:Bind Indentation}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>


<CheckBox TabIndex="0"
MinWidth="0"
Width="28"
Height="28"
Grid.Column="1"
XYFocusKeyboardNavigation="Enabled"
Checked="Checked_ids"
IsTabStop="True"
Unchecked="Checked_ids"
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>
</DataTemplate>
</ListView.ItemTemplate>
Expand Down

0 comments on commit a018e04

Please sign in to comment.