-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/PixiEditor/PixiEditor
- Loading branch information
Showing
20 changed files
with
531 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Globalization; | ||
using System.Text; | ||
using PixiEditor.Models.Commands.Commands; | ||
|
||
namespace PixiEditor.Models.Commands.CommandLog; | ||
|
||
internal class CommandLog | ||
{ | ||
private readonly List<CommandLogEntry> list = new(MaxEntries); | ||
|
||
private const int MaxEntries = 8; | ||
|
||
public void Log(Command command, bool? canExecute) | ||
{ | ||
if (canExecute.HasValue && !list[0].CanExecute.HasValue) | ||
{ | ||
list[0].CanExecute = canExecute; | ||
return; | ||
} | ||
|
||
if (list.Count >= MaxEntries) | ||
{ | ||
list.RemoveRange(MaxEntries - 1, list.Count - MaxEntries + 1); | ||
} | ||
|
||
list.Insert(0, new CommandLogEntry(command, canExecute, DateTime.Now)); | ||
} | ||
|
||
public string GetSummary(DateTime relativeTime) | ||
{ | ||
var builder = new StringBuilder(); | ||
|
||
foreach (var entry in list) | ||
{ | ||
var relativeSpan = entry.DateTime - relativeTime; | ||
string canExecute = entry.CanExecute.HasValue ? entry.CanExecute.ToString() : "not executed"; | ||
|
||
builder.AppendLine($"{entry.Command.InternalName} | CanExecute: {canExecute} | {relativeSpan.TotalSeconds.ToString("F3", CultureInfo.InvariantCulture)}s ago | {entry.DateTime.ToString("O", CultureInfo.InvariantCulture)}"); | ||
} | ||
|
||
return builder.ToString(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/PixiEditor/Models/Commands/CommandLog/CommandLogEntry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using PixiEditor.Models.Commands.Commands; | ||
|
||
namespace PixiEditor.Models.Commands.CommandLog; | ||
|
||
internal class CommandLogEntry | ||
{ | ||
public Command Command { get; } | ||
|
||
public bool? CanExecute { get; set; } | ||
|
||
public DateTime DateTime { get; } | ||
|
||
public CommandLogEntry(Command command, bool? commandMethod, DateTime dateTime) | ||
{ | ||
Command = command; | ||
CanExecute = commandMethod; | ||
DateTime = dateTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.