Esempio n. 1
0
        /// <summary>
        /// Initialize Blockly and layout.  Called on page load.
        /// </summary>
        public void init()
        {
            // Block Factory has a dependency on bits of Closure that core Blockly
            // doesn't have. When you run this from file:// without a copy of Closure,
            // it breaks it non-obvious ways.  Warning about this for now until the
            // dependency is broken.
            // TODO: #668.
            if (!goog.dom.xml.isNotDefined())
            {
                Window.Alert("Sorry: Closure dependency not found. We are working on removing " +
                             "this dependency.  In the meantime, you can use our hosted demo\n " +
                             "https://blockly-demo.appspot.com/static/demos/blockfactory/index.html" +
                             "\nor use these instructions to continue running locally:\n" +
                             "https://developers.google.com/blockly/guides/modify/web/closure");
                return;
            }

            var self = this;

            // Handle Blockly Storage with App Engine.
            if (BlocklyStorage.InWindow())
            {
                this.initializeBlocklyStorage();
            }

            // Assign click handlers.
            this.assignExporterClickHandlers();
            this.assignLibraryClickHandlers();
            this.assignBlockFactoryClickHandlers();
            // Hide and show the block library dropdown.
            Document.GetElementById("modalShadow").AddEventListener("click",
                                                                    new Action(() => {
                self.closeModal();
            }));

            this.onresize(null);
            Window.AddEventListener("resize", new Action(() => {
                self.onresize(null);
            }));

            // Inject Block Factory Main Workspace.
            var toolbox = Document.GetElementById("blockfactory_toolbox");

            BlockFactory.mainWorkspace = Blockly.Core.inject("blockly", new Dictionary <string, object> {
                { "collapse", false },
                { "toolbox", toolbox },
                { "media", "../../media/" }
            });

            // Add tab handlers for switching between Block Factory and Block Exporter.
            this.addTabHandlers(this.tabMap);

            // Assign exporter change listeners.
            this.assignExporterChangeListeners();

            // Create the root block on Block Factory main workspace.
            if (BlocklyStorage.InWindow() && Window.Location.Hash != null && Window.Location.Hash.Length > 1)
            {
                BlocklyStorage.retrieveXml(Window.Location.Hash.Substring(1),
                                           BlockFactory.mainWorkspace);
            }
            else
            {
                BlockFactory.showStarterBlock();
            }
            BlockFactory.mainWorkspace.clearUndo();

            // Add Block Factory event listeners.
            this.addBlockFactoryEventListeners();

            // Workspace Factory init.
            WorkspaceFactoryInit.initWorkspaceFactory(this.workspaceFactoryController);
        }