using System.Collections.Generic;
using Pinta.Actions;
using Pinta.Core;
namespace Pinta;
public sealed class ActionHandlers
{
private readonly List<IActionHandler> action_handlers;
public ActionHandlers ()
{
ChromeManager chrome = PintaCore.Chrome;
WorkspaceManager workspace = PintaCore.Workspace;
ActionManager actions = PintaCore.Actions;
RecentFileManager recentFiles = PintaCore.RecentFiles;
ImageConverterManager imageFormats = PintaCore.ImageFormats;
SettingsManager settings = PintaCore.Settings;
SystemManager system = PintaCore.System;
ToolManager tools = PintaCore.Tools;
PaletteManager palette = PintaCore.Palette;
CanvasGridManager canvasGrid = PintaCore.CanvasGrid;
string applicationVersion = PintaCore.ApplicationVersion;
action_handlers = [
new NewDocumentAction (actions, chrome, palette, settings, workspace),
new NewScreenshotAction (system, chrome, workspace, actions),
new OpenDocumentAction (actions.File, chrome, workspace, recentFiles, imageFormats),
new SaveDocumentAction (actions.File, workspace),
new SaveDocumentAsAction (actions.File, workspace),
new SaveDocumentImplmentationAction (actions.File, actions.Image, chrome, imageFormats, recentFiles, tools),
new ModifyCompressionAction (actions.File),
new CloseDocumentAction (actions, chrome, workspace, tools),
new ExitProgramAction (actions, chrome, workspace),
new OffsetSelectionAction (actions.Edit, chrome, workspace, tools),
new PasteAction (chrome, actions, workspace, tools),
new PasteIntoNewLayerAction (actions, chrome, workspace, tools),
new PasteIntoNewImageAction (actions, chrome, workspace),
new ResizePaletteAction (actions.Edit, chrome, palette),
new AddinManagerAction (actions.Addins, chrome, system),
new ResizeImageAction (actions.Image, chrome, workspace, settings),
new ResizeCanvasAction (chrome, workspace, settings, actions),
new LayerPropertiesAction (chrome, actions.Layers, workspace),
new RotateZoomLayerAction (chrome, actions.Layers, workspace, tools),
new MenuBarToggledAction (actions.View, chrome),
new ToolBarToggledAction (actions.View, chrome),
new ImageTabsToggledAction (actions.View, chrome),
new ToolWindowsToggledAction (actions.View, chrome),
new StatusBarToggledAction (actions.View, chrome),
new ToolBoxToggledAction (actions.View, chrome),
new ColorSchemeChangedAction (actions.View),
new EditCanvasGridAction (actions.View, chrome, canvasGrid),
new CloseAllDocumentsAction (actions, workspace),
new SaveAllDocumentsAction (actions.Window, workspace),
new AboutDialogAction (actions.App, chrome, applicationVersion),
];
foreach (var action in action_handlers)
action.Initialize ();
PintaCore.Workspace.DocumentActivated += Workspace_DocumentCreated;
PintaCore.Workspace.DocumentClosed += Workspace_DocumentClosed;
ToggleActions (false);
}
private void Workspace_DocumentClosed (object? sender, DocumentEventArgs e)
{
if (!PintaCore.Workspace.HasOpenDocuments)
ToggleActions (false);
}
private void Workspace_DocumentCreated (object? sender, DocumentEventArgs e)
{
ToggleActions (true);
}
private static void ToggleActions (bool enable)
{
PintaCore.Actions.File.Close.Sensitive = enable;
PintaCore.Actions.File.Save.Sensitive = enable;
PintaCore.Actions.File.SaveAs.Sensitive = enable;
PintaCore.Actions.File.Print.Sensitive = enable;
PintaCore.Actions.Edit.Copy.Sensitive = enable;
PintaCore.Actions.Edit.CopyMerged.Sensitive = enable;
PintaCore.Actions.Edit.Cut.Sensitive = enable;
PintaCore.Actions.Edit.PasteIntoNewLayer.Sensitive = enable;
PintaCore.Actions.Edit.EraseSelection.Sensitive = enable;
PintaCore.Actions.Edit.FillSelection.Sensitive = enable;
PintaCore.Actions.Edit.InvertSelection.Sensitive = enable;
PintaCore.Actions.Edit.OffsetSelection.Sensitive = enable;
PintaCore.Actions.Edit.SelectAll.Sensitive = enable;
PintaCore.Actions.Edit.Deselect.Sensitive = enable;
PintaCore.Actions.View.ActualSize.Sensitive = enable;
PintaCore.Actions.View.ZoomIn.Sensitive = enable;
PintaCore.Actions.View.ZoomOut.Sensitive = enable;
PintaCore.Actions.View.ZoomToSelection.Sensitive = enable;
PintaCore.Actions.View.ZoomToWindow.Sensitive = enable;
PintaCore.Actions.View.ZoomComboBox.Sensitive = enable;
PintaCore.Actions.Image.CropToSelection.Sensitive = enable;
PintaCore.Actions.Image.AutoCrop.Sensitive = enable;
PintaCore.Actions.Image.CanvasSize.Sensitive = enable;
PintaCore.Actions.Image.Resize.Sensitive = enable;
PintaCore.Actions.Image.FlipHorizontal.Sensitive = enable;
PintaCore.Actions.Image.FlipVertical.Sensitive = enable;
PintaCore.Actions.Image.Rotate180.Sensitive = enable;
PintaCore.Actions.Image.RotateCCW.Sensitive = enable;
PintaCore.Actions.Image.RotateCW.Sensitive = enable;
PintaCore.Actions.Image.Flatten.Sensitive = enable;
PintaCore.Actions.Layers.AddNewLayer.Sensitive = enable;
PintaCore.Actions.Layers.DeleteLayer.Sensitive = enable;
PintaCore.Actions.Layers.DuplicateLayer.Sensitive = enable;
PintaCore.Actions.Layers.MergeLayerDown.Sensitive = enable;
PintaCore.Actions.Layers.ImportFromFile.Sensitive = enable;
PintaCore.Actions.Layers.FlipHorizontal.Sensitive = enable;
PintaCore.Actions.Layers.FlipVertical.Sensitive = enable;
PintaCore.Actions.Layers.RotateZoom.Sensitive = enable;
PintaCore.Actions.Layers.MoveLayerUp.Sensitive = enable;
PintaCore.Actions.Layers.MoveLayerDown.Sensitive = enable;
PintaCore.Actions.Layers.Properties.Sensitive = enable;
PintaCore.Actions.Adjustments.ToggleActionsSensitive (enable);
PintaCore.Actions.Effects.ToggleActionsSensitive (enable);
PintaCore.Actions.Window.SaveAll.Sensitive = enable;
PintaCore.Actions.Window.CloseAll.Sensitive = enable;
}
}