Skip to content

Commit

Permalink
Some more code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Nov 20, 2023
1 parent 5473cdc commit 99dc35d
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ private void DocumentsCollectionChanged(object? sender, NotifyCollectionChangedE
{
foreach (DocumentFile x in e.OldItems!) RemoveProject(x);
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
else if (e.Action == NotifyCollectionChangedAction.Reset && !documentService.DocumentFiles.Any()) // Clear
{
if (!documentService.DocumentFiles.Any()) foreach (var x in documentIds.Keys.ToArray()) RemoveProject(x);
foreach (var x in documentIds.Keys.ToArray()) RemoveProject(x);
}
else throw new NotSupportedException("Collection modification is not supported!");
}
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetPad/DotNetPad.Presentation/Controls/CodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private void UpdateErrorMarkers()
errorMarkerService.Clear();
foreach (var errorListItem in DocumentFile.Content?.ErrorList ?? Array.Empty<ErrorListItem>())
{
var startOffset = Document.GetOffset(new TextLocation(errorListItem.StartLine + 1, errorListItem.StartColumn + 1));
var endOffset = Document.GetOffset(new TextLocation(errorListItem.EndLine + 1, errorListItem.EndColumn + 1));
var startOffset = Document.GetOffset(new(errorListItem.StartLine + 1, errorListItem.StartColumn + 1));
var endOffset = Document.GetOffset(new(errorListItem.EndLine + 1, errorListItem.EndColumn + 1));
errorMarkerService.Create(startOffset, endOffset - startOffset, errorListItem.Description);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public VersionedHighlightedLine(IDocument document, IDocumentLine documentLine,
{
if (IsOutsideLine(documentLine, oldSection.Offset, oldSection.Length)) continue;

Sections.Add(new HighlightedSection
Sections.Add(new()
{
Color = oldSection.Color,
Offset = oldSection.Offset,
Expand All @@ -170,7 +170,7 @@ public VersionedHighlightedLine(IDocument document, IDocumentLine documentLine,

private sealed class HighlightedSectionComparer : IEqualityComparer<HighlightedSection>
{
public static HighlightedSectionComparer Default { get; } = new HighlightedSectionComparer();
public static HighlightedSectionComparer Default { get; } = new();

public bool Equals(HighlightedSection? x, HighlightedSection? y)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ErrorTextMarkerService(TextEditor textEditor)
this.textEditor = textEditor;
markers = new(textEditor.Document);

TextView textView = textEditor.TextArea.TextView;
var textView = textEditor.TextArea.TextView;
textView.BackgroundRenderers.Add(this);
textView.LineTransformers.Add(this);
textView.Services.AddService(typeof(ErrorTextMarkerService), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ namespace Waf.DotNetPad.Presentation.DesignData;

public class MockShellService : Model, IShellService
{
public MockShellService()
{
Settings = new AppSettings();
}

public AppSettings Settings { get; set; } = null!;
public AppSettings Settings { get; set; } = new AppSettings();

public object ShellView { get; set; } = null!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static void Main()
}
}
}";
DocumentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", code);
DocumentFile = new(DocumentType.CSharp, "Script 1.cs", code);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ public class SampleErrorListViewModel : ErrorListViewModel
public SampleErrorListViewModel() : base(new MockErrorListView(), new MockDocumentService(), null!, null!)
{
var documentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", "");
documentFile.Content!.ErrorList = new[]
{
new ErrorListItem(ErrorSeverity.Info, "Info", 0, 0, 0, 0),
new ErrorListItem(ErrorSeverity.Warning, "Warning", 3, 13, 3, 13),
new ErrorListItem(ErrorSeverity.Error, "Error", 20, 8, 20, 8)
};
documentFile.Content!.ErrorList = [
new(ErrorSeverity.Info, "Info", 0, 0, 0, 0),
new(ErrorSeverity.Warning, "Warning", 3, 13, 3, 13),
new(ErrorSeverity.Error, "Error", 20, 8, 20, 8)
];
DocumentService.ActiveDocumentFile = documentFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ public class SampleSaveChangesViewModel : SaveChangesViewModel
{
public SampleSaveChangesViewModel() : base(new MockSaveChangesView())
{
DocumentFiles = new[]
{
new DocumentFile(DocumentType.CSharp, null!) { FileName = "Script 1.cs" },
new DocumentFile(DocumentType.CSharp, null!) { FileName = "Script 2.cs" },
new DocumentFile(DocumentType.VisualBasic, null!) { FileName = @"C:\Users\Luke\Documents\Waf DotNetPad\Script 3.vb" },
};
DocumentFiles = [
new(DocumentType.CSharp, null!) { FileName = "Script 1.cs" },
new(DocumentType.CSharp, null!) { FileName = "Script 2.cs" },
new(DocumentType.VisualBasic, null!) { FileName = @"C:\Users\Luke\Documents\Waf DotNetPad\Script 3.vb" },
];
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ICSharpCode.AvalonEdit.Document;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition;
using System.Waf.Applications;
using System.Windows;
using Waf.DotNetPad.Applications.Services;
Expand Down Expand Up @@ -58,7 +57,7 @@ private async void UpdateCaretPosition()
private void CodeEditorServiceRequestSetCaret(object? sender, SetCaretEventArgs e)
{
if (e.DocumentFile != ViewModel.DocumentFile) return;
var offset = codeEditor.Document.GetOffset(new TextLocation(e.Line + 1, e.Column + 1));
var offset = codeEditor.Document.GetOffset(new(e.Line + 1, e.Column + 1));
codeEditor.TextArea.Caret.Offset = offset;
codeEditor.Focus();
}
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetPad/DotNetPad.Presentation/Views/OutputView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ private void DocumentsCollectionChanged(object? sender, NotifyCollectionChangedE
{
foreach (DocumentFile x in e.OldItems!) outputParagraphs.Remove(x);
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
{
if (!ViewModel.DocumentService.DocumentFiles.Any()) outputParagraphs.Clear();
else if (e.Action == NotifyCollectionChangedAction.Reset && !ViewModel.DocumentService.DocumentFiles.Any()) // Clear
{
outputParagraphs.Clear();
}
else throw new NotSupportedException("Collection modification is not supported!");
}
Expand Down

0 comments on commit 99dc35d

Please sign in to comment.