Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
700790e
Added Adaptive Layout Mode
d2dyno1 Feb 10, 2021
50a8be3
Added to filter .gif
d2dyno1 Feb 10, 2021
c1388d8
Small Tweaks
d2dyno1 Feb 10, 2021
ff292a2
Small Tweaks 2
d2dyno1 Feb 10, 2021
bf8e8c0
Small Tweaks 3
d2dyno1 Feb 10, 2021
a15d021
Build Fix
d2dyno1 Feb 10, 2021
56e4d2b
Fixed layout mode evaluating (finally)
d2dyno1 Feb 10, 2021
dcb3826
Moved Adaptive Layout to settings and improved code
d2dyno1 Feb 11, 2021
b5cf8de
Added desktop.ini reading
d2dyno1 Feb 12, 2021
7ab7ee6
Improved exception handling
d2dyno1 Feb 12, 2021
4fe0e9c
CodeFactor
d2dyno1 Feb 12, 2021
876699d
Adaptive Layout now remembers preferred GridView SizeMode
d2dyno1 Feb 12, 2021
a025af0
Added Overriding for Adaptive Layout Mode
d2dyno1 Feb 16, 2021
dbd77e7
Added some more logic
d2dyno1 Feb 16, 2021
da4f6fb
Added Yair's suggestions
d2dyno1 Feb 16, 2021
9527037
Merge branch 'main' into adaptive_layout_mode
d2dyno1 Feb 16, 2021
901a1b5
Fixed Build Error
d2dyno1 Feb 16, 2021
b22b689
Merge branch 'adaptive_layout_mode' of https://github.com/d2dyno1/Fil…
d2dyno1 Feb 16, 2021
9f69b3a
Quick UID translations fix
d2dyno1 Feb 16, 2021
1b3b152
Fixed Browser not appearing
d2dyno1 Feb 16, 2021
ee11495
Updated saving logic where Adaptive Layout is disabled
d2dyno1 Feb 17, 2021
035af65
Fixed GetDesktopIniProperties
d2dyno1 Feb 19, 2021
b65746e
Hid Adaptive Layout toggle
d2dyno1 Feb 23, 2021
3cbff07
Removed strings and xaml code
d2dyno1 Feb 23, 2021
060e41e
Remember different GridViewSizeModes for every directory
d2dyno1 Feb 26, 2021
9e0465f
Quick Fix
d2dyno1 Mar 1, 2021
bc29bae
Prep for removing "Re-enable Adaptive Layout" button
d2dyno1 Mar 2, 2021
4359cda
Quick Fix to bc29bae
d2dyno1 Mar 2, 2021
9b97330
Removed "Re-enable Adaptive Layout" button
d2dyno1 Mar 2, 2021
d712a36
Code improvements
d2dyno1 Mar 2, 2021
d562701
Resolve Conflicts
d2dyno1 Mar 2, 2021
73fdbcf
Fixed build issues
d2dyno1 Mar 2, 2021
2ce8021
Fixed build issues 2
d2dyno1 Mar 2, 2021
46a5b0f
Restore Fulltrust.DragDrop
d2dyno1 Mar 3, 2021
73dd362
Removed unnecessary code
d2dyno1 Mar 3, 2021
0519944
Parse desktop.ini in uwp
gave92 Mar 7, 2021
332e4f0
Fix layout preference not saved to settings
gave92 Mar 7, 2021
02f0cf9
Removed adaptive setting from FilesAndFoldersViewModel
gave92 Mar 7, 2021
af3d353
Save adaptive layout mode
gave92 Mar 7, 2021
91a84a6
Renamed AdaptiveLayoutDisabledOverride -> IsAdaptiveLayoutOverridden
gave92 Mar 7, 2021
ace3a72
Resolve Merge conflicts
d2dyno1 Mar 7, 2021
89ab975
Merge pull request #1 from gave92/rev_adaptive
d2dyno1 Mar 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Files/BaseLayout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Files.Common;
using Files.DataModels;
using Files.EventArguments;
using Files.Extensions;
using Files.Filesystem;
using Files.Helpers;
Expand Down Expand Up @@ -283,7 +284,7 @@ public virtual void SetItemOpacity(ListedItem item)

protected abstract ListedItem GetItemFromElement(object element);

