Beispiel #1
0
        private void SledLuaTreeListViewEditorMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var editor = sender.As <SledLuaTreeListViewEditor>();

            if (editor == null)
            {
                return;
            }

            var luaVar = editor.LastHit.As <ISledLuaVarBaseType>();

            if (luaVar == null)
            {
                return;
            }

            // if it's a cell that can't be edited then go to to the variable

            var iColumn           = editor.GetItemColumnIndexAt(e.Location);
            var canModifyVariable =
                DebugService.IsConnected &&
                !DebugService.IsDebugging &&
                (iColumn == ValueColumnIndexValue) &&
                SledLuaUtil.IsEditableLuaType(luaVar);

            if (!canModifyVariable)
            {
                GotoService.GotoVariable(luaVar);
            }
        }
Beispiel #2
0
        private void TreeListViewAdapterCanItemPropertyChange(object sender, TreeListViewAdapter.CanItemPropertyChangeEventArgs e)
        {
            e.CanChange = false;

            var luaVar = e.Item.As <ISledLuaVarBaseType>();

            if (luaVar == null)
            {
                return;
            }

            e.CanChange =
                DebugService.IsConnected &&
                !DebugService.IsDebugging &&
                (e.PropertyIndex == ValuePropertyIndexValue) &&
                SledLuaUtil.IsEditableLuaType(luaVar);
        }
Beispiel #3
0
            public override void DrawLabel(TreeListView.Node node, Graphics gfx, Rectangle bounds, int column)
            {
                var text =
                    column == 0
                        ? node.Label
                        : ((node.Properties != null) &&
                           (node.Properties.Length >= column))
                            ? GetObjectString(node.Properties[column - 1])
                            : null;

                if (string.IsNullOrEmpty(text))
                {
                    text = string.Empty;
                }

                var editable = false;

                if (column == 2)
                {
                    var luaVar = node.Tag.As <ISledLuaVarBaseType>();
                    if (luaVar != null)
                    {
                        editable = SledLuaUtil.IsEditableLuaType(luaVar);
                    }
                }

                var flags = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix;

                // Add ellipsis if needed
                {
                    var textSize = TextRenderer.MeasureText(gfx, text, Owner.Control.Font);

                    if (textSize.Width > bounds.Width)
                    {
                        flags |= TextFormatFlags.EndEllipsis;
                    }
                }

                if (node.Selected && Owner.Control.Enabled)
                {
                    using (var b = new SolidBrush(Owner.HighlightBackColor))
                        gfx.FillRectangle(b, bounds);
                }

                var textColor =
                    node.Selected
                        ? Owner.HighlightTextColor
                        : Owner.TextColor;

                if (editable)
                {
                    textColor = node.Selected
                        ? Owner.ModifiableHighlightTextColor
                        : Owner.ModifiableTextColor;
                }

                if (!Owner.Control.Enabled)
                {
                    textColor = Owner.DisabledTextColor;
                }

                TextRenderer.DrawText(gfx, text, Owner.Control.Font, bounds, textColor, flags);
            }
        protected virtual void DomNodeAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (UndoingAttribute)
            {
                return;
            }

            if ((e.AttributeInfo != SledLuaSchema.SledLuaVarGlobalType.valueAttribute) &&
                (e.AttributeInfo != SledLuaSchema.SledLuaVarLocalType.valueAttribute) &&
                (e.AttributeInfo != SledLuaSchema.SledLuaVarUpvalueType.valueAttribute) &&
                (e.AttributeInfo != SledLuaSchema.SledLuaVarEnvType.valueAttribute))
            {
                return;
            }

            var bUndo = true;

            try
            {
                var bCanModifyVariables =
                    DebugService.IsConnected &&
                    !DebugService.IsDebugging;

                if (!bCanModifyVariables)
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Error,
                        Localization.SledLuaModifyVarInvalidTime);

                    return;
                }

                var luaVar = e.DomNode.As <ISledLuaVarBaseType>();
                if (luaVar == null)
                {
                    return;
                }

                // Check if variable type is modifiable by SLED
                if (!SledLuaUtil.IsEditableLuaType(luaVar))
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Error,
                        Localization.SledLuaModifyVarInvalidType);

                    return;
                }

                string szNewValue = null;

                // Check if what the user entered is valid for that particular Lua type
                switch (luaVar.LuaType)
                {
                case LuaType.LUA_TNUMBER:
                {
                    // Make sure no letters
                    double dNumber;
                    var    szValue = e.NewValue.ToString();
                    if (!double.TryParse(szValue, out dNumber))
                    {
                        SledOutDevice.OutLine(
                            SledMessageType.Error,
                            SledUtil.TransSub(Localization.SledLuaModifyVarInvalidValue1, szValue));

                        return;
                    }

                    szNewValue = szValue;
                }
                break;

                case LuaType.LUA_TSTRING:
                {
                    szNewValue = e.NewValue.ToString();
                }
                break;

                case LuaType.LUA_TBOOLEAN:
                {
                    // Make sure true/false/1/0
                    var szValue = e.NewValue.ToString().ToLower();
                    if (string.Compare(szValue, Resources.Resource.True, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        szNewValue = Resources.Resource.One;
                    }
                    else if (string.Compare(szValue, Resources.Resource.False, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        szNewValue = Resources.Resource.Zero;
                    }
                    else
                    {
                        if ((string.Compare(szValue, Resources.Resource.One, StringComparison.Ordinal) != 0) &&
                            (string.Compare(szValue, Resources.Resource.Zero, StringComparison.Ordinal) != 0))
                        {
                            SledOutDevice.OutLine(
                                SledMessageType.Error,
                                SledUtil.TransSub(Localization.SledLuaModifyVarInvalidValue2, e.NewValue));

                            return;
                        }

                        szNewValue = szValue;
                    }
                }
                break;
                }

                // Somehow the value the user wanted didn't make it through
                if (string.IsNullOrEmpty(szNewValue))
                {
                    return;
                }

                // Cheat and use this to get all the key value pairs.
                // This takes into account watched variables as well!
                var lookUp = SledLuaVarLookUpType.FromLuaVar(luaVar, SledLuaVarLookUpContextType.Normal);
                if (lookUp == null)
                {
                    return;
                }

                SledOutDevice.OutLine(SledMessageType.Info, Localization.SledLuaModifyVarSent);

                // Send message off
                DebugService.SendScmp(new Scmp.LuaVarUpdate(LuaLanguagePlugin.LanguageId, lookUp, szNewValue, (int)luaVar.LuaType));

                bUndo = false;
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLineDebug(
                    SledMessageType.Error,
                    "{0}: Exception in DomNodeAttributeChanged: {1}",
                    this, ex.Message);

                bUndo = true;
            }
            finally
            {
                if (bUndo)
                {
                    UndoAttributeChange(e);
                }
            }
        }