summaryrefslogtreecommitdiff
path: root/vsplugin/src/Connect.cs
blob: 82b149ad357a7f4178fdaa933c6489d7d4274caa (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// **********************************************************************
//
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

using System;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using Microsoft.VisualStudio.VCProjectEngine;
using Microsoft.VisualStudio.VCProject;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Runtime.InteropServices;

namespace Ice.VisualStudio
{
    public class Connect : IDTExtensibility2, IDTCommandTarget
    {

        public static Builder getBuilder()
        {
            return _builder;
        }

        public static DTE getCurrentDTE()
        {
            return _builder.getCurrentDTE();
        }


        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            if(connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                if(_builder == null)
                {

                    //
                    // This property is set to false to avoid VC++ "not maching rule" dialog
                    //
                    EnvDTE.Properties props = _applicationObject.get_Properties("Projects", "VCGeneral");
                    EnvDTE.Property prop = props.Item("ShowNoMatchingRuleDlg");
                    prop.Value = false;

                    _builder = new Builder();
                    _builder.init(_applicationObject, _addInInstance);
                }
            }
        }


        //
        // VS call this method to retrive the status of AddIn commands.
        //
        public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status,
                                ref object commandText)
        {
            if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if(commandName == "Ice.VisualStudio.Connect.IceConfiguration")
                {
                    Builder builder = getBuilder();
                    if(builder == null)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported;
                        return;
                    }
                    if(builder.isBuilding())
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported;
                        return;
                    }
                    Project project = builder.getSelectedProject();

                    if(project == null)
                    {
                       ProjectItem item = Util.getSelectedProjectItem(_applicationObject.DTE);
                       if(item != null)
                       {
                           project = item.ContainingProject;
                       }
                    }

                    if(project == null)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported;
                        return;
                    }

                    if(!Util.isCppProject(project) && !Util.isCSharpProject(project))
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported;
                        return;
                    }
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported |
                                              vsCommandStatus.vsCommandStatusEnabled;
                }
            }
        }

        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut,
                         ref bool handled)
        {
            handled = false;
            Builder builder = getBuilder();
            if(builder == null)
            {
                return;
            }

            if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if(commandName == "Ice.VisualStudio.Connect.IceConfiguration")
                {
                    Project project = builder.getSelectedProject();
                    if(project == null)
                    {
                       ProjectItem item = Util.getSelectedProjectItem(_applicationObject.DTE);
                       if(item != null)
                       {
                           project = item.ContainingProject;
                       }
                    }

                    if(project == null)
                    {
                        handled = false;
                        return;
                    }

                    if(Util.isCSharpProject(project))
                    {
                        if(Util.isSilverlightProject(project))
                        {
                            IceSilverlightConfigurationDialog dialog = new IceSilverlightConfigurationDialog(project);
                            dialog.ShowDialog();
                        }
                        else
                        {
                            IceCsharpConfigurationDialog dialog = new IceCsharpConfigurationDialog(project);
                            dialog.ShowDialog();
                        }
                    }
                    else if(Util.isCppProject(project))
                    {
                        IceCppConfigurationDialog dialog = new IceCppConfigurationDialog(project);
                        dialog.ShowDialog();
                    }
                    handled = true;
                }
            }
        }

        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            if(disconnectMode == ext_DisconnectMode.ext_dm_HostShutdown ||
               disconnectMode == ext_DisconnectMode.ext_dm_UserClosed)
            {
                if(_builder != null)
                {
                    _builder.disconnect();
                    _builder.Dispose();
                    _builder = null;
                }
            }
        }

        public void OnAddInsUpdate(ref Array custom)
        {
        }

        public void OnStartupComplete(ref Array custom)
        {
        }
        public void OnBeginShutdown(ref Array custom)
        {
        }

        private DTE2 _applicationObject;
        private AddIn _addInInstance;
        private static Builder _builder;
    }
}