Ejemplo n.º 1
0
 /// <summary> Called when Name changes on any sector. </summary>
 private void OnSectorRenamed(object Object, FieldOrProperty field, object oldValue)
 {
     if (widgets.ContainsKey(Object))
     {
         SetTabLabelText(widgets[Object], (string)field.GetValue(Object));
     }
 }
Ejemplo n.º 2
0
 public static object[] GetValues(Object t, IReadOnlyDictionary<string, object> specifiedValues, FieldOrProperty[] props, ConstructorInfo ctor)
 {
     var ctorParams = ctor.GetParameters();
     var values = new object[ctorParams.Length];
     for (int i = 0; i < values.Length; i++)
     {
         var param = ctorParams[i];
         if (specifiedValues.ContainsKey(param.Name))
         {
             values[i] = specifiedValues[param.Name].Coerce(param.ParameterType);
             continue;
         }
         var p = props.SingleOrDefault(prop => prop.Name.Equals(param.Name,
             StringComparison.InvariantCultureIgnoreCase));
         if (p != null)
         {
             values[i] = p.GetValue(t).Coerce(param.ParameterType);
         }
         else
         {
             throw new MissingValueException(param.Name);
         }
     }
     return values;
 }
Ejemplo n.º 3
0
    /// <summary> Called when our data changes, use this for re-loading. </summary>
    protected override void OnFieldChanged(FieldOrProperty field)
    {
        // set current value
        string val = (string)Field.GetValue(Object);

        comboBox.Entry.Text = val;
    }
Ejemplo n.º 4
0
    public Widget Create(object caller, object _object, FieldOrProperty field)
    {
        this.field   = field;
        this._object = _object;
        //HACK: two "this." on the following two lines are there only for hiding 2 compilation warnings and can be removed after implementation of undo mechanism.
        this.Name = this.field.Name;

        field.Changed += OnFieldChanged;
        OnFieldChanged(_object, field, null);         //load&update code is the same, why to keep it twice?

        ButtonPressEvent += OnButtonPress;
        AddEvents((int)Gdk.EventMask.ButtonPressMask);

        Gtk.Drag.DestSet(this, Gtk.DestDefaults.All,
                         target_table, DragAction.Move | DragAction.Copy);

        DragBegin  += OnDragBegin;
        DragMotion += OnDragMotion;
        DragEnd    += OnDragEnd;

        DragDataReceived += OnDragDataReceived;
        DragDataGet      += OnDragDataGet;
        DragLeave        += OnDragLeave;

        SizeAllocated += OnSizeAllocated;

        // Create a tooltip if we can.
        CustomSettingsWidget.CreateToolTip(caller, this, field);

        return(this);
    }
        private void updateSimpleProperty(string entire_name, string st, Type gOType, object obj)
        {
            MemberInfo[] members = gOType.GetMember(st, BindingAttr);
            //Debug.Log("update "+entire_name+" members length"+ members.Length+" st "+st+" type "+gOType);
            if (members.Length == 0)
            {
                return;
            }
            FieldOrProperty property = new FieldOrProperty(members[0]);

            //Debug.Log(property.Type()+" contained: "+ dictionaryPerType.ContainsKey(property.Type()));
            if (dictionaryPerType.ContainsKey(property.Type()))
            {
                Type listType = dictionaryPerType[property.Type()].GetType().GetGenericArguments()[1];
                Type argType  = listType.GetGenericArguments()[0];
                if (!dictionaryPerType[property.Type()].Contains(entire_name))
                {
                    dictionaryPerType[property.Type()].Add(entire_name, Activator.CreateInstance(listType));
                }
                ((IList)dictionaryPerType[property.Type()][entire_name]).Add(Convert.ChangeType(property.GetValue(obj), argType));
                int listCount = ((IList)dictionaryPerType[property.Type()][entire_name]).Count;
                if (listCount > 500)
                {
                    ((IList)dictionaryPerType[property.Type()][entire_name]).RemoveAt(0);
                }
                //Debug.Log("added " + entire_name);
            }
            else
            {
                //Debug.Log("advanced update for " + entire_name);
                advancedUpdate(property, entire_name, obj);
            }

            //Debug.Log("added " + st + "with value " + ((IList)dictionaryPerType[property.Type()][st])[((IList)dictionaryPerType[property.Type()][st]).Count - 1]);
        }
Ejemplo n.º 6
0
            private FieldOrProperty FindField(Type type, string name)
            {
                FieldOrProperty f = new FieldOrProperty();

                f.Name = name;

                var field = type.GetField(name);

                if (field != null)
                {
                    f.Field    = field;
                    f.Property = null;
                    f.Type     = field.FieldType;
                }
                else
                {
                    var property = type.GetProperty(name);
                    if (property != null)
                    {
                        f.Property = property;
                        f.Field    = null;
                        f.Type     = property.PropertyType;
                    }
                }

                return(f);
            }
