mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Implement SaveButtonDefaultAction prompts
This commit is contained in:
parent
65c946e280
commit
2c2f2a2c29
@ -5,7 +5,6 @@ using Gdk;
|
||||
using Gtk;
|
||||
using NAPS2.EtoForms.Desktop;
|
||||
using NAPS2.EtoForms.Gtk;
|
||||
using NAPS2.EtoForms.Layout;
|
||||
using NAPS2.ImportExport.Images;
|
||||
using Command = Eto.Forms.Command;
|
||||
|
||||
@ -13,6 +12,7 @@ namespace NAPS2.EtoForms.Ui;
|
||||
|
||||
public class GtkDesktopForm : DesktopForm
|
||||
{
|
||||
private readonly Dictionary<DesktopToolbarMenuType, MenuToolButton> _menuButtons = new();
|
||||
private Toolbar _toolbar = null!;
|
||||
private int _toolbarButtonCount;
|
||||
private int _toolbarMenuToggleCount;
|
||||
@ -130,7 +130,8 @@ public class GtkDesktopForm : DesktopForm
|
||||
_toolbarButtonCount++;
|
||||
}
|
||||
|
||||
protected override void CreateToolbarButtonWithMenu(Command command, MenuProvider menu)
|
||||
protected override void CreateToolbarButtonWithMenu(Command command, DesktopToolbarMenuType menuType,
|
||||
MenuProvider menu)
|
||||
{
|
||||
var button = new MenuToolButton(command.Image.ToGtk(), command.ToolBarText)
|
||||
{
|
||||
@ -144,6 +145,7 @@ public class GtkDesktopForm : DesktopForm
|
||||
_toolbar.Add(button);
|
||||
_toolbarButtonCount++;
|
||||
_toolbarMenuToggleCount++;
|
||||
_menuButtons[menuType] = button;
|
||||
}
|
||||
|
||||
protected override void CreateToolbarMenu(Command command, MenuProvider menu)
|
||||
@ -215,6 +217,12 @@ public class GtkDesktopForm : DesktopForm
|
||||
return (_, _) => menuWidget.PopupAtWidget(button, Gravity.SouthWest, Gravity.NorthWest, null);
|
||||
}
|
||||
|
||||
public override void ShowToolbarMenu(DesktopToolbarMenuType menuType)
|
||||
{
|
||||
var button = _menuButtons.Get(menuType);
|
||||
(button?.Menu as Menu)?.PopupAtWidget(button, Gravity.SouthWest, Gravity.NorthWest, null);
|
||||
}
|
||||
|
||||
private void AddCustomToolItem(Widget item)
|
||||
{
|
||||
var toolItem = new ToolItem();
|
||||
|
@ -74,7 +74,6 @@ public class DesktopControllerTests : ContextualTests
|
||||
_imageClipboard,
|
||||
new ImageListActions(_imageList, _operationFactory.Object, _operationProgress.Object,
|
||||
_config, _thumbnailController, _exportHelper.Object, _notificationManager.Object),
|
||||
_exportHelper.Object,
|
||||
_dialogHelper.Object,
|
||||
_desktopImagesController,
|
||||
_desktopScanController.Object,
|
||||
|
@ -15,6 +15,7 @@ public class WinFormsDesktopForm : DesktopForm
|
||||
{
|
||||
public static wf.ApplicationContext? ApplicationContext { get; set; }
|
||||
|
||||
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!;
|
||||
@ -139,7 +140,8 @@ public class WinFormsDesktopForm : DesktopForm
|
||||
_toolStrip.Items.Add(item);
|
||||
}
|
||||
|
||||
protected override void CreateToolbarButtonWithMenu(Command command, MenuProvider menu)
|
||||
protected override void CreateToolbarButtonWithMenu(Command command, DesktopToolbarMenuType menuType,
|
||||
MenuProvider menu)
|
||||
{
|
||||
var item = new wf.ToolStripSplitButton
|
||||
{
|
||||
@ -148,6 +150,7 @@ public class WinFormsDesktopForm : DesktopForm
|
||||
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)
|
||||
@ -236,6 +239,11 @@ public class WinFormsDesktopForm : DesktopForm
|
||||
_toolStrip.Items.Add(new wf.ToolStripSeparator());
|
||||
}
|
||||
|
||||
public override void ShowToolbarMenu(DesktopToolbarMenuType menuType)
|
||||
{
|
||||
_menuButtons.Get(menuType)?.ShowDropDown();
|
||||
}
|
||||
|
||||
|
||||
// TODO: Call these
|
||||
|
||||
|
@ -25,7 +25,6 @@ public class DesktopController
|
||||
private readonly ImageTransfer _imageTransfer;
|
||||
private readonly ImageClipboard _imageClipboard;
|
||||
private readonly ImageListActions _imageListActions;
|
||||
private readonly IExportController _exportController;
|
||||
private readonly DialogHelper _dialogHelper;
|
||||
private readonly DesktopImagesController _desktopImagesController;
|
||||
private readonly IDesktopScanController _desktopScanController;
|
||||
@ -41,7 +40,7 @@ public class DesktopController
|
||||
OperationProgress operationProgress, Naps2Config config, IOperationFactory operationFactory,
|
||||
StillImage stillImage,
|
||||
IUpdateChecker updateChecker, INotificationManager notify, ImageTransfer imageTransfer,
|
||||
ImageClipboard imageClipboard, ImageListActions imageListActions, IExportController exportController,
|
||||
ImageClipboard imageClipboard, ImageListActions imageListActions,
|
||||
DialogHelper dialogHelper,
|
||||
DesktopImagesController desktopImagesController, IDesktopScanController desktopScanController,
|
||||
DesktopFormProvider desktopFormProvider, IScannedImagePrinter scannedImagePrinter)
|
||||
@ -59,7 +58,6 @@ public class DesktopController
|
||||
_imageTransfer = imageTransfer;
|
||||
_imageClipboard = imageClipboard;
|
||||
_imageListActions = imageListActions;
|
||||
_exportController = exportController;
|
||||
_dialogHelper = dialogHelper;
|
||||
_desktopImagesController = desktopImagesController;
|
||||
_desktopScanController = desktopScanController;
|
||||
@ -409,8 +407,7 @@ public class DesktopController
|
||||
if (action == SaveButtonDefaultAction.AlwaysPrompt
|
||||
|| action == SaveButtonDefaultAction.PromptIfSelected && _imageList.Selection.Any())
|
||||
{
|
||||
// TODO
|
||||
// tsdSavePDF.ShowDropDown();
|
||||
_desktopFormProvider.DesktopForm.ShowToolbarMenu(DesktopToolbarMenuType.SavePdf);
|
||||
}
|
||||
else if (action == SaveButtonDefaultAction.SaveSelected && _imageList.Selection.Any())
|
||||
{
|
||||
@ -429,8 +426,7 @@ public class DesktopController
|
||||
if (action == SaveButtonDefaultAction.AlwaysPrompt
|
||||
|| action == SaveButtonDefaultAction.PromptIfSelected && _imageList.Selection.Any())
|
||||
{
|
||||
// TODO
|
||||
// tsdSaveImages.ShowDropDown();
|
||||
_desktopFormProvider.DesktopForm.ShowToolbarMenu(DesktopToolbarMenuType.SaveImages);
|
||||
}
|
||||
else if (action == SaveButtonDefaultAction.SaveSelected && _imageList.Selection.Any())
|
||||
{
|
||||
@ -449,8 +445,7 @@ public class DesktopController
|
||||
if (action == SaveButtonDefaultAction.AlwaysPrompt
|
||||
|| action == SaveButtonDefaultAction.PromptIfSelected && _imageList.Selection.Any())
|
||||
{
|
||||
// TODO
|
||||
// tsdEmailPDF.ShowDropDown();
|
||||
_desktopFormProvider.DesktopForm.ShowToolbarMenu(DesktopToolbarMenuType.EmailPdf);
|
||||
}
|
||||
else if (action == SaveButtonDefaultAction.SaveSelected && _imageList.Selection.Any())
|
||||
{
|
||||
|
@ -1,10 +1,12 @@
|
||||
using NAPS2.EtoForms.Ui;
|
||||
|
||||
namespace NAPS2.EtoForms.Desktop;
|
||||
|
||||
public class DesktopFormProvider
|
||||
{
|
||||
private EtoFormBase? _desktopForm;
|
||||
private DesktopForm? _desktopForm;
|
||||
|
||||
public EtoFormBase DesktopForm
|
||||
public DesktopForm DesktopForm
|
||||
{
|
||||
get => _desktopForm ?? throw new InvalidOperationException();
|
||||
set
|
||||
|
9
NAPS2.Lib/EtoForms/Desktop/DesktopToolbarMenuType.cs
Normal file
9
NAPS2.Lib/EtoForms/Desktop/DesktopToolbarMenuType.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace NAPS2.EtoForms.Desktop;
|
||||
|
||||
public enum DesktopToolbarMenuType
|
||||
{
|
||||
Scan,
|
||||
SavePdf,
|
||||
SaveImages,
|
||||
EmailPdf
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
@ -225,7 +224,7 @@ public abstract class DesktopForm : EtoFormBase
|
||||
var hiddenButtons = Config.Get(c => c.HiddenButtons);
|
||||
|
||||
if (!hiddenButtons.HasFlag(ToolbarButtons.Scan))
|
||||
CreateToolbarButtonWithMenu(Commands.Scan, new MenuProvider()
|
||||
CreateToolbarButtonWithMenu(Commands.Scan, DesktopToolbarMenuType.Scan, new MenuProvider()
|
||||
.Dynamic(_scanMenuCommands)
|
||||
.Separator()
|
||||
.Append(Commands.NewProfile)
|
||||
@ -238,19 +237,19 @@ public abstract class DesktopForm : EtoFormBase
|
||||
CreateToolbarButton(Commands.Import);
|
||||
CreateToolbarSeparator();
|
||||
if (!hiddenButtons.HasFlag(ToolbarButtons.SavePdf))
|
||||
CreateToolbarButtonWithMenu(Commands.SavePdf, new MenuProvider()
|
||||
CreateToolbarButtonWithMenu(Commands.SavePdf, DesktopToolbarMenuType.SavePdf, new MenuProvider()
|
||||
.Append(Commands.SaveAllPdf)
|
||||
.Append(Commands.SaveSelectedPdf)
|
||||
.Separator()
|
||||
.Append(Commands.PdfSettings));
|
||||
if (!hiddenButtons.HasFlag(ToolbarButtons.SaveImages))
|
||||
CreateToolbarButtonWithMenu(Commands.SaveImages, new MenuProvider()
|
||||
CreateToolbarButtonWithMenu(Commands.SaveImages, DesktopToolbarMenuType.SaveImages, new MenuProvider()
|
||||
.Append(Commands.SaveAllImages)
|
||||
.Append(Commands.SaveSelectedImages)
|
||||
.Separator()
|
||||
.Append(Commands.ImageSettings));
|
||||
if (!hiddenButtons.HasFlag(ToolbarButtons.EmailPdf) && PlatformCompat.System.CanEmail)
|
||||
CreateToolbarButtonWithMenu(Commands.EmailPdf, new MenuProvider()
|
||||
CreateToolbarButtonWithMenu(Commands.EmailPdf, DesktopToolbarMenuType.EmailPdf, new MenuProvider()
|
||||
.Append(Commands.EmailAll)
|
||||
.Append(Commands.EmailSelected)
|
||||
.Separator()
|
||||
@ -298,6 +297,10 @@ public abstract class DesktopForm : EtoFormBase
|
||||
CreateToolbarButton(Commands.About);
|
||||
}
|
||||
|
||||
public virtual void ShowToolbarMenu(DesktopToolbarMenuType menuType)
|
||||
{
|
||||
}
|
||||
|
||||
protected MenuProvider GetRotateMenuProvider() =>
|
||||
new MenuProvider()
|
||||
.Append(Commands.RotateLeft)
|
||||
@ -317,7 +320,8 @@ public abstract class DesktopForm : EtoFormBase
|
||||
|
||||
protected virtual void CreateToolbarButton(Command command) => throw new InvalidOperationException();
|
||||
|
||||
protected virtual void CreateToolbarButtonWithMenu(Command command, MenuProvider menu) =>
|
||||
protected virtual void CreateToolbarButtonWithMenu(Command command, DesktopToolbarMenuType menuType,
|
||||
MenuProvider menu) =>
|
||||
throw new InvalidOperationException();
|
||||
|
||||
protected virtual void CreateToolbarMenu(Command command, MenuProvider menu) =>
|
||||
|
Loading…
Reference in New Issue
Block a user