private void OnEditorLoad(object Sender, EventArgs Args) { Lb_Selecter.Items.AddRange(XmlFunctionLibrary.GetMacroTypes(true, false, false)); Lb_Selecter.SelectedIndex = 0; InitializeEditorColor(); }
/// <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 GenerateMacroCallback(object Sender, EventArgs Args) { ThreadHelper.ThrowIfNotOnUIThread(); // マクロの種類を取得 EditorSelecter SelecterDialog = new EditorSelecter(); SelecterDialog.ShowDialog(); if (SelecterDialog.DialogResult == DialogResult.OK) { // エディタを起動 DialogResult DialogResult = DialogResult.None; string EditResult = string.Empty; switch (XmlFunctionLibrary.GetEditorType(SelecterDialog.MacroType)) { case EditorType.MacroEditor: MacroEditor MacroEditor = new MacroEditor(SelecterDialog.MacroType); MacroEditor.ShowDialog(); DialogResult = MacroEditor.DialogResult; EditResult = MacroEditor.MacroString; break; case EditorType.LogEditor: LogEditor LogEditor = new LogEditor(SelecterDialog.MacroType); LogEditor.ShowDialog(); DialogResult = LogEditor.DialogResult; EditResult = LogEditor.MacroString; break; case EditorType.DelegateEditor: DelegateEditor DelegateEditor = new DelegateEditor(SelecterDialog.MacroType); DelegateEditor.ShowDialog(); DialogResult = DelegateEditor.DialogResult; EditResult = DelegateEditor.MacroString; break; } if (DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult)) { // カーソル位置に結果の文字列を挿入 DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE)); Assumes.Present(Dte); var Selection = (TextSelection)Dte.ActiveDocument.Selection; Selection.Text = EditResult; // カーソルの行を更新 Selection.SelectLine(); Selection.SmartFormat(); Selection.EndOfLine(); } } }
private void InitializeList() { Tlp_Arguments.SuspendLayout(); Tlp_Arguments.RowCount = 0; Tlp_Arguments.RowStyles.Clear(); string[] SelecterNames = new string[2]; Label[] Labels = new Label[] { Lbl_Selecter1, Lbl_Selecter2 }; List <string[]> SelecterItems = new List <string[]>(); ComboBox[] Selecters = new ComboBox[] { Cb_Selecter1, Cb_Selecter2 }; if (MacroName == "UE_LOG") { SelecterItems.Add(SettingsFunctionLibrary.GetLogCategory()); SelecterItems.Add(XmlFunctionLibrary.GetLogVerbosity()); SelecterNames[0] = "CategoryName"; SelecterNames[1] = "Verbosity"; Lbl_Input.Text = "Format"; Tb_Input.TextChanged += new EventHandler(OnTextChanged); Cb_Selecter1.SelectedText = "LogTemp"; Cb_Selecter2.SelectedText = "Log"; } else { var Verbosities = XmlFunctionLibrary.GetLogVerbosity(); SelecterItems.Add(Verbosities); SelecterItems.Add(Verbosities); SelecterNames[0] = "DefaultVerbosity"; SelecterNames[1] = "CompileTimeVerbosity"; Cb_Selecter1.SelectedText = "Log"; Cb_Selecter2.SelectedText = "All"; Lbl_Input.Text = "CategoryName"; Lbl_Arguments.Text = "MacroType"; string[] MacroTypes = XmlFunctionLibrary.GetMacroTypes(false, false, true); List <string> LogMacroTypes = new List <string>(); foreach (var MacroType in MacroTypes) { if (MacroType.Contains("LOG_CATEGORY")) { LogMacroTypes.Add(MacroType); } } ComboBox Type = new ComboBox(); Type.Items.AddRange(LogMacroTypes.ToArray()); Type.Width = 300; Type.SelectedIndexChanged += new EventHandler(OnMacroTypeChanged); if (!string.IsNullOrEmpty(EditTarget)) { Type.Text = MacroName; } else { Type.SelectedIndex = 0; MacroName = Type.Text; } Tlp_Arguments.Controls.Add(Type); } for (int Index = 0; Index < Selecters.Length; Index++) { if (!string.IsNullOrEmpty(SelecterNames[Index])) { Labels[Index].Text = SelecterNames[Index]; Selecters[Index].Items.AddRange(SelecterItems[Index]); } else { Labels[Index].Visible = false; Selecters[Index].Visible = false; } } Tlp_Arguments.Dock = DockStyle.Top; Tlp_Arguments.AutoSize = true; Tlp_Arguments.AutoSizeMode = AutoSizeMode.GrowAndShrink; Tlp_Arguments.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0); Tlp_Arguments.ResumeLayout(); }
/// <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(); } } } }