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
|
// 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;
using System.Collections.Generic;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
namespace QtVsTools
{
using Core;
using Core.MsBuild;
using VisualStudio;
/// <summary>
/// Command handler
/// </summary>
internal sealed class QtSolutionContextMenu
{
/// <summary>
/// Gets the instance of the command.
/// </summary>
private static QtSolutionContextMenu Instance
{
get;
set;
}
/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
public static void Initialize()
{
Instance = new QtSolutionContextMenu();
}
/// <summary>
/// Command ID.
/// TODO: Remove, take form QtMenus.Package
/// </summary>
private enum CommandId
{
LUpdateOnSolution = QtMenus.Package.lUpdateOnSolution,
LReleaseOnSolution = QtMenus.Package.lReleaseOnSolution,
SolutionConvertToQtMsBuild = QtMenus.Package.SolutionConvertToQtMsBuild,
SolutionEnableProjectTracking = QtMenus.Package.SolutionEnableProjectTracking
}
/// <summary>
/// Initializes a new instance of the <see cref="QtMainMenu"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
private QtSolutionContextMenu()
{
var commandService = VsServiceProvider
.GetService<IMenuCommandService, OleMenuCommandService>();
if (commandService == null)
return;
foreach (int id in Enum.GetValues(typeof(CommandId))) {
var command = new OleMenuCommand(ExecHandler,
new CommandID(QtMenus.Package.Guid, id));
commandService.AddCommand(command);
}
}
private static void ExecHandler(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is not OleMenuCommand command)
return;
var properties = new Dictionary<string, string>
{
{"Command", Enum.GetName(typeof(CommandId), command.CommandID.ID)}
};
Telemetry.TrackEvent(typeof(QtSolutionContextMenu) + ".ExecHandler", properties);
var dte = QtVsToolsPackage.Instance.Dte;
switch (command.CommandID.ID) {
case QtMenus.Package.lUpdateOnSolution:
Translation.RunLUpdate(QtVsToolsPackage.Instance.Dte.Solution);
break;
case QtMenus.Package.lReleaseOnSolution:
Translation.RunLRelease(QtVsToolsPackage.Instance.Dte.Solution);
break;
case QtMenus.Package.SolutionConvertToQtMsBuild:
MsBuildProjectConverter.SolutionToQtMsBuild();
break;
case QtMenus.Package.SolutionEnableProjectTracking:
foreach (var vcProject in HelperFunctions.ProjectsInSolution(dte))
MsBuildProject.GetOrAdd(vcProject);
break;
}
}
}
}
|