Commit 47724d97 authored by carlosperate's avatar carlosperate

Add save sketch from web app, added option to electron and fetch name from sketch name input.

parent d88458fe
......@@ -48,7 +48,7 @@ window.addEventListener('load', function load(event) {
ArduinoMaterial.bindActionFunctions_ = function() {
// Navigation buttons
ArduinoMaterial.bindClick_('button_load', ArduinoMaterial.loadUserXmlFile);
ArduinoMaterial.bindClick_('button_save', ArduinoMaterial.saveXmlFile);
ArduinoMaterial.bindClick_('button_save', ArduinoMaterial.saveXmlFileAs);
ArduinoMaterial.bindClick_('button_delete', ArduinoMaterial.discard);
// Side menu buttons, they also close the side menu
......@@ -57,7 +57,7 @@ ArduinoMaterial.bindActionFunctions_ = function() {
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_save', function() {
ArduinoMaterial.saveXmlFile();
ArduinoMaterial.saveXmlFileAs();
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_delete', function() {
......@@ -192,11 +192,25 @@ ArduinoMaterial.loadUserXmlFile = function() {
* Creates an XML file containing the blocks from the Blockly workspace and
* prompts the users to save it into their local file system.
*/
ArduinoMaterial.saveXmlFile = function() {
ArduinoMaterial.saveXmlFileAs = function() {
var xmlName = document.getElementById('sketch_name').value;
var blob = new Blob(
[ArduinoMaterial.generateXml()],
{type: 'text/plain;charset=utf-8'});
saveAs(blob, 'ardublockly.xml');
saveAs(blob, xmlName + '.xml');
};
/**
* Creates an Arduino Sketch file containing the Arduino code generated from
* the Blockly workspace and prompts the users to save it into their local file
* system.
*/
ArduinoMaterial.saveSketchFileAs = function() {
var sketchName = document.getElementById('sketch_name').value;
var blob = new Blob(
[ArduinoMaterial.generateArduino()],
{type: 'text/plain;charset=utf-8'});
saveAs(blob, sketchName + '.ino');
};
/**
......
......@@ -200,14 +200,30 @@ ArduinoMaterial.containerFullWidth = function() {
};
/**
* Initialises the sketch name input text javascript to dynamically adjust its
* Initialises the sketch name input text JavaScript to dynamically adjust its
* width to the width of its contents.
*/
ArduinoMaterial.sketchNameSizeEffect = function() {
var resizeInput = function() {
$(this).attr('size', $(this).val().length);
var inputSize = ($(this).val().length > 1) ? ($(this).val().length - 1) : 1;
$(this).attr('size', inputSize);
};
$('#sketch_name').keyup(resizeInput).each(resizeInput);
var correctInput = function() {
// If nothing in the input, add default name
if ($(this).val() == '') {
$(this).val('Sketch_Name');
$(this).attr('size', 10);
}
// Replace all spaces with underscores
$(this).val($(this).val().replace(/ /g, '_'));
};
var sketchNameInput = $('#sketch_name');
sketchNameInput.val('Sketch_Name');
sketchNameInput.attr('size', 10);
sketchNameInput.keyup(resizeInput).each(resizeInput);
sketchNameInput.blur(correctInput);
};
/**
......
......@@ -106,12 +106,17 @@ var getFileMenuData = function() {
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.saveXmlFile()");
.executeJavaScript("ArduinoMaterial.saveXmlFileAs()");
}
}, {
label: 'Save Arduino Sketch as',
accelerator: 'Shift+CmdOrCtrl+S',
click: functionNotImplemented
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
"ArduinoMaterial.saveSketchFileAs()");
}
}
]
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment