aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Core/CMake/CMakeProject.Messages.cs
blob: f767746bdcb51939e792516bd4d7bd60f723e548 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace QtVsTools.Core.CMake
{
    using Options;
    using VisualStudio;
    using static Common.Utils;

    public partial class CMakeProject : Concurrent<CMakeProject>
    {
        private class AlertIncompatibleProject : InfoBarMessage
        {
            protected override ImageMoniker Icon => KnownMonikers.StatusWarning;

            protected override TextSpan[] Text => new[]
            {
                new TextSpan { Bold = true, Text = "Qt Visual Studio Tools" },
                new TextSpacer(2), EmDash, new TextSpacer(2),
                "Found a reference to Qt. Projects that use a CMakeSettings.json configuration "
                + "file are not supported. Please convert to a CMakePresets.json configuration."
            };

            protected override Hyperlink[] Hyperlinks => new Hyperlink[]
            {
                new()
                {
                    Text = "Don't show again",
                    CloseInfoBar = true,
                    OnClicked = () =>
                    {
                        QtOptionsPage.NotifyCMakeIncompatible = false;
                        QtOptionsPage.SaveSettingsToStorageStatic();
                    }
                }
            };
        }

        private static AlertIncompatibleProject IncompatibleProjectMessage => StaticLazy.Get(
            () => IncompatibleProjectMessage, () => new AlertIncompatibleProject());

        private async Task ShowIncompatibleProjectAsync()
        {
            if (!QtOptionsPage.NotifyCMakeIncompatible)
                return;
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            IncompatibleProjectMessage.Show();
        }

        private class AskConversionConfirmation : InfoBarMessage
        {
            public AskConversionConfirmation(CMakeProject project)
            {
                Project = project;
            }

            private CMakeProject Project { get; }

            protected override ImageMoniker Icon => KnownMonikers.StatusAlert;

            protected override TextSpan[] Text => new[]
            {
                new TextSpan { Bold = true, Text = "Qt Visual Studio Tools" },
                new TextSpacer(2), EmDash, new TextSpacer(2),
                "Found a reference to Qt."
            };

            protected override Hyperlink[] Hyperlinks => new Hyperlink[]
            {
                new()
                {
                    Text = "Convert project to Qt/CMake",
                    CloseInfoBar = true,
                    OnClicked = Project.ConfirmConversion
                },
                new()
                {
                    Text = "Don't show again",
                    CloseInfoBar = true,
                    OnClicked = () =>
                    {
                        QtOptionsPage.NotifyCMakeConversion = false;
                        QtOptionsPage.SaveSettingsToStorageStatic();
                    }
                }
            };
        }

        private AskConversionConfirmation ConversionConfirmationMessage => Lazy.Get(
            () => ConversionConfirmationMessage, () => new AskConversionConfirmation(this));

        private async Task ShowConversionConfirmationAsync()
        {
            if (!QtOptionsPage.NotifyCMakeConversion)
                return;
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            ConversionConfirmationMessage.Show();
        }

        private void ConfirmConversion()
        {
            if (Status != QtStatus.ConversionPending)
                return;
            Status = QtStatus.True;
            ThreadHelper.JoinableTaskFactory.Run(async () => await RefreshAsync());
        }

        private async Task CloseMessagesAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            IncompatibleProjectMessage.Close();
            ConversionConfirmationMessage.Close();
        }
    }
}