From 00fbd252af0c7d1fe6cfb70ea47dc5e44bd710b5 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 20 Sep 2020 01:08:38 -0400 Subject: [PATCH] really broken (but it's a start) print handler for FileSystemObjectModel --- .../PrintHandlers/FileSystemPrintHandler.cs | 77 +++++++++++++++++++ .../UniversalEditor.UserInterface.csproj | 2 + 2 files changed, 79 insertions(+) create mode 100644 Libraries/UniversalEditor.UserInterface/PrintHandlers/FileSystemPrintHandler.cs diff --git a/Libraries/UniversalEditor.UserInterface/PrintHandlers/FileSystemPrintHandler.cs b/Libraries/UniversalEditor.UserInterface/PrintHandlers/FileSystemPrintHandler.cs new file mode 100644 index 00000000..74215dc6 --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/PrintHandlers/FileSystemPrintHandler.cs @@ -0,0 +1,77 @@ +// +// FileSystemPrintHandler.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.Drawing; +using MBS.Framework.UserInterface.Drawing; +using UniversalEditor.ObjectModels.FileSystem; +using UniversalEditor.Printing; + +namespace UniversalEditor.UserInterface.PrintHandlers +{ + public class FileSystemPrintHandler : PrintHandler + { + private static PrintHandlerReference _pr = null; + protected override PrintHandlerReference MakeReferenceInternal() + { + if (_pr == null) + { + _pr = base.MakeReferenceInternal(); + _pr.SupportedObjectModels.Add(typeof(FileSystemObjectModel)); + } + return _pr; + } + + protected override void PrintInternal(ObjectModel objectModel, Graphics g) + { + FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); + IFileSystemObject[] fsos = fsom.GetAllObjects(); + + Rectangle rect = new Rectangle(0, 0, 1920, 13); + SolidBrush brush = new SolidBrush(Colors.Black); + for (int i = 0; i < fsos.Length; i++) + { + g.DrawText(fsos[i].Name, null, rect, brush); + if (fsos[i] is File) + { + rect.X += 320; + g.DrawText(Common.FileInfo.FormatSize((fsos[i] as File).Size), null, rect, brush); + rect.X += 64; + g.DrawText(String.Format("{0} file", System.IO.Path.GetExtension(fsos[i].Name)), null, rect, brush); + rect.X += 64; + g.DrawText((fsos[i] as File).ModificationTimestamp.ToString(), null, rect, brush); + rect.X = 0; + } + else if (fsos[i] is Folder) + { + rect.X += 320; + g.DrawText(String.Format("{0} file(s), {1} folder(s)", (fsos[i] as Folder).Files.Count, (fsos[i] as Folder).Folders.Count), null, rect, brush); + rect.X += 64; + g.DrawText("Folder", null, rect, brush); + rect.X += 64; + // g.DrawText((fsos[i] as Folder).ModificationTimestamp.ToString(), null, rect, brush); + rect.X = 0; + } + + rect.Y += rect.Height; + } + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index 0ceec796..976d9c2e 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -137,6 +137,7 @@ + @@ -193,6 +194,7 @@ +