Skip to content

Commit

Permalink
Refactor ExplorerBrowser (#40)
Browse files Browse the repository at this point in the history
Refactor `ExplorerBrowser`
  • Loading branch information
tajbender authored Oct 23, 2024
2 parents 7236266 + 69b8714 commit 4722643
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 179 deletions.
153 changes: 3 additions & 150 deletions src/electrifier/Controls/Vanara/ExplorerBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,159 +10,12 @@
<!-- TODO: Fix TeachingTip -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- TODO: Move `CommandBar` into single Control, cause `FileManagerPage` will use it, too -->
<CommandBar x:Name="CommandBar"
Grid.Row="0"
HorizontalAlignment="Left"
Background="Transparent"
DefaultLabelPosition="Right"
IsOpen="False"
Visibility="{x:Bind TopCommandBarVisibility}">
<AppBarElementContainer>
<SplitButton x:Name="NewItemSplitButton"
Content="New">
<SplitButton.Flyout>
<Flyout>
<StackPanel>
<AppBarButton Icon="Folder"
Label="Folder" />
<AppBarButton Icon="Link"
Label="Shortcut" />
</StackPanel>
</Flyout>
</SplitButton.Flyout>
</SplitButton>
</AppBarElementContainer>
<AppBarSeparator />
<AppBarButton Icon="Cut"
IsEnabled="False"
Label="Cut" />
<AppBarButton Icon="Copy"
IsEnabled="False"
Label="Copy" />
<AppBarButton Icon="Paste"
IsEnabled="False"
Label="Paste" />
<AppBarButton Icon="Rename"
IsEnabled="False"
Label="Rename" />
<AppBarButton Icon="Share"
IsEnabled="False"
Label="Share" />
<AppBarButton Icon="Delete"
IsEnabled="False"
Label="Delete" />
<AppBarSeparator />
<AppBarElementContainer>
<SplitButton x:Name="SortSplitButton"
Content="Sort">
<SplitButton.Flyout>
<Flyout>
<StackPanel>
<Button Content="Name" />
<Button Content="Date Modified" />
<Button Content="Type" />
<Button Content="~" />
<Button Content="More" />
<Button Content="~" />
<Button Content="Ascending" />
<Button Content="Descending" />
<Button Content="~" />
<Button Content="Group by" />
</StackPanel>
</Flyout>
</SplitButton.Flyout>
<SplitButton.Resources>
<TeachingTip x:Name="SortSplitButtonTeachingTip"
Title="TODO: Add Sort and Group options."
Subtitle="Use the dropdown button option to save your item and create another."
Target="{x:Bind SortSplitButton}" />
</SplitButton.Resources>
</SplitButton>
</AppBarElementContainer>
<AppBarElementContainer>
<SplitButton x:Name="ViewSplitButton"
Content="View">
<SplitButton.Flyout>
<Flyout>
<StackPanel>
<Button Content="Tiles" />
<Button Content="Content" />
<Button Content="~" />
<Button Content="Navigation pane" />
<Button Content="Details pane" />
<Button Content="Preview pane" />
<Button Content="~" />
<Button Content="Show" />
<Button Content="~" />
<Button Content="Two Pages" />
<!-- Glyph: E89A, TwoPage -->
<AppBarButton Icon="TwoPage"
Label="Double pane mode" />
<AppBarButton Icon="Refresh"
Label="Refresh" />
<AppBarButton Icon="Orientation"
Label="Orientation" />
</StackPanel>
</Flyout>
</SplitButton.Flyout>
<SplitButton.Resources>
<TeachingTip x:Name="ViewSplitButtonTeachingTip"
Title="TODO: Sort and Group options."
Subtitle="Use the dropdown button option to save your item and create another."
Target="{x:Bind SortSplitButton}" />
</SplitButton.Resources>
</SplitButton>
</AppBarElementContainer>
<AppBarElementContainer>
<SplitButton x:Name="FilterSplitButton"
Content="Filter">
<SplitButton.Flyout>
<Flyout>
<StackPanel>
<Button Content="All File Types" />
<Button Content="~" />
<Button Content="Files" />
<Button Content="Folders" />
</StackPanel>
</Flyout>
</SplitButton.Flyout>
<SplitButton.Resources>
<TeachingTip x:Name="FilterSplitButtonTeachingTip"
Title="TODO: Add filter options title text."
Subtitle="Use the dropdown button option to save your item and create another."
Target="{x:Bind FilterSplitButton}" />
</SplitButton.Resources>
</SplitButton>
</AppBarElementContainer>
<AppBarSeparator />
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Undo"
Label="Undo" />
<AppBarSeparator />
<AppBarButton Icon="Pin"
Label="Pin to Quick access" />
<AppBarSeparator />
<AppBarButton Icon="SelectAll"
Label="Select all" />
<!-- TODO: The Icon="ViewAll" is the one, that Windows Explorer uses for `Select none` -->
<AppBarButton Icon="ClearSelection"
Label="Select none" />
<AppBarButton Icon="Shuffle"
Label="Invert selection" />
<AppBarSeparator />
<AppBarButton Icon="Repair"
Label="Properties" />
<AppBarButton Icon="Setting"
Label="Options" />
</CommandBar.SecondaryCommands>
</CommandBar>
<Border Grid.Row="1">
<Border Grid.Row="0">
<InfoBar x:Name="NavigationFailedInfoBar"
Title="Navigation failed"
BorderBrush="DarkRed"
Expand All @@ -183,7 +36,7 @@
</InfoBar>
</Border>
<Grid x:Name="ArenaGrid"
Grid.Row="2">
Grid.Row="1">
<Grid.ColumnDefinitions>
<!-- controls:DockPanel.Dock="Left" -->
<ColumnDefinition Width="176"
Expand Down Expand Up @@ -233,7 +86,7 @@
</StackPanel>
</Border>
</Grid>
<CommandBar Grid.Row="3"
<CommandBar Grid.Row="2"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Left"
Expand Down
29 changes: 26 additions & 3 deletions src/electrifier/Controls/Vanara/ExplorerBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ private async Task InitializeViewModel()
{
_ = InitializeStockIcons();

var home = new ShellFolder("shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}");

var rootItems = new List<ExplorerBrowserItem>
{
new ExplorerBrowserItem(home),

// todo: add home folder
// todo: add Gallery
Shell32FolderService.KnownFolderItem(Shell32.KNOWNFOLDERID.FOLDERID_OneDrive),
Expand Down Expand Up @@ -315,14 +319,35 @@ public void ExtractChildItems(ExplorerBrowserItem? targetFolder)
var folderCount = 0;
Debug.Print($".ExtractChildItems(<{targetFolder?.DisplayName}>) extracting...");

_shellItems?.Clear();



if (targetFolder is null)
{
throw new ArgumentNullException(nameof(targetFolder));
}

try
{
/*
Debug.Assert(targetFolder.ShellItem.PIDL != Shell32.PIDL.Null);
var shItemId = targetFolder.ShellItem.PIDL;
using var shFolder = new ShellFolder(shItemId);
if ((shFolder.Attributes & ShellItemAttribute.Removable) != 0)
{
// TODO: Check for Disc in Drive, fail only if device not present
// TODO: Add `Eject-Buttons` to TreeView (right side, instead of TODO: Pin header) and GridView
Debug.WriteLine($"GetChildItems: IsRemovable = true");
var eventArgs = new NavigationFailedEventArgs();
return;
}
var ext = new ShellIconExtractor(new ShellFolder(targetFolder.ShellItem));
ext.Complete += ShellIconExtractorComplete;
ext.IconExtracted += ShellIconExtractorIconExtracted;
ext.Start();
*/
Debug.Assert(targetFolder.ShellItem.PIDL != Shell32.PIDL.Null);
var shItemId = targetFolder.ShellItem.PIDL;
using var shFolder = new ShellFolder(shItemId);
Expand Down Expand Up @@ -382,7 +407,6 @@ public void ExtractChildItems(ExplorerBrowserItem? targetFolder)
private void ShellIconExtractorIconExtracted(object? sender, ShellIconExtractedEventArgs e) => throw new NotImplementedException();
private void ShellIconExtractorComplete(object? sender, EventArgs e) => throw new NotImplementedException();

private List<ShellItem>? _shellItems;
private bool _isLoading;
private Visibility _gridViewVisibility;
private Visibility _topCommandBarVisibility;
Expand All @@ -397,7 +421,6 @@ private void ShellTreeView_SelectionChanged(TreeView sender, TreeViewSelectionCh
if (ebItem is not ExplorerBrowserItem)
{
Debug.Print($".ShellTreeView_SelectionChanged({args})");
_shellItems?.Clear();
return;
}

Expand Down
50 changes: 24 additions & 26 deletions src/electrifier/Views/ShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,45 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- todo: Convert `TitleStackPanelLeft` to Grid. -->
<StackPanel x:Name="TitleStackPanelLeft"
Grid.Column="0"
VerticalAlignment="Stretch"
Orientation="Horizontal">
<Image x:Name="WindowIcon"
Height="32"
Margin="23,0,13,0"
Source="ms-appx:///Assets/Square44x44Logo_unplated.png" />
<StackPanel>
<TextBlock x:Name="TitleTextBlockLeft"
Margin="0,0"
FontSize="23"
Text="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}" />
<TextBlock x:Name="SubTitleTextBlockLeft"
Margin="0,0"
FontSize="11"
FontStyle="Italic"
Text="electrifier alpha octavian" />
</StackPanel>
<Image x:Name="WindowIcon"
Height="32"
Margin="23,0,13,0"
Source="/Assets/Square44x44Logo.scale-200_unplated.png" />
</StackPanel>
<!-- todo: Convert `CenterStackPanel` to Grid. -->
<StackPanel x:Name="CenterStackPanel"
Grid.Column="1">
<Border>
<StackPanel Orientation="Horizontal">
<Button>
<Image x:Name="AppTitleBarBackButtonImageCenter"
VerticalAlignment="Center"
MaxHeight="23"
Source="ms-appx:///Assets/Themes/Aero Blackcomb/Back Button 48px.png" />
</Button>
<Button>
<Image x:Name="AppTitleBarForwardButtonImageCenter"
VerticalAlignment="Center"
MaxHeight="23"
Source="ms-appx:///Assets/Themes/Aero Blackcomb/Forward Button 48px.png" />

</Button>
<TextBox x:Name="CenterStackPanelTextBlock"
Text="Search..."
VerticalAlignment="Stretch" />
</StackPanel>
Grid.Column="1"
Orientation="Horizontal"
HorizontalAlignment="Center"
MaxHeight="36">
<Button>
<Image x:Name="AppTitleBarBackButtonImageCenter"
Source="ms-appx:///Assets/Themes/Aero Blackcomb/Back Button 48px.png" />
</Button>
<Button>
<Image x:Name="AppTitleBarForwardButtonImageCenter"
Source="ms-appx:///Assets/Themes/Aero Blackcomb/Forward Button 48px.png" />
</Button>
<Border BorderThickness="1"
BorderBrush="WhiteSmoke"
Opacity="0.5"
MinWidth="256">
<BreadcrumbBar x:Name="NavigationBreadcrumbBar"
VerticalAlignment="Center" />
</Border>
</StackPanel>
<Grid x:Name="SystemIconGrid"
Expand Down
3 changes: 3 additions & 0 deletions src/electrifier/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ private void OnLoaded(object sender, RoutedEventArgs e)
KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu));
KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack));


NavigationBreadcrumbBar.ItemsSource = new string[]
{ "Home", "Documents" };
//var targetPageType = typeof(WorkbenchPage);
//string targetPageKey = targetPageType.FullName; // .ToString()
//string targetPageArguments = string.Empty;
Expand Down

0 comments on commit 4722643

Please sign in to comment.