Skip to content

Commit

Permalink
Writer: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Apr 28, 2024
1 parent 2b960e3 commit ab64a12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ internal class FileController
private readonly ExportFactory<SaveChangesViewModel> saveChangesViewModelFactory;
private readonly List<IDocumentType> documentTypes;
private readonly RecentFileList recentFileList;
private readonly DelegateCommand newCommand;
private readonly DelegateCommand openCommand;
private readonly DelegateCommand closeCommand;
private readonly DelegateCommand saveCommand;
private readonly DelegateCommand saveAsCommand;
Expand All @@ -39,8 +37,8 @@ public FileController(IMessageService messageService, ISystemService systemServi
this.fileService = fileService;
this.saveChangesViewModelFactory = saveChangesViewModelFactory;
documentTypes = [ richTextDocumentType, xpsExportDocumentType ];
fileService.NewCommand = newCommand = new(NewCommand);
fileService.OpenCommand = openCommand = new(OpenCommand);
fileService.NewCommand = new DelegateCommand(NewCommand);
fileService.OpenCommand = new DelegateCommand(OpenCommand);
fileService.CloseCommand = closeCommand = new(CloseCommand, CanCloseCommand);
fileService.SaveCommand = saveCommand = new(SaveCommand, CanSaveCommand);
fileService.SaveAsCommand = saveAsCommand = new(SaveAsCommand, CanSaveAsCommand);
Expand All @@ -62,7 +60,7 @@ private IDocument? ActiveDocument

public IDocument? Open(string fileName)
{
if (string.IsNullOrEmpty(fileName)) throw new ArgumentException("The argument fileName must not be null or empty.", nameof(fileName));
ArgumentException.ThrowIfNullOrEmpty(fileName);
return OpenCore(fileName!);
}

Expand Down Expand Up @@ -169,7 +167,7 @@ private void SaveAs(IDocument document)

private void Close(IDocument document)
{
if (!CanDocumentsClose(new[] { document })) return;
if (!CanDocumentsClose([ document ])) return;
if (ActiveDocument == document) ActiveDocument = null;
fileService.RemoveDocument(document);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public abstract class DocumentType : Model, IDocumentType
{
protected DocumentType(string description, string fileExtension)
{
if (string.IsNullOrEmpty(description)) throw new ArgumentException("description must not be null or empty.", nameof(description));
if (string.IsNullOrEmpty(fileExtension)) throw new ArgumentException("fileExtension must not be null or empty", nameof(fileExtension));
ArgumentException.ThrowIfNullOrEmpty(description);
ArgumentException.ThrowIfNullOrEmpty(fileExtension);
if (fileExtension[0] != '.') throw new ArgumentException("The argument fileExtension must start with the '.' character.", nameof(fileExtension));
Description = description;
FileExtension = fileExtension;
Expand All @@ -27,7 +27,7 @@ public IDocument New()

public IDocument Open(string fileName)
{
if (string.IsNullOrEmpty(fileName)) throw new ArgumentException("fileName must not be null or empty.", nameof(fileName));
ArgumentException.ThrowIfNullOrEmpty(fileName);
if (!CanOpen()) throw new NotSupportedException("The Open operation is not supported. CanOpen returned false.");
var document = OpenCore(fileName);
document.FileName = fileName;
Expand All @@ -39,7 +39,7 @@ public IDocument Open(string fileName)
public void Save(IDocument document, string fileName)
{
ArgumentNullException.ThrowIfNull(document);
if (string.IsNullOrEmpty(fileName)) throw new ArgumentException("fileName must not be null or empty.", nameof(fileName));
ArgumentException.ThrowIfNullOrEmpty(fileName);
if (!CanSave(document)) throw new NotSupportedException("The Save operation is not supported. CanSave returned false.");

SaveCore(document, fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ private sealed class DisabledZoomCommands : Model, IZoomCommands
{
public IReadOnlyList<string> DefaultZooms => [];

public double Zoom
{
get => 1;
set { }
}
public double Zoom { get => 1; set { } }

public ICommand ZoomInCommand => DelegateCommand.DisabledCommand;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class App
private static readonly Lazy<string> logFileName = new(() => ((FileTarget)((AsyncTargetWrapper)LogManager.Configuration.FindTargetByName("fileTarget")).WrappedTarget).FileName.Render(new LogEventInfo()));
private AggregateCatalog? catalog;
private CompositionContainer? container;
private IEnumerable<IModuleController> moduleControllers = Array.Empty<IModuleController>();
private IEnumerable<IModuleController> moduleControllers = [];

public static string LogFileName => logFileName.Value;

Expand Down

0 comments on commit ab64a12

Please sign in to comment.