public void InsertFunction(CalcManager.Function func)
 {
     if (output.IsInputMode)
     {
         HandleSys("exe");
     }
     program.AddItem($"U{func.Name}", func.Name);
 }
Beispiel #2
0
        private void OnAdded(object sender, RoutedEventArgs e)
        {
            var fn = new CalcManager.Function()
            {
                Name     = null,
                Descr    = null,
                ParamNum = 0,
                Code     = new CalcCommand[0],
            };

            mPage.EditFunction    = fn;
            lvFuncs.SelectedIndex = -1;
            Frame.GoBack();
        }
        private async void HandleSys(string cmd)
        {
            switch (cmd)
            {
            case "clr":
                if (output.IsInputMode)
                {
                    output.SendInput('*');
                }
                else
                {
                    EditFunction     = null;
                    output.OutResult = null;
                    program.ClearItems();
                }
                break;

            case "del":
                if (output.IsInputMode)
                {
                    output.SendInput('<');
                }
                else
                {
                    program.RemoveItem();
                }
                break;

            case "exe":
                if (output.IsInputMode)
                {
                    var num = output.FinishInput();
                    program.AddItem($"#{num}", num.ToNumeric());
                }
                else if (editFunc != null)
                {
                    var isNew  = (editFunc.Name == null);
                    var dialog = new NewFunction(editFunc);
                    await dialog.ShowAsync();

                    if (dialog.FunctionName != null)
                    {
                        var app = (Application.Current as App);
                        if (isNew)
                        {
                            editFunc.Name = dialog.FunctionName;
                            app.CalcManager.Functions.Add(editFunc);
                        }
                        editFunc.Descr    = dialog.FunctionDescr;
                        editFunc.ParamNum = dialog.ParameterCount;
                        editFunc.Code     = program.Items();
                        var fn = editFunc.Compile(app.Calculator);
                        app.Calculator.SetUserFunc(editFunc.Name, fn);
                        program.ClearItems();
                        EditFunction = null;
                    }
                }
                else
                {
                    try {
                        var calc = (Application.Current as App).Calculator;
                        var fn   = calc.Compile(program.CompiledItems(), 0);
                        output.OutResult = calc.Execute(fn);
                    } catch (Exception e) {
                        output.Message = e.Message;
                    }
                }
                break;
            }
        }