Skip to content
Snippets Groups Projects
Commit 9768e879 authored by Stekelenburg, A.V. (Alexander, Student )'s avatar Stekelenburg, A.V. (Alexander, Student )
Browse files

Cosmetic changes to sidebar. Added revert buttons to sidebar. Support for...

Cosmetic changes to sidebar. Added revert buttons to sidebar. Support for tools that don't output analysis results.
parent 5e8e5b29
No related branches found
No related tags found
No related merge requests found
......@@ -42,14 +42,29 @@ ul.option-list li input.name {
width: 70%;
}
ul.option-list li input.value,
ul.option-list li select.value {
vertical-align: middle;
margin:0;
height:100%;
ul.option-list li div.value {
height: 100%;
width: 60%;
display: flex;
align-items: center;
align-content: space-between;
}
ul.option-list li div.value input.value,
ul.option-list li div.value select.value {
width: 100%;
vertical-align: middle;
margin: 0;
height: 100%;
}
ul.option-list li input.value[type='checkbox']:focus {
ul.option-list li div.value input.value[type='checkbox'] {
width: 12.8px;
height: 12.8px;
margin-left: calc(50% - 6.4px);
}
ul.option-list li div.value input.value[type='checkbox']:focus {
outline: none;
}
......@@ -60,6 +75,19 @@ ul.option-list li label.name {
overflow: hidden;
}
ul.option-list li div.value button.revert {
margin-left: auto;
width: fit-content;
align-items: center;
height:100%;
display: flex;
background-color: var(--vscode-button-secondaryBackground);
}
ul.option-list li div.value button.revert:hover {
background-color: var(--vscode-button-secondaryHoverBackground);
}
h3 {
font-size: 11px;
min-width: 3ch;
......@@ -120,8 +148,11 @@ h3 {
.pane-view {
width: 100%;
height: 100%;
padding-right: var(--container-paddding);
position: absolute;
left:0;
}
ul.option-list li div.value button.revert.hidden {
display: none;
}
......@@ -4,6 +4,8 @@
const vscode = acquireVsCodeApi();
document.getElementById("constants").parentElement.style.height = "0";
for (const element of document.querySelectorAll(".pane-view .pane")) {
addCollapseBehaviour(element);
......@@ -82,7 +84,7 @@
function expandHeight(body, additional) {
let amount = 0;
for (const child of body.childNodes) {
if(child.scrollHeight) {
if (child.scrollHeight) {
amount += child.scrollHeight;
}
}
......@@ -93,7 +95,7 @@
// const newHeight = (body.scrollHeight + amount) + "px";
// body.style.height = previousHeight;
// body.style.removeProperty("transition");
body.style.height = (amount + additional)+ "px";
body.style.height = (amount + additional) + "px";
body.style.margin = "0.2em 0 0.4em var(--container-paddding)";
if (body.parentElement.parentElement.classList.contains("pane-body")) {
......@@ -235,6 +237,7 @@
for (const parameter of tool.parameters) {
const oldParameterIndex = oldState.parameters[index].parameters.findIndex(x => x.id === parameter.id);
if (oldParameterIndex !== -1) {
parameter.defaultValue = parameter.value;
parameter.value = oldState.parameters[index].parameters[oldParameterIndex].value;
}
}
......@@ -253,7 +256,7 @@
for (const tool of parameters) {
if (tool.toolName === toolName) {
for (const parameter of tool.parameters) {
addParameterItem(parameter.id, parameter.value, parameter.category, parameter.type, parameter.description, parameter.possibleValues);
addParameterItem(parameter.id, parameter.value, parameter.category, parameter.type, parameter.description, parameter.possibleValues, parameter.defaultValue);
}
break;
}
......@@ -276,6 +279,11 @@
fillTools(tools);
updateParameters(parameters, currentTool);
updateDocumentVars(documentVars, currentUri);
for (const body of document.querySelectorAll(".pane-body")) {
if (body.style.height) {
expandHeight(body, 0);
}
}
}
//#region help functions
......@@ -295,7 +303,7 @@
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
valueBox.addEventListener("input", _ => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
......@@ -331,7 +339,7 @@
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
valueBox.addEventListener("input", _ => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
......@@ -391,7 +399,7 @@
return categoryUl;
}
function addParameterItem(name, value, category, type, description, possibleValues) {
function addParameterItem(name, value, category, type, description, possibleValues, defaultValue) {
if (category === "") {
category = "Other";
}
......@@ -400,6 +408,10 @@
categoryUl = addCategory(category);
}
if (defaultValue === undefined) {
defaultValue = value;
}
const li = document.createElement("li");
const nameBox = document.createElement("label");
......@@ -410,13 +422,12 @@
li.appendChild(nameBox);
/**
* @type {HTMLSelectElement|HTMLInputElement}
*/
let valueBox;
if (type === "Enum") {
/**
* @type {HTMLSelectElement}
*/
const valueBox = document.createElement("select");
valueBox.id = "value-" + name;
valueBox.classList.add("value");
valueBox = document.createElement("select");
for (const value of possibleValues) {
const option = document.createElement("option");
option.value = value;
......@@ -427,6 +438,12 @@
valueBox.value = value;
valueBox.addEventListener("input", _ => {
if (valueBox.value === defaultValue) {
valueBox.revertButton.classList.add("hidden");
} else {
valueBox.revertButton.classList.remove("hidden");
}
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
......@@ -441,34 +458,91 @@
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
} else {
valueBox = document.createElement("input");
if (type === "Boolean") {
valueBox.type = "checkbox";
valueBox.checked = value;
valueBox.addEventListener("input", _ => {
if (valueBox.checked === defaultValue) {
valueBox.revertButton.classList.add("hidden");
} else {
valueBox.revertButton.classList.remove("hidden");
}
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
for (const parameter of tool.parameters) {
if (parameter.id === name) {
parameter.value = valueBox.checked;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
} else {
valueBox.type = "text";
valueBox.value = value;
valueBox.addEventListener("input", _ => {
// TODO: Store as actual type using valueBox.value.asNumber and such?
if(type === "Real") {
valueBox.value = valueBox.value.replace(",", ".");
}
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = type;
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", _ => {
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
for (const parameter of tool.parameters) {
if (parameter.id === name) {
parameter.value = valueBox.value;
break;
if (String(valueBox.value) === String(defaultValue)) {
valueBox.revertButton.classList.add("hidden");
} else {
valueBox.revertButton.classList.remove("hidden");
}
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
for (const parameter of tool.parameters) {
if (parameter.id === name) {
parameter.value = valueBox.value;
break;
}
}
break;
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
}
}
valueBox.id = "value-" + name;
valueBox.classList.add("value");
li.appendChild(valueBox);
const valueDiv = document.createElement("div");
valueDiv.classList.add("value");
valueDiv.appendChild(valueBox);
const revertButton = document.createElement("button");
revertButton.id = "revert-" + name;
const codicon = document.createElement("i");
codicon.classList.add("codicon", "codicon-discard");
revertButton.appendChild(codicon);
revertButton.classList.add("revert");
if (String(value) === String(defaultValue)) {
revertButton.classList.add("hidden");
}
revertButton.title = "Revert to default";
valueBox.revertButton = revertButton;
revertButton.addEventListener("click", _ => {
if (type === "checkbox") {
valueBox.checked = defaultValue;
}else{
valueBox.value = defaultValue;
}
valueBox.dispatchEvent(new InputEvent("input"));
});
valueDiv.appendChild(revertButton);
li.appendChild(valueDiv);
categoryUl.appendChild(li);
}
......
......@@ -74,7 +74,7 @@ function getParameters(toolName: string) {
if (parameter.type.valueType === "Enum") {
return { id: parameter.id, value: parameter.defaultValue, type: "Enum", category: parameter.category, description: parameter.description, possibleValues: parameter.type.possibleValues };
}
return { id: parameter.id, value: parameter.defaultValue, type: getType(parameter.type.valueType), category: parameter.category, description: parameter.description };
return { id: parameter.id, value: parameter.defaultValue, type: parameter.type.valueType, category: parameter.category, description: parameter.description };
});
if (index === -1) {
localParameters.push({ toolName: toolName, parameters: newParameters });
......@@ -96,7 +96,7 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
for (const parameter of suppliedParameters) {
const parameterIndex = localParameters[toolIndex].parameters.findIndex(x => x.id === parameter.id);
if (parameterIndex !== -1) {
if (localParameters[toolIndex].parameters[parameterIndex].value !== parameter.value) {
if (String(localParameters[toolIndex].parameters[parameterIndex].value) !== String(parameter.value)) {
serverParameters.push(parameter);
}
}
......@@ -115,7 +115,6 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
await new Promise<null>(async (resolve, _) => {
if (!clientReady) {
vscode.window.showErrorMessage("Server not ready yet, try again later");
console.error("test");
resolve(null);
return;
}
......@@ -127,11 +126,26 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
if (data.progressToken === jsonObject.progressToken) {
if (data.data && data.data !== "") {
try {
analysisResultsProvider.setJsonString(data.data);
analysisResultsProvider.setJsonObject(JSON.parse(data.data.trim()));
const treeRoot = analysisResultsProvider.getTreeRoot();
treeView.reveal(treeRoot, { focus: false, select: false, expand: true });
} catch (error) {
console.error(error);
let extension = ".out";
if (toolName === "mopy (export-to-python)") {
extension = ".py";
} else if (toolName === "moconv (convert)") {
extension = ".jani";
}
// TODO: Look at parameters for mosta to automatically determine extension?
const newFile = vscode.Uri.parse("untitled:" + uri + extension);
vscode.workspace.openTextDocument(newFile).then(async document => {
const edit = new vscode.WorkspaceEdit();
edit.insert(newFile, new vscode.Position(0, 0), data.data);
const success = await vscode.workspace.applyEdit(edit);
if (success) {
vscode.window.showTextDocument(document);
}
});
}
}
progressHandler?.dispose();
......@@ -254,7 +268,7 @@ export class ModestSidebarProvider implements vscode.WebviewViewProvider {
<div class="split-view-view">
<div class="pane vertical">
<div class="pane-header">
<div class="codicon codicon-chevron-right"></div>
<div class="codicon codicon-chevron-down"></div>
<h3 class="title" title="Open constants">Open constants</h3>
</div>
<div class="pane-body">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment