Made the context menu en/disable able via the settings and remove the global loader context menu blocker

This commit is contained in:
WolverinDEV 2020-09-17 23:19:30 +02:00
parent 7a3f3761bd
commit 2a25d5ae83
4 changed files with 19 additions and 10 deletions

View file

@ -7,7 +7,8 @@ import {
declare global { declare global {
interface Window { interface Window {
detectedBrowser: BrowserInfo detectedBrowser: BrowserInfo,
removeLoaderContextMenuHook: () => void
} }
} }
@ -43,6 +44,9 @@ if(__build.target === "web") {
} }
/* directly disable all context menus */ /* directly disable all context menus */
if(!location.search.match(/(.*[?&]|^)disableGlobalContextMenu=1($|&.*)/)) { if(!location.search.match(/(.*[?&]|^)disableGlobalContextMenu=0($|&.*)/)) {
document.addEventListener("contextmenu", event => event.preventDefault()); const callback = event => event.preventDefault();
document.addEventListener("contextmenu", callback);
window.removeLoaderContextMenuHook = () => document.removeEventListener("contextmenu", callback);
} }

View file

@ -161,8 +161,9 @@ function main() {
/* context menu prevent */ /* context menu prevent */
$(document).on('contextmenu', (event: ContextMenuEvent) => { $(document).on('contextmenu', (event: ContextMenuEvent) => {
if(event.isDefaultPrevented()) if(event.isDefaultPrevented()) {
return; return;
}
if(event.target instanceof HTMLInputElement) { if(event.target instanceof HTMLInputElement) {
if((!!event.target.value || __build.target === "client") && !event.target.disabled && !event.target.readOnly && event.target.type !== "number") { if((!!event.target.value || __build.target === "client") && !event.target.disabled && !event.target.readOnly && event.target.type !== "number") {
@ -189,9 +190,11 @@ function main() {
return; return;
} }
if(!settings.static_global(Settings.KEY_DISABLE_GLOBAL_CONTEXT_MENU)) if(settings.static_global(Settings.KEY_DISABLE_GLOBAL_CONTEXT_MENU)) {
event.preventDefault(); event.preventDefault();
}
}); });
window.removeLoaderContextMenuHook();
top_menu.initialize(); top_menu.initialize();

View file

@ -1,5 +1,5 @@
import * as log from "./log"; import * as log from "./log";
import {LogCategory} from "./log"; import {LogCategory, logTrace} from "./log";
import * as loader from "tc-loader"; import * as loader from "tc-loader";
import {Stage} from "tc-loader"; import {Stage} from "tc-loader";
import {Registry} from "./events"; import {Registry} from "./events";
@ -196,8 +196,8 @@ export class Settings extends StaticSettings {
static readonly KEY_DISABLE_GLOBAL_CONTEXT_MENU: ValuedSettingsKey<boolean> = { static readonly KEY_DISABLE_GLOBAL_CONTEXT_MENU: ValuedSettingsKey<boolean> = {
key: 'disableGlobalContextMenu', key: 'disableGlobalContextMenu',
description: 'Disable the general context menu prevention', description: 'Disable the general context menu',
defaultValue: false, defaultValue: true,
valueType: "boolean", valueType: "boolean",
}; };
@ -672,6 +672,8 @@ export class Settings extends StaticSettings {
setting: key.key, setting: key.key,
newCastedValue: value newCastedValue: value
}); });
logTrace(LogCategory.GENERAL, tr("Changing global setting %s to %o"), key.key, value);
if(Settings.UPDATE_DIRECT) if(Settings.UPDATE_DIRECT)
this.save(); this.save();
} }

View file

@ -89,9 +89,9 @@ const SettingEditor = () => {
<Translatable>Value</Translatable> <Translatable>Value</Translatable>
<FlatInputField <FlatInputField
className={cssStyle.input} className={cssStyle.input}
value={isApplying ? "" : currentValue ? currentValue : " "} value={isApplying ? "" : typeof currentValue !== "undefined" ? currentValue + "" : ""}
editable={!isApplying} editable={!isApplying}
placeholder={isApplying ? tr("applying...") : tr("setting unset")} placeholder={isApplying ? tr("applying...") : tr("unset")}
onChange={text => { onChange={text => {
setCurrentValue(text); setCurrentValue(text);
}} }}