private void AdjustArgumentsTable(string Format) { // フォーマット文字列内の入力フォーマット指定子を数える int SpecifierCount = StringFunctionLibrary.CountOfString(Format, InputFormatSpecifiers); Tlp_Arguments.SuspendLayout(); int Different = Math.Abs(SpecifierCount - Tlp_Arguments.RowCount); //増えた if (SpecifierCount > Tlp_Arguments.RowCount) { for (int Index = 0; Index < Different; Index++) { TextBox Input = new TextBox(); Input.ScrollBars = ScrollBars.Horizontal; Input.BorderStyle = BorderStyle.FixedSingle; Input.Width = 240; Tlp_Arguments.RowCount++; Tlp_Arguments.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F)); Tlp_Arguments.Controls.Add(Input); } } // 減った else if (SpecifierCount < Tlp_Arguments.RowCount) { for (int Index = 0; Index < Different; Index++) { Tlp_Arguments.Controls.RemoveAt(Tlp_Arguments.Controls.Count - 1); Tlp_Arguments.RowStyles.RemoveAt(Tlp_Arguments.RowCount - 1); Tlp_Arguments.RowCount--; } } Tlp_Arguments.ResumeLayout(); }
private void ReflectParameterInList() { // カッコと空白を取り除く string TrimmedTarget = StringFunctionLibrary.RemoveChars(EditTarget, new char[] { '(', ')', ' ' }); // 空のマクロなら初期状態でUIを起動 if (string.IsNullOrEmpty(TrimmedTarget)) { return; } // カンマで分ける List <string> ParsedParameters = StringFunctionLibrary.SplitParameterByComma(TrimmedTarget); // meta=を取り除く for (int Index = 0; Index < ParsedParameters.Count; Index++) { if (ParsedParameters[Index].Length > 5) { string Head = ParsedParameters[Index].Substring(0, 5); if (Head == "meta=" || Head == "Meta=") { ParsedParameters[Index] = ParsedParameters[Index].Remove(0, 5); } } } // UIに反映させる foreach (var Parameter in ParsedParameters) { if (!ReflectParameterInMacroSpecifiers(Parameter) && !ReflectParameterInAdvancedSettings(Parameter) && !ReflectParameterInMetaSpecifiers(Parameter)) { MessageBox.Show( "\"" + Parameter + "\" is an illegal specifier\n" + "If you want to use this specifier, add the specifier from the Visual Studio settings", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); Close(); return; } } }
private void ReflectParameterInList() { bool bIsEvent = MacroName.Contains("_EVENT"); bool bHasRetVal = MacroName.Contains("_RetVal"); bool bIsDynamic = MacroName.Contains("_DYNAMIC"); bool bIsMulticast = MacroName.Contains("_MULTICAST"); int ArgumentsCount = 0; for (int Index = 0; Index < ParamNumbers.Length; Index++) { if (MacroName.Contains(ParamNumbers[Index])) { ArgumentsCount = Index + 1; break; } } // チェックボックスなどを設定 Cb_IsEvent.Checked = bIsEvent; Cb_HasRetVal.Checked = bHasRetVal; Cb_IsDynamic.Checked = bIsDynamic; Cb_IsMulticast.Checked = bIsMulticast; ReflectCheckBox(); // カッコと空白を取り除く string TrimmedTarget = StringFunctionLibrary.RemoveChars(EditTarget, new char[] { '(', ')', ' ', ';' }); // カンマで分ける List <string> ParsedParameters = StringFunctionLibrary.SplitParameterByComma(TrimmedTarget); // 項目数が足りなければエラー if (((bIsEvent || bHasRetVal) && ParsedParameters.Count < 2) || (!(bIsEvent || bHasRetVal) && ParsedParameters.Count < 1)) { MessageBox.Show( "Macro structure is abnormal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); Close(); return; } int ParameterIndex = 0; // Type if (bIsEvent || bHasRetVal) { Tb_Type.Text = ParsedParameters[ParameterIndex++]; } // Name Tb_Name.Text = ParsedParameters[ParameterIndex++]; // Arguments if (ArgumentsCount > 0) { for (int Row = 0; Row < ArgumentsCount; Row++) { AddArgumets(); } var Controls = Tlp_Arguments.Controls; foreach (var Control in Controls) { if (Control is TextBox TextBox && TextBox.Enabled && ParameterIndex < ParsedParameters.Count) { TextBox.Text = ParsedParameters[ParameterIndex++]; } } } }
private void ReflectParameterInList() { // カッコと空白を取り除く string TrimmedTarget = StringFunctionLibrary.RemoveChars(EditTarget, new char[] { '(', ')', ' ', ';' }); // カンマで分ける List <string> ParsedParameters = StringFunctionLibrary.SplitParameterByComma(TrimmedTarget); if (MacroName == "UE_LOG") { // TEXTを取り除く for (int Index = 0; Index < ParsedParameters.Count; Index++) { if (ParsedParameters[Index].Length > 4) { string Head = ParsedParameters[Index].Substring(0, 4); if (Head == "TEXT") { ParsedParameters[Index] = ParsedParameters[Index].Remove(0, 4); } } } // 項目数が足りなければエラー if (ParsedParameters.Count < 3) { MessageBox.Show( "Macro structure is abnormal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); Close(); return; } // カテゴリを設定 Cb_Selecter1.Text = ParsedParameters[0]; // 詳細度を設定 Cb_Selecter2.Text = ParsedParameters[1]; // フォーマット文字列を設定 Tb_Input.Text = ParsedParameters[2].TrimStart('\"').TrimEnd('\"'); // 引数を設定 if (ParsedParameters.Count > 3) { ParsedParameters.RemoveRange(0, 3); var Controls = Tlp_Arguments.Controls; for (int Index = 0; Index < Controls.Count; Index++) { if (Controls[Index] is TextBox TextBox) { TextBox.Text = ParsedParameters[Index]; } } } } else { if (ParsedParameters.Count == 1) { Tb_Input.Text = ParsedParameters[0]; Cb_Selecter1.Visible = false; Cb_Selecter2.Visible = false; Lbl_Selecter1.Visible = false; Lbl_Selecter2.Visible = false; } else if (ParsedParameters.Count == 3) { Tb_Input.Text = ParsedParameters[0]; Cb_Selecter1.Text = ParsedParameters[1]; Cb_Selecter2.Text = ParsedParameters[2]; } else { MessageBox.Show( "Macro structure is abnormal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); Close(); return; } } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// </summary> /// <param name="Sender">Event sender.</param> /// <param name="Args">Event args.</param> private void EditMacroCallback(object Sender, EventArgs Args) { ThreadHelper.ThrowIfNotOnUIThread(); DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE)); Assumes.Present(Dte); var ActiveDocument = Dte.ActiveDocument; if (ActiveDocument != null) { // 一旦カーソル位置の行を全て選択 var Selection = (TextSelection)ActiveDocument.Selection; Selection.SelectLine(); // マクロの名前だけ選択 string TargetType = string.Empty; List <string> MacroTypes = new List <string>(XmlFunctionLibrary.GetMacroTypes(true, true, false)); foreach (var MacroType in MacroTypes) { if (Selection.Text.Contains(MacroType)) { TargetType = MacroType; break; } } Selection.StartOfLine(); Selection.LineUp(); while (true) { if (Selection.Text.Contains(TargetType)) { break; } Selection.WordRight(true); } Selection.WordLeft(); Selection.WordRight(true); TargetType = Selection.Text; // サポートしてなかったらエラー MacroTypes.Clear(); MacroTypes.AddRange(XmlFunctionLibrary.GetMacroTypes(false, false, true)); if (!MacroTypes.Contains(TargetType)) { string SupportedMacros = string.Empty; for (int Index = 0; Index < MacroTypes.Count; Index++) { SupportedMacros += MacroTypes[Index] + "\r\n"; } MessageBox.Show( TargetType + " is not a supported macro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } // マクロの中身だけ選択する string TargetParameters = string.Empty; bool bIsInString = false; int Depth = 0; while (true) { Selection.CharRight(true); var LastChar = Selection.Text[Selection.Text.Length - 1]; // マクロ名以降のみを取得 TargetParameters += LastChar; // 文字列中はカウントしない if (LastChar == '\"') { bIsInString = !bIsInString; } // カッコの深さをカウント if (!bIsInString && LastChar == '(') { Depth++; } else if (!bIsInString && LastChar == ')') { Depth--; } // カッコの数が合ったら終了 if (Depth <= 0) { break; } // カッコの数が合わなかった時の対策 if (Selection.ActivePoint.AtEndOfLine) { break; } } // 文字列中に"が入っている場合はエラー if (StringFunctionLibrary.CountOfChar(TargetParameters, '\"') % 2 != 0) { MessageBox.Show( "The string literal contains double quotes\r\n" + "Remove the double quotes inside the string literal to edit the macro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } if (!string.IsNullOrEmpty(TargetParameters)) { // エディタを起動 DialogResult DialogResult = DialogResult.None; string EditResult = string.Empty; switch (XmlFunctionLibrary.GetEditorType(TargetType)) { case EditorType.MacroEditor: MacroEditor MacroEditor = new MacroEditor(TargetType, TargetParameters); MacroEditor.ShowDialog(); DialogResult = MacroEditor.DialogResult; EditResult = MacroEditor.MacroString; break; case EditorType.LogEditor: LogEditor LogEditor = new LogEditor(TargetType, TargetParameters); LogEditor.ShowDialog(); DialogResult = LogEditor.DialogResult; EditResult = LogEditor.MacroString; break; case EditorType.DelegateEditor: DelegateEditor DelegateEditor = new DelegateEditor(TargetType, TargetParameters); DelegateEditor.ShowDialog(); DialogResult = DelegateEditor.DialogResult; EditResult = DelegateEditor.MacroString; break; } if (ActiveDocument != null && DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult)) { // カーソル位置に結果の文字列を挿入 Selection.Text = EditResult; // カーソルの行を更新 Selection.SelectLine(); Selection.SmartFormat(); Selection.EndOfLine(); } } } }