Ejemplo n.º 7
0
 /// <summary> Called when our field changes on any instance of same type as our Object. </summary>
 private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
 {
     if (this.Object == Object)
     {
         if (field.Type == typeof(string) || field.Type == typeof(float) ||
             field.Type == typeof(int))
         {
             Gtk.Entry entry = (Gtk.Entry)widgetTable[fieldTable.IndexOf(field)];
             object    val   = field.GetValue(Object);
             if (val != null)
             {
                 entry.Text = val.ToString();
             }
         }
         else if (field.Type == typeof(bool))
         {
             Gtk.CheckButton checkButton = (Gtk.CheckButton)widgetTable[fieldTable.IndexOf(field)];
             checkButton.Active = (bool)field.GetValue(Object);
         }
         else if (field.Type.IsEnum)
         {
             Gtk.ComboBox comboBox = (Gtk.ComboBox)widgetTable[fieldTable.IndexOf(field)];
             // FIXME: This will break if:
             //        1) the first enum isn't 0 and/or
             //        2) the vaules are not sequential (0, 1, 3, 4 wouldn't work)
             object val = field.GetValue(Object);
             if (val != null)
             {
                 comboBox.Active = (int)val;
             }
         }
     }
 }
Ejemplo n.º 8
0
    public static object[] GetArrayProperty(string path, string collectionElementProperty, Type type, object obj, int i, int j)
    {
        //////Debug.unityLogger.logEnabled = false;

        MemberInfo[] members = type.GetMember(path, BindingAttr);
        //////MyDebugger.MyDebug("LOOKING FOR " + path + " MATRIX");
        object[] toReturn = new object[2];
        if (members.Length == 0)
        {
            return(toReturn);
        }
        //////MyDebugger.MyDebug("MATRIX FOUND");

        FieldOrProperty property = new FieldOrProperty(members[0]);
        Array           matrix   = property.GetValue(obj) as Array;

        //////MyDebugger.MyDebug("THE MATRIX "+property.Name()+" IN " + obj + " IS " + matrix);
        toReturn[0] = matrix;
        if (matrix != null && matrix.GetLength(0) > i && matrix.GetLength(1) > j)
        {
            ////MyDebugger.MyDebug("COLLECTION ELEMENT PROPERTY " + collectionElementProperty);
            MemberInfo[] m = matrix.GetValue(i, j).GetType().GetMember(collectionElementProperty, BindingAttr);
            ////MyDebugger.MyDebug("MATRIX ELEMENTS TYPE " + matrix.GetValue(i, j).GetType());
            if (m.Length == 0)
            {
                return(toReturn);
            }
            else
            {
                ////MyDebugger.MyDebug("FOUND INNER PROPERTY ");
            }
            toReturn[1] = new FieldOrProperty(m[0]);
        }
        return(toReturn);
    }
Ejemplo n.º 9
0
    public static object ReadComposedProperty(GameObject gameObject, string entire_name, string st, Type objType, object obj, ReadSimpleProperty ReadSimpleProperty)
    {
        ////Debug.unityLogger.logEnabled = false;
        string parentName = st.Substring(0, st.IndexOf("^"));
        string child      = st.Substring(st.IndexOf("^") + 1, st.Length - st.IndexOf("^") - 1);

        MemberInfo[] members = objType.GetMember(parentName, SensorsUtility.BindingAttr);
        MyDebugger.MyDebug("members with name " + parentName + " " + members.Length);
        if (members.Length == 0)
        {
            return(ReadComponent(gameObject, entire_name, st, objType, obj, ReadSimpleProperty));
        }
        FieldOrProperty parentProperty = new FieldOrProperty(members[0]);
        ///MyDebugger.MyDebug(parentProperty.Name());
        object parent     = parentProperty.GetValue(obj);
        Type   parentType = parent.GetType();

        if (!child.Contains("^"))
        {
            return(ReadSimpleProperty(child, parentType, parent));
        }
        else
        {
            return(ReadComposedProperty(gameObject, entire_name, child, parentType, parent, ReadSimpleProperty));
        }
    }
        private static void HandleProperty(SyntaxNodeAnalysisContext context)
        {
            if (context.IsExcludedFromAnalysis())
            {
                return;
            }

            var property = (IPropertySymbol)context.ContainingSymbol;

            if (property.IsStatic ||
                property.IsIndexer)
            {
                return;
            }

            var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;

            if (propertyDeclaration.ExpressionBody != null)
            {
                return;
            }

            if (propertyDeclaration.TryGetSetter(out var setter) &&
                setter.Body != null)
            {
                // Handle the backing field
                return;
            }

            if (FieldOrProperty.TryCreate(property, out var fieldOrProperty) &&
                Disposable.IsPotentiallyAssignableFrom(property.Type, context.Compilation))
            {
                HandleFieldOrProperty(context, fieldOrProperty);
            }
        }
