ws.send({type: "renameFile", oldPath: oldPath, newPath: newPath}, function (err, res) { if (!err) { file.path = newPath; _this.fire({type: "SpecFileRenamed", file: file}); Logger.log("File " + oldPath + " has been renamed to " + newPath); } else { Logger.log(err); } if (cb && typeof cb === "function") { cb(err, res); } });
wscBase.send({type: "sendCommand", data: {command: action}}, function (err, res) { //do stuff to update the explored state graph and invoke the callback with the same parameters wscBase.fire({type: "GraphUpdate", transition: action, target: res.data, source: o.lastState()}); //update the lastState if it was a valid pvsio state if (PVSioStateParser.isState(res.data)) { o.lastState(res.data); } else { Logger.log("Warning: PVSio was not able to execute " + action); Logger.log(res.data); //update res.data with previous valid state res.data = o.lastState(); } if (cb && typeof cb === "function") { cb(err, res); } });
WSManager.getWebSocket().writeDirectory(path, function (err, res) { if (err) { var msg = "Folder " + err.path + " could not be created in project " + _this.name() + JSON.stringify(err); if (!opt || !opt.silentMode) { NotificationManager.error(msg); } else { Logger.log(msg); } reject(err); } else { var notification = "Folder " + res.path + " successfully added to project " + _this.name(); if (!opt || !opt.silentMode) { NotificationManager.show(notification); } else { Logger.log(notification); } return resolve(new Descriptor(res.path, null, { isDirectory: true })); } });
d3.select("#btnStop").on("click", function () { if (d3.select("#btnRecord").attr("active")) { d3.select("#btnRecord") .attr("active", null) .style("color", "red") .style("cursor", "pointer"); d3.select("#btnStop") .style("cursor", "default") .style("color", "grey"); actions = Recorder.stopRecording(); //do something with actions Logger.log(actions); //ask user to give name to script Prompt.create({header: "Would you like to save this script?", message: "Please enter a name for your script", buttons: ["Cancel", "Save"]}) .on("save", function (e, view) { scriptName = e.data.prompt.trim() || scriptName; view.remove(); var script = {name: scriptName, actions: actions, startState: recStartState}; //add the script to the project projectManager.project().addScript(script); }).on("cancel", function (e, view) { view.remove(); }); } });
/** * @private * Called when the websocket connection to the server has been established. It sets the appropriate UI markers * that signifies that the websocket connection is active. */ function webSocketConnected() { var el = d3.select("#lblWebSocketStatus"); Logger.log("connection to pvsio server established"); d3.select("#btnCompile").attr("disabled", null); el.classed("disconnected", false) .select("span").attr("class", "glyphicon glyphicon-ok");//style("background", "rgb(8, 88, 154)"); PVSioWeb.isWebSocketConnected(true); }
/** * @private * Called when the pvs process has been connected. It sets the appropriate UI markers * that signifies that the process is connected and ready. */ function pvsProcessReady() { var pvsioStatus = d3.select("#lblPVSioStatus"); pvsioStatus.select("span").remove(); var msg = "PVSio process ready!"; Logger.log(msg); pvsioStatus.append("span").attr("class", "glyphicon glyphicon-ok"); PVSioWeb.isPVSProcessConnected(true); }
WidgetManager.updateMapCreator(function () { try { var wd = JSON.parse(p.getWidgetDefinitionFile().content()); WidgetManager.restoreWidgetDefinitions(wd); } catch (err) { Logger.log(err); } });
/** * @private * Called when the pvs process has been disconnected. It sets the appropriate UI markers * that signifies that the process is disconnected. * @param {object|string} err The error message or object returned from the server signifying why the process disconnected */ function pvsProcessDisconnected(err) { var pvsioStatus = d3.select("#lblPVSioStatus"); pvsioStatus.select("span").remove(); Logger.log(err); pvsioStatus.classed("disconnected", true) .append("span").attr("class", "glyphicon glyphicon-warning-sign"); //style("background", "red"); PVSioWeb.isPVSProcessConnected(false); }
/** * @private * Called when the websocket connection to the server has been disconnected. It sets the appropriate UI markers * that signifies that the connection is disconnected. It also triggers the disconnection of the pvs process since * connection to the pvs process depends on connection to the server. */ function webSocketDisconnected() { var el = d3.select("#lblWebSocketStatus"); Logger.log("connection to pvsio server closed"); d3.select("#btnCompile").attr("disabled", true); el.classed("disconnected", true) .select("span").attr("class", "glyphicon glyphicon-warning-sign");//.style("background", "red"); PVSioWeb.isWebSocketConnected(false); pvsProcessDisconnected("Websocket connection closed"); }
WSManager.getWebSocket().writeDirectory(path, function (err, res) { if (err) { var msg = "Folder " + err.path; if (err.code === "EEXIST") { msg += " already exists."; } else { msg += " could not be created" + JSON.stringify(err); } if (!opt || !opt.silentMode) { NotificationManager.error(msg); } else { Logger.log(msg); } reject(err); } else { var notification = "Directory " + res.path + " successfully created"; if (!opt || !opt.silentMode) { NotificationManager.show(notification); } else { Logger.log(notification); } resolve(new Descriptor(res.path, null, { isDirectory: true })); } });
ws.getFile(f, function (err, res) { if (!err) { editor.off("change", _editorChangedHandler); pvsFile.content(res.fileContent).dirty(false); editor.setValue(pvsFile.content()); editor.markClean(); editor.focus(); editor.on("change", _editorChangedHandler); } else { Logger.log(err); } });
WSManager.getWebSocket().writeFile(token, function (err, res) { if (err || res.path !== token.path) { return reject(err); } let notification = "File " + res.path + " correctly written to disk"; if (opt && opt.silentMode) { Logger.log(notification); } else { NotificationManager.show(notification); this.fire({ type: "filewritten", path: path }); //pvsFilesListView.selectItem(path); } return resolve(new Descriptor(token.path, token.content, { encoding: token.encoding })); });
project.save(function (err, p) { if (!err) { project = p; //repaint the list and sourcecode toolbar project.pvsFilesList().forEach(function (f) { f.dirty(false); }); project._dirty(false); pm.fire({type: "ProjectSaved", project: project}); var notification = "Project " + project.name() + " saved successfully!"; d3.select("#project-notification-area").insert("p", "p").html(notification); Logger.log(notification); if (typeof cb === "function") { cb(); } } });
WSManager.getWebSocket().send(token, function (err) { //if there was no error update the main file else alert user if (!err) { //project.prototypeImage = newImage; project.prototypeImage = new Descriptor(project + "/" + imagePath, imageData, { encoding: "base64" }); //FIXME: in the current implementation project.prototypeImage needs to start with the project name -- we need to check whether this is actually needed, if not we should remove this prefix as this makes things easier when renaming projects. resolve({ path: newImage.path, content: newImage.content }); } else { Logger.log(err); reject(err); } });
}, function (err, res) { if (!err) { //update the paths of descriptors saved in the project _this._updateDescriptorsPath(oldName, newName); // update the project name and the dirty flag _this.name(newName); _this._dirty(false); } else { Logger.log(err); } if (cb && typeof cb === "function") { cb(err, _this); } });
}, function (err, res) { if (!err) { // check if we are renaming the project if (oldPath === _this.name()) { _this.name(newPath); } //update the paths of descriptors saved in the project _this._updateDescriptorsPath(oldPath, newPath); } else { Logger.log(err); } if (cb && typeof cb === "function") { cb(err, res); } });
pm.updateImage(image, function (res) { if (res.type !== "error") { WidgetManager.updateMapCreator(function () { try { var wd = JSON.parse(p.getWidgetDefinitionFile().content()); WidgetManager.restoreWidgetDefinitions(wd); } catch (err) { Logger.log(err); } }); d3.select("#imageDragAndDrop.dndcontainer").style("display", "none"); } else { Logger.log(res); //show the image drag and drop div d3.select("#imageDragAndDrop.dndcontainer").style("display", null); } if (callback && typeof callback === "function") { callback(p); } });
project.saveNew(name, function (err, res) { if (!err) { project = res; project.setProjectName(name); project.pvsFilesList().forEach(function (f) { f.dirty(false); }); project._dirty(false); projectNameChanged({current: name}); pvsFilesListView.renameProject(name); pm.fire({type: "ProjectSaved", project: project}); var notification = "Project " + project.name() + " saved successfully!"; d3.select("#project-notification-area").insert("p", "p").html(notification); Logger.log(notification); if (typeof cb === "function") { cb(); } } else { if (err.code === "EEXIST") { alert("Error: project not saved (project name \"" + name + "\" already exists, please use a different name.)"); } if (typeof cb === "function") { cb(); } } });
project.saveNew(data.projectName, function (err, res, folderStructure) { Logger.log({err: err, res: res}); if (!err) { image = project.getImage(); project.getProjectFiles().forEach(function (f) { f.dirty(false); }); //set the main pvs file project.mainPVSFile(project.pvsFilesList()[0]); WidgetManager.updateMapCreator(); pm.project(project); pm.renderSourceFileList(folderStructure); pvsFilesListView.selectItem(project.mainPVSFile() || project.pvsFilesList()[0] || project.name()); if (image) { pm.updateImage(image, function () { //fire project changed event pm.fire({type: "ProjectChanged", current: project, previous: previousProject}); //invoke callback if (cb && typeof cb === "function") { cb(err, project); } }); } else { //fire project changed event pm.fire({type: "ProjectChanged", current: project, previous: previousProject}); //invoke callback if (cb && typeof cb === "function") { cb(err, project); } } } else { if (err.code === "EEXIST") { alert("Please choose a different name -- project " + data.projectName + " already exists."); } //invoke callback if (cb && typeof cb === "function") { cb(err, project); } } });
}).catch(function (err) { Logger.log(err); });
newProjectForm.create().on("cancel", function (e, formView) { Logger.log(e); formView.remove(); }).on("ok", function (e, formView) {
}).on("ok", function (e, formView) { var data = e.data; Logger.log(e); formView.remove(); pm.createProject(data); });
}, function (err) { Logger.log(err); });
project.saveFile(pvsFiles, function (err, res) { if (!err) { Logger.log(pvsFiles.map(function (f) {return f.path(); }).toString() + " saved."); } else { Logger.log(err); } if (typeof cb === "function") { cb(err, res); } });