Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MainWindow.Clipboard.cs « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32784c77740778fa3c72866787ed2aa3105ec669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 *                     GNU AFFERO GENERAL PUBLIC LICENSE
 *                       Version 3, 19 November 2007
 *  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 *  Everyone is permitted to copy and distribute verbatim copies
 *  of this license document, but changing it is not allowed.
 */


using System;
using System.ComponentModel;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;
using MessageBox.Avalonia.Enums;
using UVtools.WPF.Extensions;

namespace UVtools.WPF
{
    public partial class MainWindow
    {
        public ListBox ClipboardList;

        public void InitClipboardLayers()
        {
            ClipboardList = this.FindControl<ListBox>(nameof(ClipboardList));
            Clipboard.PropertyChanged += ClipboardOnPropertyChanged;
        }

        private void ClipboardOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Clipboard.CurrentIndex))
            {
                if (Clipboard.CurrentIndex < 0 || Clipboard.SuppressRestore) return;

                AddLogVerbose($"Clipboard change: {Clipboard.CurrentIndex}");

                if (Clipboard.ReallocatedLayerCount)
                {
                    DispatcherTimer.RunOnce(() =>
                    {
                        RefreshProperties();
                        ResetDataContext();
                    }, TimeSpan.FromMilliseconds(1));
                }

                ShowLayer();
                return;
            }
        }

        public void ClipboardUndo()
        {
            CanSave = true;
            if ((_globalModifiers & KeyModifiers.Shift) != 0)
            {
                ClipboardUndo(true);
                return;
            }
            Clipboard.Undo();
        } 

        public async void ClipboardUndo(bool rerun)
        {
            CanSave = true;
            var clip = Clipboard.CurrentClip;
            Clipboard.Undo();
            if (!rerun)
            {
                return;
            }
            if (clip?.Operation is null) return;
            /*if (clip.Operation.HaveROI)
            {
                ROI = GetTransposedRectangle(clip.Operation.ROI);
            }

            if (clip.Operation.HaveMask)
            {
                AddMaskPoints(clip.Operation.MaskPoints);
            }*/

            var operation = await ShowRunOperation(clip.Operation.GetType(), clip.Operation);
            if (operation is null)
            {
                Clipboard.Redo();
                CanSave = false;
            }
        }

        public void ClipboardRedo()
        {
            CanSave = true;
            Clipboard.Redo();
        }

        public async void ClipboardClear()
        {
            if (await this.MessageBoxQuestion("Are you sure you want to clear the clipboard?\n" +
                                              "Current layers will be placed as original layers\n" +
                                              "This action is permanent!", "Clear clipboard?") != ButtonResult.Yes) return;
            Clipboard.Clear(true);
        }
    }
}