Exemple #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService iwes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            AdvancedTextBox atb = new AdvancedTextBox();

            atb.normalmode      = false;
            atb.Buffer.Language = ComponentModel.ServiceHost.Language["ls"];
            atb.ProjectHint     = (ServiceHost.Scripting as ScriptingService).proj;

            string sv = conshistory[value] as string;

            if (sv == null)
            {
                if (value is Symbol && value == LSharp.Runtime.Eval(value, (context.Instance as Grid).Environment))
                {
                }
                else
                {
                    sv = Printer.WriteToString(value);
                }
            }
            if (sv == null)
            {
                sv = string.Empty;
            }

            if (sv.Length > 0)
            {
                // convert ranges
                ArrayList reps = new ArrayList();

                foreach (Match m in rangematch2.Matches(sv))
                {
                    string[] sr = m.Value.Split(' ');
                    int      l  = sr.Length;
                    if (sr.Length > 1)
                    {
                        Grid.Range r = new Grid.Range(sr[0] + ".." + sr[l - 1]);
                        if (r.Count == l)
                        {
                            int i = 0;
                            foreach (Grid.Cell c in r)
                            {
                                if (c.ToString().ToLower() != sr[i])
                                {
                                    if (i > 0)
                                    {
                                        r  = new Grid.Range(sr[0] + ".." + sr[i - 1]);
                                        sv = sv.Replace(string.Join(" ", sr, 0, i), r.ToString().ToLower());
                                    }
                                    goto NEXTMATCH;
                                }
                                i++;
                            }
                            sv = sv.Replace(m.Value, r.ToString().ToLower());
                        }
                    }
                    NEXTMATCH :;
                }
            }

            atb.Buffer.InsertString(sv);

            atb.Width  = 350;
            atb.Height = 200;

            // HACK HACK HACK HACK
            FileManager fm = ServiceHost.File as FileManager;
            //fm.buffers.Add("$hack$", atb);
            string ob = fm.current;

            fm.current = "$hack$";
            ApplicationState os = ServiceHost.State;

            ServiceHost.State |= (ApplicationState.Edit | ApplicationState.Buffer);
            ServiceHost.State &= ~(ApplicationState.Grid);

            iwes.DropDownControl(atb);
            fm.buffers.Remove("$hack$");
            ServiceHost.State = os;
            fm.current        = ob;
            object o    = null;
            string text = atb.Text.Trim();

            if (text.Length > 0)
            {
                // convert ranges
                ArrayList reps = new ArrayList();

                foreach (Match m in rangematch.Matches(text))
                {
                    Grid.Range r  = new Grid.Range(m.Value);
                    ArrayList  cs = new ArrayList();
                    foreach (Grid.Cell c in r)
                    {
                        cs.Add(c.ToString());
                    }
                    string[] sr = cs.ToArray(typeof(string)) as string[];

                    text = text.Replace(m.Value, string.Join(" ", sr));
                }

                if (text.StartsWith("="))
                {
                    o = LSharp.Runtime.EvalString(text.TrimStart('='), (context.Instance as Grid).Environment);
                }
                else
                {
                    o = LSharp.Runtime.ReadString(text, (context.Instance as Grid).Environment);
                    conshistory[o] = atb.Text;
                }
            }
            atb.Dispose();
            return(o);
        }