Skip to content

Commit

Permalink
show image size at window titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan committed Nov 9, 2015
1 parent d6ae284 commit 4242c66
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
20 changes: 1 addition & 19 deletions src/WinQuickLook/Converters/FileInfoToFileSizeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
var length = fileInfo.Length;

return GetSizeFormat(length);
return WinExplorerHelper.GetSizeFormat(length);
}

var directoryInfo = value as DirectoryInfo;
Expand All @@ -41,23 +41,5 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
{
return DependencyProperty.UnsetValue;
}

private static object GetSizeFormat(long length)
{
if (length >= 1024 * 1024 * 1024)
{
return $"{length / (double)(1024 * 1024 * 1024):0.##} GB";
}
if (length >= 1024 * 1024)
{
return $"{length / (double)(1024 * 1024):0.##} MB";
}
if (length >= 1024)
{
return $"{length / (double)1024:0.##} KB";
}

return $"{length} B";
}
}
}
3 changes: 3 additions & 0 deletions src/WinQuickLook/Handlers/TextPreviewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

using WinQuickLook.Interop;

Expand Down Expand Up @@ -35,6 +36,8 @@ public override FrameworkElement GetElement(string fileName)
textBox.Text = encoding.GetString(contents);
textBox.IsReadOnly = true;
textBox.IsReadOnlyCaretVisible = false;
textBox.FontFamily = new FontFamily("Consolas");
textBox.FontSize = 13;
textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
textBox.EndInit();
Expand Down
2 changes: 1 addition & 1 deletion src/WinQuickLook/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
12 changes: 11 additions & 1 deletion src/WinQuickLook/QuickLookWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Forms.Integration;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using WinQuickLook.Handlers;
using WinQuickLook.Interop;
Expand Down Expand Up @@ -96,7 +97,16 @@ public void Open(string fileName)

public new void Show()
{
Title = _fileInfo.Name;
if (PreviewHost is Image)
{
var bitmap = (BitmapSource)((Image)PreviewHost).Source;

Title = $"{_fileInfo.Name} ({bitmap.PixelWidth}x{bitmap.PixelHeight} - {WinExplorerHelper.GetSizeFormat(_fileInfo.Length)})";
}
else
{
Title = _fileInfo.Name;
}

base.Show();

Expand Down
18 changes: 18 additions & 0 deletions src/WinQuickLook/WinExplorerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ public static void CreateLink(string linkPath)
Marshal.FinalReleaseComObject(shellLink);
}

public static object GetSizeFormat(long length)
{
if (length >= 1024 * 1024 * 1024)
{
return $"{length / (double)(1024 * 1024 * 1024):0.##} GB";
}
if (length >= 1024 * 1024)
{
return $"{length / (double)(1024 * 1024):0.##} MB";
}
if (length >= 1024)
{
return $"{length / (double)1024:0.##} KB";
}

return $"{length} B";
}

public static string GetSelectedItem()
{
var foregroundHwnd = NativeMethods.GetForegroundWindow();
Expand Down

0 comments on commit 4242c66

Please sign in to comment.