Ejemplo n.º 11
0
        internal static Result IsDisposed(FieldOrProperty member, INamedTypeSymbol context, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (context is null)
            {
                return(Result.Unknown);
            }

            using var walker = DisposeWalker.Borrow(context, semanticModel, cancellationToken);
            var isMemberDisposed = walker.IsMemberDisposed(member.Symbol);

            switch (isMemberDisposed)
            {
            case Result.Yes:
            case Result.AssumeYes:
                return(isMemberDisposed);

            default:
                if (context.IsAssignableTo(KnownSymbol.SystemWindowsFormsForm, semanticModel.Compilation) &&
                    Winform.IsAddedToComponents(member, context, semanticModel, cancellationToken))
                {
                    return(Result.Yes);
                }

                return(isMemberDisposed);
            }
        }
Ejemplo n.º 12
0
        internal static bool TryGetDefaultFieldsOrProperties(ITypeSymbol type, Compilation compilation, out IReadOnlyList <FieldOrProperty> defaults)
        {
            List <FieldOrProperty> temp = null;

            foreach (var member in type.GetMembers())
            {
                if (member.IsStatic &&
                    (member.DeclaredAccessibility == Accessibility.Public ||
                     member.DeclaredAccessibility == Accessibility.Internal))
                {
                    if (FieldOrProperty.TryCreate(member, out var fieldOrProperty) &&
                        (fieldOrProperty.Type.IsAssignableTo(KnownSymbol.IValueConverter, compilation) ||
                         fieldOrProperty.Type.IsAssignableTo(KnownSymbol.IMultiValueConverter, compilation)))
                    {
                        if (temp == null)
                        {
                            temp = new List <FieldOrProperty>();
                        }

                        temp.Add(fieldOrProperty);
                    }
                }
            }

            defaults = temp;
            return(defaults != null);
        }
