From 7e5eafda4bdd279af7447d2288c8bf8ec2dbd656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Sat, 29 Aug 2020 21:30:29 +0200 Subject: [PATCH] Concept to better notify lang support in tools (#1992) * Concept to better notify lang support in tools c.f: #1991 * also disable when compiler doesn't support tool Co-authored-by: Partouf --- static/panes/tool.js | 28 ++++++++++++++++++++++++++++ views/templates.pug | 2 ++ 2 files changed, 30 insertions(+) diff --git a/static/panes/tool.js b/static/panes/tool.js index 65c42ef00..5692604f3 100644 --- a/static/panes/tool.js +++ b/static/panes/tool.js @@ -31,6 +31,7 @@ var AnsiToHtml = require('../ansi-to-html'); var Toggles = require('../toggles'); var ga = require('../analytics'); var monaco = require('monaco-editor'); +var ceoptions = require('../options'); require('../modes/asm6502-mode'); function makeAnsiToHtml(color) { @@ -55,6 +56,7 @@ function Tool(hub, container, state) { this.editorContentRoot = this.domRoot.find('.monaco-placeholder'); this.plainContentRoot = this.domRoot.find('pre.content'); this.optionsToolbar = this.domRoot.find('.options-toolbar'); + this.badLangToolbar = this.domRoot.find('.bad-lang'); this.compilerName = ''; this.normalAnsiToHtml = makeAnsiToHtml(); this.errorAnsiToHtml = makeAnsiToHtml('red'); @@ -109,6 +111,7 @@ Tool.prototype.initCallbacks = function () { this.eventHub.on('compileResult', this.onCompileResult, this); this.eventHub.on('compilerClose', this.onCompilerClose, this); this.eventHub.on('settingsChange', this.onSettingsChange, this); + this.eventHub.on('languageChange', this.onLanguageChange, this); this.toggleArgs.on('click', _.bind(function () { this.togglePanel(this.toggleArgs, this.panelArgs); @@ -125,6 +128,25 @@ Tool.prototype.initCallbacks = function () { } }; +Tool.prototype.onLanguageChange = function (editorId, newLangId) { + if (this.editorId === editorId) { + var tools = ceoptions.tools[newLangId]; + this.toggleUsable(tools && tools[this.toolId]); + } +}; + +Tool.prototype.toggleUsable = function (isUsable) { + if (isUsable) { + this.plainContentRoot.css('opacity', '1'); + this.badLangToolbar.hide(); + this.optionsToolbar.show(); + } else { + this.plainContentRoot.css('opacity', '0.5'); + this.optionsToolbar.hide(); + this.badLangToolbar.show(); + } +}; + Tool.prototype.onSettingsChange = function (newSettings) { this.outputEditor.updateOptions({ contextmenu: newSettings.useCustomContextMenu, @@ -295,6 +317,12 @@ Tool.prototype.onCompileResult = function (id, compiler, result) { if (id !== this.compilerId) return; if (compiler) this.compilerName = compiler.name; + var foundTool = _.find(compiler.tools, function (tool) { + return (tool.tool.id === this.toolId); + }, this); + + this.toggleUsable(foundTool); + var toolResult = null; if (result && result.tools) { toolResult = _.find(result.tools, function (tool) { diff --git a/views/templates.pug b/views/templates.pug index 6441df56a..2b39fbfc4 100644 --- a/views/templates.pug +++ b/views/templates.pug @@ -233,6 +233,8 @@ pre.content #tool-output + .top-bar.bad-lang.bg-warning(role="toolbar" style="display: none") + p The current language or compiler does not support this tool .top-bar.btn-toolbar.options-toolbar.bg-light(role="toolbar") include font-size .btn-group.btn-group-sm.options(role="group" aria-label="Tool options")