/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE)application; _addInInstance = (AddIn)addInInst; // determine the installation directory System.Uri uri = new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase); installationDir = Path.GetDirectoryName(System.Uri.UnescapeDataString(uri.AbsolutePath)); installationDir += "\\"; // General startup code if ((ext_ConnectMode.ext_cm_AfterStartup == connectMode) || (ext_ConnectMode.ext_cm_Startup == connectMode) || (ext_ConnectMode.ext_cm_CommandLine == connectMode)) { QtVersionManager vm = QtVersionManager.The(); string error = null; if (vm.HasInvalidVersions(out error)) { Messages.DisplayErrorMessage(error); } eventHandler = new AddInEventHandler(_applicationObject); extLoader = new ExtLoader(); if (ext_ConnectMode.ext_cm_CommandLine != connectMode) { try { initializer = new AddinInit(_applicationObject); initializer.removeCommands(); initializer.registerCommands(); UpdateDefaultEditors(true); } catch (System.Exception e) { MessageBox.Show(e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace); } } else { commandLine = true; } } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE)application; _addInInstance = (AddIn)addInInst; // determine the installation directory System.Uri uri = new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase); installationDir = Path.GetDirectoryName(System.Uri.UnescapeDataString(uri.AbsolutePath)); installationDir += "\\"; // General startup code if ((ext_ConnectMode.ext_cm_AfterStartup == connectMode) || (ext_ConnectMode.ext_cm_Startup == connectMode) || (ext_ConnectMode.ext_cm_CommandLine == connectMode)) { QtVersionManager vm = QtVersionManager.The(); string error = null; if (vm.HasInvalidVersions(out error)) Messages.DisplayErrorMessage(error); eventHandler = new AddInEventHandler(_applicationObject); extLoader = new ExtLoader(); if (ext_ConnectMode.ext_cm_CommandLine != connectMode) { try { initializer = new AddinInit(_applicationObject); initializer.removeCommands(); initializer.registerCommands(); UpdateDefaultEditors(true); } catch (System.Exception e) { MessageBox.Show(e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace); } } else commandLine = true; } }
public void Exec(string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { try { handled = false; if (executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault) { switch (commandName) { case Res.LaunchDesignerFullCommand: handled = true; extLoader.loadDesigner(null); break; case Res.LaunchLinguistFullCommand: handled = true; ExtLoader.loadLinguist(null); break; case Res.LaunchAssistantFullCommand: handled = true; ExtLoader.loadAssistant(); break; case Res.ImportProFileFullCommand: handled = true; ExtLoader.ImportProFile(); break; case Res.ImportPriFileFullCommand: handled = true; ExtLoader.ImportPriFile(HelperFunctions.GetSelectedQtProject(_applicationObject)); break; case Res.ExportPriFileFullCommand: handled = true; ExtLoader.ExportPriFile(); break; case Res.ExportProFileFullCommand: handled = true; ExtLoader.ExportProFile(); break; case Res.ChangeSolutionQtVersionFullCommand: QtVersionManager vManager = QtVersionManager.The(); if (formChangeQtVersion == null) { formChangeQtVersion = new FormChangeQtVersion(); } formChangeQtVersion.UpdateContent(ChangeFor.Solution); if (formChangeQtVersion.ShowDialog() == DialogResult.OK) { string newQtVersion = formChangeQtVersion.GetSelectedQtVersion(); if (newQtVersion != null) { string currentPlatform = null; try { SolutionConfiguration config = _applicationObject.Solution.SolutionBuild.ActiveConfiguration; SolutionConfiguration2 config2 = config as SolutionConfiguration2; currentPlatform = config2.PlatformName; } catch { } if (string.IsNullOrEmpty(currentPlatform)) { return; } vManager.SetPlatform(currentPlatform); foreach (Project project in HelperFunctions.ProjectsInSolution(_applicationObject)) { if (HelperFunctions.IsQt5Project(project)) { string OldQtVersion = vManager.GetProjectQtVersion(project, currentPlatform); if (OldQtVersion == null) { OldQtVersion = vManager.GetDefaultVersion(); } QtProject qtProject = QtProject.Create(project); bool newProjectCreated = false; qtProject.ChangeQtVersion(OldQtVersion, newQtVersion, ref newProjectCreated); } } vManager.SaveSolutionQtVersion(_applicationObject.Solution, newQtVersion); } } break; case Res.ProjectQtSettingsFullCommand: handled = true; EnvDTE.DTE dte = _applicationObject; Project pro = HelperFunctions.GetSelectedQtProject(dte); if (pro != null) { if (formProjectQtSettings == null) { formProjectQtSettings = new FormProjectQtSettings(); } formProjectQtSettings.SetProject(pro); formProjectQtSettings.StartPosition = FormStartPosition.CenterParent; MainWinWrapper ww = new MainWinWrapper(dte); formProjectQtSettings.ShowDialog(ww); } else { MessageBox.Show(SR.GetString("NoProjectOpened")); } break; case Res.ChangeProjectQtVersionFullCommand: handled = true; dte = _applicationObject; pro = HelperFunctions.GetSelectedProject(dte); if (pro != null && HelperFunctions.IsQMakeProject(pro)) { if (formChangeQtVersion == null) { formChangeQtVersion = new FormChangeQtVersion(); } formChangeQtVersion.UpdateContent(ChangeFor.Project); MainWinWrapper ww = new MainWinWrapper(dte); if (formChangeQtVersion.ShowDialog(ww) == DialogResult.OK) { string qtVersion = formChangeQtVersion.GetSelectedQtVersion(); QtVersionManager vm = QtVersionManager.The(); string qtPath = vm.GetInstallPath(qtVersion); HelperFunctions.SetDebuggingEnvironment(pro, "PATH=" + qtPath + "\\bin;$(PATH)", true); } } break; case Res.VSQtOptionsFullCommand: handled = true; if (formQtVersions == null) { formQtVersions = new FormVSQtSettings(); formQtVersions.LoadSettings(); } formQtVersions.StartPosition = FormStartPosition.CenterParent; MainWinWrapper mww = new MainWinWrapper(_applicationObject); if (formQtVersions.ShowDialog(mww) == DialogResult.OK) { formQtVersions.SaveSettings(); } break; case Res.CreateNewTranslationFileFullCommand: handled = true; pro = HelperFunctions.GetSelectedQtProject(_applicationObject); Translation.CreateNewTranslationFile(pro); break; case Res.CommandBarName + ".Connect.lupdate": handled = true; Translation.RunlUpdate(HelperFunctions.GetSelectedFiles(_applicationObject), HelperFunctions.GetSelectedQtProject(_applicationObject)); break; case Res.CommandBarName + ".Connect.lrelease": handled = true; Translation.RunlRelease(HelperFunctions.GetSelectedFiles(_applicationObject)); break; case Res.lupdateProjectFullCommand: handled = true; pro = HelperFunctions.GetSelectedQtProject(Connect._applicationObject); Translation.RunlUpdate(pro); break; case Res.lreleaseProjectFullCommand: handled = true; pro = HelperFunctions.GetSelectedQtProject(Connect._applicationObject); Translation.RunlRelease(pro); break; case Res.lupdateSolutionFullCommand: handled = true; Translation.RunlUpdate(Connect._applicationObject.Solution); break; case Res.lreleaseSolutionFullCommand: handled = true; Translation.RunlRelease(Connect._applicationObject.Solution); break; case Res.ConvertToQtFullCommand: case Res.ConvertToQMakeFullCommand: if (MessageBox.Show(SR.GetString("ConvertConfirmation"), SR.GetString("ConvertTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes) { handled = true; dte = _applicationObject; pro = HelperFunctions.GetSelectedProject(dte); HelperFunctions.ToggleProjectKind(pro); } break; } } } catch (System.Exception e) { MessageBox.Show(e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace); } }