/// <summary>
        /// Get selected blocks from block selector, pulls info from the Export
        /// Settings form in Block Exporter, and downloads code accordingly.
        /// </summary>
        public void export()
        {
            // Get selected blocks" information.
            var blockTypes  = this.view.getSelectedBlockTypes();
            var blockXmlMap = this.blockLibStorage.getBlockXmlMap(blockTypes);

            // Pull block definition(s) settings from the Export Settings form.
            var wantBlockDef      = ((HTMLInputElement)Document.GetElementById("blockDefCheck")).Checked;
            var definitionFormat  = ((HTMLSelectElement)Document.GetElementById("exportFormat")).Value;
            var blockDef_filename = ((HTMLInputElement)Document.GetElementById("blockDef_filename")).Value;

            // Pull block generator stub(s) settings from the Export Settings form.
            var wantGenStub            = ((HTMLInputElement)Document.GetElementById("genStubCheck")).Checked;
            var language               = ((HTMLSelectElement)Document.GetElementById("exportLanguage")).Value;
            var generatorStub_filename = ((HTMLInputElement)Document.GetElementById(
                                              "generatorStub_filename")).Value;

            if (wantBlockDef)
            {
                // User wants to export selected blocks" definitions.
                if (blockDef_filename == null)
                {
                    // User needs to enter filename.
                    Window.Alert("Please enter a filename for your block definition(s) download.");
                }
                else
                {
                    // Get block definition code in the selected format for the blocks.
                    var blockDefs = this.tools.getBlockDefinitions(blockXmlMap,
                                                                   definitionFormat);
                    // Download the file, using .js file ending for JSON or Javascript.
                    FactoryUtils.createAndDownloadFile(
                        blockDefs, blockDef_filename, "javascript");
                }
            }

            if (wantGenStub)
            {
                // User wants to export selected blocks" generator stubs.
                if (generatorStub_filename == null)
                {
                    // User needs to enter filename.
                    Window.Alert("Please enter a filename for your generator stub(s) download.");
                }
                else
                {
                    // Get generator stub code in the selected language for the blocks.
                    var genStubs = this.tools.getGeneratorCode(blockXmlMap,
                                                               language);
                    // Get the correct file extension.
                    var fileType = (language == "JavaScript") ? "javascript" : "plain";
                    // Download the file.
                    FactoryUtils.createAndDownloadFile(
                        genStubs, generatorStub_filename, fileType);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Tied to the "Export Block Library" button. Exports block library to file that
        /// contains JSON mapping each block type to its XML text representation.
        /// </summary>
        public void exportBlockLibraryToFile()
        {
            // Get map of block type to XML.
            var blockLib = this.blockLibraryController.getBlockLibrary();
            // Concatenate the XMLs, each separated by a blank line.
            var blockLibText = this.formatBlockLibraryForExport_(blockLib);
            // Get file name.
            var filename = Window.Prompt("Enter the file name under which to save your block " +
                                         "library.", "library.xml");

            // Download file if all necessary parameters are provided.
            if (!String.IsNullOrEmpty(filename))
            {
                FactoryUtils.createAndDownloadFile(blockLibText, filename, "xml");
            }
            else
            {
                Window.Alert("Could not export Block Library without file name under which to " +
                             "save library.");
            }
        }