--- /dev/null
+// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+
+namespace Crow
+{
+ public enum DirectoryViewStyle {
+ Icons,
+ Detailed,
+ Compact,
+ }
+ /// <summary>
+ /// templated directory viewer
+ /// </summary>
+ public class DirectoryView2 : TemplatedGroup
+ {
+ #region CTOR
+ protected DirectoryView2() {}
+ public DirectoryView2 (Interface iface, string style = null) : base (iface, style) { }
+ #endregion
+
+ string currentDirectory = "/";
+ bool showFiles, showHidden;
+ string fileMask = "*.*";
+ int iconSize;
+ DirectoryViewStyle viewStyle;
+
+ [DefaultValue(DirectoryViewStyle.Icons)]
+ public virtual DirectoryViewStyle ViewStyle {
+ get => viewStyle;
+ set {
+ if (viewStyle == value)
+ return;
+ viewStyle = value;
+ NotifyValueChangedAuto (viewStyle);
+ updateItemTemplates ();
+ }
+ }
+ [DefaultValue(32)]
+ public virtual int IconSize {
+ get => iconSize;
+ set {
+ if (iconSize == value)
+ return;
+ iconSize = value;
+ NotifyValueChangedAuto (iconSize);
+ NotifyValueChanged ("IconSizeMeasure", new Measure(iconSize, Unit.Pixel));
+ updateItemTemplates ();
+ }
+ }
+ //public Measure IconSizeMeasure => new Measure(iconSize, Unit.Pixel);
+ [DefaultValue(true)]
+ public virtual bool ShowFiles {
+ get { return showFiles; }
+ set {
+ if (showFiles == value)
+ return;
+ showFiles = value;
+ NotifyValueChangedAuto (showFiles);
+ NotifyValueChanged ("FileSystemEntries", FileSystemEntries);
+ }
+ }
+ [DefaultValue(false)]
+ public virtual bool ShowHidden {
+ get { return showHidden; }
+ set {
+ if (showHidden == value)
+ return;
+ showHidden = value;
+ NotifyValueChangedAuto (showHidden);
+ NotifyValueChanged ("FileSystemEntries", FileSystemEntries);
+ }
+ }
+ [DefaultValue("*.*")]
+ public virtual string FileMask {
+ get { return fileMask; }
+ set {
+ if (fileMask == value)
+ return;
+ fileMask = value;
+ NotifyValueChangedAuto (fileMask);
+ NotifyValueChanged ("FileSystemEntries", FileSystemEntries);
+ }
+ }
+ [DefaultValue(".")]
+ public virtual string CurrentDirectory {
+ get { return currentDirectory; }
+ set {
+ if (currentDirectory == value)
+ return;
+ currentDirectory = value;
+ NotifyValueChangedAuto (currentDirectory);
+ NotifyValueChanged ("FileSystemEntries", FileSystemEntries);
+ updateFileSystemEntries();
+ }
+ }
+ [XmlIgnore]public FileSystemInfo[] FileSystemEntries {
+ get {
+ try {
+ if (string.IsNullOrEmpty(CurrentDirectory))
+ return null;
+ DirectoryInfo di = new DirectoryInfo(CurrentDirectory);
+ List<FileSystemInfo> fi = new List<FileSystemInfo> (di.GetDirectories());
+ if (showFiles && !string.IsNullOrEmpty(fileMask))
+ fi.AddRange(di.GetFiles(fileMask));
+ return showHidden ?
+ fi.OrderBy(f=>f.Attributes).ThenBy(f=>f.Name).ToArray() :
+ fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).OrderBy (f => f.Attributes).ThenBy (f => f.Name).ToArray();
+ } catch (Exception ex) {
+ System.Diagnostics.Debug.WriteLine (ex.ToString ());
+ return null;
+ }
+ }
+ }
+ //set template and itemTemplates depending on view configuration
+ void updateItemTemplates () {
+ return;
+ ItemTemplate = fileItemTemplates;
+ }
+ void updateFileSystemEntries () {
+
+ }
+ string fileItemTemplates => @"
+
+<ItemTemplate DataType='System.IO.FileInfo'>
+ <ListItem Fit='true'
+ BubbleEvents='All'
+ Selected = '{Background=${ControlHighlight}}'
+ Unselected = '{Background=Transparent}'>
+ <HorizontalStack>
+ <Image Margin='2' Width='ICON_SIZE' Height='ICON_SIZE' Path='${FileIcon}'/>
+ <Label Text='{Name}' />
+ </HorizontalStack>
+ </ListItem>
+</ItemTemplate>
+<ItemTemplate DataType='System.IO.DirectoryInfo'>
+ <ListItem Fit='true'
+ BubbleEvents='All'
+ Selected = '{Background=${ControlHighlight}}'
+ Unselected = '{Background=Transparent}'>
+ <HorizontalStack>
+ <Image Margin='2' Width='ICON_SIZE' Height='ICON_SIZE' Path='${FolderIcon}'/>
+ <Label Text='{Name}' />
+ <!--<Label Text='{LastAccessTime}' />-->
+ </HorizontalStack>
+ </ListItem>
+</ItemTemplate>
+".Replace ("ICON_SIZE", iconSize.ToString());
+ }
+}
+
}
[DefaultValue("/home")]
public virtual string CurrentDirectory {
- get { return curDir; }
+ get => curDir;
set {
if (curDir == value)
return;
[DefaultValue("*")]
public virtual string SearchPattern {
- get { return searchPattern; }
+ get => searchPattern;
set {
if (searchPattern == value)
return;
}
[DefaultValue(false)]
public virtual bool ShowHidden {
- get { return showHidden; }
+ get => showHidden;
set {
if (showHidden == value)
return;
}
[DefaultValue(true)]
public virtual bool ShowFiles {
- get { return showFiles; }
+ get => showFiles;
set {
if (showFiles == value)
return;
}
}
public string SelectedFile {
- get { return _selectedFile; }
+ get => _selectedFile;
set {
if (value == _selectedFile)
return;
}
}
public string SelectedDirectory {
- get { return _selectedDir; }
+ get => _selectedDir;
set {
if (value == _selectedDir)
return;
<?xml version="1.0"?>
-<ListBox Data="{TestList}" Width="Fit" Focusable="true" >
+<ListBox Data="{TestList}" Width="Fit" Focusable="true" Foreground="Red" >
<Template>
<Scroller Name="ItemsScroller" Height="Stretched" Background="Onyx" Margin="10">
<VerticalStack Name="ItemsContainer" Orientation="Horizontal" VerticalAlignment="Top" Height="Fit" Background="Grey" Margin="20"/>
<ListItem Width="Stretched" Margin="1" CornerRadius="5"
Selected="{Background=Yellow}"
Unselected="{Background=Transparent}">
- <Label Text="{}" TextAlignment="Center" Font="mono, 9" Foreground="Black" Margin="6" Background="{}" Width="Stretched" />
+ <Label Text="{}" TextAlignment="Center" Font="mono, 9" Foreground="{Foreground}" Margin="6" Background="{}" Width="Stretched" />
</ListItem>
</ItemTemplate>
--- /dev/null
+<DirectoryView2 CurrentDirectory="/mnt/devel" Data="{/FileSystemEntries}">
+ <Template>
+ <VerticalStack>
+ <Spinner Value="{²./IconSize}" SmallIncrement="1" LargeIncrement="1"/>
+ <HorizontalStack Background="Grey" Margin="5">
+ <Scroller Name="scroller1">
+ <Wrapper Orientation="Vertical" Height="Fit" VerticalAlignment="Top"
+ Name="ItemsContainer" Margin="0" Spacing="2"/>
+ </Scroller>
+ <ScrollBar Name="scrollbar1" Orientation="Vertical"
+ Value="{²../scroller1.ScrollY}" Maximum="{../scroller1.MaxScrollY}"
+ CursorRatio="{../scroller1.ChildHeightRatio}"
+ LargeIncrement="{../scroller1.PageHeight}" SmallIncrement="30"
+ Width="14" />
+ </HorizontalStack>
+ </VerticalStack>
+ </Template>
+ <ItemTemplate DataType="System.IO.FileInfo">
+ <ListItem Width="70" Height="60"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <VerticalStack>
+ <Image Margin="8" Width="Fit" Height="Stretched" Path="${FileIcon}" Scaled="true"/>
+ <Label Text="{Name}" Background="Jet" Width="Stretched" TextAlignment="Center" Multiline="true" Font="sans,9" />
+ </VerticalStack>
+ </ListItem>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.DirectoryInfo">
+ <ListItem Width="90" Height="60"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <VerticalStack>
+ <Image Margin="0" Width="Fit" Height="Stretched" Path="${FolderIcon}" Scaled="true"/>
+ <Label Text="{Name}" Background="Jet" Width="Stretched" TextAlignment="Center" Multiline="true" Font="sans,9"/>
+ </VerticalStack>
+ </ListItem>
+ </ItemTemplate>
+</DirectoryView2>
\ No newline at end of file
--- /dev/null
+<DirectoryView2 CurrentDirectory="/mnt/devel" Data="{/FileSystemEntries}">
+ <Template>
+ <VerticalStack>
+ <Spinner Value="{²./IconSize}" SmallIncrement="1" LargeIncrement="1"/>
+ <VerticalStack Background="Grey" Margin="5">
+ <Scroller Name="scroller1">
+ <Wrapper Orientation="Horizontal" Height="Stretched" Width="Fit" HorizontalAlignment="Left"
+ Name="ItemsContainer" Margin="0" Spacing="2"/>
+ </Scroller>
+ </VerticalStack>
+ </VerticalStack>
+ </Template>
+ <ItemTemplate DataType="System.IO.FileInfo">
+ <ListItem Width="Fit" Height="Fit"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Margin="0" Width="16" Height="16" Path="${FileIcon}" Scaled="true"/>
+ <Label Text="{Name}" Width="Fit" Font="sans,9" />
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.DirectoryInfo">
+ <ListItem Width="Fit" Height="Fit"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Margin="0" Width="16" Height="16" Path="${FolderIcon}" Scaled="true"/>
+ <Label Text="{Name}" Width="Fit" Font="sans,9"/>
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+</DirectoryView2>
\ No newline at end of file
--- /dev/null
+<DirectoryView2 CurrentDirectory="/mnt/devel" Data="{/FileSystemEntries}">
+ <Template>
+ <VerticalStack>
+ <Spinner Value="{²./IconSize}" SmallIncrement="1" LargeIncrement="1"/>
+ <VerticalStack Background="Grey" Margin="5">
+ <Scroller Name="scroller1">
+ <VerticalStack Height="Fit" Width="Stretched" VerticalAlignment="Top"
+ Name="ItemsContainer" Margin="0" Spacing="2"/>
+ </Scroller>
+ </VerticalStack>
+ </VerticalStack>
+ </Template>
+ <ItemTemplate DataType="System.IO.FileInfo">
+ <ListItem Width="Stretched" Height="Fit"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Margin="0" Width="16" Height="16" Path="${FileIcon}" Scaled="true"/>
+ <Label Text="{Name}" Width="Stretched" Font="sans,9" />
+ <Label Text="{Length}" Width="Fit" Font="sans,9"/>
+ <Label Text="{Attributes}" Width="Fit" Font="sans,9"/>
+ <Label Text="{LastAccessTime}" Width="Fit" Font="sans,9"/>
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.DirectoryInfo">
+ <ListItem Width="Stretched" Height="Fit"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Margin="0" Width="16" Height="16" Path="${FolderIcon}" Scaled="true"/>
+ <Label Text="{Name}" Width="Stretched" Font="sans,9"/>
+ <Label Text="{Attributes}" Width="Fit" Font="sans,9"/>
+ <Label Text="{LastAccessTime}" Width="Fit" Font="sans,9"/>
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+</DirectoryView2>
\ No newline at end of file
--- /dev/null
+<DirectoryView2 CurrentDirectory="/mnt/devel" Data="{/FileSystemEntries}">
+ <Template>
+ <VerticalStack>
+ <Spinner Value="{²./IconSize}" SmallIncrement="1" LargeIncrement="1"/>
+ <VerticalStack Background="DarkGrey" Margin="0">
+ <Scroller Name="scroller1">
+ <Table Columns=",20;Name,Stretched;Size,100;Accessed,Fit" Height="Fit" Width="Stretched" VerticalAlignment="Top"
+ Name="ItemsContainer" Margin="0" Spacing="0" RowsMargin="0" ColumnSpacing="10"
+ HorizontalLineWidth="0" VerticalLineWidth="1" />
+ </Scroller>
+ </VerticalStack>
+ </VerticalStack>
+ </Template>
+ <ItemTemplate DataType="System.IO.DirectoryInfo">
+ <TableRow Width="Stretched" Height="Fit" Focusable="true"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected="{Background=${ControlHighlight}}"
+ Unselected="{Background=Transparent}">
+ <Image Width="Stretched" Height="Stretched" Path="${FolderIcon}" Margin="0" />
+ <Label Text="{Name}" Width="Fit" Font="sans,11" Margin="3"/>
+ <Label Text="" Font="sans,9"/>
+ <Label Text="{LastAccessTime}" Font="sans,9"/>
+ </TableRow>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.FileInfo">
+ <TableRow Width="Stretched" Height="Fit" Focusable="true"
+ BubbleEvents="All" Tooltip="{Name}"
+ Selected="{Background=${ControlHighlight}}"
+ Unselected="{Background=Transparent}">
+ <Image Width="Stretched" Height="Stretched" Path="${FileIcon}" Margin="2" />
+ <Label Text="{Name}" Width="Fit" Font="sans,11" Margin="3"/>
+ <Label Text="{Length}" Font="sans,9" TextAlignment="Right"/>
+ <Label Text="{LastAccessTime}" Font="sans,9"/>
+ </TableRow>
+ </ItemTemplate>
+</DirectoryView2>
\ No newline at end of file
<Label Text="{ActiveWidget}" Font="mono, 8"/>
</HorizontalStack>
<Container>
- <FileDialog Focusable="true" Resizable="true"/>
+ <FileDialog Focusable="true" Resizable="true">
+ <Template>
+ <Border Name="SizeHandle" Style="winBorder" CornerRadius="{./CornerRadius}" Background="{./Background}">
+ <VerticalStack Spacing="0">
+ <HorizontalStack Background="${WindowTitleBarBackground}" Margin="0" Spacing="0" Height="Fit">
+ <Widget Width="5"/>
+ <Image Margin="1" Width="12" Height="12" Path="{./Icon}"/>
+ <Label Name="MoveHandle" Width="Stretched" Foreground="${WindowTitleBarForeground" Margin="2" TextAlignment="Center" Text="{./Caption}" />
+ <Border CornerRadius="0" BorderWidth="1" Foreground="Transparent" Height="12" Width="12"
+ MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}">
+ <Image Focusable="true" Name="Image" Margin="0" Width="Stretched" Height="Stretched" Path="#Crow.Icons.exit2.svg"
+ MouseClick="./onQuitPress"/>
+ </Border>
+ <Widget Width="5"/>
+ </HorizontalStack>
+ <Container Name="Content" MinimumSize="50,50" Background="Jet">
+ <VerticalStack Spacing="2" Margin="1">
+ <HorizontalStack Height="Fit" Margin="2">
+ <Button MinimumSize="1,1" Fit="true" Caption="Up" MouseClick="./goUpDirClick">
+ <Image Margin="2" Width="18" Height="18"
+ Path="#Crow.Icons.level-up.svg"/>
+ </Button>
+ <TextBox Style="TxtInFileDialog" Text="{²./CurrentDirectory}" Margin="3"/>
+ </HorizontalStack>
+ <DirectoryView ShowHidden="{²../cbShowHidden.IsChecked}" FileMask="{²../txtFileMask.Text}"
+ ShowFiles="{²../cbShowFiles.IsChecked}" Name="fv" CurrentDirectory="{./CurrentDirectory}"
+ SelectedItemChanged="./onFVSelectedItemChanged"
+ Width="100%" Margin="1" MouseDoubleClick="./onFileSelectDblClick">
+ <Template>
+ <ListBox Name="fileView" Data="{./FileSystemEntries}"
+ SelectedItemChanged="./onSelectedItemChanged">
+ <Template>
+ <HorizontalStack Background="Grey">
+ <Scroller Name="scroller1">
+ <VerticalStack Height="Fit" VerticalAlignment="Top"
+ Name="ItemsContainer" Margin="2" Spacing="1"/>
+ </Scroller>
+ <ScrollBar Name="scrollbar1" Orientation="Vertical"
+ Value="{²../scroller1.ScrollY}" Maximum="{../scroller1.MaxScrollY}"
+ CursorRatio="{../scroller1.ChildHeightRatio}"
+ LargeIncrement="{../scroller1.PageHeight}" SmallIncrement="30"
+ Width="14" />
+ </HorizontalStack>
+ </Template>
+ <ItemTemplate>
+ <Widget Height="16" Background="Red"/>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.FileInfo">
+ <ListItem Height="Fit"
+ BubbleEvents="All"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Width="20" Height="20" Path="#Crow.Icons.file.svg"/>
+ <Label Margin="2" Text="{Name}" Width="Stretched"/>
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+ <ItemTemplate DataType="System.IO.DirectoryInfo">
+ <ListItem Height="Fit"
+ BubbleEvents="All"
+ Selected = "{Background=${ControlHighlight}}"
+ Unselected = "{Background=Transparent}">
+ <HorizontalStack Spacing="5">
+ <Image Width="20" Height="20" Path="#Crow.Icons.folder.svg"/>
+ <Label Margin="2" Text="{Name}" Width="Stretched"/>
+ <Label Margin="2" Text="{LastAccessTime}" />
+ </HorizontalStack>
+ </ListItem>
+ </ItemTemplate>
+ </ListBox>
+ </Template>
+ </DirectoryView>
+ <HorizontalStack Height="Fit">
+ <TextBox Style="TxtInFileDialog" Text="{²./SelectedFile}"/>
+ <TextBox Style="TxtInFileDialog" Width="50" Name="txtFileMask" Text="{²./SearchPattern}"/>
+ </HorizontalStack>
+ <HorizontalStack Height="Fit" Margin="2" Spacing="2">
+ <CheckBox Style="CheckBoxAlt" Name="cbShowFiles" Caption="Show Files" IsChecked="{²./ShowFiles}" Width="Fit"/>
+ <CheckBox Style="CheckBoxAlt" Name="cbShowHidden" Caption="Show Hidden" IsChecked="{²./ShowHidden}" Width="Fit"/>
+ <Widget Width="Stretched"/>
+ <Button Caption="Ok" Command="{./CMDOk}"/>
+ <Button Caption="Cancel" Command="{./CMDCancel}"/>
+ </HorizontalStack>
+ </VerticalStack>
+ </Container>
+ </VerticalStack>
+ </Border>
+ </Template>
+ </FileDialog>
</Container>
</VerticalStack>
\ No newline at end of file
<TabView>
- <GroupBox Caption="test" Background="Red"/>
- <GroupBox Caption="test" Background="Blue"/>
+ <GroupBox Name="test" Background="Red"/>
+ <GroupBox Name="test2" Background="Blue"/>
</TabView>
\ No newline at end of file
<TabView Orientation="Horizontal">
<Template>
- <GenericStack Orientation="{./OppositeOrientation}" Spacing="0" Background="{./Background}">
+ <VerticalStack Spacing="0" Background="{./Background}">
<ListBox Data="{./Items}" Height="Fit" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedItem="{²./SelectedItem}">
<Template>
<VerticalStack Spacing="0" >
- <Scroller Name="ItemsScroller" >
- <GenericStack Orientation="{../../../../../Orientation}" Width="Fit" Name="ItemsContainer" HorizontalAlignment="Left"/>
- </Scroller>
<ScrollBar Orientation="Horizontal" Foreground="RoyalBlue" Height="6" Width="Stretched" CornerRadius="3"
Value="{²../ItemsScroller.ScrollX}"
LargeIncrement="{../ItemsScroller.PageWidth}" SmallIncrement="1"
</Container>
</Template>
</ScrollBar>
+ <Scroller Name="ItemsScroller" >
+ <HorizontalStack Width="Fit" Name="ItemsContainer" HorizontalAlignment="Left"/>
+ </Scroller>
</VerticalStack>
</Template>
<ItemTemplate>
</ItemTemplate>
</ListBox>
<Group Name="ItemsContainer" />
- </GenericStack>
+ </VerticalStack>
</Template>
<GroupBox Name="item 1" Caption="item 1" IsVisible="true" Background="Violet"/>
<GroupBox Name="item 2" Caption="item 2" IsVisible="false" Background="CornflowerBlue"/>