mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-17 10:47:11 +03:00
Migrate select device form to Eto
This commit is contained in:
parent
834d8c37f9
commit
47376fb6a0
@ -26,7 +26,6 @@ public class MacModule : NinjectModule
|
||||
Bind<INotificationManager>().To<StubNotificationManager>().InSingletonScope();
|
||||
Bind<ISaveNotify>().ToMethod(ctx => ctx.Kernel.Get<INotificationManager>());
|
||||
Bind<IScannedImagePrinter>().To<StubScannedImagePrinter>();
|
||||
Bind<IDevicePrompt>().To<StubDevicePrompt>();
|
||||
Bind<DesktopController>().ToSelf().InSingletonScope();
|
||||
Bind<IUpdateChecker>().To<UpdateChecker>();
|
||||
Bind<IWinFormsExportHelper>().To<StubExportHelper>();
|
||||
@ -165,14 +164,6 @@ public class StubExportHelper : IWinFormsExportHelper
|
||||
}
|
||||
}
|
||||
|
||||
public class StubDevicePrompt : IDevicePrompt
|
||||
{
|
||||
public ScanDevice? PromptForDevice(List<ScanDevice> deviceList, IntPtr dialogParent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class StubScannedImagePrinter : IScannedImagePrinter
|
||||
{
|
||||
public Task<bool> PromptToPrint(IList<ProcessedImage> images, IList<ProcessedImage> selectedImages)
|
||||
|
@ -26,7 +26,6 @@ public class WinFormsModule : NinjectModule
|
||||
Bind<INotificationManager>().To<NotificationManager>().InSingletonScope();
|
||||
Bind<ISaveNotify>().ToMethod(ctx => ctx.Kernel.Get<INotificationManager>());
|
||||
Bind<IScannedImagePrinter>().To<PrintDocumentPrinter>();
|
||||
Bind<IDevicePrompt>().To<WinFormsDevicePrompt>();
|
||||
Bind<DesktopController>().ToSelf().InSingletonScope();
|
||||
Bind<IUpdateChecker>().To<UpdateChecker>();
|
||||
Bind<IWinFormsExportHelper>().To<WinFormsExportHelper>();
|
||||
|
@ -1,22 +1,23 @@
|
||||
using NAPS2.Platform.Windows;
|
||||
using NAPS2.EtoForms.Ui;
|
||||
using NAPS2.Scan;
|
||||
using NAPS2.WinForms;
|
||||
|
||||
namespace NAPS2.WinForms;
|
||||
namespace NAPS2.EtoForms;
|
||||
|
||||
public class WinFormsDevicePrompt : IDevicePrompt
|
||||
public class EtoDevicePrompt : IDevicePrompt
|
||||
{
|
||||
private readonly IFormFactory _formFactory;
|
||||
|
||||
public WinFormsDevicePrompt(IFormFactory formFactory)
|
||||
public EtoDevicePrompt(IFormFactory formFactory)
|
||||
{
|
||||
_formFactory = formFactory;
|
||||
}
|
||||
|
||||
public ScanDevice? PromptForDevice(List<ScanDevice> deviceList, IntPtr dialogParent)
|
||||
{
|
||||
var deviceForm = _formFactory.Create<FSelectDevice>();
|
||||
var deviceForm = _formFactory.Create<SelectDeviceForm>();
|
||||
deviceForm.DeviceList = deviceList;
|
||||
deviceForm.ShowDialog(new Win32Window(dialogParent));
|
||||
deviceForm.ShowModal();
|
||||
return deviceForm.SelectedDevice;
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ public class EditProfileForm : EtoDialogBase
|
||||
_appleDriver = new RadioButton(_wiaDriver) { Text = UiStrings.AppleDriver };
|
||||
_saneDriver = new RadioButton(_wiaDriver) { Text = UiStrings.SaneDriver };
|
||||
_predefinedSettings = new RadioButton { Text = UiStrings.UsePredefinedSettings };
|
||||
_nativeUi = new RadioButton(_nativeUi) { Text = UiStrings.UseNativeUi };
|
||||
_nativeUi = new RadioButton(_predefinedSettings) { Text = UiStrings.UseNativeUi };
|
||||
_pageSize.SelectedIndexChanged += PageSize_SelectedIndexChanged;
|
||||
_contrastSlider.ValueChanged += ContrastSlider_Scroll;
|
||||
_contrastText.TextChanged += ContrastText_TextChanged;
|
||||
|
82
NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs
Normal file
82
NAPS2.Lib/EtoForms/Ui/SelectDeviceForm.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using NAPS2.Scan;
|
||||
|
||||
namespace NAPS2.EtoForms.Ui;
|
||||
|
||||
public class SelectDeviceForm : EtoDialogBase
|
||||
{
|
||||
private readonly ListBox _devices;
|
||||
|
||||
public SelectDeviceForm(Naps2Config config) : base(config)
|
||||
{
|
||||
FormStateController.SaveFormState = false;
|
||||
FormStateController.RestoreFormState = false;
|
||||
|
||||
var selectButton = new Button
|
||||
{
|
||||
Text = UiStrings.Select
|
||||
};
|
||||
DefaultButton = selectButton;
|
||||
var cancelButton = new Button
|
||||
{
|
||||
Text = UiStrings.Cancel
|
||||
};
|
||||
AbortButton = cancelButton;
|
||||
|
||||
_devices = new ListBox();
|
||||
|
||||
selectButton.Click += Select_Click;
|
||||
cancelButton.Click += Cancel_Click;
|
||||
|
||||
Title = UiStrings.SelectSource;
|
||||
Size = new Size(330, 170);
|
||||
Content = L.Root(
|
||||
L.Row(
|
||||
_devices.XScale(),
|
||||
L.Column(
|
||||
selectButton,
|
||||
cancelButton,
|
||||
C.ZeroSpace().YScale()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public List<ScanDevice> DeviceList { get; set; } = null!;
|
||||
|
||||
public ScanDevice? SelectedDevice { get; private set; }
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
foreach (var device in DeviceList)
|
||||
{
|
||||
_devices.Items.Add(new ListItem
|
||||
{
|
||||
Key = device.ID,
|
||||
Text = device.Name
|
||||
});
|
||||
}
|
||||
if (_devices.Items.Count > 0)
|
||||
{
|
||||
_devices.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void Select_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (_devices.SelectedValue == null)
|
||||
{
|
||||
_devices.Focus();
|
||||
return;
|
||||
}
|
||||
SelectedDevice = DeviceList.FirstOrDefault(x => x.ID == _devices.SelectedKey);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Cancel_Click(object? sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
18
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
18
NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs
generated
@ -743,6 +743,24 @@ namespace NAPS2.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Select.
|
||||
/// </summary>
|
||||
internal static string Select {
|
||||
get {
|
||||
return ResourceManager.GetString("Select", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Select Source.
|
||||
/// </summary>
|
||||
internal static string SelectSource {
|
||||
get {
|
||||
return ResourceManager.GetString("SelectSource", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Set Default.
|
||||
/// </summary>
|
||||
|
@ -384,4 +384,10 @@
|
||||
<data name="Cancel" xml:space="preserve">
|
||||
<value>Cancel</value>
|
||||
</data>
|
||||
<data name="Select" xml:space="preserve">
|
||||
<value>Select</value>
|
||||
</data>
|
||||
<data name="SelectSource" xml:space="preserve">
|
||||
<value>Select Source</value>
|
||||
</data>
|
||||
</root>
|
@ -1,4 +1,5 @@
|
||||
using NAPS2.ImportExport;
|
||||
using NAPS2.EtoForms;
|
||||
using NAPS2.ImportExport;
|
||||
using NAPS2.ImportExport.Email;
|
||||
using NAPS2.ImportExport.Email.Mapi;
|
||||
using NAPS2.ImportExport.Images;
|
||||
@ -64,6 +65,7 @@ public class CommonModule : NinjectModule
|
||||
Bind<ScanningContext>().ToSelf().InSingletonScope();
|
||||
Bind<OcrOperationManager>().ToSelf().InSingletonScope();
|
||||
Bind<ThumbnailRenderQueue>().ToSelf().InSingletonScope();
|
||||
Bind<IDevicePrompt>().To<EtoDevicePrompt>();
|
||||
|
||||
//Kernel.Get<ImageContext>().PdfRenderer = Kernel.Get<PdfiumWorkerCoordinator>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user