private void FolderSettings_LayoutModeChangeRequested(object sender, EventArgs e)
private void FolderSettings_LayoutModeChangeRequested(object sender, LayoutModeEventArgs e)
{
if (ParentShellPageInstance.ContentPage != null)
{
Expand Down
11 changes: 11 additions & 0 deletions Files/Enums/FolderLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Files.Enums
{
public enum FolderLayout
{
DetailsView = 0,
TilesView = 1,
GridViewSmall = 2,
GridViewMedium = 4,
GridViewLarge = 8
}
}
6 changes: 3 additions & 3 deletions Files/Enums/FolderLayoutModes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
public enum FolderLayoutModes
{
DetailsView = 0,
TilesView,
GridView
DetailsView = 1,
TilesView = 2,
GridView = 4,
}
}
17 changes: 17 additions & 0 deletions Files/EventArguments/LayoutModeEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Files.Enums;

namespace Files.EventArguments
{
public class LayoutModeEventArgs
{
public readonly FolderLayoutModes LayoutMode;

public readonly int GridViewSize;

internal LayoutModeEventArgs(FolderLayoutModes layoutMode, int gridViewSize)
{
LayoutMode = layoutMode;
GridViewSize = gridViewSize;
}
}
}
4 changes: 4 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
</Compile>
<Compile Include="Enums\DynamicDialogButtons.cs" />
<Compile Include="Enums\DynamicDialogResult.cs" />
<Compile Include="Enums\FolderLayout.cs" />
<Compile Include="Enums\FolderLayoutModes.cs" />
<Compile Include="Extensions\TaskExtensions.cs" />
<Compile Include="Filesystem\FolderHelpers.cs" />
Expand All @@ -185,7 +186,9 @@
<Compile Include="Filesystem\StorageEnumerators\UniversalStorageEnumerator.cs" />
<Compile Include="Filesystem\StorageEnumerators\Win32StorageEnumerator.cs" />
<Compile Include="Enums\FileSystemStatusCode.cs" />
<Compile Include="EventArguments\LayoutModeEventArgs.cs" />
<Compile Include="Filesystem\CloudDrivesManager.cs" />
<Compile Include="Helpers\AdaptiveLayoutHelpers.cs" />
<Compile Include="Filesystem\Cloud\Providers\OneDriveSharePointCloudProvider.cs" />
<Compile Include="Filesystem\NetworkDrivesManager.cs" />
<Compile Include="Helpers\AppServiceConnectionHelper.cs" />
Expand Down Expand Up @@ -219,6 +222,7 @@
<Compile Include="Helpers\ExtensionManager.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
<Compile Include="Helpers\RegistryHelper.cs" />
<Compile Include="Helpers\XamlHelpers\SystemTypeToXaml.cs" />
<Compile Include="UserControls\FilePreviews\BasicPreview.xaml.cs">
<DependentUpon>BasicPreview.xaml</DependentUpon>
</Compile>
Expand Down
131 changes: 131 additions & 0 deletions Files/Helpers/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Linq;
using Windows.Storage;
using System.Windows.Input;
using Files.ViewModels.Previews;
using Files.ViewModels;

namespace Files.Helpers
{
public static class AdaptiveLayoutHelpers
{
public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, ItemViewModel filesystemViewModel)
{
if (App.AppSettings.AreLayoutPreferencesPerFolder && App.AppSettings.AdaptiveLayoutEnabled && !folderSettings.LayoutPreference.IsAdaptiveLayoutOverridden)
{
bool desktopIniFound = false;

var iniPath = System.IO.Path.Combine(filesystemViewModel.CurrentFolder.ItemPath, "desktop.ini");
var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim();
if (!string.IsNullOrEmpty(iniContents))
{
var parser = new IniParser.Parser.IniDataParser();
parser.Configuration.ThrowExceptionsOnError = false;
var data = parser.Parse(iniContents);
if (data != null)
{
var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase));
if (viewModeSection != null)
{
var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase));
if (folderTypeKey != null)
{
switch (folderTypeKey.Value)
{
case "Documents":
{
folderSettings.ToggleLayoutModeTiles.Execute(false);
break;
}

case "Pictures":
{
folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
break;
}

case "Music":
{
folderSettings.ToggleLayoutModeDetailsView.Execute(false);
break;
}

case "Videos":
{
folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
break;
}

default:
{
folderSettings.ToggleLayoutModeDetailsView.Execute(false);
break;
}
}

desktopIniFound = true;
}
}
}
}

if (desktopIniFound)
{
return true;
}
if (filesystemViewModel.FilesAndFolders.Count == 0)
{
return false;
}

int imagesAndVideosCount = filesystemViewModel.FilesAndFolders.Where((item) =>

!string.IsNullOrEmpty(item.FileExtension)

// Images
&& (ImagePreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase))

// Audio & Video
|| MediaPreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase))
)).Count();

int foldersCount = filesystemViewModel.FilesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();

int otherFilesCount = filesystemViewModel.FilesAndFolders.Count - (imagesAndVideosCount + foldersCount);

if (foldersCount > 0)
{ // There are folders in current directory

if ((filesystemViewModel.FilesAndFolders.Count - imagesAndVideosCount) < (filesystemViewModel.FilesAndFolders.Count - 20) || (filesystemViewModel.FilesAndFolders.Count <= 20 && imagesAndVideosCount >= 5))
{ // Most of items are images/videos
folderSettings.ToggleLayoutModeTiles.Execute(false);
}
else
{
folderSettings.ToggleLayoutModeDetailsView.Execute(false);
}
}
else
{ // There are only files

if (imagesAndVideosCount == filesystemViewModel.FilesAndFolders.Count)
{ // Only images/videos
folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
}
else if (otherFilesCount < 20)
{ // Most of files are images/videos
folderSettings.ToggleLayoutModeTiles.Execute(false);
}
else
{ // Images/videos and other files
folderSettings.ToggleLayoutModeDetailsView.Execute(false);
}
}

