Esempio n. 1
0
        /// <summary>
        /// Parse the user-specified grid options, using reasonable defaults where
        /// behaviour is unspecified. See grid documentation:
        /// https://developers.google.com/blockly/guides/configure/web/grid
        /// </summary>
        /// <param name="options">Dictionary of options.</param>
        /// <returns>A dictionary of normalized options.</returns>
        private static GridOptions parseGridOptions_(Dictionary <string, object> options)
        {
            var grid        = options.ContainsKey("grid") ? (Dictionary <string, object>)options["grid"] : new Dictionary <string, object>();
            var gridOptions = new GridOptions();

            gridOptions.spacing = grid.ContainsKey("spacing") ? Script.ParseFloat(grid["spacing"].ToString()) : 0.0;
            gridOptions.colour  = grid.ContainsKey("colour") ? grid["colour"].ToString() : "#888";
            gridOptions.length  = grid.ContainsKey("length") ? Script.ParseFloat(grid["length"].ToString()) : 1.0;
            gridOptions.snap    = gridOptions.spacing > 0 ? (grid.ContainsKey("snap") ? (bool)grid["snap"] : false) : false;
            return(gridOptions);
        }
Esempio n. 2
0
        public Options(Dictionary <string, object> options = null)
        {
            if (options == null)
            {
                options = new Dictionary <string, object>();
            }

            var     readOnly      = options.ContainsKey("readOnly") ? (bool)options["readOnly"] : false;
            Element languageTree  = null;
            var     hasCategories = false;
            var     hasTrashcan   = false;
            var     hasCollapse   = false;
            var     hasComments   = false;
            var     hasDisable    = false;
            var     hasSounds     = false;

            if (!readOnly)
            {
                languageTree  = options.ContainsKey("toolbox") ? Options.parseToolboxTree(new Union <string, Element>(options["toolbox"])) : null;
                hasCategories = languageTree != null &&
                                languageTree.GetElementsByTagName("category").Length != 0;
                if (options.ContainsKey("trashcan"))
                {
                    hasTrashcan = (bool)options["trashcan"];
                }
                else
                {
                    hasTrashcan = hasCategories;
                }
                if (options.ContainsKey("collapse"))
                {
                    hasCollapse = (bool)options["collapse"];
                }
                else
                {
                    hasCollapse = hasCategories;
                }
                if (options.ContainsKey("comments"))
                {
                    hasComments = (bool)options["comments"];
                }
                else
                {
                    hasComments = hasCategories;
                }
                if (options.ContainsKey("disable"))
                {
                    hasDisable = (bool)options["disable"];
                }
                else
                {
                    hasDisable = hasCategories;
                }
                if (options.ContainsKey("sounds"))
                {
                    hasSounds = (bool)options["sounds"];
                }
                else
                {
                    hasSounds = true;
                }
            }
            var  rtl = options.ContainsKey("rtl") ? (bool)options["rtl"] : false;
            bool horizontalLayout;

            if (options.ContainsKey("horizontalLayout"))
            {
                horizontalLayout = (bool)options["horizontalLayout"];
            }
            else
            {
                horizontalLayout = false;
            }
            bool toolboxAtStart = true;

            if (options.ContainsKey("toolboxPosition"))
            {
                if (options["toolboxPosition"].ToString() == "end")
                {
                    toolboxAtStart = false;
                }
            }

            int toolboxPosition;

            if (horizontalLayout)
            {
                toolboxPosition = toolboxAtStart ?
                                  Core.TOOLBOX_AT_TOP : Core.TOOLBOX_AT_BOTTOM;
            }
            else
            {
                toolboxPosition = (toolboxAtStart == rtl) ?
                                  Core.TOOLBOX_AT_RIGHT : Core.TOOLBOX_AT_LEFT;
            }

            bool hasScrollbars;

            if (options.ContainsKey("scrollbars"))
            {
                hasScrollbars = (bool)options["scrollbars"];
            }
            else
            {
                hasScrollbars = hasCategories;
            }
            bool hasCss;

            if (options.ContainsKey("css"))
            {
                hasCss = (bool)options["css"];
            }
            else
            {
                hasCss = true;
            }
            var pathToMedia = "https://blockly-demo.appspot.com/static/media/";

            if (options.ContainsKey("media"))
            {
                pathToMedia = options["media"].ToString();
            }
            else if (options.ContainsKey("path"))
            {
                // "path" is a deprecated option which has been replaced by "media".
                pathToMedia = options["path"] + "media/";
            }
            var oneBasedIndex = true;

            if (options.ContainsKey("oneBasedIndex"))
            {
                oneBasedIndex = (bool)options["oneBasedIndex"];
            }

            this.RTL              = rtl;
            this.oneBasedIndex    = oneBasedIndex;
            this.collapse         = hasCollapse;
            this.comments         = hasComments;
            this.disable          = hasDisable;
            this.readOnly         = readOnly;
            this.maxBlocks        = options.ContainsKey("maxBlocks") ? (int)options["maxBlocks"] : int.MaxValue;
            this.pathToMedia      = pathToMedia;
            this.hasCategories    = hasCategories;
            this.hasScrollbars    = hasScrollbars;
            this.hasTrashcan      = hasTrashcan;
            this.hasSounds        = hasSounds;
            this.hasCss           = hasCss;
            this.horizontalLayout = horizontalLayout;
            this.languageTree     = languageTree;
            this.gridOptions      = Options.parseGridOptions_(options);
            this.zoomOptions      = Options.parseZoomOptions_(options);
            this.toolboxPosition  = toolboxPosition;
        }