예제 #1
0
        public static void SetByDeclaration(this DeclarationUI ui, Declaration declaration)
        {
            ui.Name = declaration.Name;
            ui.FSelection.SelectedItem = declaration;

            ui.ClearBody();
            foreach (var l in declaration.Lines)
            {
                if ((l as Comment) != null)
                {
                    ui.CurrentColor = Color.DimGray;
                }
                else if ((l as Field).ContainerType == "Null")
                {
                    ui.CurrentColor = Color.Red;
                }
                else
                {
                    ui.CurrentColor = Color.Black;
                }

                ui.AppendLine(l.ToString());
            }
            ui.CurrentColor = Color.Black;
            ui.KeyIsDirty   = false;
            ui.BodyIsDirty  = false;
        }
예제 #2
0
        void EditorUpdateDeclaration(DeclarationUI ui, IStructDeclarer declarer, string newName, string newFields)
        {
            var oldDecl = declarer.Declaration;

            if (oldDecl.Name != newName && FDeclarationFactory.Get(newName) != null)
            {
                ui.AppendError($"Declaration named '{newName}' already exists");
                return;
            }
            else if (!FDeclarationFactory.WellformedDeclarationName(newName))
            {
                ui.AppendError($"Declaration name malformed");
                return;
            }
            var d = FDeclarationFactory.Create(newName, newFields);

            if (!d.Equals(oldDecl))
            {
                FDeclarationFactory.Update(oldDecl.Name, d);
                SetDescriptiveName(declarer, d.Name);
            }
        }
예제 #3
0
        void EditorCreateDeclaration(DeclarationUI ui, IStructDeclarer declarer, string newName, string newFields)
        {
            if (!FDeclarationFactory.WellformedDeclarationName(newName))
            {
                ui.AppendError($"Declaration name malformed");
                return;
            }
            Declaration d = FDeclarationFactory.Get(newName);

            if (d == null)
            {
                d = FDeclarationFactory.Create(newName, newFields);
                FDeclarationFactory.Add(d);
                declarer.Declaration = d;
                (declarer.IOManager as IOManager).UpdateFromDeclaration(d);
                SetDescriptiveName(declarer, d.Name);
            }
            else
            {
                ui.AppendError($"Declaration named '{newName}' already exists");
            }
        }
예제 #4
0
        void InitializeDeclarer(IInternalPluginHost nodeHost, IStructDeclareEmit declareEmit)
        {
            var declarer = declareEmit as IStructDeclarer;

            var editor = new DeclarationUI(nodeHost, FHDEHost, FDeclarationFactory.FBindingList);

            editor.SelectionChanged  += (o, e) => EditorDeclarationSelectionChanged(declarer, e);
            editor.CreateDeclaration += (o, e) => EditorCreateDeclaration(o as DeclarationUI, declarer, e.Name, e.Fields);
            editor.UpdateDeclaration += (o, e) => EditorUpdateDeclaration(o as DeclarationUI, declarer, e.Name, e.Fields);

            nodeHost.Win32Window          = editor;
            declareEmit.InputWindowHandle = editor.Handle;

            declarer.IOManager.IOsChanged += (o, e) =>
            {
                var d = declarer.Declaration;
                editor.SetByDeclaration(d);
                if ((o as Declaration) != null)
                {
                    var text = d.ToString();
                    if (text != declareEmit.Cache[0])
                    {
                        declareEmit.Cache[0] = text;
                    }
                }
            };
            declareEmit.Cache.Changed += (s) => LoadDeclaration(nodeHost, declarer, s[0]); //only for startup

            if (string.IsNullOrWhiteSpace(declareEmit.Cache[0]))
            {
                declareEmit.Cache[0] = FDeclarationFactory.Get("Template").ToString();
                LoadDeclaration(nodeHost, declarer, declareEmit.Cache[0]);
            }
            //else
            //    declareEmit.Cache[0] = declareEmit.Cache[0]; //HACK! making sure to get a callback once vvvv is configuring for the first time
        }