Example #1
0
        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]);
        }
Example #2
0
        /// <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);
        }