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: b2a4f1102f6e92d3dd901e505b6f24d4a9a14092 (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
/*
 *                     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.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 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);
        }
    }
}