Ejemplo n.º 13
0
 /// <summary> Called when our field changes on any instance of same type as our Object. </summary>
 private void OnAnyFieldChanged(object Object, FieldOrProperty field, object oldValue)
 {
     if (this.Object == Object)
     {
         OnFieldChanged(field);
     }
 }
        private static bool IsRelayReturn(MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (memberAccess == null ||
                !memberAccess.IsKind(SyntaxKind.SimpleMemberAccessExpression) ||
                memberAccess.Expression is InstanceExpressionSyntax ||
                memberAccess.Expression == null)
            {
                return(false);
            }

            if (semanticModel.TryGetSymbol(memberAccess.Expression, cancellationToken, out ISymbol member) &&
                FieldOrProperty.TryCreate(member, out FieldOrProperty fieldOrProperty) &&
                memberAccess.TryFirstAncestor <TypeDeclarationSyntax>(out var typeDeclaration) &&
                !IsInjected(fieldOrProperty, typeDeclaration, semanticModel, cancellationToken))
            {
                return(false);
            }

            if (memberAccess.Expression is IdentifierNameSyntax &&
                memberAccess.Name is IdentifierNameSyntax)
            {
                return(true);
            }

            if (memberAccess.Expression is MemberAccessExpressionSyntax &&
                memberAccess.Name is IdentifierNameSyntax)
            {
                return(true);
            }

            return(false);
        }
 private object[] ReadSimpleListProperty(string path, string collectionElementProperty, Type type, object obj, int i)
 {
     object[] toReturn  = new object[3];
     object[] listValue = SensorsUtility.GetListProperty(path, collectionElementProperty, type, obj, i);
     if (listValue[0] != null && listValue[1] != null)
     {
         FieldOrProperty toRead = (FieldOrProperty)listValue[1];
         IList           list   = (IList)listValue[0];
         toReturn[0] = toRead.GetValue(list[i]).GetType(); //Property type of the element of the collection
         toReturn[1] = list.Count;
         toReturn[2] = list[i].GetType();                  //Collection Element Type
         return(toReturn);
     }
     else if (listValue[0] != null)
     {
         toReturn[1] = 0;
         toReturn[2] = listValue[0].GetType().GetGenericArguments()[0];
         foreach (FieldOrProperty member in ReflectionExecutor.GetFieldsAndProperties(toReturn[2]))
         {
             if (member.Name().Equals(currentSubProperty))
             {
                 toReturn[0] = member.Type();
                 return(toReturn);
             }
         }
     }
     return(null);
 }
 private object[] ReadSimpleArrayProperty(string path, string collectionElementProperty, Type type, object obj, int i, int j)
 {
     object[] matrixValue = SensorsUtility.GetArrayProperty(path, collectionElementProperty, type, obj, i, j);//matrixValue[0] is the actual matrix, matrixValue[1] is the Property
     object[] toReturn    = new object[4];
     if (matrixValue[0] != null && matrixValue[1] != null)
     {
         MyDebugger.MyDebug("READING THE MATRIX!");
         FieldOrProperty toRead = (FieldOrProperty)matrixValue[1];
         Array           matrix = (Array)matrixValue[0];
         toReturn[0] = toRead.GetValue(matrix.GetValue(i, j)).GetType(); //Property type of the element of the collection
         toReturn[1] = matrix.GetLength(0);
         toReturn[2] = matrix.GetLength(1);
         toReturn[3] = matrix.GetValue(i, j).GetType(); //Collection Element Type
         MyDebugger.MyDebug("LENGTH " + toReturn[1] + " " + toReturn[2]);
         return(toReturn);
     }
     else if (matrixValue[0] != null)
     {
         toReturn[1] = 0;
         toReturn[2] = 0;
         toReturn[3] = matrixValue[0].GetType().GetGenericArguments()[0];
         foreach (FieldOrProperty member in ReflectionExecutor.GetFieldsAndProperties(toReturn[3]))
         {
             if (member.Name().Equals(currentSubProperty))
             {
                 toReturn[0] = member.Type();
                 return(toReturn);
             }
         }
     }
     return(null);
 }
        private static bool ShouldCallBase(IMethodSymbol method, MethodDeclarationSyntax methodDeclaration, SyntaxNodeAnalysisContext context)
        {
            if (method.Parameters.TrySingle(out var parameter) &&
                parameter.Type == KnownSymbol.Boolean &&
                method.IsOverride &&
                method.OverriddenMethod is IMethodSymbol overridden &&
                !DisposeMethod.TryFindBaseCall(methodDeclaration, context.SemanticModel, context.CancellationToken, out _))
            {
                if (overridden.DeclaringSyntaxReferences.Length == 0)
                {
                    return(true);
                }
                else
                {
                    using (var disposeWalker = DisposeWalker.Borrow(overridden, context.SemanticModel, context.CancellationToken))
                    {
                        foreach (var disposeCall in disposeWalker)
                        {
                            if (DisposeCall.TryGetDisposed(disposeCall, context.SemanticModel, context.CancellationToken, out var disposed) &&
                                FieldOrProperty.TryCreate(disposed, out var fieldOrProperty) &&
                                !DisposableMember.IsDisposed(fieldOrProperty, method, context.SemanticModel, context.CancellationToken))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 18
0
        internal static bool TryGetAssignedValue(this FieldOrProperty fieldOrProperty, CancellationToken cancellationToken, out ExpressionSyntax value)
        {
            value = null;
            if (fieldOrProperty.Symbol is IFieldSymbol field)
            {
                return(field.TryGetAssignedValue(cancellationToken, out value));
            }

            if (fieldOrProperty.Symbol is IPropertySymbol property)
            {
                if (property.TrySingleDeclaration(cancellationToken, out PropertyDeclarationSyntax declaration))
                {
                    if (declaration.Initializer != null)
                    {
                        value = declaration.Initializer.Value;
                    }
                    else if (declaration.ExpressionBody != null)
                    {
                        value = declaration.ExpressionBody.Expression;
                    }

                    return(value != null);
                }
            }

            return(false);
        }
        private static void HandleFieldOrProperty(SyntaxNodeAnalysisContext context, FieldOrProperty fieldOrProperty)
        {
            using (var assignedValues = AssignedValueWalker.Borrow(fieldOrProperty.Symbol, context.SemanticModel, context.CancellationToken))
            {
                using (var recursive = RecursiveValues.Borrow(assignedValues, context.SemanticModel, context.CancellationToken))
                {
                    if (Disposable.IsAnyCreation(recursive, context.SemanticModel, context.CancellationToken).IsEither(Result.Yes, Result.AssumeYes))
                    {
                        if (Disposable.IsAnyCachedOrInjected(recursive, context.SemanticModel, context.CancellationToken).IsEither(Result.Yes, Result.AssumeYes) ||
                            IsMutableFromOutside(fieldOrProperty))
                        {
                            context.ReportDiagnostic(Diagnostic.Create(IDISP008DontMixInjectedAndCreatedForMember.Descriptor, context.Node.GetLocation()));
                        }
                        else if (context.Node.TryFirstAncestorOrSelf <TypeDeclarationSyntax>(out var typeDeclaration) &&
                                 DisposableMember.IsDisposed(fieldOrProperty, typeDeclaration, context.SemanticModel, context.CancellationToken).IsEither(Result.No, Result.AssumeNo) &&
                                 !TestFixture.IsAssignedAndDisposedInSetupAndTearDown(fieldOrProperty, typeDeclaration, context.SemanticModel, context.CancellationToken))
                        {
                            context.ReportDiagnostic(Diagnostic.Create(IDISP002DisposeMember.Descriptor, context.Node.GetLocation()));

                            if (!DisposeMethod.TryFindFirst(fieldOrProperty.ContainingType, context.Compilation, Search.TopLevel, out _) &&
                                !TestFixture.IsAssignedInSetUp(fieldOrProperty, typeDeclaration, context.SemanticModel, context.CancellationToken, out _))
                            {
                                context.ReportDiagnostic(Diagnostic.Create(IDISP006ImplementIDisposable.Descriptor, context.Node.GetLocation()));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
    protected void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
    {
        if (_object == Object)
        {
            badguys = (List <string>)field.GetValue(this._object);

            foreach (string name in badguys)                    //process each badguy name and crate sprite for it

            {
                if (!badguySprites.ContainsKey(name))
                {
                    badguySprites.Add(name, CrateSprite(name));
                }
            }

            SetSizeRequest(-1, ROW_HEIGHT * ((badguys.Count - 1) / TILES_PER_ROW + 1));

            if (badguys.Count > 0)                      //we need at least one badguy for dragging
            {
                Gtk.Drag.SourceSet(this, Gdk.ModifierType.Button1Mask,
                                   source_table, DragAction.Move);
            }
            else
            {
                Gtk.Drag.SourceUnset(this);
            }

            draggedID     = NONE;
            draggedBadguy = "";
            dragging      = false;

            QueueDraw();
        }
    }
Ejemplo n.º 21
0
        internal static bool IsAssignedAndDisposedInSetupAndTearDown(FieldOrProperty fieldOrProperty, TypeDeclarationSyntax scope, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            if (AssignmentExecutionWalker.SingleFor(fieldOrProperty.Symbol, scope, Scope.Member, semanticModel, cancellationToken, out var assignment) &&
                assignment.FirstAncestor <MethodDeclarationSyntax>() is MethodDeclarationSyntax methodDeclaration)
            {
                if (Attribute.TryFind(methodDeclaration, KnownSymbol.NUnitSetUpAttribute, semanticModel, cancellationToken, out _))
                {
                    if (fieldOrProperty.ContainingType.TryFindFirstMethodRecursive(x => x.GetAttributes().Any(a => a.AttributeClass == KnownSymbol.NUnitTearDownAttribute), out var tearDown))
                    {
                        return(DisposableMember.IsDisposed(fieldOrProperty, tearDown, semanticModel, cancellationToken));
                    }
                }

                if (Attribute.TryFind(methodDeclaration, KnownSymbol.NUnitOneTimeSetUpAttribute, semanticModel, cancellationToken, out _))
                {
                    if (fieldOrProperty.ContainingType.TryFindFirstMethodRecursive(
                            x => x.GetAttributes().Any(a => a.AttributeClass == KnownSymbol.NUnitOneTimeTearDownAttribute),
                            out var tearDown))
                    {
                        return(DisposableMember.IsDisposed(fieldOrProperty, tearDown, semanticModel, cancellationToken));
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 22
0
        internal static bool IsDisposed(FieldOrProperty member, MethodDeclarationSyntax disposeMethod, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            using var walker = DisposeWalker.Borrow(disposeMethod, semanticModel, cancellationToken);
            if (Disposable.IsAssignableFrom(member.Type, semanticModel.Compilation))
            {
                foreach (var candidate in walker.Invocations)
                {
                    if (DisposeCall.IsDisposing(candidate, member.Symbol, semanticModel, cancellationToken))
                    {
                        return(true);
                    }
                }
            }

            foreach (var candidate in walker.Identifiers)
            {
                if (candidate.Identifier.Text == member.Name &&
                    semanticModel.TryGetSymbol(candidate, cancellationToken, out var candidateSymbol) &&
                    candidateSymbol.OriginalDefinition.Equals(member.Symbol))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 23
0
        internal static bool HasMutableInstanceMembers(ITypeSymbol type)
        {
            if (type == null)
            {
                return(false);
            }

            while (type != null &&
                   type != KnownSymbols.Object)
            {
                foreach (var member in type.GetMembers())
                {
                    if (FieldOrProperty.TryCreate(member, out var fieldOrProperty) &&
                        !fieldOrProperty.IsStatic)
                    {
                        switch (member)
                        {
                        case IFieldSymbol field when !field.IsConst && !field.IsReadOnly:
                        case IPropertySymbol property when property.SetMethod != null:
                            return(true);
                        }

                        if (fieldOrProperty.Type.Is(KnownSymbols.IEnumerable) &&
                            fieldOrProperty.Type.TryFindFirstMethod("Add", out _))
                        {
                            return(true);
                        }
                    }
                }

                type = type.BaseType;
            }

            return(false);
        }
        private void setDefaultValue(string entire_name, string st, Type objType, object obj)
        {
            MemberInfo[] members = objType.GetMember(st, BindingAttr);
            if (members.Length == 0)
            {
                return;
            }
            FieldOrProperty property = new FieldOrProperty(members[0]);

            //Debug.Log("property " + property.Name() + " " + property.Type());
            if (dictionaryPerType.ContainsKey(property.Type()))
            {
                IDictionary dic = dictionaryPerType[property.Type()];
                Type        propertyInDictionaryType = dic.GetType().GetGenericArguments()[1];
                if (!dic.Contains(entire_name))
                {
                    //Debug.Log("Adding " + entire_name);
                    dic.Add(entire_name, Convert.ChangeType("0", propertyInDictionaryType));
                }
                else
                {
                    dic[entire_name] = Convert.ChangeType("0", propertyInDictionaryType);
                }
            }
        }
Ejemplo n.º 25
0
    /// <summary> Moves any ILayer from layer to layer when ZPos is changed. </summary>
    private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
    {
        if (!(Object is IGameObject && sector.Contains((IGameObject)Object)))           //return, if it's not (GameObject in our sector)
        {
            return;
        }

        if (Object is IDrawableLayer && field.Name == "Layer")           //filter for ILayer.Layer
        {
            Layer     layer    = (Layer)SceneGraphRoot;
            ILayer    ILayer   = (ILayer)Object;
            ColorNode color    = colors[ILayer];
            int       oldLayer = (int)oldValue;

            layer.Remove(oldLayer, color);
            layer.Add(ILayer.Layer, color);

            QueueDraw();
        }

        PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
                                                         field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));

        if (propertyProperties != null && propertyProperties.RedrawOnChange)            //Every property that affects appearance is marked using this attribute
        {
            QueueDraw();
        }
    }
        //public bool GetBoolProperty()
        private void updateComposedProperty(string entire_name, string st, Type objType, object obj)
        {
            string parentName = st.Substring(0, st.IndexOf("^"));
            string child      = st.Substring(st.IndexOf("^") + 1, st.Length - st.IndexOf("^") - 1);

            MemberInfo[] members = objType.GetMember(parentName, BindingAttr);
            // Debug.Log("members with name " + parentName + " " + members.Length);
            if (members.Length == 0)
            {
                updateComponent(entire_name, st, objType, obj);
                return;
            }
            FieldOrProperty parentProperty = new FieldOrProperty(objType.GetMember(parentName)[0]);
            //Debug.Log(parentProperty.Name());
            object parent     = parentProperty.GetValue(obj);
            Type   parentType = parent.GetType();

            if (!child.Contains("^"))
            {
                updateSimpleProperty(entire_name, child, parentType, parent);
            }
            else
            {
                updateComposedProperty(entire_name, child, parentType, parent);
            }
        }
Ejemplo n.º 27
0
    public LayerListWidget(IEditorApplication application)
    {
        this.application  = application;
        RowSeparatorFunc  = OurRowSeparatorFunc;
        ButtonPressEvent += OnButtonPressed;

        VisibilityRenderer visibilityRenderer = new VisibilityRenderer();

        visibilityRenderer.VisibilityChanged += OnVisibilityChange;
        TreeViewColumn visibilityColumn = new TreeViewColumn("Visibility",
                                                             visibilityRenderer);

        visibilityColumn.SetCellDataFunc(visibilityRenderer, (TreeCellDataFunc)VisibilityDataFunc);
        AppendColumn(visibilityColumn);

        CellRendererText TextRenderer = new CellRendererText();
        TreeViewColumn   TypeColumn   = new TreeViewColumn();

        TypeColumn.PackStart(TextRenderer, true);
        TypeColumn.SetCellDataFunc(TextRenderer, (TreeCellDataFunc)TextDataFunc);
        TypeColumn.Title = "Type";
        AppendColumn(TypeColumn);

        HeadersVisible = false;

        application.SectorChanged  += OnSectorChanged;
        application.TilemapChanged += OnTilemapChanged;
        application.LevelChanged   += OnLevelChanged;

        FieldOrProperty.Lookup(typeof(Tilemap).GetField("Name")).Changed += OnTilemapModified;
        FieldOrProperty.Lookup(typeof(Tilemap).GetField("ZPos")).Changed += OnTilemapModified;
    }
Ejemplo n.º 28
0
 public PropertyChangeCommand(string title, FieldOrProperty field, Object obj, Object newData, Object oldData)
     : base(title)
 {
     this.obj = obj;
     this.field = field;
     this.oldData = oldData;
     this.newData = newData;
 }
Ejemplo n.º 29
0
 public override void Dispose()
 {
     sector.ObjectAdded         -= OnObjectAdded;
     sector.ObjectRemoved       -= OnObjectRemoved;
     sector.SizeChanged         -= OnSizeChanged;
     application.TilemapChanged -= OnTilemapChanged;
     FieldOrProperty.Lookup(typeof(Tilemap).GetField("ZPos")).Changed -= OnTilemapZPosModified;
 }
Ejemplo n.º 30
0
 public SortedListMoveCommand(string title, object Object, FieldOrProperty field, int position, int newPosition) : base(title)
 {
     this.Object      = Object;
     this.field       = field;
     this.position    = position;
     this.newPosition = newPosition;
     this.changedList = (List <T>) this.field.GetValue(this.Object);
 }
Ejemplo n.º 31
0
 /// <summary> Called when our data changes, use this for re-loading. </summary>
 protected override void OnFieldChanged(FieldOrProperty field)
 {
     // Get the index of the current value from the original list
     // due to limitations in ComboBox
     string val = (string)Field.GetValue(Object);
     if (val != null)
         comboBox.Active = sectorNames.IndexOf(val);
 }
 /// <summary> Called when our data changes, use this for re-loading. </summary>
 protected override void OnFieldChanged(FieldOrProperty field)
 {
     string val = (string) Field.GetValue(Object);
     if (val != null)
         entry.Text = val;
     else
         entry.Text = "";
 }
Ejemplo n.º 33
0
 public PropertyChangeCommand(string title, FieldOrProperty field, Object obj, Object newData, Object oldData)
     : base(title)
 {
     this.obj     = obj;
     this.field   = field;
     this.oldData = oldData;
     this.newData = newData;
 }
Ejemplo n.º 34
0
 /// <summary> Called when our field changes on any instance of same type as our Object. </summary>
 private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
 {
     if (object_ == Object)
     {
         object val = field.GetValue(object_);
         scriptEditor.Buffer.Text = val != null?val.ToString() : String.Empty;
     }
 }
Ejemplo n.º 35
0
 public PathTool(Application application, Path path)
 {
     this.application = application;
     this.path = path;
     field = FieldOrProperty.Lookup(typeof(Path).GetField("Nodes"));
     application.EditProperties(path, "Path");
     killTimer = false;
     GLib.Timeout.Add(100, Animate);
 }
 /// <summary> Static member accesible for other ICustomSettingsWidgets. </summary>
 public static void CreateToolTip(object caller, Widget widget, FieldOrProperty field)
 {
     // Create a tooltip if we can.
     PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
         field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));
     if ((propertyProperties != null) && (caller.GetType() == typeof(PropertiesView))) {
         //PropertiesView propview = (PropertiesView)caller;
         widget.TooltipText = propertyProperties.Tooltip;
     }
 }
Ejemplo n.º 37
0
    public ScriptEditor(string title, FieldOrProperty field, object object_)
    {
        this.field = field;
        this.object_ = object_;

        Glade.XML gxml = new Glade.XML("editor.glade", "scriptDialog");
        gxml.Autoconnect(this);

        if(scriptDialog == null || scriptEditor == null)
            throw new Exception("Couldn't load ScriptEditor dialog");

        /*
        window = new Window("Supertux - ScriptEditor - " + title);
        window.SetSizeRequest(640, 500);
        */

        object val = field.GetValue(object_);
        scriptEditor.Buffer.Text = val != null ? val.ToString() : "";

        scriptDialog.ShowAll();
    }
Ejemplo n.º 38
0
    public ScriptEditor(string title, FieldOrProperty field, object object_)
    {
        this.field = field;
        this.object_ = object_;

        Glade.XML gxml = new Glade.XML("editor.glade", "scriptDialog");
        gxml.Autoconnect(this);

        if(scriptDialog == null || scriptEditor == null)
            throw new Exception("Couldn't load ScriptEditor dialog");

        /*
        window = new Window("Supertux - ScriptEditor - " + title);
        window.SetSizeRequest(640, 500);
        */

        scriptDialog.Title = title + "  -  " + scriptDialog.Title;
        OnFieldChanged(object_, field, null);	//same code as for initialization
        field.Changed += OnFieldChanged;

        scriptDialog.ShowAll();
    }
 /// <summary> Called when our data changes, use this for re-loading. </summary>
 protected virtual void OnFieldChanged(FieldOrProperty field)
 {
 }
 public Widget Create(object caller, object Object, FieldOrProperty field)
 {
     this.Field = field;
     this.Object = Object;
     return Create(caller);
 }
Ejemplo n.º 41
0
    protected void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
    {
        if (_object == Object) {
            badguys = (List<string>)field.GetValue(this._object);

            foreach(string name in badguys){	//process each badguy name and crate sprite for it

                if(!badguySprites.ContainsKey(name)) {
                    badguySprites.Add(name, CrateSprite(name));
                }
            }

            SetSizeRequest( -1, ROW_HEIGHT * ((badguys.Count  - 1) / TILES_PER_ROW + 1));

            if (badguys.Count > 0)		//we need at least one badguy for dragging
                Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask,
                            source_table, DragAction.Move);
            else
                Gtk.Drag.SourceUnset(this);

            draggedID = NONE;
            draggedBadguy = "";
            dragging = false;

            QueueDraw();
        }
    }
Ejemplo n.º 42
0
    private void OnFieldModified(object Object, FieldOrProperty field, object oldValue)
    {
        if (! (Object is ILayer)) //ignore changes on other objects
            return;
        if (! (field.Name=="Layer" || field.Name=="Name")) //ignore changes on other fields
            return;

        //TODO: Is that sorting execute-once or what? (found no other working way)
        TreeStore store = (TreeStore) Model;
        if (store != null)
            store.SetSortFunc( 0, compareLayer );
        QueueDraw();
    }
Ejemplo n.º 43
0
 /// <summary> Called when our field changes on any instance of same type as our Object. </summary>
 private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
 {
     if (object_ == Object) {
         object val = field.GetValue(object_);
         scriptEditor.Buffer.Text = val != null ? val.ToString() : String.Empty;
     }
 }
Ejemplo n.º 44
0
    public Widget Create(object caller, object _object, FieldOrProperty field)
    {
        this.field = field;
        this._object = _object;
        //HACK: two "this." on the following two lines are there only for hiding 2 compilation warnings and can be removed after implementation of undo mechanism.
        this.Name = this.field.Name;

        field.Changed += OnFieldChanged;
        OnFieldChanged(_object, field, null); //load&update code is the same, why to keep it twice?

        ButtonPressEvent += OnButtonPress;
        AddEvents((int) Gdk.EventMask.ButtonPressMask);

        Gtk.Drag.DestSet (this, Gtk.DestDefaults.All,
                            target_table, DragAction.Move | DragAction.Copy);

        DragBegin += OnDragBegin;
        DragMotion += OnDragMotion;
        DragEnd += OnDragEnd;

        DragDataReceived += OnDragDataReceived;
        DragDataGet += OnDragDataGet;
        DragLeave += OnDragLeave;

        SizeAllocated += OnSizeAllocated;

        // Create a tooltip if we can.
        CustomSettingsWidget.CreateToolTip(caller, this, field);

        return this;
    }
Ejemplo n.º 45
0
    protected override void OnFieldChanged(FieldOrProperty field)
    {
        Drawing.Color val = (Drawing.Color) Field.GetValue(Object);

        Gdk.Color color = new Gdk.Color();
        color.Red = (ushort) (val.Red * 65535f);
        color.Green = (ushort) (val.Green * 65535f);
        color.Blue = (ushort) (val.Blue * 65535f);

        if (useAlpha)
            colorButton.Alpha = (ushort) (val.Alpha * 65535f);

        colorButton.Color = color;
    }
Ejemplo n.º 46
0
    /// <summary> Moves any ILayer from layer to layer when ZPos is changed. </summary>
    private void OnFieldChanged(object Object, FieldOrProperty field, object oldValue)
    {
        if (! (Object is IGameObject && sector.Contains((IGameObject)Object)))	//return, if it's not (GameObject in our sector)
            return;

        if (Object is IDrawableLayer && field.Name == "Layer") { //filter for ILayer.Layer
            Layer layer = (Layer) SceneGraphRoot;
            ILayer ILayer = (ILayer) Object;
            ColorNode color = colors[ILayer];
            int oldLayer = (int) oldValue;

            layer.Remove(oldLayer, color);
            layer.Add(ILayer.Layer, color);

            QueueDraw();
        }

        PropertyPropertiesAttribute propertyProperties = (PropertyPropertiesAttribute)
                field.GetCustomAttribute(typeof(PropertyPropertiesAttribute));
        if (propertyProperties != null && propertyProperties.RedrawOnChange)	//Every property that affects appearance is marked using this attribute
            QueueDraw();
    }
 /// <summary> Called when our field changes on any instance of same type as our Object. </summary>
 private void OnAnyFieldChanged(object Object, FieldOrProperty field, object oldValue)
 {
     if (this.Object == Object)
         OnFieldChanged(field);
 }
 /// <summary> Called when our data changes, use this for re-loading. </summary>
 protected override void OnFieldChanged(FieldOrProperty field)
 {
     // set current value
     string val = (string)Field.GetValue(Object);
     comboBox.Entry.Text = val;
 }
 /// <summary> Called when Name changes on any sector. </summary>
 private void OnSectorRenamed(object Object, FieldOrProperty field, object oldValue)
 {
     if (widgets.ContainsKey(Object))
         SetTabLabelText (widgets[Object], (string) field.GetValue(Object));
 }