Commit d88458fe authored by carlosperate's avatar carlosperate

Electron: Add menu functionality for preferences, copy cut paste, save blocks, and add examples.

Also the developer menu can trigger the hidden side menu.
parent a3b97071
......@@ -54,16 +54,20 @@ ArduinoMaterial.bindActionFunctions_ = function() {
// Side menu buttons, they also close the side menu
ArduinoMaterial.bindClick_('menu_load', function() {
ArduinoMaterial.loadUserXmlFile();
$('.button-collapse').sideNav('hide'); });
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_save', function() {
ArduinoMaterial.saveXmlFile();
$('.button-collapse').sideNav('hide'); });
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_delete', function() {
ArduinoMaterial.discard();
$('.button-collapse').sideNav('hide'); });
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_settings', function() {
ArduinoMaterial.openSettings();
$('.button-collapse').sideNav('hide'); });
$('.button-collapse').sideNav('hide');
});
ArduinoMaterial.bindClick_('menu_example_1', function() {
ArduinoMaterial.loadServerXmlFile('examples/blink.xml')});
ArduinoMaterial.bindClick_('menu_example_2', function() {
......@@ -164,15 +168,20 @@ ArduinoMaterial.loadUserXmlFile = function() {
}
};
reader.readAsText(files[0]);
}
};
// Create once invisible browse button with event listener, and click it
var selectFile = document.getElementById('select_file');
if (selectFile == null) {
var selectFileDom = document.createElement('INPUT');
selectFileDom.type = 'file';
selectFileDom.id = 'select_file';
selectFileDom.style.display = 'none';
document.body.appendChild(selectFileDom);
var selectFileWrapperDom = document.createElement('DIV');
selectFileWrapperDom.id = 'select_file_wrapper';
selectFileWrapperDom.style.display = 'none';
selectFileWrapperDom.appendChild(selectFileDom);
document.body.appendChild(selectFileWrapperDom);
selectFile = document.getElementById('select_file');
selectFile.addEventListener('change', parseInputXMLfile, false);
}
......
......@@ -193,6 +193,42 @@ ArduinoMaterial.discard = function() {
}
};
/**
* Wraps the blockly 'cut' functionality
*/
ArduinoMaterial.blocklyCut = function() {
Blockly.copy_(Blockly.selected);
Blockly.selected.dispose(true, true);
};
/**
* Wraps the blockly 'copy' functionality
*/
ArduinoMaterial.blocklyCopy = function() {
Blockly.hideChaff();
Blockly.copy_(Blockly.selected);
};
/**
* Wraps the blockly 'paste' functionality
*/
ArduinoMaterial.blocklyPaste = function() {
if (Blockly.clipboardXml_) {
Blockly.hideChaff();
Blockly.clipboardSource_.paste(Blockly.clipboardXml_);
}
};
/**
* Wraps the blockly 'paste' functionality
*/
ArduinoMaterial.blocklyDelete = function() {
if (Blockly.selected && Blockly.selected.isDeletable()) {
Blockly.hideChaff();
Blockly.selected.dispose(true, true);
}
};
/**
* Creates an AJAX request.
* @return An XML HTTP Request
......
......@@ -20,7 +20,7 @@ var BrowserWindow = require('browser-window');
module.exports.setArdublocklyMenu = function(devMode) {
if (typeof(devMode)==='undefined') devMode = false;
var ardublocklyMenu = []
var ardublocklyMenu = [];
if (process.platform == "darwin") {
ardublocklyMenu.push(getMacMenuData());
}
......@@ -51,8 +51,12 @@ var getMacMenuData = function() {
type: 'separator'
}, {
label: 'Preferences',
//accelerator: 'CmdOrCtrl+comma',
click: functionNotImplemented
accelerator: 'CmdOrCtrl+,',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.openSettings()");
}
}, {
type: 'separator'
}, {
......@@ -97,8 +101,16 @@ var getFileMenuData = function() {
accelerator: 'CmdOrCtrl+O',
click: functionNotImplemented
}, {
label: 'Save as',
label: 'Save Blocks as',
accelerator: 'CmdOrCtrl+S',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.saveXmlFile()");
}
}, {
label: 'Save Arduino Sketch as',
accelerator: 'Shift+CmdOrCtrl+S',
click: functionNotImplemented
}
]
......@@ -139,15 +151,43 @@ var getEditMenuData = function() {
}, {
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
click: functionNotImplemented
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.blocklyCut()");
}
}, {
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
click: functionNotImplemented
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.blocklyCopy()");
}
}, {
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
click: functionNotImplemented
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.blocklyPaste()");
}
}, {
label: 'Delete',
accelerator: 'Delete',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.blocklyDelete()");
}
}, {
label: 'Delete All',
accelerator: 'Delete',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.discard()");
}
}
]
};
......@@ -159,8 +199,12 @@ var getEditMenuData = function() {
type: 'separator'
}, {
label: 'Preferences',
//accelerator: 'CmdOrCtrl+comma',
click: functionNotImplemented
accelerator: 'CmdOrCtrl+,',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript("ArduinoMaterial.openSettings()");
}
}
);
}
......@@ -173,14 +217,41 @@ var getExamplesMenuData = function() {
label: 'Examples',
submenu: [
{
label: 'Example 1',
click: functionNotImplemented
label: 'Blinky',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
'ArduinoMaterial.loadServerXmlFile("examples/' +
'blink.xml");');
}
}, {
label: 'Example 2',
click: functionNotImplemented
label: 'Print Serial',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
'ArduinoMaterial.loadServerXmlFile("examples/' +
'serial_print_ascii_.xml");');
}
}, {
label: 'Example 3',
click: functionNotImplemented
label: 'Servo Knob',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
'ArduinoMaterial.loadServerXmlFile("examples/' +
'servo_knob.xml");');
}
}, {
label: 'Stepper Knob',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
'ArduinoMaterial.loadServerXmlFile("examples/' +
'stepper_knob.xml");');
}
}
]
};
......@@ -196,11 +267,11 @@ var getProgramMenuData = function() {
click: functionNotImplemented
}, {
label: 'Verify',
//accelerator: 'CmdOrCtrl+S',
accelerator: 'CmdOrCtrl+R',
click: functionNotImplemented
}, {
label: 'Upload program',
//accelerator: 'CmdOrCtrl+S',
accelerator: 'CmdOrCtrl+U',
click: functionNotImplemented
}
]
......@@ -274,7 +345,7 @@ var getDevMenuData = function() {
submenu: [
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
accelerator: 'CmdOrCtrl+F5',
click: function() {
BrowserWindow.getFocusedWindow().reloadIgnoringCache();
}
......@@ -284,6 +355,8 @@ var getDevMenuData = function() {
click: function() {
BrowserWindow.getFocusedWindow().toggleDevTools();
}
}, {
type: 'separator'
}, {
label: 'Stop server',
accelerator: 'Shift+CmdOrCtrl+S',
......@@ -292,6 +365,18 @@ var getDevMenuData = function() {
label: 'Restart server',
accelerator: 'Shift+CmdOrCtrl+R',
click: server.restartServer
}, {
type: 'separator'
}, {
label: 'Open side menu',
click: function() {
BrowserWindow.getFocusedWindow()
.webContents
.executeJavaScript(
"$('.button-collapse').sideNav('show')");
}
}, {
type: 'separator'
}, {
label: 'Test menu item',
click: testFunction
......
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