Esempio n. 1
0
        public VcInfoSet()
        {
            InitializeComponent();

            envCfgs.LoadConfig();
            ThkVCDirSet vcconfig = envCfgs.GetVCConfig();

            if (vcconfig != null)
            {
                ThkVCDirItem[] vcitem = vcconfig.EnvConfigItems;
                if (vcitem != null)
                {
                    int nselidx = -1;
                    foreach (ThkVCDirItem vci in vcitem)
                    {
                        int idx = cbEncConfig.Items.Add(vci.StrVCVer);
                        if (vcconfig.CurVCItem == vci.StrVCVer)
                        {
                            nselidx = idx;
                        }
                    }
                    int idx1 = cbEncConfig.Items.Add(vcconfig.VcDefault.StrVCVer);
                    if (vcconfig.CurVCItem == vcconfig.VcDefault.StrVCVer)
                    {
                        nselidx = idx1;
                    }

                    if (nselidx == -1)
                    {
                        nselidx = 0;
                    }
                    cbEncConfig.SelectedIndex = nselidx;
                    cbEncConfig_SelectedIndexChanged(null, null);
                }
            }
        }
Esempio n. 2
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

            OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            bool bbuildok = true;

            try
            {
                m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("生成");
            }
            catch
            {
                //我们试图查找“工具”一词的本地化版本,但未能找到。
                //  默认值为 en-US 单词,该值可能适用于当前区域性。
                bbuildok = false;
            }

            if (!bbuildok)
            {
                try
                {
                    m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("Build");
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    bbuildok = false;
                }
            }


            // Register for the various build events taht we're hooking in to
            EnvDTE.Events events = _applicationObject.Events;
            m_BuildEvents = (EnvDTE.BuildEvents)events.BuildEvents;
            m_BuildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(OnBuildProjConfigBegin);
            m_BuildEvents.OnBuildProjConfigDone  += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(OnBuildProjConfigDone);
            m_BuildEvents.OnBuildBegin           += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
            m_BuildEvents.OnBuildDone            += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);

            m_envcfgs = new ThkEnvCfgs();
            if (m_envcfgs.LoadConfig())
            {
                ThkEnvConfig enc = m_envcfgs.GetCurEnvConfig();
                if (enc != null)
                {
                    //if (m_OutputWindowPane != null)
                    //{
                    //    m_OutputWindowPane.OutputString("现在开始自动设置配置信息中的环境变量\n");
                    //}

                    ThkEnvCfgItem[] encitems = enc.EnvConfigItems;
                    foreach (ThkEnvCfgItem ci in encitems)
                    {
                        if (ci.EnvCfgFlatform == null || ci.EnvCfgFlatform.Length == 0 || ci.EnvCfgFlatform == "全部" || ci.EnvCfgFlatform == "")
                        {
                            Environment.SetEnvironmentVariable(ci.EnvCfgItem, ci.EnvCfgValue, EnvironmentVariableTarget.Process);
                            //if (m_OutputWindowPane !=null)
                            //{
                            //    m_OutputWindowPane.OutputString(ci.EnvCfgItem + ":" + ci.EnvCfgValue+"\n");
                            //}
                        }
                    }
                }
                else
                {
                    MessageBox.Show("获取配置中的环境变量信息失败");
                }
            }
            else
            {
                MessageBox.Show("加载配置变量配置文件失败");
            }
            {
                string   path       = System.Environment.CurrentDirectory;
                Assembly myAssembly = Assembly.GetEntryAssembly();
                if (myAssembly == null)
                {
                    myAssembly = Assembly.GetExecutingAssembly();
                }
                if (myAssembly != null)
                {
                    path = myAssembly.Location;
                    DirectoryInfo dr = new DirectoryInfo(path);
                    path = dr.Parent.FullName;  //当前目录的上一级目录
                }
                Environment.SetEnvironmentVariable("THK_VS_ADDIN_PATH", path, EnvironmentVariableTarget.Process);
            }

            //debug
            ThkVCDirSet vcset = m_envcfgs.GetVCConfig();

            if (vcset != null && vcset.EnvConfigItems.Length < 2)
            {
                //vcset.AddVcConfig("VC6", @"D:\develop\VS60\VC98\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2002\Vc7\", "");
                //vcset.AddVcConfig("VC2003", @"D:\develop\vs2003\Vc7\", "");
                //vcset.AddVcConfig("VC2005", @"D:\develop\vs2005\Vc\", "");
                //vcset.AddVcConfig("VC2008", @"D:\develop\vs2008\Vc\", "");
                //vcset.AddVcConfig("VC2010", @"D:\develop\vs2010\Vc\", "");
                //vcset.AddVcConfig("VC2012", @"D:\develop\vs2012\Vc\", "");
                //vcset.AddVcConfig("VC2013", @"D:\develop\vs2013\Vc\", "");


                //m_envcfgs.SaveConfig();
            }
            //end of debug

            if (connectMode == ext_ConnectMode.ext_cm_CommandLine || connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_UISetup ||
                connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                object[]  contextGUIDS = new object[] { };
                Commands2 commands     = (Commands2)_applicationObject.Commands;
                string    toolsMenuName;



                try
                {
                    //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
                    //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
                    //  您会在此文件中看到全部顶级菜单的列表
                    //  CommandBar.resx.
                    string          resourceName;
                    ResourceManager resourceManager = new ResourceManager("ThkDevEnc.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo     cultureInfo     = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    }
                    toolsMenuName = resourceManager.GetString(resourceName);
                    if (toolsMenuName == null || toolsMenuName.Length == 0)
                    {
                        toolsMenuName = "工具";
                    }
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    toolsMenuName = "Tools";
                }

                //将此命令置于“工具”菜单上。
                //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //在 MenuBar 命令栏上查找“工具”命令栏:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                //////////////try
                //////////////{
                //////////////    //将一个命令添加到 Commands 集合:
                //////////////    Command command = commands.AddNamedCommand2(_addInInstance, "ProUnlock", "解锁ProE插件", "Executes the command for ProUnlock", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                //////////////    //将对应于该命令的控件添加到“工具”菜单:
                //////////////    if ((command != null) && (toolsPopup != null))
                //////////////    {
                //////////////        command.AddControl(toolsPopup.CommandBar, 1);
                //////////////    }
                //////////////}
                //////////////catch (System.ArgumentException)
                //////////////{
                //////////////    //如果出现此异常,原因很可能是由于具有该名称的命令
                //////////////    //  已存在。如果确实如此,则无需重新创建此命令,并且
                //////////////    //  可以放心忽略此异常。
                //////////////}
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "ProeAttach", "调试ProE", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CatiaAttach", "调试Catia", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "DevEnvCfg", "森科开发环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "VCSet", "当前编译环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }

                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "UnAttach", "全部分离调试", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }


                try
                {
                    //将一个命令添加到 Commands 集合:
                    Command command = commands.AddNamedCommand2(_addInInstance, "CopyFile", "文件拷贝", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                    //将对应于该命令的控件添加到“工具”菜单:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令
                    //  已存在。如果确实如此,则无需重新创建此命令,并且
                    //  可以放心忽略此异常。
                }
            }
        }