Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Nov 25, 2023
1 parent 804f110 commit 8a7c304
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 119 deletions.
1 change: 0 additions & 1 deletion NAPS2.Escl.Server/EsclServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private void StartServer(EsclDeviceConfig deviceConfig)
.WithMode(HttpListenerMode.EmbedIO)
.WithUrlPrefix(url))
.WithWebApi("/escl", m => m.WithController(() => new EsclApiController(deviceConfig, serverState)));
server.HandleHttpException(async (_, _) => { });
server.StateChanged += ServerOnStateChanged;
server.RunAsync(CancellationTokenSource.CreateLinkedTokenSource(_cts.Token, _devices[deviceConfig].Token).Token);
}
Expand Down
8 changes: 4 additions & 4 deletions NAPS2.Images.Mac/MacImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public MacImage(ImageContext imageContext, NSImage image)
}
PixelFormat = GetPixelFormat(Rep);
// TODO: Any replacement for deprecated ColorSpaceName?
#pragma warning disable CA1416
#pragma warning disable CA1416,CA1422
bool isDeviceColorSpace = Rep.ColorSpaceName == NSColorSpace.DeviceRGB ||
Rep.ColorSpaceName == NSColorSpace.DeviceWhite;
#pragma warning restore CA1416
#pragma warning restore CA1416,CA1422
if (PixelFormat == ImagePixelFormat.Unsupported)
{
var rep = MacBitmapHelper.CopyRep(Rep);
Expand Down Expand Up @@ -153,13 +153,13 @@ private NSData GetRepForSaving(ImageFileFormat imageFormat, ImageSaveOptions? op
var fileType = imageFormat switch
{
// TODO: Any replacement for deprecated UTType?
#pragma warning disable CA1416
#pragma warning disable CA1416,CA1422
ImageFileFormat.Jpeg => UTType.JPEG,
ImageFileFormat.Png => UTType.PNG,
ImageFileFormat.Bmp => UTType.BMP,
ImageFileFormat.Tiff => UTType.TIFF,
ImageFileFormat.Jpeg2000 => UTType.JPEG2000,
#pragma warning restore CA1416
#pragma warning restore CA1416,CA1422
_ => throw new InvalidOperationException("Unsupported image format")
};
var targetFormat = options.PixelFormatHint;
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Images.Mac/MacImageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override IMemoryImage LoadCore(Stream stream, ImageFileFormat format)
{
lock (ConstructorLock)
{
var image = NSImage.FromStream(stream);
var image = NSImage.FromStream(stream)!;
var reps = image.Representations();
try
{
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Images.Mac/MacTiffWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static NSData GetTiffData(IList<IMemoryImage> images, TiffCompressionTyp
{
data = new NSMutableData();
// TODO: We get a warning for UTType
#pragma warning disable CA1416
#pragma warning disable CA1416,CA1422
#if MONOMAC
dest = CGImageDestination.FromData(
#else
Expand Down
72 changes: 36 additions & 36 deletions NAPS2.Lib.WinForms/EtoForms/Ui/WinFormsDesktopForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
using NAPS2.EtoForms.WinForms;
using NAPS2.ImportExport.Images;
using NAPS2.WinForms;
using wf = System.Windows.Forms;
using WF = System.Windows.Forms;

namespace NAPS2.EtoForms.Ui;

public class WinFormsDesktopForm : DesktopForm
{
public static wf.ApplicationContext? ApplicationContext { get; set; }
public static WF.ApplicationContext? ApplicationContext { get; set; }

private readonly Dictionary<DesktopToolbarMenuType, wf.ToolStripSplitButton> _menuButtons = new();
private readonly Dictionary<DesktopToolbarMenuType, WF.ToolStripSplitButton> _menuButtons = new();
private readonly ToolbarFormatter _toolbarFormatter = new(new StringWrapper());
private readonly wf.Form _form;
private wf.ToolStrip _toolStrip = null!;
private wf.ToolStripContainer _container = null!;
private readonly WF.Form _form;
private WF.ToolStrip _toolStrip = null!;
private WF.ToolStripContainer _container = null!;

public WinFormsDesktopForm(
Naps2Config config,
Expand Down Expand Up @@ -56,9 +56,9 @@ protected override void OnClosing(CancelEventArgs e)
// That allows us to check the close reason (which Eto doesn't provide)
}

private void OnFormClosing(object? sender, wf.FormClosingEventArgs e)
private void OnFormClosing(object? sender, WF.FormClosingEventArgs e)
{
if (!_desktopController.PrepareForClosing(e.CloseReason == wf.CloseReason.UserClosing))
if (!_desktopController.PrepareForClosing(e.CloseReason == WF.CloseReason.UserClosing))
{
e.Cancel = true;
}
Expand All @@ -77,7 +77,7 @@ protected override void OnLoad(EventArgs e)
LoadToolStripLocation();

NativeListView.TabIndex = 7;
NativeListView.Dock = wf.DockStyle.Fill;
NativeListView.Dock = WF.DockStyle.Fill;
NativeListView.Focus();
}

Expand All @@ -92,19 +92,19 @@ protected override LayoutElement GetZoomButtons()
// Disabled buttons don't prevent click events from being sent to the listview below the button, so without this
// "mouse catcher" control you could e.g. spam click zoom out until it's maxed and then accidentally keep
// clicking and change the listview selection.
var mouseCatcher = new wf.Button
var mouseCatcher = new WF.Button
{
BackColor = Color.White,
Size = new Size(45, 23),
FlatStyle = wf.FlatStyle.Flat
FlatStyle = WF.FlatStyle.Flat
};
return L.Overlay(
L.Row(mouseCatcher.ToEto().AlignTrailing()),
base.GetZoomButtons()
);
}

private wf.ListView NativeListView => ((WinFormsListView<UiImage>) _listView).NativeControl;
private WF.ListView NativeListView => ((WinFormsListView<UiImage>) _listView).NativeControl;

protected override void SetMainForm(Form newMainForm)
{
Expand Down Expand Up @@ -134,16 +134,16 @@ protected override void ConfigureToolbar()

protected override LayoutElement GetMainContent()
{
_container = new wf.ToolStripContainer();
_container = new WF.ToolStripContainer();
_container.TopToolStripPanel.Controls.Add(_toolStrip);
foreach (var panel in _container.Controls.OfType<wf.ToolStripPanel>())
foreach (var panel in _container.Controls.OfType<WF.ToolStripPanel>())
{
// Allow tabbing through the toolbar for accessibility
WinFormsHacks.SetControlStyle(panel, wf.ControlStyles.Selectable, true);
WinFormsHacks.SetControlStyle(panel, WF.ControlStyles.Selectable, true);
}

var wfContent = _listView.Control.ToNative();
wfContent.Dock = wf.DockStyle.Fill;
wfContent.Dock = WF.DockStyle.Fill;
_container.ContentPanel.Controls.Add(wfContent);

return _container.ToEto();
Expand All @@ -163,9 +163,9 @@ protected override void SetThumbnailSpacing(int thumbnailSize)

protected override void CreateToolbarButton(Command command)
{
var item = new wf.ToolStripButton
var item = new WF.ToolStripButton
{
TextImageRelation = wf.TextImageRelation.ImageAboveText
TextImageRelation = WF.TextImageRelation.ImageAboveText
};
ApplyCommand(item, command);
_toolStrip.Items.Add(item);
Expand All @@ -174,34 +174,34 @@ protected override void CreateToolbarButton(Command command)
protected override void CreateToolbarButtonWithMenu(Command command, DesktopToolbarMenuType menuType,
MenuProvider menu)
{
var item = new wf.ToolStripSplitButton
var item = new WF.ToolStripSplitButton
{
TextImageRelation = wf.TextImageRelation.ImageAboveText
TextImageRelation = WF.TextImageRelation.ImageAboveText
};
ApplyCommand(item, command);
_toolStrip.Items.Add(item);
menu.Handle(subItems => SetUpMenu(item, subItems));
_menuButtons[menuType] = item;
}

private void SetUpMenu(wf.ToolStripDropDownItem item, List<MenuProvider.Item> subItems)
private void SetUpMenu(WF.ToolStripDropDownItem item, List<MenuProvider.Item> subItems)
{
item.DropDownItems.Clear();
foreach (var subItem in subItems)
{
switch (subItem)
{
case MenuProvider.SeparatorItem:
item.DropDownItems.Add(new wf.ToolStripSeparator());
item.DropDownItems.Add(new WF.ToolStripSeparator());
break;
case MenuProvider.CommandItem commandSubItem:
item.DropDownItems.Add(ApplyCommand(new wf.ToolStripMenuItem
item.DropDownItems.Add(ApplyCommand(new WF.ToolStripMenuItem
{
ImageScaling = wf.ToolStripItemImageScaling.None
ImageScaling = WF.ToolStripItemImageScaling.None
}, commandSubItem.Command));
break;
case MenuProvider.SubMenuItem subMenuSubItem:
var subMenu = new wf.ToolStripMenuItem();
var subMenu = new WF.ToolStripMenuItem();
ApplyCommand(subMenu, subMenuSubItem.Command);
// TODO: If submenus are dynamic this will memory leak or something
subMenuSubItem.MenuProvider.Handle(subSubItems => SetUpMenu(subMenu, subSubItems));
Expand All @@ -213,9 +213,9 @@ private void SetUpMenu(wf.ToolStripDropDownItem item, List<MenuProvider.Item> su

protected override void CreateToolbarMenu(Command command, MenuProvider menu)
{
var item = new wf.ToolStripDropDownButton
var item = new WF.ToolStripDropDownButton
{
TextImageRelation = wf.TextImageRelation.ImageAboveText,
TextImageRelation = WF.TextImageRelation.ImageAboveText,
ShowDropDownArrow = false
};
ApplyCommand(item, command);
Expand All @@ -238,9 +238,9 @@ protected override void CreateToolbarStackedButtons(Command command1, Command co
_toolStrip.Items.Add(item);
}

private wf.ToolStripItem ApplyCommand(wf.ToolStripItem item, Command command)
private WF.ToolStripItem ApplyCommand(WF.ToolStripItem item, Command command)
{
void SetItemText() => item.Text = item is wf.ToolStripMenuItem ? command.MenuText : command.ToolBarText;
void SetItemText() => item.Text = item is WF.ToolStripMenuItem ? command.MenuText : command.ToolBarText;
item.Image = command.Image.ToSD();
SetItemText();
if (command is ActionCommand actionCommand)
Expand All @@ -249,12 +249,12 @@ private wf.ToolStripItem ApplyCommand(wf.ToolStripItem item, Command command)
}
// TODO: We want a better way of determining which keyboard shortcuts are worth showing
// Ideally we could show them all, but it can be really distracting. So only showing F2/F3 etc. right now.
if (item is wf.ToolStripMenuItem menuItem && !command.Shortcut.ToString().Contains(","))
if (item is WF.ToolStripMenuItem menuItem && !command.Shortcut.ToString().Contains(","))
{
menuItem.ShortcutKeys = command.Shortcut.ToSWF();
}
command.EnabledChanged += (_, _) => item.Enabled = command.Enabled;
if (item is wf.ToolStripSplitButton button)
if (item is WF.ToolStripSplitButton button)
{
button.ButtonClick += (_, _) => command.Execute();
}
Expand All @@ -267,7 +267,7 @@ private wf.ToolStripItem ApplyCommand(wf.ToolStripItem item, Command command)

protected override void CreateToolbarSeparator()
{
_toolStrip.Items.Add(new wf.ToolStripSeparator());
_toolStrip.Items.Add(new WF.ToolStripSeparator());
}

public override void ShowToolbarMenu(DesktopToolbarMenuType menuType)
Expand All @@ -277,20 +277,20 @@ public override void ShowToolbarMenu(DesktopToolbarMenuType menuType)

private void SaveToolStripLocation()
{
Config.User.Set(c => c.DesktopToolStripDock, _toolStrip.Parent.Dock.ToConfig());
Config.User.Set(c => c.DesktopToolStripDock, _toolStrip.Parent!.Dock.ToConfig());
}

private void LoadToolStripLocation()
{
var dock = Config.Get(c => c.DesktopToolStripDock).ToWinForms();
if (dock != wf.DockStyle.None)
if (dock != WF.DockStyle.None)
{
var panel = _container.Controls.OfType<wf.ToolStripPanel>().FirstOrDefault(x => x.Dock == dock);
var panel = _container.Controls.OfType<WF.ToolStripPanel>().FirstOrDefault(x => x.Dock == dock);
if (panel != null)
{
_toolStrip.Parent = panel;
}
}
_toolStrip.Parent.TabStop = true;
_toolStrip.Parent!.TabStop = true;
}
}
Loading

0 comments on commit 8a7c304

Please sign in to comment.