public void GetConstInstructionItemTest() { ConstInstructionItem ciItem = AInstruction_Macro.GetConstInstructionItem("@add testName(param1, param2)"); Assert.AreEqual("testName", ciItem.ConstInstruction); Assert.AreEqual(2, ciItem.ParameterList.Count); Assert.AreEqual("param1", ciItem.ParameterList[0]); Assert.AreEqual("param2", ciItem.ParameterList[1]); }
/// <summary> /// 获取指令补全 /// </summary> /// <param name="currentInput">当前的指令输入</param> /// <returns></returns> public static InputAttribution GetInstructionCompletion(InputAttribution currentInput) { if (string.IsNullOrEmpty(currentInput.content)) { return(currentInput); } string targetInstructionLeft, targetInstructionPart, targetInstructionRight; GetInstructionCompletionDepart(currentInput, out targetInstructionLeft, out targetInstructionPart, out targetInstructionRight); if (string.IsNullOrEmpty(targetInstructionPart)) { return(currentInput); } InputAttribution retn = currentInput; retn.selectEmpty = true; string cp = ""; switch (GetInstructionCompletionPartType(targetInstructionPart)) { case InstructionType.STARTUP: cp = AInstruction_Startup.GetCompletion(targetInstructionPart); break; case InstructionType.MACRO: cp = AInstruction_Macro.GetCompletion(targetInstructionPart); break; case InstructionType.CONST: cp = AConstQuote.GetCompletion(targetInstructionPart); break; case InstructionType.BUILDIN: break; } if (!string.IsNullOrEmpty(cp)) { retn.content = targetInstructionLeft + cp + targetInstructionRight; retn.selectStart = retn.caretPosition = currentInput.caretPosition; retn.selectEnd = retn.selectStart + cp.Length - targetInstructionPart.Length - 1; retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart; } // Check const-instruction completion at last. if (retn.selectEmpty) { cp = AConstInstruction.GetCompletion(targetInstructionPart); retn.content = targetInstructionLeft + cp + targetInstructionRight; retn.selectStart = retn.caretPosition = currentInput.caretPosition; retn.selectEnd = retn.selectStart + cp.Length - targetInstructionPart.Length - 1; retn.selectEmpty = retn.selectEnd <= 0 || retn.selectEnd < retn.selectStart; } return(retn); }
public void GetMacroInstructionPartsListTest() { AInstruction_Macro ins = new AInstruction_Macro("@new a.txt"); List <string> actual = ins.GetMacroInstructionPartsList(); Assert.AreEqual(2, actual.Count); Assert.AreEqual("@new", actual[0]); Assert.AreEqual("a.txt", actual[1]); ins = new AInstruction_Macro("@add #const instruction"); actual = ins.GetMacroInstructionPartsList(); Assert.AreEqual(3, actual.Count); Assert.AreEqual("@add", actual[0]); Assert.AreEqual("#const", actual[1]); Assert.AreEqual("instruction", actual[2]); }
/// <summary> /// 窗体回调函数,接收所有窗体消息的事件处理函数 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="msg">消息</param> /// <param name="wideParam">附加参数1</param> /// <param name="longParam">附加参数2</param> /// <param name="handled">是否处理</param> /// <returns>返回句柄</returns> private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wideParam, IntPtr longParam, ref bool handled) { var hotkeySetting = new AHotKeySetting(); // Console.WriteLine(wideParam.ToInt32()); switch (msg) { case HotKeyManager.WM_HOTKEY: int sid = wideParam.ToInt32(); if (sid == m_HotKeySettings[AHotKeySetting.AWAKEN]) { hotkeySetting = AHotKeySetting.AWAKEN; //TODO AWAKEN Visibility = IsVisible ? Visibility.Hidden : Visibility.Visible; showOutput = constInstructionInputMode; Resize(); if (Visibility == Visibility.Visible) { InstructionTextBox.Focus(); } } else if (constInstructionInputMode && sid == m_HotKeySettings[AHotKeySetting.CANCEL_CONST_INSTRUCTION_INPUT]) { constInstructionInputMode = false; TestRichTextbox.IsReadOnly = true; InstructionTextBox.IsEnabled = true; // Get const instruction lines and update max width. foreach (string ciLine in GetConstInstructionInputLines()) { UpdateMaxWidth(ciLine); } string outputMsg = "\nOperation [" + InstructionTextBox.Text + "] cancelled."; UpdateMaxWidth(outputMsg); AppendRTBLine(TestRichTextbox, outputMsg, themeConfig.ForegroundOutputError, themeConfig.BackgroundOutputError); TestRichTextbox.BorderThickness = new Thickness(1, 1, 1, 0); InstructionTextBox.Focus(); showOutput = true; Resize(); } else if (constInstructionInputMode && sid == m_HotKeySettings[AHotKeySetting.CONFIRM_CONST_INSTRUCTION_INPUT]) { ConstInstructionItem ciItem = AInstruction_Macro.GetConstInstructionItem(InstructionTextBox.Text); constInstructionInputMode = false; TestRichTextbox.IsReadOnly = true; InstructionTextBox.IsEnabled = true; string outputHead = ciItem.ConstInstruction + "("; foreach (string paramName in ciItem.ParameterList) { outputHead += paramName + ","; } outputHead = (outputHead[outputHead.Length - 1] == ',' ? outputHead.Substring(0, outputHead.Length - 1) : outputHead) + ")"; string output = ""; // Get const instruction lines and update max width. foreach (string ciLine in GetConstInstructionInputLines()) { output += ciLine + "\n"; UpdateMaxWidth(ciLine); } string outputMsg = ""; SolidColorBrush colorBackground = themeConfig.BackgroundOutputOk; try { try { File.Delete(AHelper.CONST_INSTRUCTION_PATH + @"\" + OldConstInstructionFileName); } catch { } using (StreamWriter writer = new StreamWriter(AHelper.CONST_INSTRUCTION_PATH + @"\" + outputHead, false)) { writer.WriteLine(output); } outputMsg = "\nAdd const instruction [" + InstructionTextBox.Text + "] successfully."; } catch (Exception exception) { outputMsg = "\n" + exception.Message; colorBackground = themeConfig.BackgroundOutputError; } finally { UpdateMaxWidth(outputMsg); AppendRTBLine(TestRichTextbox, outputMsg, themeConfig.BackgroundOutput, colorBackground); TestRichTextbox.BorderThickness = new Thickness(1, 1, 1, 0); InstructionTextBox.Focus(); showOutput = true; InstructionTextBox.Text = ""; Resize(); } } handled = true; break; } hotkeySetting = hotkeySetting + 0; // Meaningless, just for clearing up warnning return(IntPtr.Zero); }
public void GetMacroDelTypeTest(string paramOfMacroDelItemString, AInstruction_Macro.MacroDelType expected) { Assert.AreEqual(expected, AInstruction_Macro.GetMacroDelType(paramOfMacroDelItemString)); }
public void GetMacroAddTypeTest(string firstParamOfMacroAddInstruction, AInstruction_Macro.MacroAddType expected) { Assert.AreEqual(expected, AInstruction_Macro.GetMacroAddType(firstParamOfMacroAddInstruction)); }
public void GetMacroTypeTest(string instruction, AInstruction_Macro.MacroType expected) { AInstruction_Macro ins = new AInstruction_Macro(instruction); Assert.AreEqual(expected, ins.GetMacroType()); }