Skip to content

Commit

Permalink
To address review comments from #106: revised built-in panels to use …
Browse files Browse the repository at this point in the history
…addButtons(), added missing semicolon, and corrected misleading comment.
  • Loading branch information
barnettwilliam committed Nov 10, 2023
1 parent 6f90c68 commit 1032f28
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
25 changes: 12 additions & 13 deletions platform/src/ConsolePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ class ConsolePanel extends Panel {
super(id);
this.editor.setReadOnly(true);
this.editor.setValue("", 1);
this.element.dataset.customButtons = JSON.stringify(this.getButtons());
this.detectHyperlinks(this.editor);
this.setTitleAndIcon("Console", "console");
}

getButtons() {
let clearButton = new Button({
id:"clear",
hint:"Clear the console",
internal: `panels.find((p) => p.id==="${this.id}").editor.setValue('')`,
icon: "clear"
}, this.id
let buttons = [];
let clearButton = new Button(
{ id:"clear",
hint:"Clear the console",
internal: `panels.find((p) => p.id==="${this.id}").editor.setValue('')`,
icon: "clear" },
this.id
);

return [clearButton.getView()];
buttons.push(clearButton);
this.addButtons(buttons);

this.detectHyperlinks(this.editor);
this.setTitleAndIcon("Console", "console");
}

setOutput(str) {
Expand Down
29 changes: 15 additions & 14 deletions platform/src/OutputPanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ModelPanel } from "./ModelPanel.js";
import { language } from "./Playground.js"
import { language } from "./Playground.js";
import { Button } from "./Button.js";

class OutputPanel extends ModelPanel {
Expand All @@ -15,25 +15,26 @@ class OutputPanel extends ModelPanel {
this.outputType = outputType;
this.outputLanguage = outputLanguage;
this.language = language;
this.element.dataset.customButtons = JSON.stringify(this.getButtons());
this.getEditor().getSession().setMode("ace/mode/" + outputLanguage.toLowerCase());
//this.getEditor().getSession().setUseWrapMode(false);
}

setupSyntaxHighlighting() {}

getButtons() {
let highlightButton = new Button({
id:"highlight",
let buttons = [];
if (this.outputType == "code"){
let highlightButton = new Button(
{ id:"highlight",
hint:"Set generated text language",
internal: `panels.find((p) => p.id==="${this.id}").editor.setOutputLanguage()`,
icon: "highlight"
}, this.id
);
icon: "highlight" },
this.id
);
buttons.push(highlightButton);
}
this.addButtons(buttons);

return (this.outputType == "code") ? [highlightButton.getView()] : [];
this.getEditor().getSession().setMode("ace/mode/" + outputLanguage.toLowerCase());
}

setupSyntaxHighlighting() {}


getSelect() {
return Metro.getPlugin("#generatedFiles", 'select');
}
Expand Down
15 changes: 8 additions & 7 deletions platform/src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ class Panel {

/**
* Add the buttons to the page
* @param {Button[]} buttons the Button objects to add
* @param {Button[]} buttons - The Button objects to add.
*/
addButtons(buttons){
if (buttons.length > 0){
var buttonViewData= buttons.map( (btn) => {
return btn.getView();
});

var buttonViewData= buttons.map( (btn) => {
return btn.getView();
});
buttonViewData.reverse(); // So they are displayed in the order they are defined

buttonViewData.reverse(); // So they are displayed in the order they are defined

this.element.dataset.customButtons = JSON.stringify(buttonViewData);
this.element.dataset.customButtons = JSON.stringify(buttonViewData);
}
}


Expand Down
4 changes: 2 additions & 2 deletions platform/src/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ function initialisePanels() {
/**
* Create a panel for a given panel config entry
*
* @param {Object} activity config panel definition
* @return {Panel} platform Panel
* @param {Object} panel - The activity config panel definition.
* @return {Panel} the platform Panel
*/
function createPanelForDefinitionId(panel){
const panelDefinition = panel.ref;
Expand Down

0 comments on commit 1032f28

Please sign in to comment.