Commit 4e5b27da authored by Antoine Thevenet's avatar Antoine Thevenet
Browse files

added comments and splited somme function

parent b5c393c2
......@@ -27,12 +27,12 @@
/*------------------------------------------------------------------
---------------------Ace Context menu handler-----------------------
-------------------------------------------------------------------*/
/**
* This function resets and enable the different items of the editor's context menu
*/
function aceContextMenuHandler() {
removeAceContextMenu();
clearContextMenu();
var arrayActivePlugins = scanPlugins();
var uniqueActivePlugin = arrayActivePlugins.filter(getUniqueVal);
var booleanDisablePrimitive = disableMenuItems("behavior");
var booleanDisablePlugins = disableMenuItems("plugins");
......@@ -51,18 +51,28 @@ function aceContextMenuHandler() {
if (booleanDisableLoadprofile == false) {
enableContextualSubmenu("parentLoadprofileSubmenu");
}
if (booleanDisableBehavior == false){
if (booleanDisableBehavior == false) {
enableContextualSubmenu("parentBehaviorSubmenu");
}
}
/**
* This function removes a css class that prevent the user to click on a contextmenu item
*/
function enableContextualSubmenu(menuId) {
var selectedSubmenu = document.getElementById(menuId);
if (selectedSubmenu.classList.contains("noHover") == true) {
selectedSubmenu.classList.remove("noHover");
}
}
/**
*This function browses the editor to determine where the user right-cliked.
*If the user didn't'right clicked between the ">" and "<", the returned value
*will disable some menu options
*
*@return {boolean} disable - If disable == true, some menu options will be disabled
*will disable some menu items
*@param {String} tagType - Depending of tagType value, the checks will be done for different menu items
*@return {boolean} If disable == true, some menu items will be disabled
*/
function disableMenuItems(tagType) {
var editor = ace.edit(getActiveEditor());
......@@ -81,8 +91,45 @@ function disableMenuItems(tagType) {
}
cursorAbsolutePosition += cursorPosition["column"];
//depanding on the tag type,
//depanding on the tag type, we check if we are between two specific tags
disable = disableBetweenSpecificTag(tagType, completeText, cursorAbsolutePosition);
//We are inside the wanted tags, check if the cursor is between > and <
if (disable == false) {
var openChevronPos = completeText.indexOf("<", cursorAbsolutePosition);
var closeChevronPos = completeText.lastIndexOf(">", cursorAbsolutePosition);
var tempCloseChevron = completeText.indexOf(">", cursorAbsolutePosition)
if (openChevronPos > closeChevronPos && cursorAbsolutePosition > closeChevronPos && tempCloseChevron > openChevronPos) {
disable = false;
//check for comments
var temp = openChevronPos;
var indexComment = completeText.indexOf("<!--", cursorAbsolutePosition);
while (temp == indexComment) {
indexComment = completeText.indexOf("<!--", indexComment + 1);
temp = completeText.indexOf("<", temp + 1);
openChevronPos = temp;
}
}
else {
disable = true;
}
}
//We are between > and <. Check if the next closing tag allows to insert content
if (disable == false) {
disable = disableUncorrectNextTag(tagType, completeText, openChevronPos);
}
return disable;
}
/**
* This function checks if the user's cursor is between two specific major tags
* @param {String} tagType - Depending of tagType value, the checks will be done for different tag
* @param {String} completeText - The text contained on the editor
* @param {number} cursorAbsolutePosition - a number indicating at which character the cursor is located
* @returns {boolean} If disable = true, the menu items corresponding to tagType must be disaabled
*/
function disableBetweenSpecificTag(tagType, completeText, cursorAbsolutePosition) {
var disable = true;
if (tagType == "behavior") {
//add to an array the <behavior and </behavior> positions
//the first value of behaviorBeginTagArray is shifted as the <behaviors> tag is taken into account
......@@ -118,7 +165,7 @@ function disableMenuItems(tagType) {
}
}
}
else if (tagType == "behaviors") {
var loadprofileBeginTagArray = getMatchIndexes(completeText, "<behaviors");
var loadprofileEndTagArray = getMatchIndexes(completeText, "</behaviors>");
......@@ -129,82 +176,68 @@ function disableMenuItems(tagType) {
}
}
}
return disable;
}
//We are inside the wanted tags, check if the cursor is between > and <
if (disable == false) {
var openChevronPos = completeText.indexOf("<", cursorAbsolutePosition);
var closeChevronPos = completeText.lastIndexOf(">", cursorAbsolutePosition);
var tempCloseChevron = completeText.indexOf(">", cursorAbsolutePosition)
if (openChevronPos > closeChevronPos && cursorAbsolutePosition > closeChevronPos && tempCloseChevron > openChevronPos) {
/**
* This function checks if the next allows to insert content before it
* @param {String} tagType - Depending of tagType value, the checks will be done for different tag
* @param {String} completeText - The text contained on the editor
* @param {number} openChevronPos - a number indicating at which character the next "<" is located
* @returns {boolean} If disable = true, the menu items corresponding to tagType must be disaabled
*/
function disableUncorrectNextTag(tagType, completeText, openChevronPos) {
//retrieve next tag name
var disable = false;
var openTagSpace = completeText.indexOf(" ", openChevronPos); //next tag = <tagName ...>
var openTagClose = completeText.indexOf(">", openChevronPos); //next tag = <tagName>
var openTagClose2 = completeText.indexOf("/>", openChevronPos); //next tag = </tagName>
var tagAfter = "";
if (openTagSpace != -1 && (openTagSpace < openTagClose || openTagClose == -1) && (openTagSpace < openTagClose2 || openTagClose2 == -1)) {
tagAfter = completeText.substring(openChevronPos + 1, openTagSpace);
}
else if (openTagClose != -1 && (openTagClose < openTagSpace || openTagSpace == -1) && (openTagClose < openTagClose2 || openTagClose2 == -1)) {
tagAfter = completeText.substring(openChevronPos + 1, openTagClose);
}
else {
tagAfter = completeText.substring(openChevronPos + 1, openTagClose2);
}
//the supported following next tags are not the same depending on the tag type
if (tagType == "behavior") {
if (tagAfter == "control" || tagAfter == "sample" || tagAfter == "timer"
|| tagAfter == "if" || tagAfter == "while" || tagAfter == "preemption" || tagAfter == "nchoice"
|| tagAfter == "/while" || tagAfter == "/preemption" || tagAfter == "/nchoice"
|| tagAfter == "/then" || tagAfter == "/else" || tagAfter == "/behavior" || tagAfter == "/choice") {
disable = false;
//check for comments
var temp = openChevronPos;
var indexComment = completeText.indexOf("<!--", cursorAbsolutePosition);
while (temp == indexComment) {
indexComment = completeText.indexOf("<!--", indexComment + 1);
temp = completeText.indexOf("<", temp + 1);
openChevronPos = temp;
}
}
else {
disable = true;
}
}
//We are between > and <. Check if the next closing tag allows to insert content
if (disable == false) {
//retrieve next tag name
var openTagSpace = completeText.indexOf(" ", openChevronPos); //next tag = <tagName ...>
var openTagClose = completeText.indexOf(">", openChevronPos); //next tag = <tagName>
var openTagClose2 = completeText.indexOf("/>", openChevronPos); //next tag = </tagName>
var tagAfter = "";
if (openTagSpace != -1 && (openTagSpace < openTagClose || openTagClose == -1) && (openTagSpace < openTagClose2 || openTagClose2 == -1)) {
tagAfter = completeText.substring(openChevronPos + 1, openTagSpace);
}
else if (openTagClose != -1 && (openTagClose < openTagSpace || openTagSpace == -1) && (openTagClose < openTagClose2 || openTagClose2 == -1)) {
tagAfter = completeText.substring(openChevronPos + 1, openTagClose);
else if (tagType == "plugins") {
if (tagAfter == "use" || tagAfter == "/plugins") {
disable = false;
}
else {
tagAfter = completeText.substring(openChevronPos + 1, openTagClose2);
disable = true;
}
}
if (tagType == "behavior") {
if (tagAfter == "control" || tagAfter == "sample" || tagAfter == "timer"
|| tagAfter == "if" || tagAfter == "while" || tagAfter == "preemption" || tagAfter == "nchoice"
|| tagAfter == "/while" || tagAfter == "/preemption" || tagAfter == "/nchoice"
|| tagAfter == "/then" || tagAfter == "/else" || tagAfter == "/behavior" || tagAfter == "/choice") {
disable = false;
}
else {
disable = true;
}
else if (tagType == "loadprofile") {
if (tagAfter == "group" || tagAfter == "/loadprofile") {
disable = false;
}
else if (tagType == "plugins") {
if (tagAfter == "use" || tagAfter == "/plugins") {
disable = false;
}
else {
disable = true;
}
else {
disable = true;
}
else if (tagType == "loadprofile") {
if (tagAfter == "group" || tagAfter == "/loadprofile") {
disable = false;
}
else {
disable = true;
}
}
else if (tagType == "behaviors") {
if (tagAfter == "behavior" || tagAfter == "/behaviors") {
disable = false;
}
else if (tagType == "behaviors") {
if (tagAfter == "behavior" || tagAfter == "/behaviors") {
disable = false;
}
else {
disable = true;
}
else {
disable = true;
}
}
return disable;
}
......@@ -232,34 +265,13 @@ function getUniqueVal(value, index, self) {
return self.indexOf(value) === index;
}
/**
*This function returns an array that contains the plugins names contained inside the cache
*/
function getAvailablePlugin() {
var arrayAvailablePlugin = [];
var cache = localCache.get("pluginInfo");
var pluginNumber = cache["plugins"].length;
for (var i = 0; i < pluginNumber; i++) {
arrayAvailablePlugin.push(cache["plugins"][i]["name"]);
}
return arrayAvailablePlugin;
}
function enableContextualSubmenu(menuId) {
var selectedSubmenu = document.getElementById(menuId);
if (selectedSubmenu.classList.contains("noHover") == true) {
selectedSubmenu.classList.remove("noHover");
}
}
/*------------------------------------------------------------------
------------------------------Clear---------------------------------
-------------------------------------------------------------------*/
/**
* This function adds the style class noHover to the statement submenu. This style class prevents the msubmenu to be clickable
* This function adds the style class noHover to the statement submenu. This style class prevents the submenu to be clickable
*/
function clearContextMenu() {
var controlSubmenu = document.getElementById("parentControlSubmenu");
......@@ -291,7 +303,7 @@ function clearContextMenu() {
if (behaviorSubmenu.classList.contains("noHover") == false) {
behaviorSubmenu.classList.add("noHover");
}
}
......@@ -303,7 +315,7 @@ function clearContextMenu() {
/**
*This function scans the xml ace editor to retrieve the plugins used for the current xis file
@returns {array} An array that contains the used plugins
@returns {Array} An array that contains the used plugins
*/
function scanPlugins() {
var editor = ace.edit(getActiveEditor());
......@@ -335,6 +347,8 @@ function scanPlugins() {
/**
* This function scans the ace editor content and retrieve the ids of a specific plugin
* @param {String} pluginName
* @retrun {Array} An array that contains the ids associated to pluginName
*/
function scanPluginId(pluginName) {
var arrayPluginId = [];
......@@ -363,6 +377,7 @@ function scanPluginId(pluginName) {
/**
* This function scans the ace editor content and defines the default ID that will be assigned to the tag <use>
* @returns {String} the name that will be given to the inserted plugin
*/
function choosePluginId(pluginName) {
......@@ -385,6 +400,7 @@ function choosePluginId(pluginName) {
/**
* This function scans the ace editor content and retrieve the ids of each behavior
* @retrun {Array} An array that contains the ids associated to the behaviors
*/
function scanBehaviorId() {
var arrayBehaviorId = [];
......@@ -406,6 +422,7 @@ function scanBehaviorId() {
/**
* This function scans the ace editor content and defines the default ID that will be assigned to the tag <behavior>
* @returns {String} the name that will be given to the inserted behavior
*/
function chooseBehaviorId() {
......
......@@ -22,6 +22,9 @@
/*------------------------------------------------------------------
--------------------------------Test--------------------------------
-------------------------------------------------------------------*/
/**
* This function completes the modal window modalHelp to display help about statement conditions
*/
function displayHelp() {
var helpWindow = document.getElementById("modalHelp");
helpWindow.removeAttribute("hidden");
......@@ -62,6 +65,12 @@ function displayHelp() {
}
}
/**
* This function browses the cache to retrieve the help associated to the statement condition that we want to insert
* @param {String} pluginName
* @param {String} testName
* @return {String} The help associated to the statement test
*/
function retrieveTestHelp(pluginName, testName) {
var cache = localCache.get("pluginInfo");
......@@ -85,6 +94,9 @@ function retrieveTestHelp(pluginName, testName) {
/*------------------------------------------------------------------
------------------------------Primitive-----------------------------
-------------------------------------------------------------------*/
/**
* This function completes the modal window modalHelp to display help about a primitive
*/
function displayHelpPrimitive() {
var helpWindow = document.getElementById("modalHelp");
helpWindow.removeAttribute("hidden");
......@@ -126,6 +138,13 @@ function displayHelpPrimitive() {
}
}
/**
* This function browses the cache to retrieve the help associated to the primitive that we want to insert
* @param {String} pluginName
* @param {String} primitiveType - timer, control or sample
* @param {String} primitiveName
* @return {String} The help associated to the statement test
*/
function retrievePrimitiveHelp(pluginName, primitiveType, primitiveName) {
var cache = localCache.get("pluginInfo");
var pluginNumber = cache["plugins"].length;
......@@ -146,6 +165,9 @@ function retrievePrimitiveHelp(pluginName, primitiveType, primitiveName) {
/*------------------------------------------------------------------
-------------------------------Plugin-------------------------------
-------------------------------------------------------------------*/
/**
* This function completes the modal window modalHelp to display help about a plugin
*/
function displayHelpPlugin() {
var helpWindow = document.getElementById("modalHelp");
helpWindow.removeAttribute("hidden");
......@@ -184,8 +206,12 @@ function displayHelpPlugin() {
}
}
/**
* This function browses the cache to retrieve the help associated to the plugin that we want to insert
* @param {String} pluginName
* @return {String} The help associated to the statement test
*/
function retrievePluginHelp(pluginName) {
var cache = localCache.get("pluginInfo");
var pluginNumber = cache["plugins"].length;
var pluginHelp;
......@@ -195,4 +221,21 @@ function retrievePluginHelp(pluginName) {
}
}
return pluginHelp;
}
/*------------------------------------------------------------------
-------------------------------Clear-------------------------------
-------------------------------------------------------------------*/
/**
*This function clears the header and the body of the modal Help window
*/
function clearModalHelp() {
//clear the header
var modalHelpTitle = document.getElementById("modalHelpTitle");
modalHelpTitle.innerHTML = "";
//clear the body
var textParentNode = document.getElementById("textHelp");
while (textParentNode.firstChild) {
textParentNode.removeChild(textParentNode.firstChild);
}
}
\ No newline at end of file
......@@ -25,7 +25,10 @@
-------------------------------------------------------------------*/
/**
*
* This function is called when the user clicks on the item if, while or preemptive on the context menu.
* It prepares the modal window about statements that will be displayed on the screen and binds the insertion of content
* to the validate button.
* @param {String} statementType - if, while or preemptive
*/
function initModalAddTest(statementType) {
clearModalSelect(["statementTestSelect", "statementPluginIdSelect", "statementPluginNameSelect"])
......@@ -39,10 +42,6 @@ function initModalAddTest(statementType) {
var idPlugin = document.getElementById("statementPluginIdSelect");
document.getElementById("statementValidate").onclick = function() { insertStatement(statementType, pluginName.options[pluginName.selectedIndex].text, testName.options[testName.selectedIndex].text, idPlugin.options[idPlugin.selectedIndex].text) };
}
/**
*
*/
/**
*This function is triggered when the user changes its selection inside the plugin name list in the modalFormChooseStatementTest menu.
......@@ -102,7 +101,12 @@ function getTest(pluginName) {
/*------------------------------------------------------------------
-------------------------Modal add Plugin--------------------------
-------------------------------------------------------------------*/
/**
* This function is called when the user clicks on the item plugin on the context menu.
* It prepares the modal window about plugins that will be displayed on the screen and binds the insertion of content
* to the validate button.
* @param {String} statementType - if, while or preemptive
*/
function initModalAddPlugin() {
//clear fields
clearModalSelect(["pluginNameSelect"]);
......@@ -122,6 +126,21 @@ function modalPluginChangeInputId() {
var pluginId = choosePluginId(stringPluginName);
inputId.value = pluginId;
}
/**
*This function returns an array that contains the plugins names contained inside the cache
*@returns {Array} - The plugins contained in the cache
*/
function getAvailablePlugin() {
var arrayAvailablePlugin = [];
var cache = localCache.get("pluginInfo");
var pluginNumber = cache["plugins"].length;
for (var i = 0; i < pluginNumber; i++) {
arrayAvailablePlugin.push(cache["plugins"][i]["name"]);
}
return arrayAvailablePlugin;
}
/*------------------------------------------------------------------
-------------------------Modal add options--------------------------
-------------------------------------------------------------------*/
......@@ -172,7 +191,7 @@ function addModalSelectOptionInit(optionArray, elementId) {
*
*@param {String} primitiveType - the primitive type, control, sample or timer
*/
function initModalAddPrimitive2(primitiveType) {
function initModalAddPrimitive(primitiveType) {
//display the menu
clearModalSelect(["primitivePluginNameSelect", "primitivePrimitiveNameSelect", "primitivePluginIdSelect"]);
var pluginArray = scanPlugins();
......@@ -330,18 +349,3 @@ function clearModalSelect(arrayId) {
}
}
}
/**
*This function clears the header and the body of the modal Help window
*/
function clearModalHelp() {
//clear the header
var modalHelpTitle = document.getElementById("modalHelpTitle");
modalHelpTitle.innerHTML = "";
//clear the body
var textParentNode = document.getElementById("textHelp");
while (textParentNode.firstChild) {
textParentNode.removeChild(textParentNode.firstChild);
}
}
\ No newline at end of file
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