mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Peek]Fix icons, removed unneeded RTL code, ui tweaks and code suggestions (#32087)
* Force file pickers to open modal * remove unneeded RTL code * better icons and analyzer suggestions * additions for preview controls * more code improvs * two nits in strings * Adressing feedback icon margin, drive usage bar, TitleBarHeightOption
This commit is contained in:
@@ -9,7 +9,5 @@ namespace Peek.Common.Constants
|
||||
public const double MaxWindowToMonitorRatio = 0.80;
|
||||
public const double MinWindowHeight = 500;
|
||||
public const double MinWindowWidth = 500;
|
||||
public const double WindowWidthContentPadding = 7;
|
||||
public const double WindowHeightContentPadding = 16;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Peek.Common.Extensions
|
||||
public static Size? GetSvgSize(this IFileSystemItem item)
|
||||
{
|
||||
Size? size = null;
|
||||
using (FileStream stream = new FileStream(item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
|
||||
using (FileStream stream = new(item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
|
||||
{
|
||||
XmlReaderSettings settings = new XmlReaderSettings();
|
||||
settings.Async = true;
|
||||
@@ -39,37 +39,35 @@ namespace Peek.Common.Extensions
|
||||
settings.IgnoreProcessingInstructions = true;
|
||||
settings.IgnoreWhitespace = true;
|
||||
|
||||
using (XmlReader reader = XmlReader.Create(stream, settings))
|
||||
using XmlReader reader = XmlReader.Create(stream, settings);
|
||||
while (reader.Read())
|
||||
{
|
||||
while (reader.Read())
|
||||
if (reader.NodeType == XmlNodeType.Element && reader.Name == "svg")
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element && reader.Name == "svg")
|
||||
string? width = reader.GetAttribute("width");
|
||||
string? height = reader.GetAttribute("height");
|
||||
if (width != null && height != null)
|
||||
{
|
||||
string? width = reader.GetAttribute("width");
|
||||
string? height = reader.GetAttribute("height");
|
||||
if (width != null && height != null)
|
||||
int widthValue = int.Parse(Regex.Match(width, @"\d+").Value, NumberFormatInfo.InvariantInfo);
|
||||
int heightValue = int.Parse(Regex.Match(height, @"\d+").Value, NumberFormatInfo.InvariantInfo);
|
||||
size = new Size(widthValue, heightValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? viewBox = reader.GetAttribute("viewBox");
|
||||
if (viewBox != null)
|
||||
{
|
||||
int widthValue = int.Parse(Regex.Match(width, @"\d+").Value, NumberFormatInfo.InvariantInfo);
|
||||
int heightValue = int.Parse(Regex.Match(height, @"\d+").Value, NumberFormatInfo.InvariantInfo);
|
||||
size = new Size(widthValue, heightValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? viewBox = reader.GetAttribute("viewBox");
|
||||
if (viewBox != null)
|
||||
var viewBoxValues = viewBox.Split(' ');
|
||||
if (viewBoxValues.Length == 4)
|
||||
{
|
||||
var viewBoxValues = viewBox.Split(' ');
|
||||
if (viewBoxValues.Length == 4)
|
||||
{
|
||||
int viewBoxWidth = int.Parse(viewBoxValues[2], NumberStyles.Integer, CultureInfo.InvariantCulture);
|
||||
int viewBoxHeight = int.Parse(viewBoxValues[3], NumberStyles.Integer, CultureInfo.InvariantCulture);
|
||||
size = new Size(viewBoxWidth, viewBoxHeight);
|
||||
}
|
||||
int viewBoxWidth = int.Parse(viewBoxValues[2], NumberStyles.Integer, CultureInfo.InvariantCulture);
|
||||
int viewBoxHeight = int.Parse(viewBoxValues[3], NumberStyles.Integer, CultureInfo.InvariantCulture);
|
||||
size = new Size(viewBoxWidth, viewBoxHeight);
|
||||
}
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,21 +78,19 @@ namespace Peek.Common.Extensions
|
||||
public static Size? GetQoiSize(this IFileSystemItem item)
|
||||
{
|
||||
Size? size = null;
|
||||
using (FileStream stream = new FileStream(item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
|
||||
using (FileStream stream = new(item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
|
||||
{
|
||||
if (stream.Length >= 12)
|
||||
{
|
||||
stream.Position = 4;
|
||||
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
uint widthValue = BinaryPrimitives.ReadUInt32BigEndian(reader.ReadBytes(4));
|
||||
uint heightValue = BinaryPrimitives.ReadUInt32BigEndian(reader.ReadBytes(4));
|
||||
using var reader = new BinaryReader(stream);
|
||||
uint widthValue = BinaryPrimitives.ReadUInt32BigEndian(reader.ReadBytes(4));
|
||||
uint heightValue = BinaryPrimitives.ReadUInt32BigEndian(reader.ReadBytes(4));
|
||||
|
||||
if (widthValue > 0 && heightValue > 0)
|
||||
{
|
||||
size = new Size(widthValue, heightValue);
|
||||
}
|
||||
if (widthValue > 0 && heightValue > 0)
|
||||
{
|
||||
size = new Size(widthValue, heightValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,22 +100,13 @@ namespace Peek.Common.Extensions
|
||||
|
||||
public static async Task<string> GetContentTypeAsync(this IFileSystemItem item)
|
||||
{
|
||||
string contentType = string.Empty;
|
||||
|
||||
var storageItem = await item.GetStorageItemAsync();
|
||||
switch (storageItem)
|
||||
string contentType = storageItem switch
|
||||
{
|
||||
case StorageFile storageFile:
|
||||
contentType = storageFile.DisplayType;
|
||||
break;
|
||||
case StorageFolder storageFolder:
|
||||
contentType = storageFolder.DisplayType;
|
||||
break;
|
||||
default:
|
||||
contentType = item.FileType;
|
||||
break;
|
||||
}
|
||||
|
||||
StorageFile storageFile => storageFile.DisplayType,
|
||||
StorageFolder storageFolder => storageFolder.DisplayType,
|
||||
_ => item.FileType,
|
||||
};
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,19 +27,10 @@ namespace Peek.Common.Extensions
|
||||
|
||||
try
|
||||
{
|
||||
PropVariant propVar;
|
||||
|
||||
propertyStore.GetValue(ref key, out propVar);
|
||||
propertyStore.GetValue(ref key, out PropVariant propVar);
|
||||
|
||||
// VT_UI4 Indicates a 4-byte unsigned integer formatted in little-endian byte order.
|
||||
if ((VarEnum)propVar.Vt == VarEnum.VT_UI4)
|
||||
{
|
||||
return propVar.UlVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (VarEnum)propVar.Vt == VarEnum.VT_UI4 ? propVar.UlVal : null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -63,19 +54,10 @@ namespace Peek.Common.Extensions
|
||||
|
||||
try
|
||||
{
|
||||
PropVariant propVar;
|
||||
|
||||
propertyStore.GetValue(ref key, out propVar);
|
||||
propertyStore.GetValue(ref key, out PropVariant propVar);
|
||||
|
||||
// VT_UI8 Indicates an 8-byte unsigned integer formatted in little-endian byte order.
|
||||
if ((VarEnum)propVar.Vt == VarEnum.VT_UI8)
|
||||
{
|
||||
return propVar.UhVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (VarEnum)propVar.Vt == VarEnum.VT_UI8 ? propVar.UhVal : null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -98,18 +80,9 @@ namespace Peek.Common.Extensions
|
||||
|
||||
try
|
||||
{
|
||||
PropVariant propVar;
|
||||
propertyStore.GetValue(ref key, out PropVariant propVar);
|
||||
|
||||
propertyStore.GetValue(ref key, out propVar);
|
||||
|
||||
if ((VarEnum)propVar.Vt == VarEnum.VT_LPWSTR)
|
||||
{
|
||||
return Marshal.PtrToStringUni(propVar.P) ?? string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (VarEnum)propVar.Vt == VarEnum.VT_LPWSTR ? Marshal.PtrToStringUni(propVar.P) ?? string.Empty : null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Peek.Common.Models
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime? dateModified = null;
|
||||
DateTime? dateModified;
|
||||
try
|
||||
{
|
||||
dateModified = System.IO.File.GetCreationTime(Path);
|
||||
|
||||
Reference in New Issue
Block a user