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 <partouf@gmail.com>
This commit is contained in:
Rubén Rincón Blanco
2020-08-29 21:30:29 +02:00
committed by GitHub
co-authored by Partouf
parent 6d4374392c
commit 7e5eafda4b
2 changed files with 30 additions and 0 deletions
+28
View File
@@ -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) {
+2
View File
@@ -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")