aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Core/CMake/CMakeProject.Events.cs
blob: 3f20457c05f0b0e309be416b22d1bd210dff19f3 (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
// 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 System.IO;
using System.Threading.Tasks;

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

    public partial class CMakeProject : Concurrent<CMakeProject>
    {
        public delegate void ProjectConfigurationDelegate(ProjectConfigurationEventArgs args);
        public event ProjectConfigurationDelegate ProjectConfigurationChanged;

        private void SubscribeEvents()
        {
            FileWatcher.OnFileSystemChanged += OnFileSystemChangedAsync;
        }

        private void UnsubscribeEvents()
        {
            FileWatcher.OnFileSystemChanged -= OnFileSystemChangedAsync;
        }

        private async Task OnFileSystemChangedAsync(object sender, FileSystemEventArgs args)
        {
            var fullPath = HelperFunctions.ToNativeSeparator(args.FullPath);
            if (IsProjectFile(fullPath))
                await CheckQtStatusAsync();

            if (!string.Equals(fullPath, GetConfigurationFileName(), IgnoreCase))
                return;

            var configurationName = GetActiveConfigurationName();
            if (string.IsNullOrEmpty(ConfigurationName))
                ConfigurationName = configurationName;

            if (ConfigurationName == configurationName)
                return;

            ConfigurationName = configurationName;
            ProjectConfigurationChanged?.Invoke(new ProjectConfigurationEventArgs
            {
                ProjectPath = RootPath,
                IsCMakeProject = true,
                ConfigurationName = configurationName
            });
        }
    }
}