From 88a27eb26facebba0cec01c609d259bf2498425f Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 1 Jul 2023 21:20:13 -0400 Subject: [PATCH] add StringBuilder extensions and ICustomPlugin, and move ProgressEvent from UniversalEditor into MBS.Framework core --- MBS.Framework/ICustomPlugin.cs | 27 +++++++++ MBS.Framework/MBS.Framework.csproj | 3 + MBS.Framework/ProgressEvent.cs | 75 ++++++++++++++++++++++++ MBS.Framework/StringBuilderExtensions.cs | 18 ++++++ 4 files changed, 123 insertions(+) create mode 100755 MBS.Framework/ICustomPlugin.cs mode change 100755 => 100644 MBS.Framework/MBS.Framework.csproj create mode 100644 MBS.Framework/ProgressEvent.cs create mode 100644 MBS.Framework/StringBuilderExtensions.cs diff --git a/MBS.Framework/ICustomPlugin.cs b/MBS.Framework/ICustomPlugin.cs new file mode 100755 index 0000000..35be4a0 --- /dev/null +++ b/MBS.Framework/ICustomPlugin.cs @@ -0,0 +1,27 @@ +// +// CardinalDirection.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2021 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; +namespace MBS.Framework +{ + public interface ICustomPlugin + { + } +} diff --git a/MBS.Framework/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj old mode 100755 new mode 100644 index 8eac4d0..3695de2 --- a/MBS.Framework/MBS.Framework.csproj +++ b/MBS.Framework/MBS.Framework.csproj @@ -138,6 +138,9 @@ + + + diff --git a/MBS.Framework/ProgressEvent.cs b/MBS.Framework/ProgressEvent.cs new file mode 100644 index 0000000..981ce2b --- /dev/null +++ b/MBS.Framework/ProgressEvent.cs @@ -0,0 +1,75 @@ +// +// ProgressEvent.cs - provide a way to signal progress to UI from non-UI code +// +// Author: +// Michael Becker +// +// Copyright (c) 2011-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 System.ComponentModel; + +namespace UniversalEditor +{ + /// + /// A delegate for the event that is raised when progress is made during an asynchronous operation. + /// + /// The control firing this event. + /// A that contains additional information about this event. + public delegate void ProgressEventHandler(object sender, ProgressEventArgs e); + /// + /// Event arguments for the event that is raised when progress is made during an asynchronous operation. + /// + public class ProgressEventArgs : CancelEventArgs + { + private long mvarTotal = 0; + /// + /// The total possible amount of progress represented by this progress event. + /// + public long Total { get { return mvarTotal; } } + + private long mvarCurrent = 0; + /// + /// The current amount of progress completed. + /// + public long Current { get { return mvarCurrent; } } + + /// + /// The amount of progress remaining. + /// + public long Remaining { get { return mvarTotal - mvarCurrent; } } + + private string mvarMessage = String.Empty; + /// + /// The progress message + /// + public string Message { get { return mvarMessage; } } + + /// + /// Creates a new instance of the event arguments for the event that is + /// raised when progress is made during an asynchronous operation. + /// + /// The current amount of progress completed. + /// The total possible amount of progress represented by this progress event. + /// The progress message + public ProgressEventArgs(long current, long total, string message = "") + { + mvarCurrent = current; + mvarTotal = total; + mvarMessage = message; + } + } +} diff --git a/MBS.Framework/StringBuilderExtensions.cs b/MBS.Framework/StringBuilderExtensions.cs new file mode 100644 index 0000000..31d85ae --- /dev/null +++ b/MBS.Framework/StringBuilderExtensions.cs @@ -0,0 +1,18 @@ +using System; +using System.Text; + +namespace MBS.Framework +{ + public static class StringBuilderExtensions + { + public static void AppendLineIndented(this StringBuilder sb, object value, int indentLevel, char indentChar = '\t', int indentCharCountPerLevel = 1) + { + for (int i = 0; i < indentLevel * indentCharCountPerLevel; i++) + { + sb.Append(indentChar); + } + sb.Append(value); + sb.AppendLine(); + } + } +}