Exemplo n.º 1
0
 private void HandleRefreshProperties(string changedMember, object oldValue)
 {
     if (this.variableGrid != null)
     {
         RefreshLogic.RefreshGrid(variableGrid);
     }
 }
Exemplo n.º 2
0
        private static MemberCategory CreateNameInstanceMember(NamedObjectSave instance)
        {
            var instanceMember = new DataGridItem();

            instanceMember.DisplayName            = "Name";
            instanceMember.UnmodifiedVariableName = "Name";

            // this gets updated in the CustomSetEvent below
            string oldValue = instance.InstanceName;

            instanceMember.CustomSetEvent += (throwaway, value) =>
            {
                instanceMember.IsDefault = false;
                RefreshLogic.IgnoreNextRefresh();

                instance.InstanceName = value as string;

                EditorObjects.IoC.Container.Get <SetVariableLogic>().ReactToPropertyChanged(
                    "InstanceName", oldValue, "InstanceName", null);


                //GlueCommands.Self.GluxCommands.SetVariableOn(
                //    instance,
                //    "Name",
                //    typeof(string),
                //    value);


                GlueCommands.Self.GluxCommands.SaveGlux();

                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                oldValue = (string)value;
            };
            instanceMember.CustomGetEvent += (throwaway) =>
            {
                return(instance.InstanceName);
            };

            instanceMember.CustomGetTypeEvent += (throwaway) => typeof(string);

            MemberCategory category = new MemberCategory();

            category.Name       = "";
            category.HideHeader = true;
            category.Members.Add(instanceMember);

            return(category);
        }
Exemplo n.º 3
0
        private static void CreateInstanceMembersForVariables(IElement element, MemberCategory category)
        {
            foreach (CustomVariable variable in element.CustomVariables)
            {
                Type type = variable.GetRuntimeType();
                if (type == null)
                {
                    type = typeof(string);
                }

                string name = variable.Name;
                //object value = variable.DefaultValue;

                // todo - do something with converter

                var instanceMember = new DataGridItem();
                instanceMember.CustomGetTypeEvent += (throwaway) => type;
                string displayName = StringFunctions.InsertSpacesInCamelCaseString(name);


                instanceMember.DisplayName            = displayName;
                instanceMember.UnmodifiedVariableName = name;

                TypeConverter converter = variable.GetTypeConverter(element);
                instanceMember.TypeConverter = converter;

                instanceMember.CustomSetEvent += (intance, value) =>
                {
                    instanceMember.IsDefault = false;

                    RefreshLogic.IgnoreNextRefresh();


                    var oldValue = variable.DefaultValue;

                    variable.DefaultValue = value;

                    EditorObjects.IoC.Container.Get <CustomVariableSaveSetVariableLogic>().ReactToCustomVariableChangedValue(
                        "DefaultValue", variable, oldValue);



                    GlueCommands.Self.GluxCommands.SaveGlux();

                    GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
                };

                instanceMember.CustomGetEvent += (instance) =>
                {
                    var foundVariable = element.GetCustomVariableRecursively(name);
                    return(foundVariable?.DefaultValue);
                };

                instanceMember.IsDefaultSet += (owner, args) =>
                {
                    element.GetCustomVariableRecursively(name).DefaultValue = null;


                    GlueCommands.Self.GluxCommands.SaveGlux();

                    GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
                };

                instanceMember.SetValueError = (newValue) =>
                {
                    if (newValue is string && string.IsNullOrEmpty(newValue as string))
                    {
                        element.GetCustomVariableRecursively(name).DefaultValue = null;

                        GlueCommands.Self.GluxCommands.SaveGlux();

                        GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                        GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
                    }
                };

                instanceMember.ContextMenuEvents.Add("Variable Properties", (sender, args) => GlueState.Self.CurrentCustomVariable = variable);

                category.Members.Add(instanceMember);
            }
        }
Exemplo n.º 4
0
        private static InstanceMember CreateInstanceMemberForSourceName(NamedObjectSave instance)
        {
            var instanceMember = new FileInstanceMember();

            instanceMember.View += () =>
            {
                var element = GlueState.Self.CurrentElement;
                var rfs     = element.ReferencedFiles.FirstOrDefault(item => item.Name == instance.SourceFile);

                if (rfs != null)
                {
                    GlueCommands.Self.SelectCommands.Select(
                        rfs,
                        instance.SourceNameWithoutParenthesis);
                }
            };

            instanceMember.FirstGridLength = new System.Windows.GridLength(140);

            instanceMember.UnmodifiedVariableName = "SourceName";
            string fileName = FlatRedBall.IO.FileManager.RemovePath(instance.SourceFile);

            instanceMember.DisplayName = $"Object in {fileName}:";

            // todo: get the type converter from the file
            var typeConverter = new AvailableNameablesStringConverter(instance);

            instanceMember.TypeConverter = typeConverter;

            instanceMember.CustomGetTypeEvent += (throwaway) => typeof(string);

            instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox);

            instanceMember.IsDefault = instance.SourceName == null;

            instanceMember.CustomGetEvent += (throwaway) =>
            {
                return(instance.SourceName);
            };

            instanceMember.CustomSetEvent += (owner, value) =>
            {
                instanceMember.IsDefault = false;
                RefreshLogic.IgnoreNextRefresh();

                instance.SourceName = value as string;

                GlueCommands.Self.GluxCommands.SaveGlux();

                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
            };

            instanceMember.IsDefaultSet += (owner, args) =>
            {
                instance.SourceName = null;
            };

            instanceMember.SetValueError += (newValue) =>
            {
                if (newValue is string && string.IsNullOrEmpty(newValue as string))
                {
                    MakeDefault(instance, "SourceName");
                }
            };

            return(instanceMember);
        }