return true;
}

return false;
}
}
}
7 changes: 6 additions & 1 deletion Files/Helpers/NativeFileOperationsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
Expand Down Expand Up @@ -204,9 +205,13 @@ public static string ReadStringFromFile(string filePath)
fixed (byte* pBuff = buff)
{
ReadFile(hStream, pBuff, 4096 - 1, &dwBytesRead, IntPtr.Zero);
str = Encoding.UTF8.GetString(pBuff, dwBytesRead);
//str = Encoding.UTF8.GetString(pBuff, dwBytesRead);
}
}
using (var reader = new StreamReader(new MemoryStream(buff, 0, dwBytesRead), true))
{
str = reader.ReadToEnd();
}
CloseHandle(hStream);
return str;
}
Expand Down
30 changes: 30 additions & 0 deletions Files/Helpers/XamlHelpers/SystemTypeToXaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Windows.UI.Xaml.Markup;

namespace Files.Helpers.XamlHelpers
{
public class SystemTypeToXaml : MarkupExtension
{
#region Private Members

private object parameter;

#endregion

#region Public Properties

public int Int { set => parameter = value; }

public double Double { set => parameter = value; }

public float Float { set => parameter = value; }

public bool Bool { set => parameter = value; }

#endregion

protected override object ProvideValue()
{
return parameter;
}
}
}
19 changes: 13 additions & 6 deletions Files/UserControls/StatusBarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:lottie="using:Microsoft.Toolkit.Uwp.UI.Lottie"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:xh="using:Files.Helpers.XamlHelpers"
d:DesignHeight="40"
d:DesignWidth="400"
mc:Ignorable="d">
Expand All @@ -18,7 +19,7 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ResourceDictionaries/ToolbarButtonStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:LayoutModeToBoolConverter x:Key="LayoutModeBoolConverter" />
<converters:LayoutModeToBoolConverter x:Key="LayoutModeConverter" />
</ResourceDictionary>
</UserControl.Resources>

Expand Down Expand Up @@ -149,14 +150,16 @@
x:Uid="StatusBarControlLayoutMode"
FontWeight="Medium"
Text="Layout Mode" />

<StackPanel Orientation="Horizontal" Spacing="4">
<RadioButton
x:Uid="StatusBarControlDetailsView"
Height="32"
MinWidth="0"
Command="{x:Bind FolderSettings.ToggleLayoutModeDetailsView}"
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
CornerRadius="4"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeBoolConverter}, Mode=OneWay, ConverterParameter=DetailsInfo}"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=DetailsInfo}"
Style="{StaticResource ToggleButtonRevealStyle}"
ToolTipService.ToolTip="Details View">
<FontIcon
Expand All @@ -169,8 +172,9 @@
Height="32"
MinWidth="0"
Command="{x:Bind FolderSettings.ToggleLayoutModeTiles}"
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
CornerRadius="4"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeBoolConverter}, Mode=OneWay, ConverterParameter=TilesInfo}"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=TilesInfo}"
Style="{StaticResource ToggleButtonRevealStyle}"
ToolTipService.ToolTip="Tiles View">
<FontIcon
Expand All @@ -185,8 +189,9 @@
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="{x:Bind FolderSettings.ToggleLayoutModeGridViewSmall}"
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
CornerRadius="4"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeBoolConverter}, Mode=OneWay, ConverterParameter=SmallGridInfo}"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=SmallGridInfo}"
Style="{StaticResource ToggleButtonRevealStyle}"
ToolTipService.ToolTip="Grid View (Small)">
<FontIcon
Expand All @@ -201,8 +206,9 @@
MinWidth="0"
Margin="0"
Command="{x:Bind FolderSettings.ToggleLayoutModeGridViewMedium}"
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
CornerRadius="4"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeBoolConverter}, Mode=OneWay, ConverterParameter=MediumGridInfo}"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=MediumGridInfo}"
Style="{StaticResource ToggleButtonRevealStyle}"
ToolTipService.ToolTip="Grid View (Medium)">
<FontIcon
Expand All @@ -216,8 +222,9 @@
Height="32"
MinWidth="0"
Command="{x:Bind FolderSettings.ToggleLayoutModeGridViewLarge}"
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
CornerRadius="4"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeBoolConverter}, Mode=OneWay, ConverterParameter=LargeGridInfo}"
IsChecked="{x:Bind FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=LargeGridInfo}"
Style="{StaticResource ToggleButtonRevealStyle}"
ToolTipService.ToolTip="Grid View (Large)">
<FontIcon
Expand Down
Loading