private void GenerateSpecifierCallback(object sender, EventArgs e) { //ThreadHelper.JoinableTaskFactory.Run(async () => //{ // await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); //}); GeneratorDialog dialog = new GeneratorDialog(); dialog.ShowModal(); if (dialog.ReturnCode == EReturnCode.RETURN_OK) { string text = dialog.ChosenSpecifier; ESpecifierMode editMode = 0; if (text.Contains("UPROPERTY")) { editMode = ESpecifierMode.MODE_UPROPERTY; } else if (text.Contains("UFUNCTION")) { editMode = ESpecifierMode.MODE_UFUNCTION; } else if (text.Contains("UCLASS")) { editMode = ESpecifierMode.MODE_UCLASS; } else if (text.Contains("UENUM")) { editMode = ESpecifierMode.MODE_UENUM; } else if (text.Contains("USTRUCT")) { editMode = ESpecifierMode.MODE_USTRUCT; } SpecifierDialog dialog2 = new SpecifierDialog(editMode, text + " (Generated)", string.Empty); dialog2.ShowModal(); if (dialog2.ReturnCode == EReturnCode.RETURN_OK) { if (!string.IsNullOrWhiteSpace(dialog2.OutputResult)) { DTE dte = (DTE)this.ServiceProvider.GetService(typeof(DTE)); if (dte != null) { var txt = (TextSelection)dte.ActiveDocument.Selection; txt.Text = dialog2.OutputResult; } } } } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName); string title = "EditSpecifiers"; // Show a message box to prove we were here /* * VsShellUtilities.ShowMessageBox( * this.ServiceProvider, * message, * title, * OLEMSGICON.OLEMSGICON_INFO, * OLEMSGBUTTON.OLEMSGBUTTON_OK, * OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); */ DTE dte = (DTE)this.ServiceProvider.GetService(typeof(DTE)); if (dte == null) { return; } string text = ""; string parameters = ""; //IWpfTextViewHost host = GetCurrentViewHost(); //text = host.TextView.Selection.SelectedSpans[0].GetText(); if (dte.ActiveDocument != null) { var selection = (TextSelection)dte.ActiveDocument.Selection; if (text.Length == 0) { selection.WordLeft(); selection.WordRight(true); text = selection.Text; // See if we have an existing specifier definition to parse through selection.WordRight(true); if (selection.Text.Contains("(")) { //selection.WordRight(false, -1); selection.EndOfLine(true); parameters = selection.Text; int depth = 0; bool entered = false; int splitpos = 0; for (int i = 0; i < parameters.Length; ++i) { if (parameters[i] == '(') { depth++; } else if (parameters[i] == ')') { depth--; } if (depth >= 1 && !entered) { entered = true; } if (entered && depth <= 0) { splitpos = i + 1; break; } } if (depth != 0) { VsShellUtilities.ShowMessageBox( this.ServiceProvider, "Edit Specifiers found parsing errors in an existing specifier\nPlease correct any mismatching parenthesis", "", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } selection.CharRight(true, (-1 * (parameters.Length - splitpos))); if (splitpos < parameters.Length) { parameters = parameters.Remove(splitpos); } } else if (!selection.ActivePoint.AtEndOfDocument) { // selection.WordRight(true, -1); selection.CharRight(true, -1); } } } else { return; } #if !DEBUG if (text.Length == 0) { return; } #endif ESpecifierMode editMode = 0; if (text.Contains("UPROPERTY")) { editMode = ESpecifierMode.MODE_UPROPERTY; } else if (text.Contains("UFUNCTION")) { editMode = ESpecifierMode.MODE_UFUNCTION; } else if (text.Contains("UCLASS")) { editMode = ESpecifierMode.MODE_UCLASS; } else if (text.Contains("UENUM")) { editMode = ESpecifierMode.MODE_UENUM; } else if (text.Contains("USTRUCT")) { editMode = ESpecifierMode.MODE_USTRUCT; } else { VsShellUtilities.ShowMessageBox( this.ServiceProvider, "Edit Specifiers did not find a correct UE4 specifier.\nValid Specifiers are as follows:\n\nUPROPERTY\nUFUNCTION\nUENUM\nUCLASS\nUSTRUCT", "", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } SpecifierDialog dialog = new SpecifierDialog(editMode, text, parameters); dialog.ShowModal(); if (dialog.ReturnCode == EReturnCode.RETURN_OK) { if (!string.IsNullOrWhiteSpace(dialog.OutputResult)) { var txt = (TextSelection)dte.ActiveDocument.Selection; txt.Text = dialog.OutputResult; } } }