mirror of
https://github.com/cyanfish/naps2.git
synced 2024-08-17 03:00:21 +03:00
C# 12: Use collection initializers
This commit is contained in:
parent
6976d5c165
commit
b92362af02
@ -11,7 +11,7 @@ namespace NAPS2.App.Tests.Appium;
|
|||||||
[Collection("appium")]
|
[Collection("appium")]
|
||||||
public class LanguageSelectionTests : AppiumTests
|
public class LanguageSelectionTests : AppiumTests
|
||||||
{
|
{
|
||||||
private static readonly HashSet<string> ExpectedMissingLanguages = new() { "bn", "hi", "id", "th", "ur" };
|
private static readonly HashSet<string> ExpectedMissingLanguages = ["bn", "hi", "id", "th", "ur"];
|
||||||
|
|
||||||
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
|
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
|
||||||
[ClassData(typeof(AppiumTestData))]
|
[ClassData(typeof(AppiumTestData))]
|
||||||
|
@ -78,7 +78,7 @@ public class GtkImage : IMemoryImage
|
|||||||
}
|
}
|
||||||
if (imageFormat == ImageFileFormat.Tiff)
|
if (imageFormat == ImageFileFormat.Tiff)
|
||||||
{
|
{
|
||||||
((GtkImageContext) ImageContext).TiffIo.SaveTiff(new List<IMemoryImage> { this }, path);
|
((GtkImageContext) ImageContext).TiffIo.SaveTiff([this], path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ImageContext.CheckSupportsFormat(imageFormat);
|
ImageContext.CheckSupportsFormat(imageFormat);
|
||||||
@ -97,7 +97,7 @@ public class GtkImage : IMemoryImage
|
|||||||
}
|
}
|
||||||
if (imageFormat == ImageFileFormat.Tiff)
|
if (imageFormat == ImageFileFormat.Tiff)
|
||||||
{
|
{
|
||||||
((GtkImageContext) ImageContext).TiffIo.SaveTiff(new List<IMemoryImage> { this }, stream);
|
((GtkImageContext) ImageContext).TiffIo.SaveTiff([this], stream);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ImageContext.CheckSupportsFormat(imageFormat);
|
ImageContext.CheckSupportsFormat(imageFormat);
|
||||||
|
@ -18,13 +18,13 @@ public abstract class XmlSerializer
|
|||||||
|
|
||||||
protected static readonly Dictionary<Type, List<CustomXmlTypes>> CustomTypesCache = new();
|
protected static readonly Dictionary<Type, List<CustomXmlTypes>> CustomTypesCache = new();
|
||||||
|
|
||||||
protected static readonly List<Type> ArrayLikeTypes = new()
|
protected static readonly List<Type> ArrayLikeTypes =
|
||||||
{
|
[
|
||||||
typeof(List<>),
|
typeof(List<>),
|
||||||
typeof(HashSet<>),
|
typeof(HashSet<>),
|
||||||
typeof(ImmutableList<>),
|
typeof(ImmutableList<>),
|
||||||
typeof(ImmutableHashSet<>),
|
typeof(ImmutableHashSet<>)
|
||||||
};
|
];
|
||||||
|
|
||||||
protected static readonly Dictionary<Type, XmlTypeInfo> TypeInfoCache = new()
|
protected static readonly Dictionary<Type, XmlTypeInfo> TypeInfoCache = new()
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ public abstract class XmlSerializer
|
|||||||
{
|
{
|
||||||
lock (TypeInfoCache)
|
lock (TypeInfoCache)
|
||||||
{
|
{
|
||||||
CustomTypesCache.GetOrSet(type, new List<CustomXmlTypes>()).Add(customTypes);
|
CustomTypesCache.GetOrSet(type, []).Add(customTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,7 @@ public class AsyncSink<T> where T : class
|
|||||||
{
|
{
|
||||||
private static TaskCompletionSource<T?> CreateTcs() => new(TaskCreationOptions.RunContinuationsAsynchronously);
|
private static TaskCompletionSource<T?> CreateTcs() => new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
private readonly List<TaskCompletionSource<T?>> _items = new()
|
private readonly List<TaskCompletionSource<T?>> _items = [CreateTcs()];
|
||||||
{
|
|
||||||
CreateTcs()
|
|
||||||
};
|
|
||||||
private bool _completed;
|
private bool _completed;
|
||||||
|
|
||||||
public async IAsyncEnumerable<T> AsAsyncEnumerable()
|
public async IAsyncEnumerable<T> AsAsyncEnumerable()
|
||||||
|
@ -39,9 +39,9 @@ public class SmoothProgress : IDisposable
|
|||||||
|
|
||||||
_stopwatch = Stopwatch.StartNew();
|
_stopwatch = Stopwatch.StartNew();
|
||||||
|
|
||||||
_previousInputPos = new LinkedList<double>();
|
_previousInputPos = [];
|
||||||
_previousInputPos.AddLast(0);
|
_previousInputPos.AddLast(0);
|
||||||
_previousInputTimes = new LinkedList<long>();
|
_previousInputTimes = [];
|
||||||
_previousInputTimes.AddLast(0);
|
_previousInputTimes.AddLast(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public static class CollectionExtensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> enumerable)
|
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> enumerable)
|
||||||
{
|
{
|
||||||
return new HashSet<T>(enumerable);
|
return [..enumerable];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public static class CollectionExtensions
|
|||||||
{
|
{
|
||||||
if (!dict.ContainsKey(key))
|
if (!dict.ContainsKey(key))
|
||||||
{
|
{
|
||||||
dict[key] = new HashSet<TValue>();
|
dict[key] = [];
|
||||||
}
|
}
|
||||||
dict[key].Add(value);
|
dict[key].Add(value);
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ public static class CollectionExtensions
|
|||||||
{
|
{
|
||||||
if (!dict.ContainsKey(key))
|
if (!dict.ContainsKey(key))
|
||||||
{
|
{
|
||||||
dict[key] = new HashSet<TValue>();
|
dict[key] = [];
|
||||||
}
|
}
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@ namespace NAPS2.Util;
|
|||||||
|
|
||||||
public class DisposableSet<T> : IDisposable where T : IDisposable
|
public class DisposableSet<T> : IDisposable where T : IDisposable
|
||||||
{
|
{
|
||||||
private readonly HashSet<T> _set = new();
|
private readonly HashSet<T> _set = [];
|
||||||
|
|
||||||
public void Add(T obj)
|
public void Add(T obj)
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ public class GtkListView<T> : IListView<T> where T : notnull
|
|||||||
private bool _refreshing;
|
private bool _refreshing;
|
||||||
private readonly ScrolledWindow _scrolledWindow;
|
private readonly ScrolledWindow _scrolledWindow;
|
||||||
private readonly FlowBox _flowBox;
|
private readonly FlowBox _flowBox;
|
||||||
private List<Entry> _entries = new();
|
private List<Entry> _entries = [];
|
||||||
|
|
||||||
public GtkListView(ListViewBehavior<T> behavior)
|
public GtkListView(ListViewBehavior<T> behavior)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ public class ListViewDataSource<T> : NSCollectionViewDataSource where T : notnul
|
|||||||
_itemActivated = itemActivated;
|
_itemActivated = itemActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> Items { get; } = new();
|
public List<T> Items { get; } = [];
|
||||||
|
|
||||||
public override nint GetNumberofItems(NSCollectionView collectionView, nint section)
|
public override nint GetNumberofItems(NSCollectionView collectionView, nint section)
|
||||||
{
|
{
|
||||||
|
@ -186,8 +186,8 @@ public class MacDesktopForm : DesktopForm
|
|||||||
|
|
||||||
private List<NSToolbarItem?> CreateMacToolbarItems()
|
private List<NSToolbarItem?> CreateMacToolbarItems()
|
||||||
{
|
{
|
||||||
return new List<NSToolbarItem?>
|
return
|
||||||
{
|
[
|
||||||
MacToolbarItems.Create("scan", Commands.Scan),
|
MacToolbarItems.Create("scan", Commands.Scan),
|
||||||
MacToolbarItems.Create("profiles", Commands.Profiles),
|
MacToolbarItems.Create("profiles", Commands.Profiles),
|
||||||
MacToolbarItems.CreateSpace(),
|
MacToolbarItems.CreateSpace(),
|
||||||
@ -214,7 +214,7 @@ public class MacDesktopForm : DesktopForm
|
|||||||
#pragma warning restore CA1422
|
#pragma warning restore CA1422
|
||||||
#pragma warning restore CA1416
|
#pragma warning restore CA1416
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LayoutElement GetZoomButtons() => C.Spacer();
|
protected override LayoutElement GetZoomButtons() => C.Spacer();
|
||||||
|
@ -50,8 +50,8 @@ public class MacPreviewForm : PreviewForm
|
|||||||
|
|
||||||
private List<NSToolbarItem?> CreateMacToolbarItems()
|
private List<NSToolbarItem?> CreateMacToolbarItems()
|
||||||
{
|
{
|
||||||
return new List<NSToolbarItem?>
|
return
|
||||||
{
|
[
|
||||||
MacToolbarItems.Create("prev", GoToPrevCommand, nav: true),
|
MacToolbarItems.Create("prev", GoToPrevCommand, nav: true),
|
||||||
MacToolbarItems.Create("next", GoToNextCommand, nav: true),
|
MacToolbarItems.Create("next", GoToNextCommand, nav: true),
|
||||||
MacToolbarItems.CreateMenu("rotate", Commands.RotateMenu, new MenuProvider()
|
MacToolbarItems.CreateMenu("rotate", Commands.RotateMenu, new MenuProvider()
|
||||||
@ -81,7 +81,7 @@ public class MacPreviewForm : PreviewForm
|
|||||||
#pragma warning restore CA1422
|
#pragma warning restore CA1422
|
||||||
#pragma warning restore CA1416
|
#pragma warning restore CA1416
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ZoomUpdated(NSSlider sender)
|
private void ZoomUpdated(NSSlider sender)
|
||||||
|
@ -54,7 +54,7 @@ public class DownloadControllerTests : ContextualTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async void NoUrl()
|
public async void NoUrl()
|
||||||
{
|
{
|
||||||
DownloadInfo info = new("", new List<DownloadMirror>(), 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip);
|
DownloadInfo info = new("", [], 0, "0000000000000000000000000000000000000000", DownloadFormat.Gzip);
|
||||||
|
|
||||||
var mockHandler = Substitute.For<Action<string>>();
|
var mockHandler = Substitute.For<Action<string>>();
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class DownloadControllerTests : ContextualTests
|
|||||||
|
|
||||||
_controller.DownloadError += mockHandler;
|
_controller.DownloadError += mockHandler;
|
||||||
|
|
||||||
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List<DownloadMirror>() { new DownloadMirror(DummyValidUrl) }, 0, "THIS IS NOT AN SHA1 AND WILL FAIL", DownloadFormat.Gzip));
|
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", [new DownloadMirror(DummyValidUrl)], 0, "THIS IS NOT AN SHA1 AND WILL FAIL", DownloadFormat.Gzip));
|
||||||
|
|
||||||
_controller.QueueFile(_mockComponent);
|
_controller.QueueFile(_mockComponent);
|
||||||
Assert.False(await _controller.StartDownloadsAsync());
|
Assert.False(await _controller.StartDownloadsAsync());
|
||||||
@ -90,7 +90,8 @@ public class DownloadControllerTests : ContextualTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async void InvalidMirrorsChecksum()
|
public async void InvalidMirrorsChecksum()
|
||||||
{
|
{
|
||||||
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List<DownloadMirror>() { new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz",
|
||||||
|
[new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
||||||
|
|
||||||
_httpHandler.Expect(DummyInvalidUrl).Respond("application/zip", _animalsZipStream);
|
_httpHandler.Expect(DummyInvalidUrl).Respond("application/zip", _animalsZipStream);
|
||||||
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
||||||
@ -110,7 +111,7 @@ public class DownloadControllerTests : ContextualTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async void Valid()
|
public async void Valid()
|
||||||
{
|
{
|
||||||
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List<DownloadMirror>() { new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", [new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
||||||
|
|
||||||
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
||||||
|
|
||||||
@ -129,7 +130,8 @@ public class DownloadControllerTests : ContextualTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async void ValidUsingMirrorUrl()
|
public async void ValidUsingMirrorUrl()
|
||||||
{
|
{
|
||||||
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz", new List<DownloadMirror>() { new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl) }, 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
_mockComponent.DownloadInfo.Returns(new DownloadInfo("temp.gz",
|
||||||
|
[new DownloadMirror(DummyInvalidUrl), new DownloadMirror(DummyValidUrl)], 0, StockDogJpegSHA1, DownloadFormat.Gzip));
|
||||||
|
|
||||||
_httpHandler.Expect(DummyInvalidUrl);
|
_httpHandler.Expect(DummyInvalidUrl);
|
||||||
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
_httpHandler.Expect(DummyValidUrl).Respond("application/gzip", _dogsGzipStream);
|
||||||
|
@ -31,7 +31,7 @@ public abstract class WinFormsImageList<T> where T : notnull
|
|||||||
|
|
||||||
public class Custom : WinFormsImageList<T>
|
public class Custom : WinFormsImageList<T>
|
||||||
{
|
{
|
||||||
private readonly List<Image> _images = new();
|
private readonly List<Image> _images = [];
|
||||||
|
|
||||||
public Custom(WinFormsListView<T> listView, ListViewBehavior<T> behavior) : base(listView, behavior)
|
public Custom(WinFormsListView<T> listView, ListViewBehavior<T> behavior) : base(listView, behavior)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ public class PrintDocumentPrinter : IScannedImagePrinter
|
|||||||
imagesToPrint = images.Skip(start).Take(length).ToList();
|
imagesToPrint = images.Skip(start).Take(length).ToList();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
imagesToPrint = new List<ProcessedImage>();
|
imagesToPrint = [];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (imagesToPrint.Count == 0)
|
if (imagesToPrint.Count == 0)
|
||||||
|
@ -88,7 +88,7 @@ internal static class TwainApi
|
|||||||
_settings = settings;
|
_settings = settings;
|
||||||
_tw = tw;
|
_tw = tw;
|
||||||
_form = form;
|
_form = form;
|
||||||
Bitmaps = new List<IMemoryImage>();
|
Bitmaps = [];
|
||||||
form.Activated += FTwainGui_Activated;
|
form.Activated += FTwainGui_Activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class AutomatedScanning
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scanList = new List<List<ProcessedImage>>();
|
_scanList = [];
|
||||||
|
|
||||||
if (_options.ImportPath != null)
|
if (_options.ImportPath != null)
|
||||||
{
|
{
|
||||||
@ -571,7 +571,7 @@ public class AutomatedScanning
|
|||||||
_config.Run.Set(c => c.PdfSettings.Compat, compat);
|
_config.Run.Set(c => c.PdfSettings.Compat, compat);
|
||||||
|
|
||||||
int scanIndex = 0;
|
int scanIndex = 0;
|
||||||
_actualOutputPaths = new List<string>();
|
_actualOutputPaths = [];
|
||||||
foreach (var fileContents in _scanList)
|
foreach (var fileContents in _scanList)
|
||||||
{
|
{
|
||||||
var op = _operationFactory.Create<SavePdfOperation>();
|
var op = _operationFactory.Create<SavePdfOperation>();
|
||||||
@ -625,7 +625,7 @@ public class AutomatedScanning
|
|||||||
}
|
}
|
||||||
OutputVerbose(ConsoleResources.StartingScan, i, _options.Number);
|
OutputVerbose(ConsoleResources.StartingScan, i, _options.Number);
|
||||||
_pagesScanned = 0;
|
_pagesScanned = 0;
|
||||||
_scanList.Add(new List<ProcessedImage>());
|
_scanList.Add([]);
|
||||||
var scanParams = new ScanParams
|
var scanParams = new ScanParams
|
||||||
{
|
{
|
||||||
NoUI = !_options.Progress,
|
NoUI = !_options.Progress,
|
||||||
|
@ -5,7 +5,7 @@ namespace NAPS2.Config;
|
|||||||
|
|
||||||
public class StubProfileManager : IProfileManager
|
public class StubProfileManager : IProfileManager
|
||||||
{
|
{
|
||||||
private readonly List<ScanProfile> _profiles = new List<ScanProfile>();
|
private readonly List<ScanProfile> _profiles = [];
|
||||||
|
|
||||||
public ImmutableList<ScanProfile> Profiles => ImmutableList.CreateRange(_profiles);
|
public ImmutableList<ScanProfile> Profiles => ImmutableList.CreateRange(_profiles);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ public class EtoOperationProgress : OperationProgress
|
|||||||
private readonly INotify _notify;
|
private readonly INotify _notify;
|
||||||
private readonly Naps2Config _config;
|
private readonly Naps2Config _config;
|
||||||
|
|
||||||
private readonly HashSet<IOperation> _activeOperations = new();
|
private readonly HashSet<IOperation> _activeOperations = [];
|
||||||
|
|
||||||
public EtoOperationProgress(IFormFactory formFactory, INotify notify, Naps2Config config)
|
public EtoOperationProgress(IFormFactory formFactory, INotify notify, Naps2Config config)
|
||||||
{
|
{
|
||||||
|
@ -145,8 +145,8 @@ public abstract class LayoutLine : LayoutContainer
|
|||||||
}
|
}
|
||||||
// If we aren't aligned or we don't have a parent to do that pre-calculation, then we just determine our cell
|
// If we aren't aligned or we don't have a parent to do that pre-calculation, then we just determine our cell
|
||||||
// sizes and scaling directly without any special alignment constraints.
|
// sizes and scaling directly without any special alignment constraints.
|
||||||
cellLengths = new List<float>();
|
cellLengths = [];
|
||||||
cellScaling = new List<bool>();
|
cellScaling = [];
|
||||||
var lengthChildContext = childContext with { IsCellLengthQuery = true };
|
var lengthChildContext = childContext with { IsCellLengthQuery = true };
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ namespace NAPS2.EtoForms;
|
|||||||
|
|
||||||
public class MenuProvider
|
public class MenuProvider
|
||||||
{
|
{
|
||||||
private readonly List<Item> _items = new();
|
private readonly List<Item> _items = [];
|
||||||
|
|
||||||
public MenuProvider Dynamic(ListProvider<Command> commandListProvider)
|
public MenuProvider Dynamic(ListProvider<Command> commandListProvider)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ public class NotificationManager
|
|||||||
ColorScheme = colorScheme;
|
ColorScheme = colorScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NotificationModel> Notifications { get; } = new();
|
public List<NotificationModel> Notifications { get; } = [];
|
||||||
|
|
||||||
public ColorScheme ColorScheme { get; }
|
public ColorScheme ColorScheme { get; }
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ public abstract class DesktopForm : EtoFormBase
|
|||||||
{
|
{
|
||||||
// TODO: Remove icon from delete command somehow
|
// TODO: Remove icon from delete command somehow
|
||||||
// TODO: Is this memory leaking (because of event handlers) when commands are converted to menuitems?
|
// TODO: Is this memory leaking (because of event handlers) when commands are converted to menuitems?
|
||||||
_contextMenu.Items.AddRange(new List<MenuItem>
|
_contextMenu.Items.AddRange(
|
||||||
{
|
[
|
||||||
Commands.ViewImage,
|
Commands.ViewImage,
|
||||||
new SeparatorMenuItem(),
|
new SeparatorMenuItem(),
|
||||||
Commands.SelectAll,
|
Commands.SelectAll,
|
||||||
@ -162,15 +162,15 @@ public abstract class DesktopForm : EtoFormBase
|
|||||||
Commands.Paste,
|
Commands.Paste,
|
||||||
new SeparatorMenuItem(),
|
new SeparatorMenuItem(),
|
||||||
Commands.Delete
|
Commands.Delete
|
||||||
});
|
]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_contextMenu.Items.AddRange(new List<MenuItem>
|
_contextMenu.Items.AddRange(
|
||||||
{
|
[
|
||||||
Commands.SelectAll,
|
Commands.SelectAll,
|
||||||
Commands.Paste
|
Commands.Paste
|
||||||
});
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class OcrDownloadForm : EtoDialogBase
|
|||||||
|
|
||||||
private HashSet<string> SelectedLanguageComponents
|
private HashSet<string> SelectedLanguageComponents
|
||||||
{
|
{
|
||||||
get { return new HashSet<string>(_languageList.Selection.Select(lang => $"ocr-{lang.Code}")); }
|
get { return [.._languageList.Selection.Select(lang => $"ocr-{lang.Code}")]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Download()
|
private void Download()
|
||||||
|
@ -21,8 +21,8 @@ public class PdfSettingsForm : EtoDialogBase
|
|||||||
private readonly CheckBox _rememberSettings = new() { Text = UiStrings.RememberTheseSettings };
|
private readonly CheckBox _rememberSettings = new() { Text = UiStrings.RememberTheseSettings };
|
||||||
private readonly Button _restoreDefaults = new() { Text = UiStrings.RestoreDefaults };
|
private readonly Button _restoreDefaults = new() { Text = UiStrings.RestoreDefaults };
|
||||||
|
|
||||||
private readonly List<CheckBox> _permissions = new()
|
private readonly List<CheckBox> _permissions =
|
||||||
{
|
[
|
||||||
new CheckBox { Text = UiStrings.AllowPrinting },
|
new CheckBox { Text = UiStrings.AllowPrinting },
|
||||||
new CheckBox { Text = UiStrings.AllowFullQualityPrinting },
|
new CheckBox { Text = UiStrings.AllowFullQualityPrinting },
|
||||||
new CheckBox { Text = UiStrings.AllowDocumentModification },
|
new CheckBox { Text = UiStrings.AllowDocumentModification },
|
||||||
@ -31,7 +31,7 @@ public class PdfSettingsForm : EtoDialogBase
|
|||||||
new CheckBox { Text = UiStrings.AllowContentCopyingForAccessibility },
|
new CheckBox { Text = UiStrings.AllowContentCopyingForAccessibility },
|
||||||
new CheckBox { Text = UiStrings.AllowAnnotations },
|
new CheckBox { Text = UiStrings.AllowAnnotations },
|
||||||
new CheckBox { Text = UiStrings.AllowFormFilling }
|
new CheckBox { Text = UiStrings.AllowFormFilling }
|
||||||
};
|
];
|
||||||
|
|
||||||
private readonly DropDown _compat = C.EnumDropDown<PdfCompat>(compat => compat switch
|
private readonly DropDown _compat = C.EnumDropDown<PdfCompat>(compat => compat switch
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ public class SelectDeviceForm : EtoDialogBase
|
|||||||
private readonly ErrorOutput _errorOutput;
|
private readonly ErrorOutput _errorOutput;
|
||||||
private readonly ListBox _devices = new();
|
private readonly ListBox _devices = new();
|
||||||
private readonly Button _selectDevice;
|
private readonly Button _selectDevice;
|
||||||
private readonly List<ScanDevice> _lazyDeviceList = new();
|
private readonly List<ScanDevice> _lazyDeviceList = [];
|
||||||
// TODO: The spinner doesn't seem to animate on WinForms
|
// TODO: The spinner doesn't seem to animate on WinForms
|
||||||
private readonly Spinner _spinner = new() { Enabled = true };
|
private readonly Spinner _spinner = new() { Enabled = true };
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ using TrimOperation = ListViewDiffs<UiImage>.TrimOperation;
|
|||||||
public class ImageListDiffer
|
public class ImageListDiffer
|
||||||
{
|
{
|
||||||
private readonly UiImageList _imageList;
|
private readonly UiImageList _imageList;
|
||||||
private List<ImageRenderState> _currentState = new();
|
private List<ImageRenderState> _currentState = [];
|
||||||
|
|
||||||
public ImageListDiffer(UiImageList imageList)
|
public ImageListDiffer(UiImageList imageList)
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ public class UiImageList
|
|||||||
private ListSelection<UiImage> _selection;
|
private ListSelection<UiImage> _selection;
|
||||||
private StateToken _savedState = new(ImmutableList<ProcessedImage.WeakReference>.Empty);
|
private StateToken _savedState = new(ImmutableList<ProcessedImage.WeakReference>.Empty);
|
||||||
|
|
||||||
public UiImageList() : this(new List<UiImage>())
|
public UiImageList() : this([])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public class UndoStack : IDisposable
|
|||||||
public UndoStack(int maxLength)
|
public UndoStack(int maxLength)
|
||||||
{
|
{
|
||||||
_maxLength = maxLength;
|
_maxLength = maxLength;
|
||||||
_stack = new LinkedList<Memento>();
|
_stack = [];
|
||||||
_stack.AddFirst(Memento.Empty);
|
_stack.AddFirst(Memento.Empty);
|
||||||
_current = _stack.First!;
|
_current = _stack.First!;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ internal static class SaveSeparatorHelper
|
|||||||
if (images.Count > 0)
|
if (images.Count > 0)
|
||||||
{
|
{
|
||||||
yield return images;
|
yield return images;
|
||||||
images = new List<ProcessedImage>();
|
images = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -48,7 +48,7 @@ public class OcrOperationManager
|
|||||||
}
|
}
|
||||||
op = _currentOp;
|
op = _currentOp;
|
||||||
op.Status.MaxProgress += 1;
|
op.Status.MaxProgress += 1;
|
||||||
_ongoingTasks.GetOrSet((OcrController) sender!, () => new HashSet<Task>()).Add(e.ResultTask);
|
_ongoingTasks.GetOrSet((OcrController) sender!, () => []).Add(e.ResultTask);
|
||||||
}
|
}
|
||||||
op.InvokeStatusChanged();
|
op.InvokeStatusChanged();
|
||||||
if (newOp)
|
if (newOp)
|
||||||
|
@ -4,11 +4,11 @@ namespace NAPS2.Ocr;
|
|||||||
|
|
||||||
public class TesseractLanguageManager
|
public class TesseractLanguageManager
|
||||||
{
|
{
|
||||||
private static readonly List<DownloadMirror> Mirrors = new()
|
private static readonly List<DownloadMirror> Mirrors =
|
||||||
{
|
[
|
||||||
new(@"https://github.com/cyanfish/naps2-components/releases/download/tesseract-4.0.0b4/{0}"),
|
new(@"https://github.com/cyanfish/naps2-components/releases/download/tesseract-4.0.0b4/{0}"),
|
||||||
new(@"https://sourceforge.net/projects/naps2/files/components/tesseract-4.0.0b4/{0}/download")
|
new(@"https://sourceforge.net/projects/naps2/files/components/tesseract-4.0.0b4/{0}/download")
|
||||||
};
|
];
|
||||||
|
|
||||||
private readonly TesseractLanguageData _languageData = TesseractLanguageData.Latest;
|
private readonly TesseractLanguageData _languageData = TesseractLanguageData.Latest;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public class RecoveryIndex
|
|||||||
|
|
||||||
public RecoveryIndex()
|
public RecoveryIndex()
|
||||||
{
|
{
|
||||||
Images = new List<RecoveryIndexImage>();
|
Images = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
|
@ -93,7 +93,7 @@ public class BatchScanPerformer : IBatchScanPerformer
|
|||||||
OcrCancelToken = _cancelToken,
|
OcrCancelToken = _cancelToken,
|
||||||
ThumbnailSize = thumbnailController.RenderSize
|
ThumbnailSize = thumbnailController.RenderSize
|
||||||
};
|
};
|
||||||
_scans = new List<List<ProcessedImage>>();
|
_scans = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Do()
|
public async Task Do()
|
||||||
|
@ -144,7 +144,7 @@ public static class ImageAsserts
|
|||||||
|
|
||||||
public class PixelColorData : IEnumerable<((int x, int y), (int r, int g, int b))>
|
public class PixelColorData : IEnumerable<((int x, int y), (int r, int g, int b))>
|
||||||
{
|
{
|
||||||
private readonly List<((int x, int y), (int r, int g, int b))> _colors = new();
|
private readonly List<((int x, int y), (int r, int g, int b))> _colors = [];
|
||||||
|
|
||||||
public void Add((int x, int y) pos, (int r, int g, int b) color)
|
public void Add((int x, int y) pos, (int r, int g, int b) color)
|
||||||
{
|
{
|
||||||
|
@ -48,11 +48,11 @@ public class BlankDetectorTests : ContextualTests
|
|||||||
return image.CopyWithPixelFormat(pixelFormat);
|
return image.CopyWithPixelFormat(pixelFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> TestCases = new List<object[]>
|
public static IEnumerable<object[]> TestCases =
|
||||||
{
|
[
|
||||||
new object[] { ImagePixelFormat.ARGB32 },
|
new object[] { ImagePixelFormat.ARGB32 },
|
||||||
new object[] { ImagePixelFormat.RGB24 },
|
new object[] { ImagePixelFormat.RGB24 },
|
||||||
new object[] { ImagePixelFormat.Gray8 },
|
new object[] { ImagePixelFormat.Gray8 },
|
||||||
new object[] { ImagePixelFormat.BW1 }
|
new object[] { ImagePixelFormat.BW1 }
|
||||||
};
|
];
|
||||||
}
|
}
|
@ -278,8 +278,8 @@ public class LoadSaveTests : ContextualTests
|
|||||||
(byte[]) ImageResources.ResourceManager.GetObject(resource, CultureInfo.InvariantCulture);
|
(byte[]) ImageResources.ResourceManager.GetObject(resource, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
// TODO: Ignore resolution by default in the existing tests, but have separate tests/test cases for resolution
|
// TODO: Ignore resolution by default in the existing tests, but have separate tests/test cases for resolution
|
||||||
public static IEnumerable<object[]> TestCases = new List<object[]>
|
public static IEnumerable<object[]> TestCases =
|
||||||
{
|
[
|
||||||
new object[]
|
new object[]
|
||||||
{
|
{
|
||||||
ImageFileFormat.Png, ".png", "dog_alpha",
|
ImageFileFormat.Png, ".png", "dog_alpha",
|
||||||
@ -387,5 +387,5 @@ public class LoadSaveTests : ContextualTests
|
|||||||
new[] { ImagePixelFormat.RGB24, ImagePixelFormat.RGB24, ImagePixelFormat.RGB24 }, false
|
new[] { ImagePixelFormat.RGB24, ImagePixelFormat.RGB24, ImagePixelFormat.RGB24 }, false
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
};
|
];
|
||||||
}
|
}
|
@ -462,8 +462,8 @@ public class TransformTests : ContextualTests
|
|||||||
Assert.True(IsDisposed(original));
|
Assert.True(IsDisposed(original));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> CommutativeGrayTransforms = new List<object[]>
|
public static IEnumerable<object[]> CommutativeGrayTransforms =
|
||||||
{
|
[
|
||||||
// Note that hue and saturation aren't commutative with grayscale as the the grayscale transform weighs each
|
// Note that hue and saturation aren't commutative with grayscale as the the grayscale transform weighs each
|
||||||
// color channel differently
|
// color channel differently
|
||||||
new object[] { new BrightnessTransform(300) },
|
new object[] { new BrightnessTransform(300) },
|
||||||
@ -472,5 +472,5 @@ public class TransformTests : ContextualTests
|
|||||||
new object[] { new RotationTransform(46) },
|
new object[] { new RotationTransform(46) },
|
||||||
new object[] { new ThumbnailTransform() },
|
new object[] { new ThumbnailTransform() },
|
||||||
new object[] { new CropTransform(10, 10, 10, 10) }
|
new object[] { new CropTransform(10, 10, 10, 10) }
|
||||||
};
|
];
|
||||||
}
|
}
|
@ -6,9 +6,9 @@ namespace NAPS2.Sdk.Tests.Mocks;
|
|||||||
|
|
||||||
internal class StubScanBridge : IScanBridge
|
internal class StubScanBridge : IScanBridge
|
||||||
{
|
{
|
||||||
public List<ScanDevice> MockDevices { get; set; } = new();
|
public List<ScanDevice> MockDevices { get; set; } = [];
|
||||||
|
|
||||||
public List<ProcessedImage> MockOutput { get; set; } = new();
|
public List<ProcessedImage> MockOutput { get; set; } = [];
|
||||||
|
|
||||||
public Exception Error { get; set; }
|
public Exception Error { get; set; }
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class ScanErrorHandling : ContextualTests
|
|||||||
public async void Scan_LocalPostProcess()
|
public async void Scan_LocalPostProcess()
|
||||||
{
|
{
|
||||||
var localPostProcessor = Substitute.For<ILocalPostProcessor>();
|
var localPostProcessor = Substitute.For<ILocalPostProcessor>();
|
||||||
var bridge = new StubScanBridge { MockOutput = new List<ProcessedImage> { CreateScannedImage() } };
|
var bridge = new StubScanBridge { MockOutput = [CreateScannedImage()] };
|
||||||
var bridgeFactory = Substitute.For<IScanBridgeFactory>();
|
var bridgeFactory = Substitute.For<IScanBridgeFactory>();
|
||||||
var controller =
|
var controller =
|
||||||
new ScanController(ScanningContext, localPostProcessor, new ScanOptionsValidator(),
|
new ScanController(ScanningContext, localPostProcessor, new ScanOptionsValidator(),
|
||||||
|
@ -30,7 +30,7 @@ public class TwainImageProcessorTests : ContextualTests
|
|||||||
_scanEvents = Substitute.For<IScanEvents>();
|
_scanEvents = Substitute.For<IScanEvents>();
|
||||||
_callback = Substitute.For<Action<IMemoryImage>>();
|
_callback = Substitute.For<Action<IMemoryImage>>();
|
||||||
|
|
||||||
_images = new List<IMemoryImage>();
|
_images = [];
|
||||||
_callback.When(x => x(Arg.Any<IMemoryImage>()))
|
_callback.When(x => x(Arg.Any<IMemoryImage>()))
|
||||||
.Do(x => _images.Add((IMemoryImage) x[0]));
|
.Do(x => _images.Add((IMemoryImage) x[0]));
|
||||||
|
|
||||||
|
@ -88,11 +88,11 @@ public class WorkerChannelTests : ContextualTests
|
|||||||
{
|
{
|
||||||
var remoteScanController = new MockRemoteScanController
|
var remoteScanController = new MockRemoteScanController
|
||||||
{
|
{
|
||||||
Images = new List<ProcessedImage>
|
Images =
|
||||||
{
|
[
|
||||||
CreateScannedImage(),
|
CreateScannedImage(),
|
||||||
CreateScannedImage()
|
CreateScannedImage()
|
||||||
}
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
using var channel = Start(remoteScanController);
|
using var channel = Start(remoteScanController);
|
||||||
@ -113,11 +113,11 @@ public class WorkerChannelTests : ContextualTests
|
|||||||
{
|
{
|
||||||
var remoteScanController = new MockRemoteScanController
|
var remoteScanController = new MockRemoteScanController
|
||||||
{
|
{
|
||||||
Images = new List<ProcessedImage>
|
Images =
|
||||||
{
|
[
|
||||||
CreateScannedImage(),
|
CreateScannedImage(),
|
||||||
CreateScannedImage()
|
CreateScannedImage()
|
||||||
},
|
],
|
||||||
Exception = new DeviceException("Test error")
|
Exception = new DeviceException("Test error")
|
||||||
};
|
};
|
||||||
using var channel = Start(remoteScanController);
|
using var channel = Start(remoteScanController);
|
||||||
@ -161,7 +161,7 @@ public class WorkerChannelTests : ContextualTests
|
|||||||
|
|
||||||
private class MockRemoteScanController : IRemoteScanController
|
private class MockRemoteScanController : IRemoteScanController
|
||||||
{
|
{
|
||||||
public List<ProcessedImage> Images { get; set; } = new();
|
public List<ProcessedImage> Images { get; set; } = [];
|
||||||
|
|
||||||
public Exception Exception { get; set; }
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
|
@ -2,19 +2,13 @@
|
|||||||
|
|
||||||
public class EmailMessage
|
public class EmailMessage
|
||||||
{
|
{
|
||||||
public EmailMessage()
|
|
||||||
{
|
|
||||||
Recipients = new List<EmailRecipient>();
|
|
||||||
Attachments = new List<EmailAttachment>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? Subject { get; set; }
|
public string? Subject { get; set; }
|
||||||
|
|
||||||
public string? BodyText { get; set; }
|
public string? BodyText { get; set; }
|
||||||
|
|
||||||
public List<EmailRecipient> Recipients { get; set; }
|
public List<EmailRecipient> Recipients { get; set; } = [];
|
||||||
|
|
||||||
public List<EmailAttachment> Attachments { get; set; }
|
public List<EmailAttachment> Attachments { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether the email should be sent automatically without prompting the user to make changes first.
|
/// Gets or sets a value indicating whether the email should be sent automatically without prompting the user to make changes first.
|
||||||
|
@ -13,7 +13,7 @@ internal class OcrRequestQueue
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<OcrRequestParams, OcrRequest> _requestCache = new();
|
private readonly Dictionary<OcrRequestParams, OcrRequest> _requestCache = new();
|
||||||
private Semaphore _queueWaitHandle = new(0, int.MaxValue);
|
private Semaphore _queueWaitHandle = new(0, int.MaxValue);
|
||||||
private List<Task> _workerTasks = new();
|
private List<Task> _workerTasks = [];
|
||||||
private CancellationTokenSource _workerCts = new();
|
private CancellationTokenSource _workerCts = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -94,7 +94,7 @@ internal class OcrRequestQueue
|
|||||||
if (_workerTasks.Count > 0 && !hasPending)
|
if (_workerTasks.Count > 0 && !hasPending)
|
||||||
{
|
{
|
||||||
_workerCts.Cancel();
|
_workerCts.Cancel();
|
||||||
_workerTasks = new List<Task>();
|
_workerTasks = [];
|
||||||
_workerCts = new CancellationTokenSource();
|
_workerCts = new CancellationTokenSource();
|
||||||
_queueWaitHandle = new Semaphore(0, int.MaxValue);
|
_queueWaitHandle = new Semaphore(0, int.MaxValue);
|
||||||
}
|
}
|
||||||
|
@ -457,7 +457,7 @@ public class PdfExporter : IPdfExporter
|
|||||||
private static string ReverseText(string text)
|
private static string ReverseText(string text)
|
||||||
{
|
{
|
||||||
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(text);
|
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(text);
|
||||||
List<string> elements = new List<string>();
|
var elements = new List<string>();
|
||||||
while (enumerator.MoveNext())
|
while (enumerator.MoveNext())
|
||||||
{
|
{
|
||||||
elements.Add(enumerator.GetTextElement());
|
elements.Add(enumerator.GetTextElement());
|
||||||
|
@ -99,7 +99,7 @@ internal class ScanJob : IEsclScanJob
|
|||||||
if (ContentType == "application/pdf")
|
if (ContentType == "application/pdf")
|
||||||
{
|
{
|
||||||
var pdfExporter = new PdfExporter(_scanningContext);
|
var pdfExporter = new PdfExporter(_scanningContext);
|
||||||
await pdfExporter.Export(stream, new List<ProcessedImage> { _enumerable.Current });
|
await pdfExporter.Export(stream, [_enumerable.Current]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ internal static class BarcodeDetector
|
|||||||
var zxingOptions = options.ZXingOptions ?? new DecodingOptions
|
var zxingOptions = options.ZXingOptions ?? new DecodingOptions
|
||||||
{
|
{
|
||||||
TryHarder = true,
|
TryHarder = true,
|
||||||
PossibleFormats = options.PatchTOnly ? new List<BarcodeFormat> { PATCH_T_FORMAT } : null
|
PossibleFormats = options.PatchTOnly ? [PATCH_T_FORMAT] : null
|
||||||
};
|
};
|
||||||
var reader = new BarcodeReader<IMemoryImage>(x => new MemoryImageLuminanceSource(x))
|
var reader = new BarcodeReader<IMemoryImage>(x => new MemoryImageLuminanceSource(x))
|
||||||
{
|
{
|
||||||
|
@ -12,5 +12,5 @@ public class TranslatableString
|
|||||||
|
|
||||||
public string? Translation { get; }
|
public string? Translation { get; }
|
||||||
|
|
||||||
public List<string> Context { get; } = new List<string>();
|
public List<string> Context { get; } = [];
|
||||||
}
|
}
|
@ -59,7 +59,7 @@ public static class Program
|
|||||||
|
|
||||||
public class CommandList
|
public class CommandList
|
||||||
{
|
{
|
||||||
private readonly List<Type> _optionTypes = new();
|
private readonly List<Type> _optionTypes = [];
|
||||||
private readonly Dictionary<Type, Type> _optionTypeToCommandType = new();
|
private readonly Dictionary<Type, Type> _optionTypeToCommandType = new();
|
||||||
|
|
||||||
public CommandList Add<TOption, TCommand>() where TOption : OptionsBase where TCommand : ICommand<TOption>
|
public CommandList Add<TOption, TCommand>() where TOption : OptionsBase where TCommand : ICommand<TOption>
|
||||||
|
@ -4,8 +4,8 @@ namespace NAPS2.Tools.Project.Packaging;
|
|||||||
|
|
||||||
public class PackageInfo
|
public class PackageInfo
|
||||||
{
|
{
|
||||||
private readonly List<PackageFile> _files = new();
|
private readonly List<PackageFile> _files = [];
|
||||||
private readonly HashSet<string> _destPaths = new();
|
private readonly HashSet<string> _destPaths = [];
|
||||||
|
|
||||||
public PackageInfo(Platform platform, string versionName, string versionNumber, string? packageName)
|
public PackageInfo(Platform platform, string versionName, string versionNumber, string? packageName)
|
||||||
{
|
{
|
||||||
@ -30,7 +30,7 @@ public class PackageInfo
|
|||||||
|
|
||||||
public IEnumerable<PackageFile> Files => _files;
|
public IEnumerable<PackageFile> Files => _files;
|
||||||
|
|
||||||
public HashSet<string> Languages { get; } = new();
|
public HashSet<string> Languages { get; } = [];
|
||||||
|
|
||||||
public void AddFile(FileInfo file, string destFolder, string? destFileName = null)
|
public void AddFile(FileInfo file, string destFolder, string? destFileName = null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user